Commit bfb9dc7f by Zack Weinberg Committed by Zack Weinberg

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
parent ffc14f31
2000-07-08 Zack Weinberg <zack@wolery.cumb.org>
* 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.
2000-07-08 Geoffrey Keating <geoffk@cygnus.com> 2000-07-08 Geoffrey Keating <geoffk@cygnus.com>
* config/rs6000/rs6000.c (rs6000_emit_move): Fix conditions for * config/rs6000/rs6000.c (rs6000_emit_move): Fix conditions for
......
...@@ -137,10 +137,10 @@ parse_number (pfile, tok) ...@@ -137,10 +137,10 @@ parse_number (pfile, tok)
const cpp_token *tok; const cpp_token *tok;
{ {
struct op op; struct op op;
const U_CHAR *start = tok->val.name.text; const U_CHAR *start = tok->val.str.text;
const U_CHAR *end = start + tok->val.name.len; const U_CHAR *end = start + tok->val.str.len;
const U_CHAR *p = start; const U_CHAR *p = start;
int c, i, nsuff; int c = 0, i, nsuff;
unsigned HOST_WIDEST_INT n = 0, nd, MAX_over_base; unsigned HOST_WIDEST_INT n = 0, nd, MAX_over_base;
int base = 10; int base = 10;
int overflow = 0; int overflow = 0;
...@@ -261,8 +261,8 @@ parse_charconst (pfile, tok) ...@@ -261,8 +261,8 @@ parse_charconst (pfile, tok)
int num_bits; int num_bits;
unsigned int width = MAX_CHAR_TYPE_SIZE, mask = MAX_CHAR_TYPE_MASK; unsigned int width = MAX_CHAR_TYPE_SIZE, mask = MAX_CHAR_TYPE_MASK;
int max_chars; int max_chars;
const U_CHAR *ptr = tok->val.name.text; const U_CHAR *ptr = tok->val.str.text;
const U_CHAR *end = ptr + tok->val.name.len; const U_CHAR *end = ptr + tok->val.str.len;
int c = -1; int c = -1;
...@@ -304,8 +304,7 @@ parse_charconst (pfile, tok) ...@@ -304,8 +304,7 @@ parse_charconst (pfile, tok)
/* If char type is signed, sign-extend the constant. */ /* If char type is signed, sign-extend the constant. */
num_bits = num_chars * width; num_bits = num_chars * width;
if (cpp_defined (pfile, U"__CHAR_UNSIGNED__", if (pfile->spec_nodes->n__CHAR_UNSIGNED__->type != T_VOID
sizeof ("__CHAR_UNSIGNED__")-1)
|| ((result >> (num_bits - 1)) & 1) == 0) || ((result >> (num_bits - 1)) & 1) == 0)
op.value = result & ((unsigned HOST_WIDEST_INT) ~0 op.value = result & ((unsigned HOST_WIDEST_INT) ~0
>> (HOST_BITS_PER_WIDEST_INT - num_bits)); >> (HOST_BITS_PER_WIDEST_INT - num_bits));
...@@ -345,9 +344,12 @@ parse_defined (pfile) ...@@ -345,9 +344,12 @@ parse_defined (pfile)
if (paren && _cpp_get_raw_token (pfile)->type != CPP_CLOSE_PAREN) if (paren && _cpp_get_raw_token (pfile)->type != CPP_CLOSE_PAREN)
SYNTAX_ERROR ("missing close paren after \"defined\""); 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.unsignedp = 0;
op.op = CPP_INT; op.op = CPP_INT;
op.value = cpp_defined (pfile, tok->val.name.text, tok->val.name.len);
return op; return op;
syntax_error: syntax_error:
...@@ -419,7 +421,7 @@ lex (pfile, skip_evaluation) ...@@ -419,7 +421,7 @@ lex (pfile, skip_evaluation)
SYNTAX_ERROR2 ("invalid character '\\%03o' in #if", tok->val.aux); SYNTAX_ERROR2 ("invalid character '\\%03o' in #if", tok->val.aux);
case CPP_NAME: 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); return parse_defined (pfile);
op.op = CPP_INT; op.op = CPP_INT;
...@@ -427,8 +429,7 @@ lex (pfile, skip_evaluation) ...@@ -427,8 +429,7 @@ lex (pfile, skip_evaluation)
op.value = 0; op.value = 0;
if (CPP_OPTION (pfile, warn_undef) && !skip_evaluation) if (CPP_OPTION (pfile, warn_undef) && !skip_evaluation)
cpp_warning (pfile, "\"%.*s\" is not defined", cpp_warning (pfile, "\"%s\" is not defined", tok->val.node->name);
(int) tok->val.name.len, tok->val.name.text);
return op; return op;
case CPP_HASH: case CPP_HASH:
......
...@@ -61,8 +61,6 @@ static int save_expansion PARAMS((cpp_reader *, cpp_toklist *, ...@@ -61,8 +61,6 @@ static int save_expansion PARAMS((cpp_reader *, cpp_toklist *,
static unsigned int find_param PARAMS ((const cpp_token *, static unsigned int find_param PARAMS ((const cpp_token *,
const cpp_token *)); const cpp_token *));
static const unsigned char var_args_str[] = "__VA_ARGS__";
/* Calculate hash of a string of length LEN. */ /* Calculate hash of a string of length LEN. */
unsigned int unsigned int
_cpp_calc_hash (str, len) _cpp_calc_hash (str, len)
...@@ -131,7 +129,7 @@ cpp_lookup (pfile, name, len) ...@@ -131,7 +129,7 @@ cpp_lookup (pfile, name, len)
p = obstack_alloc (pfile->hash_ob, sizeof (cpp_hashnode) + len); p = obstack_alloc (pfile->hash_ob, sizeof (cpp_hashnode) + len);
new = (cpp_hashnode *)p; new = (cpp_hashnode *)p;
p += offsetof (cpp_hashnode, name); p += offsetof (cpp_hashnode, name);
new->type = T_VOID; new->type = T_VOID;
new->length = len; new->length = len;
new->hash = hash; new->hash = hash;
...@@ -189,9 +187,7 @@ find_param (first, token) ...@@ -189,9 +187,7 @@ find_param (first, token)
if (first->type == CPP_NAME) if (first->type == CPP_NAME)
{ {
param++; param++;
if (first->val.name.len == token->val.name.len if (first->val.node == token->val.node)
&& !memcmp (first->val.name.text, token->val.name.text,
token->val.name.len))
return param; return param;
} }
...@@ -206,15 +202,13 @@ is__va_args__ (pfile, token) ...@@ -206,15 +202,13 @@ is__va_args__ (pfile, token)
cpp_reader *pfile; cpp_reader *pfile;
const cpp_token *token; const cpp_token *token;
{ {
if (!CPP_OPTION (pfile, pedantic) if (!CPP_PEDANTIC (pfile)
|| token->val.name.len != sizeof (var_args_str) - 1 || token->val.node != pfile->spec_nodes->n__VA_ARGS__)
|| ustrncmp (token->val.name.text, var_args_str,
sizeof (var_args_str) - 1))
return 0; return 0;
cpp_pedwarn_with_line (pfile, token->line, token->col, cpp_pedwarn_with_line (pfile, token->line, token->col,
"\"%s\" is only valid in the replacement list of a function-like macro", "\"%s\" is only valid in the replacement list of a function-like macro",
var_args_str); token->val.node->name);
return 1; return 1;
} }
...@@ -257,7 +251,7 @@ count_params (pfile, first, list) ...@@ -257,7 +251,7 @@ count_params (pfile, first, list)
if (is__va_args__ (pfile, token)) if (is__va_args__ (pfile, token))
goto out; goto out;
params_len += token->val.name.len + 1; params_len += token->val.node->length + 1;
prev_ident = 1; prev_ident = 1;
list->paramc++; list->paramc++;
...@@ -265,9 +259,8 @@ count_params (pfile, first, list) ...@@ -265,9 +259,8 @@ count_params (pfile, first, list)
if (find_param (first, token)) if (find_param (first, token))
{ {
cpp_error_with_line (pfile, token->line, token->col, cpp_error_with_line (pfile, token->line, token->col,
"duplicate macro parameter \"%.*s\"", "duplicate macro parameter \"%s\"",
(int) token->val.name.len, token->val.node->name);
token->val.name.text);
goto out; goto out;
} }
break; break;
...@@ -297,19 +290,16 @@ count_params (pfile, first, list) ...@@ -297,19 +290,16 @@ count_params (pfile, first, list)
case CPP_ELLIPSIS: case CPP_ELLIPSIS:
/* Convert ISO-style var_args to named varargs by changing /* Convert ISO-style var_args to named varargs by changing
the ellipsis into an identifier with name __VA_ARGS__. the ellipsis into an identifier with name __VA_ARGS__.
This simplifies other handling. We can safely have its This simplifies other handling. */
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. */
if (!prev_ident) if (!prev_ident)
{ {
cpp_token *tok = (cpp_token *) token; cpp_token *tok = (cpp_token *) token;
tok->type = CPP_NAME; tok->type = CPP_NAME;
tok->val.name.len = sizeof (var_args_str) - 1; tok->val.node = pfile->spec_nodes->n__VA_ARGS__;
tok->val.name.text = var_args_str; /* Safe. */
list->paramc++; list->paramc++;
params_len += tok->val.node->length + 1;
if (CPP_PEDANTIC (pfile) && ! CPP_OPTION (pfile, c99)) if (CPP_PEDANTIC (pfile) && ! CPP_OPTION (pfile, c99))
cpp_pedwarn (pfile, cpp_pedwarn (pfile,
"C89 does not permit anon varargs macros"); "C89 does not permit anon varargs macros");
...@@ -344,9 +334,9 @@ count_params (pfile, first, list) ...@@ -344,9 +334,9 @@ count_params (pfile, first, list)
for (temp = first; temp <= token; temp++) for (temp = first; temp <= token; temp++)
if (temp->type == CPP_NAME) if (temp->type == CPP_NAME)
{ {
memcpy (buf, temp->val.name.text, temp->val.name.len); /* copy null too */
buf += temp->val.name.len; memcpy (buf, temp->val.node->name, temp->val.node->length + 1);
*buf++ = '\0'; buf += temp->val.node->length + 1;
} }
} }
...@@ -493,8 +483,8 @@ save_expansion (pfile, list, first, first_param) ...@@ -493,8 +483,8 @@ save_expansion (pfile, list, first, first_param)
return 1; return 1;
} }
ntokens++; ntokens++;
if (token_spellings[token->type].type > SPELL_NONE) if (token_spellings[token->type].type == SPELL_STRING)
len += token->val.name.len; len += token->val.str.len;
} }
/* Allocate space to hold the tokens. Empty expansions are stored /* Allocate space to hold the tokens. Empty expansions are stored
...@@ -553,11 +543,11 @@ save_expansion (pfile, list, first, first_param) ...@@ -553,11 +543,11 @@ save_expansion (pfile, list, first, first_param)
/* Copy the token. */ /* Copy the token. */
*dest = *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); memcpy (buf, token->val.str.text, token->val.str.len);
dest->val.name.text = buf; dest->val.str.text = buf;
buf += dest->val.name.len; buf += dest->val.str.len;
} }
dest++; dest++;
} }
...@@ -664,9 +654,9 @@ dump_funlike_macro (pfile, node) ...@@ -664,9 +654,9 @@ dump_funlike_macro (pfile, node)
CPP_PUTS(pfile, ", ", 2); CPP_PUTS(pfile, ", ", 2);
else if (list->flags & VAR_ARGS) else if (list->flags & VAR_ARGS)
{ {
if (!ustrcmp (param, var_args_str)) if (!ustrcmp (param, U"__VA_ARGS__"))
pfile->limit -= sizeof (var_args_str) - 1; pfile->limit -= sizeof (U"__VA_ARGS__") - 1;
CPP_PUTS (pfile, "...", 3); CPP_PUTS_Q (pfile, "...", 3);
} }
param += len + 1; param += len + 1;
} }
......
...@@ -25,15 +25,15 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ ...@@ -25,15 +25,15 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
typedef unsigned char U_CHAR; typedef unsigned char U_CHAR;
#define U (const U_CHAR *) /* Intended use: U"string" */ #define U (const U_CHAR *) /* Intended use: U"string" */
/* Order here matters. Those beyond SPELL_NONE store their spelling /* Tokens with SPELL_STRING store their spelling in the token list,
in the token list, and it's length in the token->val.name.len. */ and it's length in the token->val.name.len. */
enum spell_type enum spell_type
{ {
SPELL_OPERATOR = 0, SPELL_OPERATOR = 0,
SPELL_CHAR, SPELL_CHAR,
SPELL_NONE,
SPELL_IDENT, SPELL_IDENT,
SPELL_STRING SPELL_STRING,
SPELL_NONE
}; };
struct token_spelling struct token_spelling
...@@ -116,6 +116,20 @@ struct include_file ...@@ -116,6 +116,20 @@ struct include_file
time_t date; /* modification date of file, if known */ time_t date; /* modification date of file, if known */
}; };
/* Special nodes - identifiers with predefined significance.
Note that the array length of dirs[] must be kept in sync with
cpplib.c's dtable[]. */
struct spec_nodes
{
cpp_hashnode *n_L; /* L"str" */
cpp_hashnode *n_defined; /* #if defined */
cpp_hashnode *n__STRICT_ANSI__; /* STDC_0_IN_SYSTEM_HEADERS */
cpp_hashnode *n__CHAR_UNSIGNED__; /* plain char is unsigned */
cpp_hashnode *n__VA_ARGS__; /* C99 vararg macros */
cpp_hashnode *dirs[19]; /* 19 directives counting #sccs */
};
/* The cmacro works like this: If it's NULL, the file is to be /* The cmacro works like this: If it's NULL, the file is to be
included again. If it's NEVER_REREAD, the file is never to be included again. If it's NEVER_REREAD, the file is never to be
included again. Otherwise it is a macro hashnode, and the file is included again. Otherwise it is a macro hashnode, and the file is
...@@ -173,7 +187,9 @@ extern unsigned char _cpp_IStable[256]; ...@@ -173,7 +187,9 @@ extern unsigned char _cpp_IStable[256];
#define CPP_PREV_BUFFER(BUFFER) ((BUFFER)->prev) #define CPP_PREV_BUFFER(BUFFER) ((BUFFER)->prev)
#define CPP_PRINT_DEPS(PFILE) CPP_OPTION (PFILE, print_deps) #define CPP_PRINT_DEPS(PFILE) CPP_OPTION (PFILE, print_deps)
#define CPP_TRADITIONAL(PFILE) CPP_OPTION (PFILE, traditional) #define CPP_TRADITIONAL(PFILE) CPP_OPTION (PFILE, traditional)
#define CPP_IN_SYSTEM_HEADER(PFILE) (CPP_BUFFER (PFILE)->inc->sysp) #define CPP_IN_SYSTEM_HEADER(PFILE) \
(CPP_BUFFER (PFILE) && CPP_BUFFER (PFILE)->inc \
&& CPP_BUFFER (PFILE)->inc->sysp)
#define CPP_PEDANTIC(PF) \ #define CPP_PEDANTIC(PF) \
(CPP_OPTION (PF, pedantic) && !CPP_IN_SYSTEM_HEADER (PF)) (CPP_OPTION (PF, pedantic) && !CPP_IN_SYSTEM_HEADER (PF))
#define CPP_WTRADITIONAL(PF) \ #define CPP_WTRADITIONAL(PF) \
......
...@@ -421,8 +421,8 @@ cpp_reader_init (pfile) ...@@ -421,8 +421,8 @@ cpp_reader_init (pfile)
CPP_OPTION (pfile, pending) = CPP_OPTION (pfile, pending) =
(struct cpp_pending *) xcalloc (1, sizeof (struct cpp_pending)); (struct cpp_pending *) xcalloc (1, sizeof (struct cpp_pending));
_cpp_init_stacks (pfile);
_cpp_init_macros (pfile); _cpp_init_macros (pfile);
_cpp_init_stacks (pfile);
_cpp_init_includes (pfile); _cpp_init_includes (pfile);
} }
...@@ -469,10 +469,13 @@ cpp_cleanup (pfile) ...@@ -469,10 +469,13 @@ cpp_cleanup (pfile)
if (pfile->deps) if (pfile->deps)
deps_free (pfile->deps); deps_free (pfile->deps);
if (pfile->spec_nodes)
free (pfile->spec_nodes);
_cpp_free_temp_tokens (pfile);
_cpp_cleanup_includes (pfile);
_cpp_cleanup_stacks (pfile); _cpp_cleanup_stacks (pfile);
_cpp_cleanup_macros (pfile); _cpp_cleanup_macros (pfile);
_cpp_cleanup_includes (pfile);
_cpp_free_temp_tokens (pfile);
} }
......
...@@ -34,7 +34,7 @@ typedef struct cpp_options cpp_options; ...@@ -34,7 +34,7 @@ typedef struct cpp_options cpp_options;
typedef struct cpp_printer cpp_printer; typedef struct cpp_printer cpp_printer;
typedef struct cpp_token cpp_token; typedef struct cpp_token cpp_token;
typedef struct cpp_toklist cpp_toklist; typedef struct cpp_toklist cpp_toklist;
typedef struct cpp_name cpp_name; typedef struct cpp_string cpp_string;
typedef struct cpp_hashnode cpp_hashnode; typedef struct cpp_hashnode cpp_hashnode;
/* The first two groups, apart from '=', can appear in preprocessor /* The first two groups, apart from '=', can appear in preprocessor
...@@ -112,18 +112,18 @@ typedef struct cpp_hashnode cpp_hashnode; ...@@ -112,18 +112,18 @@ typedef struct cpp_hashnode cpp_hashnode;
C(CPP_OTHER, 0) /* stray punctuation */ \ C(CPP_OTHER, 0) /* stray punctuation */ \
\ \
I(CPP_NAME, 0) /* word */ \ I(CPP_NAME, 0) /* word */ \
I(CPP_INT, 0) /* 23 */ \ S(CPP_INT, 0) /* 23 */ \
I(CPP_FLOAT, 0) /* 3.14159 */ \ S(CPP_FLOAT, 0) /* 3.14159 */ \
I(CPP_NUMBER, 0) /* 34_be+ta */ \ S(CPP_NUMBER, 0) /* 34_be+ta */ \
S(CPP_CHAR, 0) /* 'char' */ \ S(CPP_CHAR, 0) /* 'char' */ \
S(CPP_WCHAR, 0) /* L'char' */ \ S(CPP_WCHAR, 0) /* L'char' */ \
S(CPP_STRING, 0) /* "string" */ \ S(CPP_STRING, 0) /* "string" */ \
S(CPP_WSTRING, 0) /* L"string" */ \ S(CPP_WSTRING, 0) /* L"string" */ \
\ \
I(CPP_COMMENT, 0) /* Only if output comments. */ \ S(CPP_COMMENT, 0) /* Only if output comments. */ \
N(CPP_MACRO_ARG, 0) /* Macro argument. */ \ N(CPP_MACRO_ARG, 0) /* Macro argument. */ \
N(CPP_EOF, 0) /* End of file. */ \ N(CPP_EOF, 0) /* End of file. */ \
I(CPP_HEADER_NAME, 0) /* <stdio.h> in #include */ S(CPP_HEADER_NAME, 0) /* <stdio.h> in #include */
#define T(e, s) e, #define T(e, s) e,
#define I(e, s) e, #define I(e, s) e,
...@@ -141,8 +141,8 @@ enum cpp_ttype ...@@ -141,8 +141,8 @@ enum cpp_ttype
#undef C #undef C
#undef N #undef N
/* Payload of a NAME, NUMBER, FLOAT, STRING, or COMMENT token. */ /* Payload of a NUMBER, FLOAT, STRING, or COMMENT token. */
struct cpp_name struct cpp_string
{ {
unsigned int len; unsigned int len;
const unsigned char *text; const unsigned char *text;
...@@ -168,7 +168,8 @@ struct cpp_token ...@@ -168,7 +168,8 @@ struct cpp_token
union union
{ {
HOST_WIDEST_INT integer; /* an integer */ HOST_WIDEST_INT integer; /* an integer */
struct cpp_name name; /* a string */ struct cpp_hashnode *node; /* an identifier */
struct cpp_string str; /* a string, or number */
unsigned int aux; /* argument no. for a CPP_MACRO_ARG, or unsigned int aux; /* argument no. for a CPP_MACRO_ARG, or
character represented by CPP_OTHER. */ character represented by CPP_OTHER. */
} val; } val;
...@@ -558,6 +559,10 @@ struct cpp_reader ...@@ -558,6 +559,10 @@ struct cpp_reader
/* True if output_line_command needs to output a newline. */ /* True if output_line_command needs to output a newline. */
unsigned char need_newline; unsigned char need_newline;
/* Special nodes - identifiers with predefined significance to the
preprocessor. */
struct spec_nodes *spec_nodes;
}; };
/* struct cpp_printer encapsulates state used to convert the stream of /* struct cpp_printer encapsulates state used to convert the stream of
...@@ -693,8 +698,8 @@ extern cpp_buffer *cpp_push_buffer PARAMS ((cpp_reader *, ...@@ -693,8 +698,8 @@ extern cpp_buffer *cpp_push_buffer PARAMS ((cpp_reader *,
extern cpp_buffer *cpp_pop_buffer PARAMS ((cpp_reader *)); extern cpp_buffer *cpp_pop_buffer PARAMS ((cpp_reader *));
extern void cpp_scan_buffer PARAMS ((cpp_reader *, cpp_printer *)); extern void cpp_scan_buffer PARAMS ((cpp_reader *, cpp_printer *));
extern void cpp_scan_buffer_nooutput PARAMS ((cpp_reader *)); extern void cpp_scan_buffer_nooutput PARAMS ((cpp_reader *));
extern int cpp_idcmp PARAMS ((const unsigned char *, extern int cpp_ideq PARAMS ((const cpp_token *,
size_t, const char *)); const char *));
/* In cpphash.c */ /* In cpphash.c */
extern int cpp_defined PARAMS ((cpp_reader *, extern int cpp_defined PARAMS ((cpp_reader *,
......
...@@ -501,7 +501,7 @@ recognized_extern (name) ...@@ -501,7 +501,7 @@ recognized_extern (name)
switch (special_file_handling) switch (special_file_handling)
{ {
case errno_h: case errno_h:
if (!cpp_idcmp (name->val.name.text, name->val.name.len, "errno")) if (cpp_ideq (name, "errno"))
seen_errno = 1, required_other--; seen_errno = 1, required_other--;
break; break;
...@@ -531,8 +531,8 @@ recognized_function (fname, kind, have_arg_list, file_seen) ...@@ -531,8 +531,8 @@ recognized_function (fname, kind, have_arg_list, file_seen)
missing_extern_C_count++; missing_extern_C_count++;
#endif #endif
fn = lookup_std_proto ((const char *)fname->val.name.text, fn = lookup_std_proto ((const char *)fname->val.node->name,
fname->val.name.len); fname->val.node->length);
/* Remove the function from the list of required function. */ /* Remove the function from the list of required function. */
if (fn) if (fn)
...@@ -653,9 +653,7 @@ read_scan_file (in_fname, argc, argv) ...@@ -653,9 +653,7 @@ read_scan_file (in_fname, argc, argv)
if (CPP_BUFFER (&scan_in) == buf) if (CPP_BUFFER (&scan_in) == buf)
break; break;
} }
else if (t->type == CPP_NAME && cpp_idcmp (t->val.name.text, else if (cpp_ideq (t, "_filbuf"))
t->val.name.len,
"_filbuf") == 0)
seen_filbuf++; seen_filbuf++;
} }
if (seen_filbuf) if (seen_filbuf)
......
...@@ -193,18 +193,17 @@ scan_decls (pfile, argc, argv) ...@@ -193,18 +193,17 @@ scan_decls (pfile, argc, argv)
break; break;
case CPP_NAME: case CPP_NAME:
/* "inline" and "extern" are recognized but skipped */ /* "inline" and "extern" are recognized but skipped */
if (!cpp_idcmp (token->val.name.text, token->val.name.len, "inline")) if (cpp_ideq (token, "inline"))
{ {
saw_inline = 1; saw_inline = 1;
} }
else if (!cpp_idcmp (token->val.name.text, else if (cpp_ideq (token, "extern"))
token->val.name.len, "extern"))
{ {
saw_extern = 1; saw_extern = 1;
token = cpp_get_token (pfile); token = cpp_get_token (pfile);
if (token->type == CPP_STRING if (token->type == CPP_STRING
&& !cpp_idcmp (token->val.name.text, && token->val.str.len == 1
token->val.name.len, "C")) && token->val.str.text[0] == 'C')
{ {
current_extern_C = 1; current_extern_C = 1;
token = cpp_get_token (pfile); token = cpp_get_token (pfile);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment