Commit 87ed109f by Neil Booth Committed by Neil Booth

cppexp.c (lex): Update to use state.skip_eval.

	* cppexp.c (lex): Update to use state.skip_eval.
	(struct op): Remove prio and flags members.
	(FLAG_BITS, FLAG_MASK, PRIO_SHIFT, EXTRACT_PRIO, EXTRACT_FLAGS,
	SHORT_CIRCUIT, RIGHT_ASSOC, ..._PRIO, op_to_prio): Remove.
	(LEFT_ASSOC): New macro.
	(optab): New table of operator priorities and flags.
	(SHIFT): Update.
	(_cpp_parse_expr): Clean up logic.  Return bool.  Use a
	malloc-ed parser stack.
	(reduce): New; reduce the operator stack.
	(_cpp_expand_op_stack): Expand the operator stack as necessary.
	* cpphash.h (struct op): Predeclare.
	(struct cpp_reader): New members op_stack, op_limit.
	(struct lexer_state): New member skip_eval.
	(_cpp_parse_expr): Update.
	(_cpp_expand_op_stack): New.
	* cpplib.c (do_if): Update.
	* cppinit.c (cpp_create_reader): Create op stack.
	(cpp_destroy): And destroy it.
	* cpplib.h (CPP_LAST_CPP_OP): Correct.
	(TTYPE_TABLE): Correct.
testsuite:
	* gcc.dg/cpp/if-mop.c: Update.
	* gcc.dg/cpp/if-mpar.c: Add test.
	* gcc.dg/cpp/if-oppr.c: Update.

