From bfb9dc7faa9330d05c109e8a40710b752dddea14 Mon Sep 17 00:00:00 2001 From: Zack Weinberg Date: Sat, 8 Jul 2000 19:00:39 +0000 Subject: cpplib.h (struct cpp_name): Now struct cpp_string. * 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. From-SVN: r34926 --- gcc/cppexp.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'gcc/cppexp.c') diff --git a/gcc/cppexp.c b/gcc/cppexp.c index 8a86c8b..7e2c85a 100644 --- a/gcc/cppexp.c +++ b/gcc/cppexp.c @@ -137,10 +137,10 @@ parse_number (pfile, tok) const cpp_token *tok; { struct op op; - const U_CHAR *start = tok->val.name.text; - const U_CHAR *end = start + tok->val.name.len; + const U_CHAR *start = tok->val.str.text; + const U_CHAR *end = start + tok->val.str.len; const U_CHAR *p = start; - int c, i, nsuff; + int c = 0, i, nsuff; unsigned HOST_WIDEST_INT n = 0, nd, MAX_over_base; int base = 10; int overflow = 0; @@ -261,8 +261,8 @@ parse_charconst (pfile, tok) int num_bits; unsigned int width = MAX_CHAR_TYPE_SIZE, mask = MAX_CHAR_TYPE_MASK; int max_chars; - const U_CHAR *ptr = tok->val.name.text; - const U_CHAR *end = ptr + tok->val.name.len; + const U_CHAR *ptr = tok->val.str.text; + const U_CHAR *end = ptr + tok->val.str.len; int c = -1; @@ -304,8 +304,7 @@ parse_charconst (pfile, tok) /* If char type is signed, sign-extend the constant. */ num_bits = num_chars * width; - if (cpp_defined (pfile, U"__CHAR_UNSIGNED__", - sizeof ("__CHAR_UNSIGNED__")-1) + if (pfile->spec_nodes->n__CHAR_UNSIGNED__->type != T_VOID || ((result >> (num_bits - 1)) & 1) == 0) op.value = result & ((unsigned HOST_WIDEST_INT) ~0 >> (HOST_BITS_PER_WIDEST_INT - num_bits)); @@ -345,9 +344,12 @@ parse_defined (pfile) if (paren && _cpp_get_raw_token (pfile)->type != CPP_CLOSE_PAREN) SYNTAX_ERROR ("missing close paren after \"defined\""); + if (tok->val.node->type == T_POISON) + SYNTAX_ERROR2 ("attempt to use poisoned \"%s\"", tok->val.node->name); + + op.value = tok->val.node->type != T_VOID; op.unsignedp = 0; op.op = CPP_INT; - op.value = cpp_defined (pfile, tok->val.name.text, tok->val.name.len); return op; syntax_error: @@ -419,7 +421,7 @@ lex (pfile, skip_evaluation) SYNTAX_ERROR2 ("invalid character '\\%03o' in #if", tok->val.aux); case CPP_NAME: - if (!cpp_idcmp (tok->val.name.text, tok->val.name.len, "defined")) + if (tok->val.node == pfile->spec_nodes->n_defined) return parse_defined (pfile); op.op = CPP_INT; @@ -427,8 +429,7 @@ lex (pfile, skip_evaluation) op.value = 0; if (CPP_OPTION (pfile, warn_undef) && !skip_evaluation) - cpp_warning (pfile, "\"%.*s\" is not defined", - (int) tok->val.name.len, tok->val.name.text); + cpp_warning (pfile, "\"%s\" is not defined", tok->val.node->name); return op; case CPP_HASH: -- cgit v1.1