157 int new_len = b->
len + 1;
159 if (new_len > b->
size)
171 int new_len = b->
len +
len;
173 if (new_len > b->
size)
176 memcpy (b->
text + b->
len, addr, len);
199 return (
'0' <= c && c <=
'9');
207 || (
'a' <= c && c <=
'z')
208 || (
'A' <= c && c <=
'Z'));
245 error (
_(
"Unterminated comment in macro expansion."));
301 && strchr (
"eEpP", *p)
302 && (p[1] ==
'+' || p[1] ==
'-'))
333 if ((p + 1 <= end && *p ==
'\'')
335 && (p[0] ==
'L' || p[0] ==
'u' || p[0] ==
'U')
343 else if (*p ==
'L' || *p ==
'u' || *p ==
'U')
351 error (
_(
"Unmatched single quote."));
355 error (
_(
"A character constant must contain at least one "
393 && (p[0] ==
'L' || p[0] ==
'u' || p[0] ==
'U')
400 else if (*p ==
'L' || *p ==
'u' || *p ==
'U')
408 error (
_(
"Unterminated string in expression."));
415 error (
_(
"Newline characters may not appear in string "
446 static const char *
const punctuators[] = {
447 "[",
"]",
"(",
")",
"{",
"}",
"?",
";",
",",
"~",
449 "->",
"--",
"-=",
"-",
455 "%>",
"%:%:",
"%:",
"%=",
"%",
460 "<<=",
"<<",
"<=",
"<:",
"<%",
"<",
461 ">>=",
">>",
">=",
">",
470 for (i = 0; punctuators[i]; i++)
472 const char *punctuator = punctuators[i];
474 if (p[0] == punctuator[0])
476 int len = strlen (punctuator);
479 && ! memcmp (p, punctuator, len))
503 char *end = p + src->
len;
541 int consumed = p - src->
text + tok->
len;
543 src->
text += consumed;
544 src->
len -= consumed;
554 consumed = p - src->
text + tok->
len;
555 src->
text += consumed;
556 src->
len -= consumed;
587 int original_dest_len = dest->
len;
617 && (new_token.
text + new_token.
len
618 == dest->
text + original_dest_len))
628 dest->
len = original_dest_len;
638 && (new_token.
text + new_token.
len
639 == dest->
text + original_dest_len))
649 _(
"unable to avoid splicing tokens during macro expansion"));
685 else if (*arg ==
'\\' || *arg ==
'"')
705 int len = strlen (str);
739 for (; list; list = list->
next)
740 if (strcmp (name, list->
name) == 0)
788 int nargs,
int *argc_p)
791 int args_len, args_size;
805 || tok.
text[0] !=
'(')
825 if (args_len >= args_size)
828 args =
xrealloc (args,
sizeof (*args) * args_size);
832 arg = &args[args_len++];
840 error (
_(
"Malformed argument list for macro `%s'."), name);
843 if (tok.
len == 1 && tok.
text[0] ==
'(')
847 else if (tok.
len == 1 && tok.
text[0] ==
')')
855 if (nargs != -1 && args_len == nargs - 1)
858 if (args_len >= args_size)
861 args =
xrealloc (args,
sizeof (*args) * args_size);
863 arg = &args[args_len++];
879 else if (tok.
len == 1 && tok.
text[0] ==
',' && depth == 0
880 && (nargs == -1 || args_len < nargs))
925 int argc,
const char *
const *argv)
932 for (i = 0; i < argc; ++i)
933 if (tok->
len == strlen (argv[i])
934 && !memcmp (tok->
text, argv[i], tok->
len))
937 if (is_varargs && tok->
len == va_arg_name->
len
938 && ! memcmp (tok->
text, va_arg_name->
text, tok->
len))
973 char *original_rl_start;
980 char *lookahead_rl_start;
988 original_rl_start = replacement_list.
text;
989 if (!
get_token (&tok, &replacement_list))
991 lookahead_rl_start = replacement_list.
text;
992 lookahead_valid =
get_token (&lookahead, &replacement_list);
998 if (tok.
text > original_rl_start)
1000 appendmem (dest, original_rl_start, tok.
text - original_rl_start);
1006 && tok.
text[0] ==
'#')
1010 if (!lookahead_valid)
1011 error (
_(
"Stringification operator requires an argument."));
1016 error (
_(
"Argument to stringification operator must name "
1017 "a macro parameter."));
1023 lookahead_rl_start = replacement_list.
text;
1024 lookahead_valid =
get_token (&lookahead, &replacement_list);
1027 else if (tok.
len == 2
1028 && tok.
text[0] ==
'#'
1029 && tok.
text[1] ==
'#')
1030 error (
_(
"Stray splicing operator"));
1032 else if (lookahead_valid
1033 && lookahead.
len == 2
1034 && lookahead.
text[0] ==
'#'
1035 && lookahead.
text[1] ==
'#')
1038 int prev_was_comma = 0;
1045 if (tok.
len == 1 && tok.
text[0] ==
',')
1061 if (!
get_token (&tok, &replacement_list))
1062 error (
_(
"Splicing operator at end of macro"));
1076 && tok.
len == va_arg_name->
len
1078 && argv[argc - 1].
len == 0))
1085 if (tok.
len == 1 && tok.
text[0] ==
',')
1100 original_rl_start = replacement_list.
text;
1101 if (!
get_token (&tok, &replacement_list))
1108 && tok.
text[0] ==
'#'
1109 && tok.
text[1] ==
'#'))
1121 lookahead_valid = 0;
1126 lookahead_rl_start = original_rl_start;
1127 lookahead_valid = 1;
1133 int substituted = 0;
1147 scan (dest, &arg_src, no_loop, lookup_func, lookup_baton);
1156 if (! lookahead_valid)
1160 original_rl_start = lookahead_rl_start;
1162 lookahead_rl_start = replacement_list.
text;
1163 lookahead_valid =
get_token (&lookahead, &replacement_list);
1193 new_no_loop.
name = id;
1194 new_no_loop.
next = no_loop;
1204 scan (dest, &replacement_list, &new_no_loop, lookup_func, lookup_baton);
1219 if (strcmp (def->
argv[def->
argc - 1],
"...") == 0)
1224 strlen (
"__VA_ARGS__"));
1232 && strcmp (def->
argv[def->
argc - 1] + len - 3,
"...") == 0)
1259 if (argc != def->
argc)
1261 if (is_varargs && argc >= def->
argc - 1)
1268 else if (! (argc == 1
1271 error (
_(
"Wrong number of arguments to macro `%s' "
1272 "(expected %d, got %d)."),
1273 id, def->
argc, argc);
1285 argc, argv, no_loop, lookup_func, lookup_baton);
1298 scan (dest, &substituted_src, &new_no_loop, lookup_func, lookup_baton);
1336 memcpy (
id, src_first->
text, src_first->
len);
1337 id[src_first->
len] = 0;
1346 if (def &&
expand (
id, def, dest, src_rest, no_loop,
1347 lookup_func, lookup_baton))
1379 char *original_src_start = src->
text;
1387 if (tok.
text > original_src_start)
1389 appendmem (dest, original_src_start, tok.
text - original_src_start);
1393 if (!
maybe_expand (dest, &tok, src, no_loop, lookup_func, lookup_baton))
1412 void *lookup_func_baton)
1423 scan (&dest, &src, 0, lookup_func, lookup_func_baton);
1435 void *lookup_func_baton)
1437 error (
_(
"Expand-once not implemented yet."));
1465 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 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 init_shared_buffer(struct macro_buffer *buf, char *addr, int len)
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)
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)
struct macro_definition *( macro_lookup_ftype)(const char *name, void *baton)
PTR xrealloc(PTR ptr, size_t size)
static int get_identifier(struct macro_buffer *tok, char *p, char *end)
static const char * lexptr
void discard_cleanups(struct cleanup *old_chain)
static void appendmem(struct macro_buffer *b, char *addr, int len)
static char * free_buffer_return_text(struct macro_buffer *b)
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)
const ULONGEST const LONGEST len
int macro_is_whitespace(int c)