diff options
author | Zack Weinberg <zack@gcc.gnu.org> | 2000-04-23 17:03:31 +0000 |
---|---|---|
committer | Zack Weinberg <zack@gcc.gnu.org> | 2000-04-23 17:03:31 +0000 |
commit | d9e0bd53b2da36f66fcd18b168b354612ef7f4df (patch) | |
tree | dce0dfebe9bc09562c88a4bc2be4eecd8f6147d6 /gcc/cpplib.c | |
parent | 3c8c10b8c691cd1f8111f4eaf50ff22beadc0088 (diff) | |
download | gcc-d9e0bd53b2da36f66fcd18b168b354612ef7f4df.zip gcc-d9e0bd53b2da36f66fcd18b168b354612ef7f4df.tar.gz gcc-d9e0bd53b2da36f66fcd18b168b354612ef7f4df.tar.bz2 |
cpphash.h (struct definition): Move file, line, col members...
* cpphash.h (struct definition): Move file, line, col members...
(struct hashnode): ... here. Also add 'disabled' flag.
(enum node_type): Add T_VOID, T_XCONST, T_FMACRO, and
T_IDENTITY. Remove T_DISABLED.
Update prototypes.
* cpphash.c (_cpp_dump_definition): Split out dump_DEFINITION.
(collect_expansion): Split into collect_objlike_expansion and
collect_funlike_expansion.
(_cpp_macroexpand): Split out scan_arguments, stringify, and
funlike_macroexpand.
(_cpp_compare_defs): Rename compare_defs, make static.
(_cpp_make_hashnode): Initialize hp->disabled.
(macro_cleanup): Adjust for new token types. Clear
m->disabled.
(_cpp_create_definition): Move code here to determine what
sort of macro it is, and code to check for redefinitions, from
do_define. Implement a few simple cases without creating a
full DEFINITION.
(_cpp_macroexpand, special_symbol, _cpp_dump_definition):
Handle the simple cases.
(push_macro_expansion): Set buf->has_escapes and hp->disabled
here.
* cppinit.c (builtin_array): Change MCONST to XCONST
everywhere.
* cpplex.c (maybe_macroexpand): Handle IDENTITY macros here;
fix check for disabled and function-like macros.
* cpplib.c (do_define): Move most logic to
_cpp_create_definition.
(do_undef): Handle new special token types.
From-SVN: r33355
Diffstat (limited to 'gcc/cpplib.c')
-rw-r--r-- | gcc/cpplib.c | 90 |
1 files changed, 13 insertions, 77 deletions
diff --git a/gcc/cpplib.c b/gcc/cpplib.c index 7f2554b..5bb5162 100644 --- a/gcc/cpplib.c +++ b/gcc/cpplib.c @@ -316,10 +316,8 @@ do_define (pfile) cpp_reader *pfile; { HASHNODE **slot; - DEFINITION *def = 0; unsigned long hash; int len; - int funlike = 0, empty = 0; U_CHAR *sym; cpp_toklist *list = &pfile->directbuf; @@ -350,90 +348,26 @@ do_define (pfile) goto out; } - - if (list->tokens_used == 2 && list->tokens[1].type == CPP_VSPACE) - empty = 1; /* Empty definition of object-like macro. */ - - /* If the next character, with no intervening whitespace, is '(', - then this is a function-like macro. Otherwise it is an object- - like macro, and C99 requires whitespace after the name - (6.10.3 para 3). */ - else if (!(list->tokens[1].flags & HSPACE_BEFORE)) - { - if (list->tokens[1].type == CPP_OPEN_PAREN) - funlike = 1; - else - cpp_pedwarn (pfile, - "The C standard requires whitespace after #define %.*s", - len, sym); - } - - if (! empty) - { - def = _cpp_create_definition (pfile, list, funlike); - if (def == 0) - goto out; - } - slot = _cpp_lookup_slot (pfile, sym, len, INSERT, &hash); if (*slot) { - int ok; - HASHNODE *hp = *slot; - - /* Redefining a macro is ok if the definitions are the same. */ - if (hp->type == T_MACRO) - ok = ! empty && ! _cpp_compare_defs (pfile, def, hp->value.defn); - else if (hp->type == T_EMPTY) - ok = empty; - /* Redefining a constant is ok with -D. */ - else if (hp->type == T_CONST || hp->type == T_STDC) - ok = ! pfile->done_initializing; - /* Otherwise it's not ok. */ - else - ok = 0; - /* Print the warning or error if it's not ok. */ - if (! ok) + /* Check for poisoned identifiers now. All other checks + are done in cpphash.c. */ + if ((*slot)->type == T_POISON) { - if (hp->type == T_POISON) - cpp_error (pfile, "redefining poisoned `%.*s'", len, sym); - else - cpp_pedwarn (pfile, "`%.*s' redefined", len, sym); - if (hp->type == T_MACRO && pfile->done_initializing) - { - DEFINITION *d = hp->value.defn; - cpp_pedwarn_with_file_and_line (pfile, d->file, d->line, d->col, - "this is the location of the previous definition"); - } - } - if (hp->type != T_POISON) - { - /* Replace the old definition. */ - if (hp->type == T_MACRO) - _cpp_free_definition (hp->value.defn); - if (empty) - { - hp->type = T_EMPTY; - hp->value.defn = 0; - } - else - { - hp->type = T_MACRO; - hp->value.defn = def; - } + cpp_error (pfile, "redefining poisoned `%.*s'", len, sym); + goto out; } } else - { - HASHNODE *hp = _cpp_make_hashnode (sym, len, empty ? T_EMPTY : T_MACRO, - hash); - hp->value.defn = def; - *slot = hp; - } + *slot = _cpp_make_hashnode (sym, len, T_VOID, hash); + + if (_cpp_create_definition (pfile, list, *slot) == 0) + goto out; if (CPP_OPTION (pfile, debug_output) || CPP_OPTION (pfile, dump_macros) == dump_definitions) - _cpp_dump_definition (pfile, sym, len, def); + _cpp_dump_definition (pfile, *slot); else if (CPP_OPTION (pfile, dump_macros) == dump_names) pass_thru_directive (sym, len, pfile, T_DEFINE); @@ -769,7 +703,9 @@ do_undef (pfile) if (CPP_OPTION (pfile, debug_output)) pass_thru_directive (hp->name, len, pfile, T_UNDEF); - if (hp->type != T_MACRO && hp->type != T_EMPTY) + if (hp->type != T_MACRO && hp->type != T_FMACRO + && hp->type != T_MCONST + && hp->type != T_EMPTY && hp->type != T_IDENTITY) cpp_warning (pfile, "undefining `%s'", hp->name); htab_clear_slot (pfile->hashtab, (void **)slot); |