summaryrefslogtreecommitdiff
path: root/gdb/c-exp.y
diff options
context:
space:
mode:
authorJim Blandy <jimb@codesourcery.com>2002-05-17 17:57:48 +0000
committerJim Blandy <jimb@codesourcery.com>2002-05-17 17:57:48 +0000
commit94980b7f6dc84758466bf8c6b0c04cc0acaa8fec (patch)
tree5eca53a8e3072f687dcad2880f08ac2871182728 /gdb/c-exp.y
parent34151e58812ec897e6152410bd7a430088a4875c (diff)
downloadgdb-94980b7f6dc84758466bf8c6b0c04cc0acaa8fec.tar.gz
Expand preprocessor macros in C expressions.
* c-lang.h: #include "macroexp.h", for macro_lookup_ftype. (scan_macro_expansion, scanning_macro_expansion, finished_macro_expansion): New function declarations. (expression_macro_lookup_func, expression_macro_lookup_baton): New variable declarations. * parser-defs.h (expression_context_pc): New declaration. * parse.c (expression_context_pc): New variable. (parse_exp_1): Set expression_context_pc, as well as expression_context_block. * c-exp.y (yylex): If we're not already reading the result of a macro expansion, try to macro-expand the next token. When we're done scanning a macro expansion, switch back to the mainline text. Commas and `if's in a macro's expansion don't terminate the input. * c-lang.c: #include "macroscope.h" and "gdb_assert.h". (macro_original_text, macro_expanded_text, expression_macro_lookup_func, expression_macro_lookup_baton): New variables. (scan_macro_expansion, scanning_macro_expansion, finished_macro_expansion, scan_macro_cleanup, null_macro_lookup, c_preprocess_and_parse): New functions. (c_language_defn, cplus_language_defn, asm_language_defn): Call c_preprocess_and_parse, instead of c_parse. * Makefile.in (c_lang_h): Note that this #includes macroexp.h. (c-lang.o): Note dependency on macroscope.h and gdb_assert.h.
Diffstat (limited to 'gdb/c-exp.y')
-rw-r--r--gdb/c-exp.y37
1 files changed, 32 insertions, 5 deletions
diff --git a/gdb/c-exp.y b/gdb/c-exp.y
index a15a4456bce..f555518ea00 100644
--- a/gdb/c-exp.y
+++ b/gdb/c-exp.y
@@ -1246,6 +1246,17 @@ yylex ()
retry:
+ /* Check if this is a macro invocation that we need to expand. */
+ if (! scanning_macro_expansion ())
+ {
+ char *expanded = macro_expand_next (&lexptr,
+ expression_macro_lookup_func,
+ expression_macro_lookup_baton);
+
+ if (expanded)
+ scan_macro_expansion (expanded);
+ }
+
prev_lexptr = lexptr;
unquoted_expr = 1;
@@ -1271,7 +1282,17 @@ yylex ()
switch (c = *tokstart)
{
case 0:
- return 0;
+ /* If we were just scanning the result of a macro expansion,
+ then we need to resume scanning the original text.
+ Otherwise, we were already scanning the original text, and
+ we're really done. */
+ if (scanning_macro_expansion ())
+ {
+ finished_macro_expansion ();
+ goto retry;
+ }
+ else
+ return 0;
case ' ':
case '\t':
@@ -1324,7 +1345,9 @@ yylex ()
return c;
case ',':
- if (comma_terminates && paren_depth == 0)
+ if (comma_terminates
+ && paren_depth == 0
+ && ! scanning_macro_expansion ())
return 0;
lexptr++;
return c;
@@ -1503,9 +1526,13 @@ yylex ()
c = tokstart[++namelen];
}
- /* The token "if" terminates the expression and is NOT
- removed from the input stream. */
- if (namelen == 2 && tokstart[0] == 'i' && tokstart[1] == 'f')
+ /* The token "if" terminates the expression and is NOT removed from
+ the input stream. It doesn't count if it appears in the
+ expansion of a macro. */
+ if (namelen == 2
+ && tokstart[0] == 'i'
+ && tokstart[1] == 'f'
+ && ! scanning_macro_expansion ())
{
return 0;
}