From-SVN: r52853
parent 14dbfa70
2002-04-28 Neil Booth <neil@daikokuya.demon.co.uk>
* cppexp.c (lex): Update to use state.skip_eval.
(struct op): Remove prio and flags members.
(FLAG_BITS, FLAG_MASK, PRIO_SHIFT, EXTRACT_PRIO, EXTRACT_FLAGS,
SHORT_CIRCUIT, RIGHT_ASSOC, ..._PRIO, op_to_prio): Remove.
(LEFT_ASSOC): New macro.
(optab): New table of operator priorities and flags.
(SHIFT): Update.
(_cpp_parse_expr): Clean up logic. Return bool. Use a
malloc-ed parser stack.
(reduce): New; reduce the operator stack.
(_cpp_expand_op_stack): Expand the operator stack as necessary.
* cpphash.h (struct op): Predeclare.
(struct cpp_reader): New members op_stack, op_limit.
(struct lexer_state): New member skip_eval.
(_cpp_parse_expr): Update.
(_cpp_expand_op_stack): New.
* cpplib.c (do_if): Update.
* cppinit.c (cpp_create_reader): Create op stack.
(cpp_destroy): And destroy it.
* cpplib.h (CPP_LAST_CPP_OP): Correct.
(TTYPE_TABLE): Correct.
2002-04-28 Franz Sirl <Franz.Sirl-kernel@lauterbach.com>
PR c/6343
......
......@@ -27,6 +27,7 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
struct directive; /* Deliberately incomplete. */
struct pending_option;
struct op;
/* Test if a sign is valid within a preprocessing number. */
#define VALID_SIGN(c, prevc) \
......@@ -153,6 +154,9 @@ struct lexer_state
/* Nonzero when parsing arguments to a function-like macro. */
unsigned char parsing_args;
/* Nonzero to skip evaluating part of an expression. */
unsigned int skip_eval;
};
/* Special nodes - identifiers with predefined significance. */
......@@ -312,6 +316,9 @@ struct cpp_reader
/* Identifier hash table. */
struct ht *hash_table;
/* Expression parser stack. */
struct op *op_stack, *op_limit;
/* User visible options. */
struct cpp_options opts;
......@@ -391,7 +398,8 @@ extern void _cpp_pop_file_buffer PARAMS ((cpp_reader *,
struct include_file *));
/* In cppexp.c */
extern int _cpp_parse_expr PARAMS ((cpp_reader *));
extern bool _cpp_parse_expr PARAMS ((cpp_reader *));
extern struct op *_cpp_expand_op_stack PARAMS ((cpp_reader *));
/* In cpplex.c */
extern cpp_token *_cpp_temp_token PARAMS ((cpp_reader *));
......
......@@ -535,6 +535,9 @@ cpp_create_reader (lang)
pfile->a_buff = _cpp_get_buff (pfile, 0);
pfile->u_buff = _cpp_get_buff (pfile, 0);
/* The expression parser stack. */
_cpp_expand_op_stack (pfile);
/* Initialise the buffer obstack. */
gcc_obstack_init (&pfile->buffer_ob);
......@@ -556,6 +559,7 @@ cpp_destroy (pfile)
free_chain (CPP_OPTION (pfile, pending)->include_head);
free (CPP_OPTION (pfile, pending));
free (pfile->op_stack);
while (CPP_BUFFER (pfile) != NULL)
_cpp_pop_buffer (pfile);
......
......@@ -1366,7 +1366,7 @@ do_if (pfile)
int skip = 1;
if (! pfile->state.skipping)
skip = _cpp_parse_expr (pfile) == 0;
skip = _cpp_parse_expr (pfile) == false;
push_conditional (pfile, skip, T_IF, pfile->mi_ind_cmacro);
}
......
......@@ -58,7 +58,7 @@ struct file_name_map_list;
#define CPP_LAST_EQ CPP_MAX
#define CPP_FIRST_DIGRAPH CPP_HASH
#define CPP_LAST_PUNCTUATOR CPP_DOT_STAR
#define CPP_LAST_CPP_OP CPP_EOF
#define CPP_LAST_CPP_OP CPP_LESS_EQ
#define TTYPE_TABLE \
OP(CPP_EQ = 0, "=") \
......@@ -86,13 +86,13 @@ struct file_name_map_list;
OP(CPP_COMMA, ",") /* grouping */ \
OP(CPP_OPEN_PAREN, "(") \
OP(CPP_CLOSE_PAREN, ")") \
TK(CPP_EOF, SPELL_NONE) \
OP(CPP_EQ_EQ, "==") /* compare */ \
OP(CPP_NOT_EQ, "!=") \
OP(CPP_GREATER_EQ, ">=") \
OP(CPP_LESS_EQ, "<=") \
\
/* These 3 are special in preprocessor expressions. */ \
TK(CPP_EOF, SPELL_NONE) \
/* These two are unary + / - in preprocessor expressions. */ \
OP(CPP_PLUS_EQ, "+=") /* math */ \
OP(CPP_MINUS_EQ, "-=") \
\
......
2002-04-28 Neil Booth <neil@daikokuya.demon.co.uk>
* gcc.dg/cpp/if-mop.c: Update.
* gcc.dg/cpp/if-mpar.c: Add test.
* gcc.dg/cpp/if-oppr.c: Update.
2002-04-28 Franz Sirl <Franz.Sirl-kernel@lauterbach.com>
PR c/6343
......
......@@ -12,7 +12,7 @@
#if ~ /* { dg-error "no right op" "no unary operand" } */
#endif
#if 3 + * 6 + 4 /* { dg-error "no left op" "no left operand" } */
#if 3 + * 6 + 4 /* { dg-error "no right op" "no right operand" } */
#endif
#if 2 ~2 /* { dg-error "missing bin" "no binary operator" } */
......
......@@ -19,3 +19,6 @@
#if 4) /* { dg-error "missing '\\('" "missing '(' no. 3" } */
#endif
#if ( /* { dg-error "missing '\\)'" "missing ')' no. 3" } */
#endif
......@@ -20,7 +20,7 @@
#endif
/* , not higher than ?. This is not a syntax error if it is. */
#if 1 ? 0, 1: 1 /* { dg-error "syntax" "? higher precedence than ," } */
#if 1 ? 0, 1: 1 /* { dg-error "without" "? higher precedence than ," } */
#error
#endif
......
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