diff options
author | neil <neil@138bc75d-0d04-0410-961f-82ee72b054a4> | 2002-02-27 07:24:53 +0000 |
---|---|---|
committer | neil <neil@138bc75d-0d04-0410-961f-82ee72b054a4> | 2002-02-27 07:24:53 +0000 |
commit | d6af03689afcb6d54e5ce66a399f68753a2aea3e (patch) | |
tree | 7ffd19f1f5d3104b1545c9af4c64c746cda65cbc /gcc/cppmacro.c | |
parent | fc54b737e45b3feef050092c62be54cf1b81c5a7 (diff) | |
download | gcc-d6af03689afcb6d54e5ce66a399f68753a2aea3e.tar.gz |
* cpplex.c (_cpp_lex_token): Handle directives in macro
arguments.
* cpplib.c (_cpp_handle_directive): Save and restore state
if parsing macro args when entering a directive.
* cppmacro.c (collect_args): No need to handle directives
in macro arguments.
(enter_macro_context, replace_args): Use the original macro
definition in case it was redefined whilst collecting arguments.
doc:
* cpp.texi: Update.
testsuite:
* gcc.dg/cpp/undef1.c: Remove.
* gcc.dg/cpp/directiv.c: Update.
* gcc.dg/cpp/mac-dir-1.c, mac-dir-2.c: New tests.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@50091 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/cppmacro.c')
-rw-r--r-- | gcc/cppmacro.c | 37 |
1 files changed, 9 insertions, 28 deletions
diff --git a/gcc/cppmacro.c b/gcc/cppmacro.c index 538c689b1e5..d44ac498658 100644 --- a/gcc/cppmacro.c +++ b/gcc/cppmacro.c @@ -74,7 +74,8 @@ static const cpp_token *stringify_arg PARAMS ((cpp_reader *, macro_arg *)); static void paste_all_tokens PARAMS ((cpp_reader *, const cpp_token *)); static bool paste_tokens PARAMS ((cpp_reader *, const cpp_token **, const cpp_token *)); -static void replace_args PARAMS ((cpp_reader *, cpp_hashnode *, macro_arg *)); +static void replace_args PARAMS ((cpp_reader *, cpp_hashnode *, cpp_macro *, + macro_arg *)); static _cpp_buff *funlike_invocation_p PARAMS ((cpp_reader *, cpp_hashnode *)); /* #define directive parsing and handling. */ @@ -546,34 +547,15 @@ collect_args (pfile, node) arg++; } } - while (token->type != CPP_CLOSE_PAREN - && token->type != CPP_EOF - && token->type != CPP_HASH); + while (token->type != CPP_CLOSE_PAREN && token->type != CPP_EOF); - if (token->type == CPP_EOF || token->type == CPP_HASH) + if (token->type == CPP_EOF) { - bool step_back = false; - - /* 6.10.3 paragraph 11: If there are sequences of preprocessing - tokens within the list of arguments that would otherwise act - as preprocessing directives, the behavior is undefined. - - This implementation will report a hard error, terminate the - macro invocation, and proceed to process the directive. */ - if (token->type == CPP_HASH) - { - cpp_error (pfile, - "directives may not be used inside a macro argument"); - step_back = true; - } - else - step_back = (pfile->context->prev || pfile->state.in_directive); - /* We still need the CPP_EOF to end directives, and to end pre-expansion of a macro argument. Step back is not unconditional, since we don't want to return a CPP_EOF to our callers at the end of an -include-d file. */ - if (step_back) + if (pfile->context->prev || pfile->state.in_directive) _cpp_backup_tokens (pfile, 1); cpp_error (pfile, "unterminated argument list invoking macro \"%s\"", NODE_NAME (node)); @@ -697,8 +679,8 @@ enter_macro_context (pfile, node) return 0; } - if (node->value.macro->paramc > 0) - replace_args (pfile, node, (macro_arg *) buff->base); + if (macro->paramc > 0) + replace_args (pfile, node, macro, (macro_arg *) buff->base); _cpp_release_buff (pfile, buff); } @@ -720,9 +702,10 @@ enter_macro_context (pfile, node) Expand each argument before replacing, unless it is operated upon by the # or ## operators. */ static void -replace_args (pfile, node, args) +replace_args (pfile, node, macro, args) cpp_reader *pfile; cpp_hashnode *node; + cpp_macro *macro; macro_arg *args; { unsigned int i, total; @@ -730,13 +713,11 @@ replace_args (pfile, node, args) const cpp_token **dest, **first; macro_arg *arg; _cpp_buff *buff; - cpp_macro *macro; /* First, fully macro-expand arguments, calculating the number of tokens in the final expansion as we go. The ordering of the if statements below is subtle; we must handle stringification before pasting. */ - macro = node->value.macro; total = macro->count; limit = macro->expansion + macro->count; |