102 buf->
text = (
char *) addr;
161 int new_len = b->
len + 1;
163 if (new_len > b->
size)
175 int new_len = b->
len + len;
177 if (new_len > b->
size)
180 memcpy (b->
text + b->
len, addr, len);
203 return (
'0' <= c && c <=
'9');
211 || (
'a' <= c && c <=
'z')
212 || (
'A' <= c && c <=
'Z'));
249 error (
_(
"Unterminated comment in macro expansion."));
305 && strchr (
"eEpP", *p)
306 && (p[1] ==
'+' || p[1] ==
'-'))
337 if ((p + 1 <= end && *p ==
'\'')
339 && (p[0] ==
'L' || p[0] ==
'u' || p[0] ==
'U')
347 else if (*p ==
'L' || *p ==
'u' || *p ==
'U')
355 error (
_(
"Unmatched single quote."));
359 error (
_(
"A character constant must contain at least one " 397 && (p[0] ==
'L' || p[0] ==
'u' || p[0] ==
'U')
404 else if (*p ==
'L' || *p ==
'u' || *p ==
'U')
412 error (
_(
"Unterminated string in expression."));
419 error (
_(
"Newline characters may not appear in string " 450 static const char *
const punctuators[] = {
451 "[",
"]",
"(",
")",
"{",
"}",
"?",
";",
",",
"~",
453 "->",
"--",
"-=",
"-",
459 "%>",
"%:%:",
"%:",
"%=",
"%",
464 "<<=",
"<<",
"<=",
"<:",
"<%",
"<",
465 ">>=",
">>",
">=",
">",
474 for (i = 0; punctuators[i]; i++)
476 const char *punctuator = punctuators[i];
478 if (p[0] == punctuator[0])
480 int len = strlen (punctuator);
483 && ! memcmp (p, punctuator, len))
507 char *end = p + src->
len;
545 int consumed = p - src->
text + tok->
len;
547 src->
text += consumed;
548 src->
len -= consumed;
558 consumed = p - src->
text + tok->
len;
559 src->
text += consumed;
560 src->
len -= consumed;
591 int original_dest_len = dest->
len;
621 && (new_token.
text + new_token.
len 622 == dest->
text + original_dest_len))
632 dest->
len = original_dest_len;
642 && (new_token.
text + new_token.
len 643 == dest->
text + original_dest_len))
653 _(
"unable to avoid splicing tokens during macro expansion"));
689 else if (*arg ==
'\\' || *arg ==
'"')
709 int len = strlen (str);
743 for (; list; list = list->
next)
792 int nargs,
int *argc_p)
795 int args_len, args_size;
809 || tok.
text[0] !=
'(')
829 if (args_len >= args_size)
836 arg = &args[args_len++];
844 error (
_(
"Malformed argument list for macro `%s'."),
name);
847 if (tok.
len == 1 && tok.
text[0] ==
'(')
851 else if (tok.
len == 1 && tok.
text[0] ==
')')
859 if (nargs != -1 && args_len == nargs - 1)
862 if (args_len >= args_size)
868 arg = &args[args_len++];
884 else if (tok.
len == 1 && tok.
text[0] ==
',' && depth == 0
885 && (nargs == -1 || args_len < nargs))
930 int argc,
const char *
const *
argv)
937 for (i = 0; i < argc; ++i)
938 if (tok->
len == strlen (
argv[i])
942 if (is_varargs && tok->
len == va_arg_name->
len 943 && ! memcmp (tok->
text, va_arg_name->
text, tok->
len))
957 char **lookahead_start,
958 int *lookahead_valid,
961 if (!*lookahead_valid)
967 *start = *lookahead_start;
968 *lookahead_start = replacement_list->
text;
969 *lookahead_valid =
get_token (lookahead, replacement_list);
1002 char *original_rl_start;
1006 int lookahead_valid;
1009 char *lookahead_rl_start;
1017 original_rl_start = replacement_list.
text;
1018 if (!
get_token (&tok, &replacement_list))
1020 lookahead_rl_start = replacement_list.
text;
1021 lookahead_valid =
get_token (&lookahead, &replacement_list);
1027 unsigned vaopt_state = 0;
1035 &lookahead_rl_start,
1039 bool token_is_vaopt = (tok.
len == 10
1040 && strncmp (tok.
text,
"__VA_OPT__", 10) == 0);
1042 if (vaopt_state > 0)
1045 error (
_(
"__VA_OPT__ cannot appear inside __VA_OPT__"));
1046 else if (tok.
len == 1 && tok.
text[0] ==
'(')
1053 else if (vaopt_state == 1)
1054 error (
_(
"__VA_OPT__ must be followed by an open parenthesis"));
1055 else if (tok.
len == 1 && tok.
text[0] ==
')')
1058 if (vaopt_state == 1)
1072 else if (token_is_vaopt)
1075 error (
_(
"__VA_OPT__ is only valid in a variadic macro"));
1083 if (tok.
text > original_rl_start)
1085 appendmem (dest, original_rl_start, tok.
text - original_rl_start);
1091 && tok.
text[0] ==
'#')
1095 if (!lookahead_valid)
1096 error (
_(
"Stringification operator requires an argument."));
1101 error (
_(
"Argument to stringification operator must name " 1102 "a macro parameter."));
1108 lookahead_rl_start = replacement_list.
text;
1109 lookahead_valid =
get_token (&lookahead, &replacement_list);
1112 else if (tok.
len == 2
1113 && tok.
text[0] ==
'#' 1114 && tok.
text[1] ==
'#')
1115 error (
_(
"Stray splicing operator"));
1117 else if (lookahead_valid
1118 && lookahead.
len == 2
1119 && lookahead.
text[0] ==
'#' 1120 && lookahead.
text[1] ==
'#')
1123 int prev_was_comma = 0;
1130 if (tok.
len == 1 && tok.
text[0] ==
',')
1146 if (!
get_token (&tok, &replacement_list))
1147 error (
_(
"Splicing operator at end of macro"));
1161 && tok.
len == va_arg_name->
len 1163 &&
argv[argc - 1].len == 0))
1170 if (tok.
len == 1 && tok.
text[0] ==
',')
1185 original_rl_start = replacement_list.
text;
1186 if (!
get_token (&tok, &replacement_list))
1193 && tok.
text[0] ==
'#' 1194 && tok.
text[1] ==
'#'))
1206 lookahead_valid = 0;
1211 lookahead_rl_start = original_rl_start;
1212 lookahead_valid = 1;
1218 int substituted = 0;
1232 scan (dest, &arg_src, no_loop, lookup_func, lookup_baton);
1242 if (vaopt_state > 0)
1243 error (
_(
"Unterminated __VA_OPT__"));
1272 new_no_loop.
name = id;
1273 new_no_loop.
next = no_loop;
1283 scan (dest, &replacement_list, &new_no_loop, lookup_func, lookup_baton);
1298 if (strcmp (def->
argv[def->
argc - 1],
"...") == 0)
1303 strlen (
"__VA_ARGS__"));
1311 && strcmp (def->
argv[def->
argc - 1] +
len - 3,
"...") == 0)
1338 if (argc != def->
argc)
1340 if (is_varargs && argc >= def->
argc - 1)
1347 else if (! (argc == 1
1350 error (
_(
"Wrong number of arguments to macro `%s' " 1351 "(expected %d, got %d)."),
1352 id, def->
argc, argc);
1364 argc,
argv, no_loop, lookup_func, lookup_baton);
1377 scan (dest, &substituted_src, &new_no_loop, lookup_func, lookup_baton);
1412 char *
id = (
char *)
xmalloc (src_first->
len + 1);
1415 memcpy (
id, src_first->
text, src_first->
len);
1416 id[src_first->
len] = 0;
1425 if (def &&
expand (
id, def, dest, src_rest, no_loop,
1426 lookup_func, lookup_baton))
1458 char *original_src_start = src->
text;
1466 if (tok.
text > original_src_start)
1468 appendmem (dest, original_src_start, tok.
text - original_src_start);
1472 if (!
maybe_expand (dest, &tok, src, no_loop, lookup_func, lookup_baton))
1491 void *lookup_func_baton)
1502 scan (&dest, &src, 0, lookup_func, lookup_func_baton);
1514 void *lookup_func_baton)
1516 error (
_(
"Expand-once not implemented yet."));
1544 if (
maybe_expand (&dest, &tok, &src, 0, lookup_func, lookup_baton))
int macro_is_digit(int c)
static void appendc(struct macro_buffer *b, int c)
char * macro_expand(const char *source, macro_lookup_ftype *lookup_func, void *lookup_func_baton)
int macro_is_identifier_nondigit(int c)
__extension__ enum macro_kind kind
static int get_punctuator(struct macro_buffer *tok, char *p, char *end)
static void resize_buffer(struct macro_buffer *b, int n)
static void scan(struct macro_buffer *dest, struct macro_buffer *src, struct macro_name_list *no_loop, macro_lookup_ftype *lookup_func, void *lookup_baton)
static void appendmem(struct macro_buffer *b, const char *addr, int len)
static int find_parameter(const struct macro_buffer *tok, int is_varargs, const struct macro_buffer *va_arg_name, int argc, const char *const *argv)
void internal_error(const char *file, int line, const char *fmt,...)
static void keep_going(struct execution_control_state *ecs)
int c_parse_escape(const char **ptr, struct obstack *output)
static int get_character_constant(struct macro_buffer *tok, char *p, char *end)
void null_cleanup(void *arg)
static void set_token(struct macro_buffer *tok, char *start, char *end)
struct macro_name_list * next
static int get_string_literal(struct macro_buffer *tok, char *p, char *end)
static struct macro_buffer * gather_arguments(const char *name, struct macro_buffer *src, int nargs, int *argc_p)
#define gdb_assert_not_reached(message)
void free_current_contents(void *ptr)
struct cleanup * make_cleanup(make_cleanup_ftype *function, void *arg)
static int get_comment(struct macro_buffer *tok, char *p, char *end)
char * macro_expand_next(const char **lexptr, macro_lookup_ftype *lookup_func, void *lookup_baton)
static void init_buffer(struct macro_buffer *b, int n)
static int get_pp_number(struct macro_buffer *tok, char *p, char *end)
static void free_buffer(struct macro_buffer *b)
static int get_token(struct macro_buffer *tok, struct macro_buffer *src)
static int expand(const char *id, struct macro_definition *def, struct macro_buffer *dest, struct macro_buffer *src, struct macro_name_list *no_loop, macro_lookup_ftype *lookup_func, void *lookup_baton)
char * macro_stringify(const char *str)
#define XRESIZEVEC(T, P, N)
static int maybe_expand(struct macro_buffer *dest, struct macro_buffer *src_first, struct macro_buffer *src_rest, struct macro_name_list *no_loop, macro_lookup_ftype *lookup_func, void *lookup_baton)
PTR xrealloc(PTR ptr, size_t size)
static int get_identifier(struct macro_buffer *tok, char *p, char *end)
static const char * lexptr
static void get_next_token_for_substitution(struct macro_buffer *replacement_list, struct macro_buffer *token, char **start, struct macro_buffer *lookahead, char **lookahead_start, int *lookahead_valid, bool *keep_going)
void discard_cleanups(struct cleanup *old_chain)
static char * free_buffer_return_text(struct macro_buffer *b)
static void init_shared_buffer(struct macro_buffer *buf, const char *addr, int len)
static void stringify(struct macro_buffer *dest, const char *arg, int len)
static void cleanup_macro_buffer(void *untyped_buf)
static int currently_rescanning(struct macro_name_list *list, const char *name)
static void substitute_args(struct macro_buffer *dest, struct macro_definition *def, int is_varargs, const struct macro_buffer *va_arg_name, int argc, struct macro_buffer *argv, struct macro_name_list *no_loop, macro_lookup_ftype *lookup_func, void *lookup_baton)
static void append_tokens_without_splicing(struct macro_buffer *dest, struct macro_buffer *src)
void error(const char *fmt,...)
char * macro_expand_once(const char *source, macro_lookup_ftype *lookup_func, void *lookup_func_baton)
void do_cleanups(struct cleanup *old_chain)
struct macro_definition *() macro_lookup_ftype(const char *name, void *baton)
int macro_is_whitespace(int c)