aboutsummaryrefslogtreecommitdiff
path: root/gcc/cppmacro.c
diff options
context:
space:
mode:
author(no author) <(no author)@138bc75d-0d04-0410-961f-82ee72b054a4>2001-10-02 14:57:59 +0000
committer(no author) <(no author)@138bc75d-0d04-0410-961f-82ee72b054a4>2001-10-02 14:57:59 +0000
commit9f1b3f6642a34d4cfd6442b4c4c719da59157c61 (patch)
treea17683d8a506e541383667f780dd0e8b4a74ea64 /gcc/cppmacro.c
parent6f1e2b25e3063f24afbd430b2ec17a738b39a6d6 (diff)
This commit was manufactured by cvs2svn to create branch
'pchmerge-branch'. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/pchmerge-branch@45961 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/cppmacro.c')
-rw-r--r--gcc/cppmacro.c147
1 files changed, 62 insertions, 85 deletions
diff --git a/gcc/cppmacro.c b/gcc/cppmacro.c
index f9fb0e1ffa0..845d90b99eb 100644
--- a/gcc/cppmacro.c
+++ b/gcc/cppmacro.c
@@ -38,6 +38,7 @@ struct cpp_macro
unsigned short paramc; /* Number of parameters. */
unsigned int fun_like : 1; /* If a function-like macro. */
unsigned int variadic : 1; /* If a variadic macro. */
+ unsigned int disabled : 1; /* If macro is disabled. */
unsigned int syshdr : 1; /* If macro defined in system header. */
};
@@ -54,11 +55,11 @@ struct macro_arg
/* Macro expansion. */
static int enter_macro_context PARAMS ((cpp_reader *, cpp_hashnode *));
-static int builtin_macro PARAMS ((cpp_reader *, cpp_hashnode *));
+static const cpp_token *builtin_macro PARAMS ((cpp_reader *, cpp_hashnode *));
static void push_token_context
- PARAMS ((cpp_reader *, cpp_hashnode *, const cpp_token *, unsigned int));
+ PARAMS ((cpp_reader *, cpp_macro *, const cpp_token *, unsigned int));
static void push_ptoken_context
- PARAMS ((cpp_reader *, cpp_hashnode *, _cpp_buff *,
+ PARAMS ((cpp_reader *, cpp_macro *, _cpp_buff *,
const cpp_token **, unsigned int));
static _cpp_buff *collect_args PARAMS ((cpp_reader *, const cpp_hashnode *));
static cpp_context *next_context PARAMS ((cpp_reader *));
@@ -75,8 +76,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 int funlike_invocation_p PARAMS ((cpp_reader *, cpp_hashnode *));
-static void replace_args PARAMS ((cpp_reader *, cpp_hashnode *, macro_arg *));
+static int funlike_invocation_p PARAMS ((cpp_reader *, const cpp_hashnode *));
+static void replace_args PARAMS ((cpp_reader *, cpp_macro *, macro_arg *));
/* #define directive parsing and handling. */
@@ -131,22 +132,17 @@ static const char * const monthnames[] =
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
};
-/* Handle builtin macros like __FILE__, and push the resulting token
- on the context stack. Also handles _Pragma, for which no new token
- is created. Returns 1 on success, 0 to return the token to the
- caller. */
-static int
+/* Handle builtin macros like __FILE__. */
+static const cpp_token *
builtin_macro (pfile, node)
cpp_reader *pfile;
cpp_hashnode *node;
{
- const cpp_token *result;
-
switch (node->value.builtin)
{
default:
cpp_ice (pfile, "invalid builtin macro \"%s\"", NODE_NAME (node));
- return 0;
+ return new_number_token (pfile, 1);
case BT_FILE:
case BT_BASE_FILE:
@@ -165,33 +161,28 @@ builtin_macro (pfile, node)
buf = _cpp_unaligned_alloc (pfile, len * 4 + 1);
len = quote_string (buf, (const unsigned char *) name, len) - buf;
- result = new_string_token (pfile, buf, len);
+ return new_string_token (pfile, buf, len);
}
- break;
-
+
case BT_INCLUDE_LEVEL:
/* The line map depth counts the primary source as level 1, but
historically __INCLUDE_DEPTH__ has called the primary source
level 0. */
- result = new_number_token (pfile, pfile->line_maps.depth - 1);
- break;
+ return new_number_token (pfile, pfile->line_maps.depth - 1);
case BT_SPECLINE:
/* If __LINE__ is embedded in a macro, it must expand to the
line of the macro's invocation, not its definition.
Otherwise things like assert() will not work properly. */
- result = new_number_token (pfile,
- SOURCE_LINE (pfile->map,
- pfile->cur_token[-1].line));
- break;
+ return new_number_token (pfile, SOURCE_LINE (pfile->map,
+ pfile->cur_token[-1].line));
case BT_STDC:
{
int stdc = (!CPP_IN_SYSTEM_HEADER (pfile)
|| pfile->spec_nodes.n__STRICT_ANSI__->type != NT_VOID);
- result = new_number_token (pfile, stdc);
+ return new_number_token (pfile, stdc);
}
- break;
case BT_DATE:
case BT_TIME:
@@ -221,24 +212,8 @@ builtin_macro (pfile, node)
tb->tm_hour, tb->tm_min, tb->tm_sec);
}
- if (node->value.builtin == BT_DATE)
- result = &pfile->date;
- else
- result = &pfile->time;
- break;
-
- case BT_PRAGMA:
- /* Don't interpret _Pragma within directives. The standard is
- not clear on this, but to me this makes most sense. */
- if (pfile->state.in_directive)
- return 0;
-
- _cpp_do__Pragma (pfile);
- return 1;
+ return node->value.builtin == BT_DATE ? &pfile->date: &pfile->time;
}
-
- push_token_context (pfile, NULL, result, 1);
- return 1;
}
/* Adds backslashes before all backslashes and double quotes appearing
@@ -619,7 +594,7 @@ collect_args (pfile, node)
static int
funlike_invocation_p (pfile, node)
cpp_reader *pfile;
- cpp_hashnode *node;
+ const cpp_hashnode *node;
{
const cpp_token *maybe_paren;
_cpp_buff *buff = NULL;
@@ -651,7 +626,7 @@ funlike_invocation_p (pfile, node)
if (buff)
{
if (node->value.macro->paramc > 0)
- replace_args (pfile, node, (macro_arg *) buff->base);
+ replace_args (pfile, node->value.macro, (macro_arg *) buff->base);
_cpp_release_buff (pfile, buff);
}
@@ -667,11 +642,9 @@ enter_macro_context (pfile, node)
cpp_reader *pfile;
cpp_hashnode *node;
{
- /* Macros invalidate controlling macros. */
- pfile->mi_valid = false;
-
- /* Handle macros and the _Pragma operator. */
- if (! (node->flags & NODE_BUILTIN))
+ if (node->flags & NODE_BUILTIN)
+ push_token_context (pfile, NULL, builtin_macro (pfile, node), 1);
+ else
{
cpp_macro *macro = node->value.macro;
@@ -679,24 +652,22 @@ enter_macro_context (pfile, node)
return 0;
/* Disable the macro within its expansion. */
- node->flags |= NODE_DISABLED;
+ macro->disabled = 1;
if (macro->paramc == 0)
- push_token_context (pfile, node, macro->expansion, macro->count);
-
- return 1;
+ push_token_context (pfile, macro, macro->expansion, macro->count);
}
-
- return builtin_macro (pfile, node);
+
+ return 1;
}
/* Take the expansion of a function-like MACRO, replacing parameters
with the actual arguments. Each argument is macro-expanded before
replacement, unless operated upon by the # or ## operators. */
static void
-replace_args (pfile, node, args)
+replace_args (pfile, macro, args)
cpp_reader *pfile;
- cpp_hashnode *node;
+ cpp_macro *macro;
macro_arg *args;
{
unsigned int i, total;
@@ -704,13 +675,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;
@@ -828,7 +797,7 @@ replace_args (pfile, node, args)
if (args[i].expanded)
free (args[i].expanded);
- push_ptoken_context (pfile, node, buff, first, dest - first);
+ push_ptoken_context (pfile, macro, buff, first, dest - first);
}
/* Return a special padding token, with padding inherited from SOURCE. */
@@ -868,7 +837,7 @@ next_context (pfile)
static void
push_ptoken_context (pfile, macro, buff, first, count)
cpp_reader *pfile;
- cpp_hashnode *macro;
+ cpp_macro *macro;
_cpp_buff *buff;
const cpp_token **first;
unsigned int count;
@@ -886,7 +855,7 @@ push_ptoken_context (pfile, macro, buff, first, count)
static void
push_token_context (pfile, macro, first, count)
cpp_reader *pfile;
- cpp_hashnode *macro;
+ cpp_macro *macro;
const cpp_token *first;
unsigned int count;
{
@@ -945,7 +914,7 @@ _cpp_pop_context (pfile)
/* Re-enable a macro when leaving its expansion. */
if (context->macro)
- context->macro->flags &= ~NODE_DISABLED;
+ context->macro->disabled = 0;
if (context->buff)
_cpp_release_buff (pfile, context->buff);
@@ -1006,30 +975,39 @@ cpp_get_token (pfile)
node = result->val.node;
- if (node->type != NT_MACRO || (result->flags & NO_EXPAND))
- break;
-
- if (!(node->flags & NODE_DISABLED))
+ /* Handle macros and the _Pragma operator. */
+ if (node->type == NT_MACRO && !(result->flags & NO_EXPAND))
{
- if (!pfile->state.prevent_expansion
- && enter_macro_context (pfile, node))
+ /* Macros invalidate controlling macros. */
+ pfile->mi_valid = false;
+
+ if (!(node->flags & NODE_BUILTIN) && node->value.macro->disabled)
+ {
+ /* Flag this token as always unexpandable. */
+ cpp_token *t = _cpp_temp_token (pfile);
+ t->type = result->type;
+ t->flags = result->flags | NO_EXPAND;
+ t->val.str = result->val.str;
+ result = t;
+ }
+ else if (!pfile->state.prevent_expansion
+ && enter_macro_context (pfile, node))
{
if (pfile->state.in_directive)
continue;
return padding_token (pfile, result);
}
}
- else
- {
- /* Flag this token as always unexpandable. */
- cpp_token *t = _cpp_temp_token (pfile);
- t->type = result->type;
- t->flags = result->flags | NO_EXPAND;
- t->val.str = result->val.str;
- result = t;
- }
- break;
+ /* Don't interpret _Pragma within directives. The standard is
+ not clear on this, but to me this makes most sense. */
+ if (node != pfile->spec_nodes.n__Pragma
+ || pfile->state.in_directive)
+ break;
+
+ /* Handle it, and loop back for another token. MI is cleared
+ since this token came from either the lexer or a macro. */
+ _cpp_do__Pragma (pfile);
}
return result;
@@ -1042,9 +1020,9 @@ int
cpp_sys_macro_p (pfile)
cpp_reader *pfile;
{
- cpp_hashnode *node = pfile->context->macro;
+ cpp_macro *macro = pfile->context->macro;
- return node && node->value.macro && node->value.macro->syshdr;
+ return macro && macro->syshdr;
}
/* Read each token in, until EOF. Directives are transparently
@@ -1140,7 +1118,7 @@ _cpp_free_definition (h)
/* Macros and assertions no longer have anything to free. */
h->type = NT_VOID;
/* Clear builtin flag in case of redefinition. */
- h->flags &= ~(NODE_BUILTIN | NODE_DISABLED);
+ h->flags &= ~NODE_BUILTIN;
}
/* Save parameter NODE to the parameter list of macro MACRO. Returns
@@ -1382,10 +1360,9 @@ _cpp_create_definition (pfile, node)
BUFF_FRONT (pfile->a_buff) = (U_CHAR *) &macro->expansion[macro->count];
/* Implement the macro-defined-to-itself optimisation. */
- if (macro->count == 1 && !macro->fun_like
- && macro->expansion[0].type == CPP_NAME
- && macro->expansion[0].val.node == node)
- node->flags |= NODE_DISABLED;
+ macro->disabled = (macro->count == 1 && !macro->fun_like
+ && macro->expansion[0].type == CPP_NAME
+ && macro->expansion[0].val.node == node);
/* To suppress some diagnostics. */
macro->syshdr = pfile->map->sysp != 0;