Commit cf00a885 by Zack Weinberg Committed by Zack Weinberg

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
parent 563dd08a
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> 2000-07-08 Neil Booth <NeilB@earthling.net>
* cpphash.c (is__va_args__): New function. * cpphash.c (is__va_args__): New function.
......
...@@ -213,8 +213,6 @@ extern void _cpp_skip_rest_of_line PARAMS ((cpp_reader *)); ...@@ -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_free_temp_tokens PARAMS ((cpp_reader *));
extern void _cpp_init_input_buffer PARAMS ((cpp_reader *)); extern void _cpp_init_input_buffer PARAMS ((cpp_reader *));
extern void _cpp_grow_token_buffer PARAMS ((cpp_reader *, long)); 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_init_toklist PARAMS ((cpp_toklist *, int));
extern void _cpp_clear_toklist PARAMS ((cpp_toklist *)); extern void _cpp_clear_toklist PARAMS ((cpp_toklist *));
extern void _cpp_free_toklist PARAMS ((const cpp_toklist *)); extern void _cpp_free_toklist PARAMS ((const cpp_toklist *));
...@@ -238,6 +236,7 @@ extern unsigned int _cpp_get_line PARAMS ((cpp_reader *, ...@@ -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 const cpp_token *_cpp_get_raw_token PARAMS ((cpp_reader *));
extern void _cpp_push_token PARAMS ((cpp_reader *, const cpp_token*)); extern void _cpp_push_token PARAMS ((cpp_reader *, const cpp_token*));
extern const cpp_token *_cpp_glue_header_name PARAMS ((cpp_reader *)); 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 */ /* In cpplib.c */
extern const struct directive *_cpp_check_directive extern const struct directive *_cpp_check_directive
......
...@@ -776,11 +776,6 @@ cpp_start_read (pfile, print, fname) ...@@ -776,11 +776,6 @@ cpp_start_read (pfile, print, fname)
if (user_label_prefix == NULL) if (user_label_prefix == NULL)
user_label_prefix = USER_LABEL_PREFIX; 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. /* Figure out if we need to save function macro parameter spellings.
We don't use CPP_PEDANTIC() here because that depends on whether 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 or not the current file is a system header, and there is no
......
...@@ -167,13 +167,13 @@ token_spellings [N_TTYPES + 1] = {TTYPE_TABLE {0, 0} }; ...@@ -167,13 +167,13 @@ token_spellings [N_TTYPES + 1] = {TTYPE_TABLE {0, 0} };
#undef N #undef N
/* For debugging: the internal names of the tokens. */ /* For debugging: the internal names of the tokens. */
#define T(e, s) STRINGX(e), #define T(e, s) U STRINGX(e) + 4,
#define I(e, s) STRINGX(e), #define I(e, s) U STRINGX(e) + 4,
#define S(e, s) STRINGX(e), #define S(e, s) U STRINGX(e) + 4,
#define C(e, s) STRINGX(e), #define C(e, s) U STRINGX(e) + 4,
#define N(e, s) STRINGX(e), #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 T
#undef I #undef I
...@@ -1872,10 +1872,9 @@ output_token (pfile, token, prev) ...@@ -1872,10 +1872,9 @@ output_token (pfile, token, prev)
} }
/* Write the spelling of a token TOKEN to BUFFER. The buffer must /* Write the spelling of a token TOKEN to BUFFER. The buffer must
already contain the enough space to hold the token's spelling. If already contain the enough space to hold the token's spelling.
WHITESPACE is true, and the token was preceded by whitespace, Returns a pointer to the character after the last character
output a single space before the token proper. Returns a pointer written. */
to the character after the last character written. */
static unsigned char * static unsigned char *
spell_token (pfile, token, buffer) spell_token (pfile, token, buffer)
...@@ -1933,6 +1932,19 @@ spell_token (pfile, token, buffer) ...@@ -1933,6 +1932,19 @@ spell_token (pfile, token, buffer)
return 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. */ /* Macro expansion algorithm. TODO. */
static const cpp_token placemarker_token = {0, 0, CPP_PLACEMARKER, 0 UNION_INIT_ZERO}; static const cpp_token placemarker_token = {0, 0, CPP_PLACEMARKER, 0 UNION_INIT_ZERO};
...@@ -2022,6 +2034,10 @@ is_macro_disabled (pfile, expansion, token) ...@@ -2022,6 +2034,10 @@ is_macro_disabled (pfile, expansion, token)
{ {
cpp_context *context = CURRENT_CONTEXT (pfile); 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 /* Arguments on either side of ## are inserted in place without
macro expansion (6.10.3.3.2). Conceptually, any macro expansion macro expansion (6.10.3.3.2). Conceptually, any macro expansion
occurs during a later rescan pass. The effect is that we expand occurs during a later rescan pass. The effect is that we expand
...@@ -3275,26 +3291,6 @@ _cpp_dump_list (pfile, list, token, flush) ...@@ -3275,26 +3291,6 @@ _cpp_dump_list (pfile, list, token, flush)
cpp_output_tokens (pfile, pfile->printer, pfile->token_list.line); 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[] /* Allocate pfile->input_buffer, and initialize trigraph_map[]
if it hasn't happened already. */ if it hasn't happened already. */
......
...@@ -476,7 +476,7 @@ read_line_number (pfile, num) ...@@ -476,7 +476,7 @@ read_line_number (pfile, num)
} }
else else
{ {
if (type != CPP_VSPACE && type != CPP_EOF) if (type != CPP_EOF)
cpp_error (pfile, "invalid format #line"); cpp_error (pfile, "invalid format #line");
return 0; return 0;
} }
...@@ -545,7 +545,7 @@ do_line (pfile) ...@@ -545,7 +545,7 @@ do_line (pfile)
str = tok->val.name.text; str = tok->val.name.text;
len = tok->val.name.len; len = tok->val.name.len;
if (type == CPP_VSPACE || type == CPP_EOF) if (type == CPP_EOF)
goto done; goto done;
else if (type != CPP_STRING) else if (type != CPP_STRING)
{ {
......
...@@ -123,10 +123,7 @@ typedef struct cpp_hashnode cpp_hashnode; ...@@ -123,10 +123,7 @@ typedef struct cpp_hashnode cpp_hashnode;
I(CPP_COMMENT, 0) /* Only if output comments. */ \ I(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 */ \ 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. */
#define T(e, s) e, #define T(e, s) e,
#define I(e, s) e, #define I(e, s) e,
...@@ -542,9 +539,6 @@ struct cpp_reader ...@@ -542,9 +539,6 @@ struct cpp_reader
containing files that matches the current status. */ containing files that matches the current status. */
unsigned char input_stack_listing_current; 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. */ /* We're printed a warning recommending against using #import. */
unsigned char import_warning; unsigned char import_warning;
...@@ -555,7 +549,8 @@ struct cpp_reader ...@@ -555,7 +549,8 @@ struct cpp_reader
/* True if we are skipping a failed conditional group. */ /* True if we are skipping a failed conditional group. */
unsigned char skipping; 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; unsigned char save_parameter_spellings;
/* If we're in lex_line. */ /* If we're in lex_line. */
......
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> 2000-07-08 Neil Booth <NeilB@earthling.net>
* gcc.dg/cpp/macsyntx.c: New tests. * gcc.dg/cpp/macsyntx.c: New tests.
......
/* { dg-do preprocess } */ /* { dg-do preprocess } */
#if 0xe-1 /* { dg-error "invalid number" } */ #if 0xe-1 /* { dg-error "invalid suffix" } */
#endif #endif
...@@ -20,5 +20,5 @@ ...@@ -20,5 +20,5 @@
#error /* { dg-bogus "error" "test w/o answer" } */ #error /* { dg-bogus "error" "test w/o answer" } */
#endif #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 #endif
...@@ -9,22 +9,29 @@ ...@@ -9,22 +9,29 @@
#error 077 != 63 /* { dg-bogus "#error" "normal conversion" } */ #error 077 != 63 /* { dg-bogus "#error" "normal conversion" } */
#endif #endif
#if 12wrt /* { dg-error "nvalid number|missing white" "invalid number" } */ #if 12wrt /* { dg-error "invalid suffix" "invalid number" } */
#endif #endif
#if 0abc /* { dg-error "nvalid number|missing white" "invalid number" } */ #if 0abc /* { dg-error "invalid suffix" "invalid number" } */
#endif #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 #endif
#if 1.2 /* { dg-error "loating point numbers" "floating point in #if" } */ #if 1.2 /* { dg-error "loating point numbers" "floating point in #if" } */
#endif #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 "invalid suffix" "too many suffixes" } */
#endif #endif
#if 124123231lll /* { dg-error "too many 'l'" "too many suffixes" } */ #if 1234lul /* { dg-error "invalid suffix" "u between ls" } */
#endif #endif
#if 099 /* { dg-error "digits beyond the radix" "decimal in octal constant" } */ #if 099 /* { dg-error "digits beyond the radix" "decimal in octal constant" } */
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
NUL terminated, so we would print garbage after it. */ NUL terminated, so we would print garbage after it. */
/* { dg-do compile } */ /* { 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 syntax_error
#endif #endif
int foo; int foo;
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