diff options
author | zack <zack@138bc75d-0d04-0410-961f-82ee72b054a4> | 2000-07-08 19:00:39 +0000 |
---|---|---|
committer | zack <zack@138bc75d-0d04-0410-961f-82ee72b054a4> | 2000-07-08 19:00:39 +0000 |
commit | 76faa4c0ab5258727ab045e4ea37a00351f0bebd (patch) | |
tree | a059282fddfed885a943028a39f8275bd50d44e0 /gcc/cpphash.c | |
parent | 39bda59f75df70a4818bcb4ed661047602d8004c (diff) | |
download | gcc-76faa4c0ab5258727ab045e4ea37a00351f0bebd.tar.gz |
* cpplib.h (struct cpp_name): Now struct cpp_string.
(CPP_INT, CPP_FLOAT, CPP_NUMBER, CPP_COMMENT,
CPP_HEADER_NAME): Change to type S.
(struct cpp_token): Rename 'name' field to 'str'. Add 'node'
field, a cpp_hashnode *. All references to val.name updated
to use val.str or val.node as appropriate.
(struct cpp_reader): Add spec_nodes field.
(cpp_idcmp): Now cpp_ideq; takes a token * and a char *.
* cpphash.h (struct spec_nodes): New.
(enum spell_type): Reorder. Only SPELL_STRING tokens use
val.str. All references to 'spelling > SPELL_NONE' updated to
match.
(CPP_IN_SYSTEM_HEADER): Check pfile->buffer and
pfile->buffer->inc are not NULL before dereferencing them.
* cpplex.c (parse_name): Take a pointer to the current token,
plus current position and limit as args; return the new
position; don't copy the text of a name into the string
buffer, instead call cpp_lookup and store the node pointer.
If extending a token, copy out the text of the old into a
scratch buffer, append the new, look that up and store the new
node pointer. Inline.
(maybe_paste_with_next): If the result of paste is a NAME,
then look up the pasted text and store its node pointer.
(lex_line): Adjust for new parse_name interface.
Check for L"str", L'str' using spec_nodes->n_L.
(spell_token): SPELL_IDENT tokens have their spelling in
val.node->name. Handle SPELL_STRING tokens that don't have
string delimiters.
(_cpp_expand_name_space,
(can_paste): Check for L ## "str" using spec_nodes->n_L.
(cpp_get_token, special_symbol): No need to call cpp_lookup.
(cpp_idcmp): Now cpp_ideq; take a token * and a const char *;
return 1=equal 0=not, not a tristate.
* cpphash.c (var_args_str): Delete.
(find_param): Compare node fields directly.
(is__va_args__): Use CPP_PEDANTIC. Just compare
token->val.node with spec_nodes->n__VA_ARGS__.
(dump_funlike_macro): Don't use var_args_str.
* cpplib.c (_cpp_check_directive): Just walk through
spec_nodes->dirs comparing pointers.
(get_define_node, do_pragma_poison, detect_if_not_defined,
parse_ifdef): The identifier has already been looked up.
(do_ifdef, do_ifndef): parse_ifdef won't return a poisoned
node.
(do_if): Only call detect_if_not_defined at beginning of file.
(_cpp_parse_assertion): Only copy string pointers for
SPELL_STRING tokens.
(pragma_dispatch): Take a node pointer and examine its name
field.
(_cpp_init_stacks): Also initialize the spec_nodes structure.
* cppinit.c (cpp_reader_init): Call _cpp_init_stacks after
_cpp_init_macros.
(cpp_cleanup): Free pfile->spec_nodes. Call _cpp_cleanup_* in
reverse order from the corresponding _cpp_init_* routines.
* cppexp.c (parse_number, parse_charconst, parse_defined,
lex): Check val.node->type instead of calling cpp_defined.
Use spec_nodes entries where appropriate.
* fix-header.c, scan-decls.c: Update for interface changes.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@34926 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/cpphash.c')
-rw-r--r-- | gcc/cpphash.c | 58 |
1 files changed, 24 insertions, 34 deletions
diff --git a/gcc/cpphash.c b/gcc/cpphash.c index ee0521b5977..c25a56bcabf 100644 --- a/gcc/cpphash.c +++ b/gcc/cpphash.c @@ -61,8 +61,6 @@ static int save_expansion PARAMS((cpp_reader *, cpp_toklist *, static unsigned int find_param PARAMS ((const cpp_token *, const cpp_token *)); -static const unsigned char var_args_str[] = "__VA_ARGS__"; - /* Calculate hash of a string of length LEN. */ unsigned int _cpp_calc_hash (str, len) @@ -131,7 +129,7 @@ cpp_lookup (pfile, name, len) p = obstack_alloc (pfile->hash_ob, sizeof (cpp_hashnode) + len); new = (cpp_hashnode *)p; p += offsetof (cpp_hashnode, name); - + new->type = T_VOID; new->length = len; new->hash = hash; @@ -189,9 +187,7 @@ find_param (first, token) if (first->type == CPP_NAME) { param++; - if (first->val.name.len == token->val.name.len - && !memcmp (first->val.name.text, token->val.name.text, - token->val.name.len)) + if (first->val.node == token->val.node) return param; } @@ -206,15 +202,13 @@ is__va_args__ (pfile, token) cpp_reader *pfile; const cpp_token *token; { - if (!CPP_OPTION (pfile, pedantic) - || token->val.name.len != sizeof (var_args_str) - 1 - || ustrncmp (token->val.name.text, var_args_str, - sizeof (var_args_str) - 1)) + if (!CPP_PEDANTIC (pfile) + || token->val.node != pfile->spec_nodes->n__VA_ARGS__) return 0; cpp_pedwarn_with_line (pfile, token->line, token->col, "\"%s\" is only valid in the replacement list of a function-like macro", - var_args_str); + token->val.node->name); return 1; } @@ -257,7 +251,7 @@ count_params (pfile, first, list) if (is__va_args__ (pfile, token)) goto out; - params_len += token->val.name.len + 1; + params_len += token->val.node->length + 1; prev_ident = 1; list->paramc++; @@ -265,9 +259,8 @@ count_params (pfile, first, list) if (find_param (first, token)) { cpp_error_with_line (pfile, token->line, token->col, - "duplicate macro parameter \"%.*s\"", - (int) token->val.name.len, - token->val.name.text); + "duplicate macro parameter \"%s\"", + token->val.node->name); goto out; } break; @@ -297,19 +290,16 @@ count_params (pfile, first, list) case CPP_ELLIPSIS: /* Convert ISO-style var_args to named varargs by changing the ellipsis into an identifier with name __VA_ARGS__. - This simplifies other handling. We can safely have its - text outside list->namebuf because there is no reason to - extend the size of the list's namebuf (and thus change - the pointer) in do_define. */ + This simplifies other handling. */ if (!prev_ident) { cpp_token *tok = (cpp_token *) token; tok->type = CPP_NAME; - tok->val.name.len = sizeof (var_args_str) - 1; - tok->val.name.text = var_args_str; /* Safe. */ + tok->val.node = pfile->spec_nodes->n__VA_ARGS__; list->paramc++; - + params_len += tok->val.node->length + 1; + if (CPP_PEDANTIC (pfile) && ! CPP_OPTION (pfile, c99)) cpp_pedwarn (pfile, "C89 does not permit anon varargs macros"); @@ -344,9 +334,9 @@ count_params (pfile, first, list) for (temp = first; temp <= token; temp++) if (temp->type == CPP_NAME) { - memcpy (buf, temp->val.name.text, temp->val.name.len); - buf += temp->val.name.len; - *buf++ = '\0'; + /* copy null too */ + memcpy (buf, temp->val.node->name, temp->val.node->length + 1); + buf += temp->val.node->length + 1; } } @@ -493,8 +483,8 @@ save_expansion (pfile, list, first, first_param) return 1; } ntokens++; - if (token_spellings[token->type].type > SPELL_NONE) - len += token->val.name.len; + if (token_spellings[token->type].type == SPELL_STRING) + len += token->val.str.len; } /* Allocate space to hold the tokens. Empty expansions are stored @@ -553,11 +543,11 @@ save_expansion (pfile, list, first, first_param) /* Copy the token. */ *dest = *token; - if (token_spellings[token->type].type > SPELL_NONE) + if (token_spellings[token->type].type == SPELL_STRING) { - memcpy (buf, token->val.name.text, token->val.name.len); - dest->val.name.text = buf; - buf += dest->val.name.len; + memcpy (buf, token->val.str.text, token->val.str.len); + dest->val.str.text = buf; + buf += dest->val.str.len; } dest++; } @@ -664,9 +654,9 @@ dump_funlike_macro (pfile, node) CPP_PUTS(pfile, ", ", 2); else if (list->flags & VAR_ARGS) { - if (!ustrcmp (param, var_args_str)) - pfile->limit -= sizeof (var_args_str) - 1; - CPP_PUTS (pfile, "...", 3); + if (!ustrcmp (param, U"__VA_ARGS__")) + pfile->limit -= sizeof (U"__VA_ARGS__") - 1; + CPP_PUTS_Q (pfile, "...", 3); } param += len + 1; } |