cppexp.c: Update all code for new lexer interface.

* cppexp.c: Update all code for new lexer interface.
	(op_t, operator codes, struct token, tokentab2, op_to_str): Remove.
	(struct suffix, vsuf_1, vsuf_2, vsuf_3, op_to_prio): New.
	* cpplex.c (token_names): Trim leading CPP_ from names; make
	the strings unsigned.
	(_cpp_spell_operator): New.
	(is_macro_disabled): Disable all macros if rescanning
	preprocessed text.
	(_cpp_get_directive_token): Remove.

	* cppinit.c: Don't set no_macro_expand.
	* cpplib.c (read_line_number, do_line): Check only for EOF,
	not VSPACE.
	* cpphash.h: Update prototypes.
	* cpplib.h (CPP_VSPACE): Remove.
	(struct cpp_reader): Remove no_macro_expand.

testsuite:
	* gcc.dg/cpp/19951227-1.c, gcc.dg/cpp/assert2.c,
	gcc.dg/cpp/if-1.c, gcc.dg/cpp/if-4.c: Tweak error regexps.

From-SVN: r34920
This commit is contained in:
Zack Weinberg 2000-07-08 02:33:00 +00:00 committed by Zack Weinberg
parent 563dd08adf
commit cf00a88510
12 changed files with 404 additions and 507 deletions

View File

@ -1,3 +1,22 @@
2000-07-07 Zack Weinberg <zack@wolery.cumb.org>
* cppexp.c: Update all code for new lexer interface.
(op_t, operator codes, struct token, tokentab2, op_to_str): Remove.
(struct suffix, vsuf_1, vsuf_2, vsuf_3, op_to_prio): New.
* cpplex.c (token_names): Trim leading CPP_ from names; make
the strings unsigned.
(_cpp_spell_operator): New.
(is_macro_disabled): Disable all macros if rescanning
preprocessed text.
(_cpp_get_directive_token): Remove.
* cppinit.c: Don't set no_macro_expand.
* cpplib.c (read_line_number, do_line): Check only for EOF,
not VSPACE.
* cpphash.h: Update prototypes.
* cpplib.h (CPP_VSPACE): Remove.
(struct cpp_reader): Remove no_macro_expand.
2000-07-08 Neil Booth <NeilB@earthling.net>
* cpphash.c (is__va_args__): New function.

File diff suppressed because it is too large Load Diff

View File

