aboutsummaryrefslogtreecommitdiff
path: root/gdb/macroexp.c
diff options
context:
space:
mode:
Diffstat (limited to 'gdb/macroexp.c')
-rw-r--r--gdb/macroexp.c452
1 files changed, 226 insertions, 226 deletions
diff --git a/gdb/macroexp.c b/gdb/macroexp.c
index 5f749ff..68fb196 100644
--- a/gdb/macroexp.c
+++ b/gdb/macroexp.c
@@ -188,10 +188,10 @@ int
macro_is_whitespace (int c)
{
return (c == ' '
- || c == '\t'
- || c == '\n'
- || c == '\v'
- || c == '\f');
+ || c == '\t'
+ || c == '\n'
+ || c == '\v'
+ || c == '\f');
}
@@ -206,8 +206,8 @@ int
macro_is_identifier_nondigit (int c)
{
return (c == '_'
- || ('a' <= c && c <= 'z')
- || ('A' <= c && c <= 'Z'));
+ || ('a' <= c && c <= 'z')
+ || ('A' <= c && c <= 'Z'));
}
@@ -228,33 +228,33 @@ get_comment (struct macro_buffer *tok, char *p, char *end)
if (p + 2 > end)
return 0;
else if (p[0] == '/'
- && p[1] == '*')
+ && p[1] == '*')
{
char *tok_start = p;
p += 2;
for (; p < end; p++)
- if (p + 2 <= end
- && p[0] == '*'
- && p[1] == '/')
- {
- p += 2;
- set_token (tok, tok_start, p);
- return 1;
- }
+ if (p + 2 <= end
+ && p[0] == '*'
+ && p[1] == '/')
+ {
+ p += 2;
+ set_token (tok, tok_start, p);
+ return 1;
+ }
error (_("Unterminated comment in macro expansion."));
}
else if (p[0] == '/'
- && p[1] == '/')
+ && p[1] == '/')
{
char *tok_start = p;
p += 2;
for (; p < end; p++)
- if (*p == '\n')
- break;
+ if (*p == '\n')
+ break;
set_token (tok, tok_start, p);
return 1;
@@ -273,9 +273,9 @@ get_identifier (struct macro_buffer *tok, char *p, char *end)
char *tok_start = p;
while (p < end
- && (macro_is_identifier_nondigit (*p)
- || macro_is_digit (*p)))
- p++;
+ && (macro_is_identifier_nondigit (*p)
+ || macro_is_digit (*p)))
+ p++;
set_token (tok, tok_start, p);
tok->is_identifier = 1;
@@ -291,25 +291,25 @@ get_pp_number (struct macro_buffer *tok, char *p, char *end)
{
if (p < end
&& (macro_is_digit (*p)
- || (*p == '.'
+ || (*p == '.'
&& p + 2 <= end
&& macro_is_digit (p[1]))))
{
char *tok_start = p;
while (p < end)
- {
+ {
if (p + 2 <= end
&& strchr ("eEpP", *p)
&& (p[1] == '+' || p[1] == '-'))
- p += 2;
- else if (macro_is_digit (*p)
+ p += 2;
+ else if (macro_is_digit (*p)
|| macro_is_identifier_nondigit (*p)
|| *p == '.')
- p++;
- else
- break;
- }
+ p++;
+ else
+ break;
+ }
set_token (tok, tok_start, p);
return 1;
@@ -341,38 +341,38 @@ get_character_constant (struct macro_buffer *tok, char *p, char *end)
int char_count = 0;
if (*p == '\'')
- p++;
+ p++;
else if (*p == 'L' || *p == 'u' || *p == 'U')
- p += 2;
+ p += 2;
else
- gdb_assert_not_reached ("unexpected character constant");
+ gdb_assert_not_reached ("unexpected character constant");
for (;;)
- {
- if (p >= end)
- error (_("Unmatched single quote."));
- else if (*p == '\'')
- {
- if (!char_count)
- error (_("A character constant must contain at least one "
- "character."));
- p++;
- break;
- }
- else if (*p == '\\')
- {
+ {
+ if (p >= end)
+ error (_("Unmatched single quote."));
+ else if (*p == '\'')
+ {
+ if (!char_count)
+ error (_("A character constant must contain at least one "
+ "character."));
+ p++;
+ break;
+ }
+ else if (*p == '\\')
+ {
const char *s, *o;
s = o = ++p;
char_count += c_parse_escape (&s, NULL);
p += s - o;
- }
- else
+ }
+ else
{
p++;
char_count++;
}
- }
+ }
set_token (tok, tok_start, p);
return 1;
@@ -392,41 +392,41 @@ get_string_literal (struct macro_buffer *tok, char *p, char *end)
if ((p + 1 <= end
&& *p == '"')
|| (p + 2 <= end
- && (p[0] == 'L' || p[0] == 'u' || p[0] == 'U')
- && p[1] == '"'))
+ && (p[0] == 'L' || p[0] == 'u' || p[0] == 'U')
+ && p[1] == '"'))
{
char *tok_start = p;
if (*p == '"')
- p++;
+ p++;
else if (*p == 'L' || *p == 'u' || *p == 'U')
- p += 2;
+ p += 2;
else
- gdb_assert_not_reached ("unexpected string literal");
+ gdb_assert_not_reached ("unexpected string literal");
for (;;)
- {
- if (p >= end)
- error (_("Unterminated string in expression."));
- else if (*p == '"')
- {
- p++;
- break;
- }
- else if (*p == '\n')
- error (_("Newline characters may not appear in string "
- "constants."));
- else if (*p == '\\')
- {
+ {
+ if (p >= end)
+ error (_("Unterminated string in expression."));
+ else if (*p == '"')
+ {
+ p++;
+ break;
+ }
+ else if (*p == '\n')
+ error (_("Newline characters may not appear in string "
+ "constants."));
+ else if (*p == '\\')
+ {
const char *s, *o;
s = o = ++p;
c_parse_escape (&s, NULL);
p += s - o;
- }
- else
- p++;
- }
+ }
+ else
+ p++;
+ }
set_token (tok, tok_start, p);
return 1;
@@ -470,21 +470,21 @@ get_punctuator (struct macro_buffer *tok, char *p, char *end)
if (p + 1 <= end)
{
for (i = 0; punctuators[i]; i++)
- {
- const char *punctuator = punctuators[i];
-
- if (p[0] == punctuator[0])
- {
- int len = strlen (punctuator);
-
- if (p + len <= end
- && ! memcmp (p, punctuator, len))
- {
- set_token (tok, p, p + len);
- return 1;
- }
- }
- }
+ {
+ const char *punctuator = punctuators[i];
+
+ if (p[0] == punctuator[0])
+ {
+ int len = strlen (punctuator);
+
+ if (p + len <= end
+ && ! memcmp (p, punctuator, len))
+ {
+ set_token (tok, p, p + len);
+ return 1;
+ }
+ }
+ }
}
return 0;
@@ -499,7 +499,7 @@ get_punctuator (struct macro_buffer *tok, char *p, char *end)
succeed, or 0 if we didn't find any more tokens in SRC. */
static int
get_token (struct macro_buffer *tok,
- struct macro_buffer *src)
+ struct macro_buffer *src)
{
char *p = src->text;
char *end = p + src->len;
@@ -509,13 +509,13 @@ get_token (struct macro_buffer *tok,
/* From the ISO C standard, ISO/IEC 9899:1999 (E), section 6.4:
preprocessing-token:
- header-name
- identifier
- pp-number
- character-constant
- string-literal
- punctuator
- each non-white-space character that cannot be one of the above
+ header-name
+ identifier
+ pp-number
+ character-constant
+ string-literal
+ punctuator
+ each non-white-space character that cannot be one of the above
We don't have to deal with header-name tokens, since those can
only occur after a #include, which we will never see. */
@@ -526,37 +526,37 @@ get_token (struct macro_buffer *tok,
else if (get_comment (tok, p, end))
p += tok->len;
else if (get_pp_number (tok, p, end)
- || get_character_constant (tok, p, end)
- || get_string_literal (tok, p, end)
- /* Note: the grammar in the standard seems to be
- ambiguous: L'x' can be either a wide character
- constant, or an identifier followed by a normal
- character constant. By trying `get_identifier' after
- we try get_character_constant and get_string_literal,
- we give the wide character syntax precedence. Now,
- since GDB doesn't handle wide character constants
- anyway, is this the right thing to do? */
- || get_identifier (tok, p, end)
- || get_punctuator (tok, p, end))
+ || get_character_constant (tok, p, end)
+ || get_string_literal (tok, p, end)
+ /* Note: the grammar in the standard seems to be
+ ambiguous: L'x' can be either a wide character
+ constant, or an identifier followed by a normal
+ character constant. By trying `get_identifier' after
+ we try get_character_constant and get_string_literal,
+ we give the wide character syntax precedence. Now,
+ since GDB doesn't handle wide character constants
+ anyway, is this the right thing to do? */
+ || get_identifier (tok, p, end)
+ || get_punctuator (tok, p, end))
{
- /* How many characters did we consume, including whitespace? */
- int consumed = p - src->text + tok->len;
+ /* How many characters did we consume, including whitespace? */
+ int consumed = p - src->text + tok->len;
- src->text += consumed;
- src->len -= consumed;
- return 1;
+ src->text += consumed;
+ src->len -= consumed;
+ return 1;
}
else
{
- /* We have found a "non-whitespace character that cannot be
- one of the above." Make a token out of it. */
- int consumed;
-
- set_token (tok, p, p + 1);
- consumed = p - src->text + tok->len;
- src->text += consumed;
- src->len -= consumed;
- return 1;
+ /* We have found a "non-whitespace character that cannot be
+ one of the above." Make a token out of it. */
+ int consumed;
+
+ set_token (tok, p, p + 1);
+ consumed = p - src->text + tok->len;
+ src->text += consumed;
+ src->len -= consumed;
+ return 1;
}
return 0;
@@ -584,7 +584,7 @@ get_token (struct macro_buffer *tok,
yield "< <", not "<<", etc. */
static void
append_tokens_without_splicing (struct macro_buffer *dest,
- struct macro_buffer *src)
+ struct macro_buffer *src)
{
int original_dest_len = dest->len;
struct macro_buffer dest_tail, new_token;
@@ -616,7 +616,7 @@ append_tokens_without_splicing (struct macro_buffer *dest,
the first time. This is not a bug fix.) */
if (get_token (&new_token, &dest_tail)
&& (new_token.text + new_token.len
- == dest->text + original_dest_len))
+ == dest->text + original_dest_len))
{
/* No splice, so we're done. */
dest->last_token = original_dest_len + src->last_token;
@@ -636,7 +636,7 @@ append_tokens_without_splicing (struct macro_buffer *dest,
/* Try to re-parse DEST's last token, as above. */
if (get_token (&new_token, &dest_tail)
&& (new_token.text + new_token.len
- == dest->text + original_dest_len))
+ == dest->text + original_dest_len))
{
/* No splice, so we're done. */
dest->last_token = original_dest_len + 1 + src->last_token;
@@ -646,7 +646,7 @@ append_tokens_without_splicing (struct macro_buffer *dest,
/* As far as I know, there's no case where inserting a space isn't
enough to prevent a splice. */
internal_error (__FILE__, __LINE__,
- _("unable to avoid splicing tokens during macro expansion"));
+ _("unable to avoid splicing tokens during macro expansion"));
}
/* Stringify an argument, and insert it into DEST. ARG is the text to
@@ -793,8 +793,8 @@ gather_arguments (const char *name, struct macro_buffer *src, int nargs,
struct macro_buffer temp (src->text, src->len);
if (! get_token (&tok, &temp)
- || tok.len != 1
- || tok.text[0] != '(')
+ || tok.len != 1
+ || tok.text[0] != '(')
return false;
}
@@ -814,21 +814,21 @@ gather_arguments (const char *name, struct macro_buffer *src, int nargs,
/* Gather the argument's tokens. */
depth = 0;
for (;;)
- {
- if (! get_token (&tok, src))
- error (_("Malformed argument list for macro `%s'."), name);
-
- /* Is tok an opening paren? */
- if (tok.len == 1 && tok.text[0] == '(')
- depth++;
-
- /* Is tok is a closing paren? */
- else if (tok.len == 1 && tok.text[0] == ')')
- {
- /* If it's a closing paren at the top level, then that's
- the end of the argument list. */
- if (depth == 0)
- {
+ {
+ if (! get_token (&tok, src))
+ error (_("Malformed argument list for macro `%s'."), name);
+
+ /* Is tok an opening paren? */
+ if (tok.len == 1 && tok.text[0] == '(')
+ depth++;
+
+ /* Is tok is a closing paren? */
+ else if (tok.len == 1 && tok.text[0] == ')')
+ {
+ /* If it's a closing paren at the top level, then that's
+ the end of the argument list. */
+ if (depth == 0)
+ {
/* In the varargs case, the last argument may be
missing. Add an empty argument in this case. */
if (nargs != -1 && args.size () == nargs - 1)
@@ -840,34 +840,34 @@ gather_arguments (const char *name, struct macro_buffer *src, int nargs,
*args_ptr = std::move (args);
return true;
- }
+ }
- depth--;
- }
+ depth--;
+ }
- /* If tok is a comma at top level, then that's the end of
- the current argument. However, if we are handling a
- variadic macro and we are computing the last argument, we
- want to include the comma and remaining tokens. */
- else if (tok.len == 1 && tok.text[0] == ',' && depth == 0
+ /* If tok is a comma at top level, then that's the end of
+ the current argument. However, if we are handling a
+ variadic macro and we are computing the last argument, we
+ want to include the comma and remaining tokens. */
+ else if (tok.len == 1 && tok.text[0] == ',' && depth == 0
&& (nargs == -1 || args.size () < nargs))
- break;
-
- /* Extend the current argument to enclose this token. If
- this is the current argument's first token, leave out any
- leading whitespace, just for aesthetics. */
- if (arg->len == 0)
- {
- arg->text = tok.text;
- arg->len = tok.len;
- arg->last_token = 0;
- }
- else
- {
- arg->len = (tok.text + tok.len) - arg->text;
- arg->last_token = tok.text - arg->text;
- }
- }
+ break;
+
+ /* Extend the current argument to enclose this token. If
+ this is the current argument's first token, leave out any
+ leading whitespace, just for aesthetics. */
+ if (arg->len == 0)
+ {
+ arg->text = tok.text;
+ arg->len = tok.len;
+ arg->last_token = 0;
+ }
+ else
+ {
+ arg->len = (tok.text + tok.len) - arg->text;
+ arg->last_token = tok.text - arg->text;
+ }
+ }
}
}
@@ -875,8 +875,8 @@ gather_arguments (const char *name, struct macro_buffer *src, int nargs,
/* The `expand' and `substitute_args' functions both invoke `scan'
recursively, so we need a forward declaration somewhere. */
static void scan (struct macro_buffer *dest,
- struct macro_buffer *src,
- struct macro_name_list *no_loop,
+ struct macro_buffer *src,
+ struct macro_name_list *no_loop,
const macro_scope &scope);
/* A helper function for substitute_args.
@@ -953,10 +953,10 @@ get_next_token_for_substitution (struct macro_buffer *replacement_list,
static void
substitute_args (struct macro_buffer *dest,
- struct macro_definition *def,
+ struct macro_definition *def,
int is_varargs, const struct macro_buffer *va_arg_name,
const std::vector<struct macro_buffer> &argv,
- struct macro_name_list *no_loop,
+ struct macro_name_list *no_loop,
const macro_scope &scope)
{
/* The token we are currently considering. */
@@ -1043,16 +1043,16 @@ substitute_args (struct macro_buffer *dest,
}
/* Just for aesthetics. If we skipped some whitespace, copy
- that to DEST. */
+ that to DEST. */
if (tok.text > original_rl_start)
- {
- dest->appendmem (original_rl_start, tok.text - original_rl_start);
- dest->last_token = dest->len;
- }
+ {
+ dest->appendmem (original_rl_start, tok.text - original_rl_start);
+ dest->last_token = dest->len;
+ }
/* Is this token the stringification operator? */
if (tok.len == 1
- && tok.text[0] == '#')
+ && tok.text[0] == '#')
{
int arg;
@@ -1165,7 +1165,7 @@ substitute_args (struct macro_buffer *dest,
dest->appendmem (",", 1);
}
- dest->last_token = dest->len;
+ dest->last_token = dest->len;
if (finished)
lookahead_valid = 0;
else
@@ -1217,10 +1217,10 @@ substitute_args (struct macro_buffer *dest,
we don't expand it.) If we return zero, leave SRC unchanged. */
static int
expand (const char *id,
- struct macro_definition *def,
- struct macro_buffer *dest,
- struct macro_buffer *src,
- struct macro_name_list *no_loop,
+ struct macro_definition *def,
+ struct macro_buffer *dest,
+ struct macro_buffer *src,
+ struct macro_name_list *no_loop,
const macro_scope &scope)
{
struct macro_name_list new_no_loop;
@@ -1274,50 +1274,50 @@ expand (const char *id,
std::vector<struct macro_buffer> argv;
/* If we couldn't find any argument list, then we don't expand
- this macro. */
+ this macro. */
if (!gather_arguments (id, src, is_varargs ? def->argc : -1,
&argv))
return 0;
/* Check that we're passing an acceptable number of arguments for
- this macro. */
+ this macro. */
if (argv.size () != def->argc)
- {
+ {
if (is_varargs && argv.size () >= def->argc - 1)
{
/* Ok. */
}
- /* Remember that a sequence of tokens like "foo()" is a
- valid invocation of a macro expecting either zero or one
- arguments. */
- else if (! (argv.size () == 1
+ /* Remember that a sequence of tokens like "foo()" is a
+ valid invocation of a macro expecting either zero or one
+ arguments. */
+ else if (! (argv.size () == 1
&& argv[0].len == 0
&& def->argc == 0))
- error (_("Wrong number of arguments to macro `%s' "
- "(expected %d, got %d)."),
- id, def->argc, int (argv.size ()));
- }
+ error (_("Wrong number of arguments to macro `%s' "
+ "(expected %d, got %d)."),
+ id, def->argc, int (argv.size ()));
+ }
/* Note that we don't expand macro invocations in the arguments
- yet --- we let subst_args take care of that. Parameters that
- appear as operands of the stringifying operator "#" or the
- splicing operator "##" don't get macro references expanded,
- so we can't really tell whether it's appropriate to macro-
- expand an argument until we see how it's being used. */
+ yet --- we let subst_args take care of that. Parameters that
+ appear as operands of the stringifying operator "#" or the
+ splicing operator "##" don't get macro references expanded,
+ so we can't really tell whether it's appropriate to macro-
+ expand an argument until we see how it's being used. */
struct macro_buffer substituted (0);
substitute_args (&substituted, def, is_varargs, &va_arg_name,
argv, no_loop, scope);
/* Now `substituted' is the macro's replacement list, with all
- argument values substituted into it properly. Re-scan it for
- macro references, but don't expand invocations of this macro.
-
- We create a new buffer, `substituted_src', which points into
- `substituted', and scan that. We can't scan `substituted'
- itself, since the tokenization process moves the buffer's
- text pointer around, and we still need to be able to find
- `substituted's original text buffer after scanning it so we
- can free it. */
+ argument values substituted into it properly. Re-scan it for
+ macro references, but don't expand invocations of this macro.
+
+ We create a new buffer, `substituted_src', which points into
+ `substituted', and scan that. We can't scan `substituted'
+ itself, since the tokenization process moves the buffer's
+ text pointer around, and we still need to be able to find
+ `substituted's original text buffer after scanning it so we
+ can free it. */
struct macro_buffer substituted_src (substituted.text, substituted.len);
scan (dest, &substituted_src, &new_no_loop, scope);
@@ -1337,9 +1337,9 @@ expand (const char *id,
SRC_FIRST must be a string built by get_token. */
static int
maybe_expand (struct macro_buffer *dest,
- struct macro_buffer *src_first,
- struct macro_buffer *src_rest,
- struct macro_name_list *no_loop,
+ struct macro_buffer *src_first,
+ struct macro_buffer *src_rest,
+ struct macro_name_list *no_loop,
const macro_scope &scope)
{
gdb_assert (src_first->shared);
@@ -1350,19 +1350,19 @@ maybe_expand (struct macro_buffer *dest,
if (src_first->is_identifier)
{
/* Make a null-terminated copy of it, since that's what our
- lookup function expects. */
+ lookup function expects. */
std::string id (src_first->text, src_first->len);
/* If we're currently re-scanning the result of expanding
- this macro, don't expand it again. */
+ this macro, don't expand it again. */
if (! currently_rescanning (no_loop, id.c_str ()))
- {
- /* Does this identifier have a macro definition in scope? */
- macro_definition *def = standard_macro_lookup (id.c_str (), scope);
+ {
+ /* Does this identifier have a macro definition in scope? */
+ macro_definition *def = standard_macro_lookup (id.c_str (), scope);
- if (def && expand (id.c_str (), def, dest, src_rest, no_loop, scope))
+ if (def && expand (id.c_str (), def, dest, src_rest, no_loop, scope))
return 1;
- }
+ }
}
return 0;
@@ -1390,20 +1390,20 @@ scan (struct macro_buffer *dest,
/* Find the next token in SRC. */
if (! get_token (&tok, src))
- break;
+ break;
/* Just for aesthetics. If we skipped some whitespace, copy
- that to DEST. */
+ that to DEST. */
if (tok.text > original_src_start)
- {
- dest->appendmem (original_src_start, tok.text - original_src_start);
- dest->last_token = dest->len;
- }
+ {
+ dest->appendmem (original_src_start, tok.text - original_src_start);
+ dest->last_token = dest->len;
+ }
if (! maybe_expand (dest, &tok, src, no_loop, scope))
- /* We didn't end up expanding tok as a macro reference, so
- simply append it to dest. */
- append_tokens_without_splicing (dest, &tok);
+ /* We didn't end up expanding tok as a macro reference, so
+ simply append it to dest. */
+ append_tokens_without_splicing (dest, &tok);
}
/* Just for aesthetics. If there was any trailing whitespace in
@@ -1458,8 +1458,8 @@ macro_expand_next (const char **lexptr, const macro_scope &scope)
if (maybe_expand (&dest, &tok, &src, 0, scope))
{
/* It was a macro invocation! Package up the expansion as a
- null-terminated string and return it. Set *lexptr to the
- start of the next token in the input. */
+ null-terminated string and return it. Set *lexptr to the
+ start of the next token in the input. */
dest.appendc ('\0');
*lexptr = src.text;
return dest.release ();