aboutsummaryrefslogtreecommitdiff
path: root/gcc/cpplib.c
diff options
context:
space:
mode:
authorZack Weinberg <zack@wolery.cumb.org>2000-07-08 19:00:39 +0000
committerZack Weinberg <zack@gcc.gnu.org>2000-07-08 19:00:39 +0000
commitbfb9dc7faa9330d05c109e8a40710b752dddea14 (patch)
treea059282fddfed885a943028a39f8275bd50d44e0 /gcc/cpplib.c
parentffc14f31599c19980371b165a7f6ad2e0a93015c (diff)
downloadgcc-bfb9dc7faa9330d05c109e8a40710b752dddea14.zip
gcc-bfb9dc7faa9330d05c109e8a40710b752dddea14.tar.gz
gcc-bfb9dc7faa9330d05c109e8a40710b752dddea14.tar.bz2
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
Diffstat (limited to 'gcc/cpplib.c')
-rw-r--r--gcc/cpplib.c126
1 files changed, 64 insertions, 62 deletions
diff --git a/gcc/cpplib.c b/gcc/cpplib.c
index 9e93e4d..f6108f4 100644
--- a/gcc/cpplib.c
+++ b/gcc/cpplib.c
@@ -148,8 +148,6 @@ _cpp_check_directive (pfile, token, bol)
const cpp_token *token;
int bol;
{
- const U_CHAR *name = token->val.name.text;
- size_t len = token->val.name.len;
unsigned int i;
/* If we are rescanning preprocessed input, don't obey any directives
@@ -158,7 +156,7 @@ _cpp_check_directive (pfile, token, bol)
return 0;
for (i = 0; i < N_DIRECTIVES; i++)
- if (dtable[i].length == len && !memcmp (dtable[i].name, name, len))
+ if (pfile->spec_nodes->dirs[i] == token->val.node)
{
/* If we are skipping a failed conditional group, all non-conditional
directives are ignored. */
@@ -250,8 +248,6 @@ get_define_node (pfile)
{
cpp_hashnode *node;
const cpp_token *token;
- const U_CHAR *sym;
- unsigned int len;
/* Skip any -C comments. */
while ((token = cpp_get_token (pfile))->type == CPP_COMMENT)
@@ -259,27 +255,26 @@ get_define_node (pfile)
if (token->type != CPP_NAME)
{
- cpp_error_with_line (pfile, pfile->token_list.line, token->col,
+ cpp_error_with_line (pfile, token->line, token->col,
"macro names must be identifiers");
return 0;
}
/* That identifier is not allowed to be "defined". See predefined
macro names (6.10.8.4). */
- len = token->val.name.len;
- sym = token->val.name.text;
- if (str_match (sym, len, "defined"))
+ node = token->val.node;
+
+ if (node == pfile->spec_nodes->n_defined)
{
cpp_error_with_line (pfile, pfile->token_list.line, token->col,
"\"defined\" is not a legal macro name");
return 0;
}
- node = cpp_lookup (pfile, sym, len);
/* Check for poisoned identifiers now. */
if (node->type == T_POISON)
{
- cpp_error (pfile, "attempt to use poisoned \"%.*s\"", (int) len, sym);
+ cpp_error (pfile, "attempt to use poisoned \"%s\"", node->name);
return 0;
}
@@ -360,7 +355,7 @@ parse_include (pfile, dir, trail, strp, lenp, abp)
return 1;
}
}
- if (name->val.name.len == 0)
+ if (name->val.str.len == 0)
{
cpp_error (pfile, "empty file name in #%s", dir);
return 1;
@@ -369,8 +364,8 @@ parse_include (pfile, dir, trail, strp, lenp, abp)
if (!trail && cpp_get_token (pfile)->type != CPP_EOF)
cpp_error (pfile, "junk at end of #%s", dir);
- *lenp = name->val.name.len;
- *strp = name->val.name.text;
+ *lenp = name->val.str.len;
+ *strp = name->val.str.text;
*abp = (name->type == CPP_HEADER_NAME);
return 0;
}
@@ -466,8 +461,8 @@ read_line_number (pfile, num)
{
const cpp_token *tok = cpp_get_token (pfile);
enum cpp_ttype type = tok->type;
- const U_CHAR *p = tok->val.name.text;
- unsigned int len = tok->val.name.len;
+ const U_CHAR *p = tok->val.str.text;
+ unsigned int len = tok->val.str.len;
if (type == CPP_NUMBER && len == 1 && p[0] >= '1' && p[0] <= '4')
{
@@ -526,8 +521,8 @@ do_line (pfile)
tok = cpp_get_token (pfile);
type = tok->type;
- str = tok->val.name.text;
- len = tok->val.name.len;
+ str = tok->val.str.text;
+ len = tok->val.str.len;
if (type != CPP_NUMBER || strtoul_for_line (str, len, &new_lineno))
{
@@ -542,8 +537,8 @@ do_line (pfile)
ip->lineno = new_lineno;
tok = cpp_get_token (pfile);
type = tok->type;
- str = tok->val.name.text;
- len = tok->val.name.len;
+ str = tok->val.str.text;
+ len = tok->val.str.len;
if (type == CPP_EOF)
goto done;
@@ -683,8 +678,7 @@ struct pragma_entry
};
static int pragma_dispatch
- PARAMS ((cpp_reader *, const struct pragma_entry *,
- const U_CHAR *, size_t));
+ PARAMS ((cpp_reader *, const struct pragma_entry *, const cpp_hashnode *));
static int do_pragma_once PARAMS ((cpp_reader *));
static int do_pragma_implementation PARAMS ((cpp_reader *));
static int do_pragma_poison PARAMS ((cpp_reader *));
@@ -710,12 +704,14 @@ static const struct pragma_entry gcc_pragmas[] =
{NULL, NULL}
};
-static int pragma_dispatch (pfile, table, p, len)
+static int pragma_dispatch (pfile, table, node)
cpp_reader *pfile;
const struct pragma_entry *table;
- const U_CHAR *p;
- size_t len;
+ const cpp_hashnode *node;
{
+ const U_CHAR *p = node->name;
+ size_t len = node->length;
+
for (; table->name; table++)
if (strlen (table->name) == len && !memcmp (p, table->name, len))
return (*table->handler) (pfile);
@@ -738,8 +734,7 @@ do_pragma (pfile)
return 0;
}
- pop = pragma_dispatch (pfile, top_pragmas,
- tok->val.name.text, tok->val.name.len);
+ pop = pragma_dispatch (pfile, top_pragmas, tok->val.node);
if (!pop)
pass_thru_directive (pfile);
return 0;
@@ -757,8 +752,7 @@ do_pragma_gcc (pfile)
else if (tok->type != CPP_NAME)
return 0;
- return pragma_dispatch (pfile, gcc_pragmas,
- tok->val.name.text, tok->val.name.len);
+ return pragma_dispatch (pfile, gcc_pragmas, tok->val.node);
}
static int
@@ -799,9 +793,9 @@ do_pragma_implementation (pfile)
}
/* Make a NUL-terminated copy of the string. */
- copy = alloca (tok->val.name.len + 1);
- memcpy (copy, tok->val.name.text, tok->val.name.len);
- copy[tok->val.name.len] = '\0';
+ copy = alloca (tok->val.str.len + 1);
+ memcpy (copy, tok->val.str.text, tok->val.str.len);
+ copy[tok->val.str.len] = '\0';
if (cpp_included (pfile, copy))
cpp_warning (pfile,
@@ -837,7 +831,7 @@ do_pragma_poison (pfile)
return 1;
}
- hp = cpp_lookup (pfile, tok->val.name.text, tok->val.name.len);
+ hp = tok->val.node;
if (hp->type == T_POISON)
; /* It is allowed to poison the same identifier twice. */
else
@@ -943,7 +937,7 @@ detect_if_not_defined (pfile)
token++;
if (token->type != CPP_NAME
- || !str_match (token->val.name.text, token->val.name.len, "defined"))
+ || token->val.node != pfile->spec_nodes->n_defined)
return 0;
token++;
@@ -953,7 +947,7 @@ detect_if_not_defined (pfile)
if (token->type != CPP_NAME)
return 0;
- cmacro = cpp_lookup (pfile, token->val.name.text, token->val.name.len);
+ cmacro = token->val.node;
if (token[-1].type == CPP_OPEN_PAREN)
{
@@ -977,15 +971,11 @@ parse_ifdef (pfile, name)
cpp_reader *pfile;
const U_CHAR *name;
{
- const U_CHAR *ident;
- unsigned int len;
enum cpp_ttype type;
const cpp_hashnode *node = 0;
const cpp_token *token = cpp_get_token (pfile);
type = token->type;
- ident = token->val.name.text;
- len = token->val.name.len;
if (!CPP_TRADITIONAL (pfile))
{
@@ -998,9 +988,13 @@ parse_ifdef (pfile, name)
}
if (type == CPP_NAME)
- node = cpp_lookup (pfile, ident, len);
+ node = token->val.node;
if (node && node->type == T_POISON)
- cpp_error (pfile, "attempt to use poisoned identifier \"%s\"", node->name);
+ {
+ cpp_error (pfile, "attempt to use poisoned identifier \"%s\"",
+ node->name);
+ node = 0;
+ }
return node;
}
@@ -1011,17 +1005,12 @@ static int
do_ifdef (pfile)
cpp_reader *pfile;
{
- int def = 0;
const cpp_hashnode *node = 0;
if (! pfile->skipping)
- {
- node = parse_ifdef (pfile, dtable[T_IFDEF].name);
- if (node)
- def = (node->type != T_VOID && node->type != T_POISON);
- }
+ node = parse_ifdef (pfile, dtable[T_IFDEF].name);
- push_conditional (pfile, !def, T_IFDEF, 0);
+ push_conditional (pfile, !(node && node->type != T_VOID), T_IFDEF, 0);
return 0;
}
@@ -1033,18 +1022,16 @@ do_ifndef (pfile)
cpp_reader *pfile;
{
int start_of_file = 0;
- int def = 0;
- const cpp_hashnode *cmacro = 0;
+ const cpp_hashnode *node = 0;
if (! pfile->skipping)
{
start_of_file = (pfile->token_list.flags & BEG_OF_FILE);
- cmacro = parse_ifdef (pfile, dtable[T_IFNDEF].name);
- if (cmacro)
- def = cmacro->type != T_VOID;
+ node = parse_ifdef (pfile, dtable[T_IFNDEF].name);
}
- push_conditional (pfile, def, T_IFNDEF, start_of_file ? cmacro : 0);
+ push_conditional (pfile, node && node->type != T_VOID,
+ T_IFNDEF, start_of_file ? node : 0);
return 0;
}
@@ -1060,7 +1047,8 @@ do_if (pfile)
if (! pfile->skipping)
{
- cmacro = detect_if_not_defined (pfile);
+ if (pfile->token_list.flags & BEG_OF_FILE)
+ cmacro = detect_if_not_defined (pfile);
value = _cpp_parse_expr (pfile);
}
push_conditional (pfile, value == 0, T_IF, cmacro);
@@ -1294,13 +1282,13 @@ _cpp_parse_assertion (pfile, answerp)
dest = &list->tokens[list->tokens_used++];
*dest = *token;
- if (token_spellings[token->type].type > SPELL_NONE)
+ if (token_spellings[token->type].type == SPELL_STRING)
{
- _cpp_expand_name_space (list, token->val.name.len);
- dest->val.name.text = list->namebuf + list->name_used;
+ _cpp_expand_name_space (list, token->val.str.len);
+ dest->val.str.text = list->namebuf + list->name_used;
memcpy (list->namebuf + list->name_used,
- token->val.name.text, token->val.name.len);
- list->name_used += token->val.name.len;
+ token->val.str.text, token->val.str.len);
+ list->name_used += token->val.str.len;
}
}
@@ -1322,12 +1310,12 @@ _cpp_parse_assertion (pfile, answerp)
lookup_node:
*answerp = answer;
- len = predicate->val.name.len;
+ len = predicate->val.node->length;
sym = alloca (len + 1);
/* Prefix '#' to get it out of macro namespace. */
sym[0] = '#';
- memcpy (sym + 1, predicate->val.name.text, len);
+ memcpy (sym + 1, predicate->val.node->name, len);
return cpp_lookup (pfile, sym, len + 1);
error:
@@ -1586,12 +1574,26 @@ cpp_pop_buffer (pfile)
#define obstack_chunk_alloc xmalloc
#define obstack_chunk_free free
+#define DSC(x) U x, sizeof x - 1
void
_cpp_init_stacks (pfile)
cpp_reader *pfile;
{
+ int i;
+ struct spec_nodes *s;
+
pfile->buffer_ob = xnew (struct obstack);
obstack_init (pfile->buffer_ob);
+
+ /* Perhaps not the ideal place to put this. */
+ pfile->spec_nodes = s = xnew (struct spec_nodes);
+ s->n_L = cpp_lookup (pfile, DSC("L"));
+ s->n_defined = cpp_lookup (pfile, DSC("defined"));
+ s->n__STRICT_ANSI__ = cpp_lookup (pfile, DSC("__STRICT_ANSI__"));
+ s->n__CHAR_UNSIGNED__ = cpp_lookup (pfile, DSC("__CHAR_UNSIGNED__"));
+ s->n__VA_ARGS__ = cpp_lookup (pfile, DSC("__VA_ARGS__"));
+ for (i = 0; i < N_DIRECTIVES; i++)
+ s->dirs[i] = cpp_lookup (pfile, dtable[i].name, dtable[i].length);
}
void