@ -213,8 +213,6 @@ extern void _cpp_skip_rest_of_line PARAMS ((cpp_reader *));
extern void _cpp_free_temp_tokens PARAMS ((cpp_reader *));
extern void _cpp_init_input_buffer PARAMS ((cpp_reader *));
extern void _cpp_grow_token_buffer PARAMS ((cpp_reader *, long));
extern enum cpp_ttype _cpp_get_directive_token
PARAMS ((cpp_reader *));
extern void _cpp_init_toklist PARAMS ((cpp_toklist *, int));
extern void _cpp_clear_toklist PARAMS ((cpp_toklist *));
extern void _cpp_free_toklist PARAMS ((const cpp_toklist *));
@ -238,6 +236,7 @@ extern unsigned int _cpp_get_line PARAMS ((cpp_reader *,
extern const cpp_token *_cpp_get_raw_token PARAMS ((cpp_reader *));
extern void _cpp_push_token PARAMS ((cpp_reader *, const cpp_token*));
extern const cpp_token *_cpp_glue_header_name PARAMS ((cpp_reader *));
extern const U_CHAR *_cpp_spell_operator PARAMS ((enum cpp_ttype));
/* In cpplib.c */
extern const struct directive *_cpp_check_directive

View File

@ -776,11 +776,6 @@ cpp_start_read (pfile, print, fname)
if (user_label_prefix == NULL)
user_label_prefix = USER_LABEL_PREFIX;
/* Don't bother trying to do macro expansion if we've already done
preprocessing. */
if (CPP_OPTION (pfile, preprocessed))
pfile->no_macro_expand++;
/* Figure out if we need to save function macro parameter spellings.
We don't use CPP_PEDANTIC() here because that depends on whether
or not the current file is a system header, and there is no

View File

@ -167,13 +167,13 @@ token_spellings [N_TTYPES + 1] = {TTYPE_TABLE {0, 0} };
#undef N
/* For debugging: the internal names of the tokens. */
#define T(e, s) STRINGX(e),
#define I(e, s) STRINGX(e),
#define S(e, s) STRINGX(e),
#define C(e, s) STRINGX(e),
#define N(e, s) STRINGX(e),
#define T(e, s) U STRINGX(e) + 4,
#define I(e, s) U STRINGX(e) + 4,
#define S(e, s) U STRINGX(e) + 4,
#define C(e, s) U STRINGX(e) + 4,
#define N(e, s) U STRINGX(e) + 4,
const char * const token_names[N_TTYPES] = { TTYPE_TABLE };
const U_CHAR *const token_names[N_TTYPES] = { TTYPE_TABLE };
#undef T
#undef I
@ -1872,10 +1872,9 @@ output_token (pfile, token, prev)
}
/* Write the spelling of a token TOKEN to BUFFER. The buffer must
already contain the enough space to hold the token's spelling. If
WHITESPACE is true, and the token was preceded by whitespace,
output a single space before the token proper. Returns a pointer
to the character after the last character written. */
already contain the enough space to hold the token's spelling.
Returns a pointer to the character after the last character
written. */
static unsigned char *
spell_token (pfile, token, buffer)
@ -1933,6 +1932,19 @@ spell_token (pfile, token, buffer)
return buffer;
}
/* Return the spelling of a token known to be an operator.
Does not distinguish digraphs from their counterparts. */
const unsigned char *
_cpp_spell_operator (type)
enum cpp_ttype type;
{
if (token_spellings[type].type == SPELL_OPERATOR)
return token_spellings[type].spelling;
else
return token_names[type];
}
/* Macro expansion algorithm. TODO. */
static const cpp_token placemarker_token = {0, 0, CPP_PLACEMARKER, 0 UNION_INIT_ZERO};
@ -2022,6 +2034,10 @@ is_macro_disabled (pfile, expansion, token)
{
cpp_context *context = CURRENT_CONTEXT (pfile);
/* Don't expand anything if this file has already been preprocessed. */
if (CPP_OPTION (pfile, preprocessed))
return 1;
/* Arguments on either side of ## are inserted in place without
macro expansion (6.10.3.3.2). Conceptually, any macro expansion
occurs during a later rescan pass. The effect is that we expand
@ -3275,26 +3291,6 @@ _cpp_dump_list (pfile, list, token, flush)
cpp_output_tokens (pfile, pfile->printer, pfile->token_list.line);
}
/* Stub function during conversion, mainly for cppexp.c's benefit. */
enum cpp_ttype
_cpp_get_directive_token (pfile)
cpp_reader *pfile;
{
const cpp_token *tok;
if (pfile->no_macro_expand)
tok = _cpp_get_raw_token (pfile);
else
tok = cpp_get_token (pfile);
if (tok->type == CPP_EOF)
return CPP_VSPACE; /* backward compat; and don't try to spell EOF */
CPP_RESERVE (pfile, TOKEN_LEN (tok));
pfile->limit = spell_token (pfile, tok, pfile->limit);
return tok->type;
}
/* Allocate pfile->input_buffer, and initialize trigraph_map[]
if it hasn't happened already. */

View File

@ -476,7 +476,7 @@ read_line_number (pfile, num)
}
else
{
if (type != CPP_VSPACE && type != CPP_EOF)
if (type != CPP_EOF)
cpp_error (pfile, "invalid format #line");
return 0;
}
@ -545,7 +545,7 @@ do_line (pfile)
str = tok->val.name.text;
len = tok->val.name.len;
if (type == CPP_VSPACE || type == CPP_EOF)
if (type == CPP_EOF)
goto done;
else if (type != CPP_STRING)
{

View File

@ -123,10 +123,7 @@ typedef struct cpp_hashnode cpp_hashnode;
I(CPP_COMMENT, 0) /* Only if output comments. */ \
N(CPP_MACRO_ARG, 0) /* Macro argument. */ \
N(CPP_EOF, 0) /* End of file. */ \
I(CPP_HEADER_NAME, 0) /* <stdio.h> in #include */ \
\
/* Obsolete - will be removed when no code uses them still. */ \
T(CPP_VSPACE, "\n") /* End of line. */
I(CPP_HEADER_NAME, 0) /* <stdio.h> in #include */
#define T(e, s) e,
#define I(e, s) e,
@ -542,9 +539,6 @@ struct cpp_reader
containing files that matches the current status. */
unsigned char input_stack_listing_current;
/* If non-zero, macros are not expanded. */
unsigned char no_macro_expand;
/* We're printed a warning recommending against using #import. */
unsigned char import_warning;
@ -555,7 +549,8 @@ struct cpp_reader
/* True if we are skipping a failed conditional group. */
unsigned char skipping;
/* Do we need to save paramter spellings. */
/* True if we need to save parameter spellings - only if -pedantic,
or we might need to write out definitions. */
unsigned char save_parameter_spellings;
/* If we're in lex_line. */

View File

@ -1,3 +1,8 @@
2000-07-07 Zack Weinberg <zack@wolery.cumb.org>
* gcc.dg/cpp/19951227-1.c, gcc.dg/cpp/assert2.c,
gcc.dg/cpp/if-1.c, gcc.dg/cpp/if-4.c: Tweak error regexps.
2000-07-08 Neil Booth <NeilB@earthling.net>
* gcc.dg/cpp/macsyntx.c: New tests.

View File

@ -1,3 +1,3 @@
/* { dg-do preprocess } */
#if 0xe-1 /* { dg-error "invalid number" } */
#if 0xe-1 /* { dg-error "invalid suffix" } */
#endif

View File

@ -20,5 +20,5 @@
#error /* { dg-bogus "error" "test w/o answer" } */
#endif
#if #abc[def] /* { dg-error "invalid char" "test with malformed answer" } */
#if #abc[def] /* { dg-error "is not valid" "test with malformed answer" } */
#endif

View File

@ -9,22 +9,29 @@
#error 077 != 63 /* { dg-bogus "#error" "normal conversion" } */
#endif
#if 12wrt /* { dg-error "nvalid number|missing white" "invalid number" } */
#if 12wrt /* { dg-error "invalid suffix" "invalid number" } */
#endif
#if 0abc /* { dg-error "nvalid number|missing white" "invalid number" } */
#if 0abc /* { dg-error "invalid suffix" "invalid number" } */
#endif
#if 42abc /* { dg-error "nvalid number|missing white" "invalid number" } */
#if 42abc /* { dg-error "invalid suffix" "invalid number" } */
#endif
#if 0xabc != 2748
#error 0xabc /* { dg-bogus "#error" "normal conversion" } */
#endif
#if 1.2 /* { dg-error "loating point numbers" "floating point in #if" } */
#endif
#if 4uu /* { dg-error "too many 'u'" "too many suffixes" } */
#if 4uu /* { dg-error "invalid suffix" "too many suffixes" } */
#endif
#if 124123231lll /* { dg-error "too many 'l'" "too many suffixes" } */
#if 124123231lll /* { dg-error "invalid suffix" "too many suffixes" } */
#endif
#if 1234lul /* { dg-error "invalid suffix" "u between ls" } */
#endif
#if 099 /* { dg-error "digits beyond the radix" "decimal in octal constant" } */

View File

@ -2,7 +2,7 @@
NUL terminated, so we would print garbage after it. */
/* { dg-do compile } */
#if 1 += 2 /* { dg-error "'\\+=' is not allowed" "+= in if" } */
#if 1 += 2 /* { dg-error "'\\+=' is not valid" "+= in if" } */
syntax_error
#endif
int foo;