2002-08-12 Alexandre Oliva * c-tree.h (skip_evaluation): Move declaration... * c-common.h: ... here. * c-typeck.c (build_external_ref): Don't assemble_external nor mark a tree as used if skip_evaluation is set. * c-parse.in (typeof): New non-terminal to set skip_evaluation around TYPEOF. (typespec_nonreserved_nonattr): Use it. --- gcc/cp/parse.y.jj 2002-05-02 12:14:49.000000000 +0200 +++ gcc/cp/parse.y 2002-08-22 23:28:34.000000000 +0200 @@ -1255,16 +1255,20 @@ unary_expr: /* Refer to the address of a label as a pointer. */ | ANDAND identifier { $$ = finish_label_address_expr ($2); } - | SIZEOF unary_expr %prec UNARY - { $$ = finish_sizeof ($2); } - | SIZEOF '(' type_id ')' %prec HYPERUNARY + | sizeof unary_expr %prec UNARY + { $$ = finish_sizeof ($2); + skip_evaluation--; } + | sizeof '(' type_id ')' %prec HYPERUNARY { $$ = finish_sizeof (groktypename ($3.t)); - check_for_new_type ("sizeof", $3); } - | ALIGNOF unary_expr %prec UNARY - { $$ = finish_alignof ($2); } - | ALIGNOF '(' type_id ')' %prec HYPERUNARY - { $$ = finish_alignof (groktypename ($3.t)); - check_for_new_type ("alignof", $3); } + check_for_new_type ("sizeof", $3); + skip_evaluation--; } + | alignof unary_expr %prec UNARY + { $$ = finish_alignof ($2); + skip_evaluation--; } + | alignof '(' type_id ')' %prec HYPERUNARY + { $$ = finish_alignof (groktypename ($3.t)); + check_for_new_type ("alignof", $3); + skip_evaluation--; } /* The %prec EMPTY's here are required by the = init initializer syntax extension; see below. */ @@ -1989,6 +1993,18 @@ reserved_typespecquals: { $$ = tree_cons ($1, NULL_TREE, NULL_TREE); } ; +sizeof: + SIZEOF { skip_evaluation++; } + ; + +alignof: + ALIGNOF { skip_evaluation++; } + ; + +typeof: + TYPEOF { skip_evaluation++; } + ; + /* A typespec (but not a type qualifier). Once we have seen one of these in a declaration, if a typedef name appears then it is being redeclared. */ @@ -2000,12 +2016,14 @@ typespec: { $$.t = $1; $$.new_type_flag = 0; $$.lookups = NULL_TREE; } | complete_type_name { $$.t = $1; $$.new_type_flag = 0; $$.lookups = NULL_TREE; } - | TYPEOF '(' expr ')' + | typeof '(' expr ')' { $$.t = finish_typeof ($3); - $$.new_type_flag = 0; $$.lookups = NULL_TREE; } - | TYPEOF '(' type_id ')' + $$.new_type_flag = 0; $$.lookups = NULL_TREE; + skip_evaluation--; } + | typeof '(' type_id ')' { $$.t = groktypename ($3.t); - $$.new_type_flag = 0; $$.lookups = NULL_TREE; } + $$.new_type_flag = 0; $$.lookups = NULL_TREE; + skip_evaluation--; } | SIGOF '(' expr ')' { tree type = TREE_TYPE ($3); --- gcc/cp/decl2.c.jj 2002-07-27 01:31:05.000000000 +0200 +++ gcc/cp/decl2.c 2002-08-22 23:24:11.000000000 +0200 @@ -5179,7 +5179,8 @@ mark_used (decl) TREE_USED (decl) = 1; if (processing_template_decl) return; - assemble_external (decl); + if (!skip_evaluation) + assemble_external (decl); /* Is it a synthesized method that needs to be synthesized? */ if (TREE_CODE (decl) == FUNCTION_DECL --- gcc/c-tree.h.jj 2002-04-02 23:17:23.000000000 +0200 +++ gcc/c-tree.h 2002-08-22 23:24:34.000000000 +0200 @@ -287,11 +287,6 @@ extern int current_function_returns_null extern int current_function_returns_abnormally; -/* Nonzero means the expression being parsed will never be evaluated. - This is a count, since unevaluated expressions can nest. */ - -extern int skip_evaluation; - /* Nonzero means `$' can be in an identifier. */ extern int dollars_in_ident; --- gcc/c-common.h.jj 2002-04-17 15:34:36.000000000 +0200 +++ gcc/c-common.h 2002-08-22 23:24:11.000000000 +0200 @@ -464,6 +464,11 @@ extern int warn_conversion; extern int warn_long_long; +/* Nonzero means the expression being parsed will never be evaluated. + This is a count, since unevaluated expressions can nest. */ + +extern int skip_evaluation; + /* C types are partitioned into three subsets: object, function, and incomplete types. */ #define C_TYPE_OBJECT_P(type) \ --- gcc/c-typeck.c.jj 2002-03-23 12:02:51.000000000 +0100 +++ gcc/c-typeck.c 2002-08-22 23:24:11.000000000 +0200 @@ -1493,7 +1493,8 @@ build_external_ref (id, fun) if (TREE_TYPE (ref) == error_mark_node) return error_mark_node; - assemble_external (ref); + if (!skip_evaluation) + assemble_external (ref); TREE_USED (ref) = 1; if (TREE_CODE (ref) == CONST_DECL) --- gcc/c-parse.in.jj 2002-04-17 15:34:46.000000000 +0200 +++ gcc/c-parse.in 2002-08-22 23:24:11.000000000 +0200 @@ -534,6 +534,10 @@ alignof: ALIGNOF { skip_evaluation++; } ; +typeof: + TYPEOF { skip_evaluation++; } + ; + cast_expr: unary_expr | '(' typename ')' cast_expr %prec UNARY @@ -1376,10 +1380,10 @@ ifobjc | non_empty_protocolrefs { $$ = get_object_reference ($1); } end ifobjc - | TYPEOF '(' expr ')' - { $$ = TREE_TYPE ($3); } - | TYPEOF '(' typename ')' - { $$ = groktypename ($3); } + | typeof '(' expr ')' + { skip_evaluation--; $$ = TREE_TYPE ($3); } + | typeof '(' typename ')' + { skip_evaluation--; $$ = groktypename ($3); } ; /* typespec_nonreserved_attr does not exist. */