OSDN Git Service

* c-tree.h (enum c_typespec_kind, struct c_typespec,
[pf3gnuchains/gcc-fork.git] / gcc / c-parse.in
index 20ed784..7542c39 100644 (file)
@@ -52,7 +52,6 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 #include "ggc.h"
 #include "c-common.h"
 
-/* Like YYERROR but do call yyerror.  */
 #define YYERROR1 { yyerror ("syntax error"); YYERROR; }
 
 /* Like the default stack expander, except (1) use realloc when possible,
@@ -102,8 +101,8 @@ do {                                                                        \
 %union {long itype; tree ttype; void *otype; struct c_expr exprtype;
        struct c_arg_info *arginfotype; struct c_declarator *dtrtype;
        struct c_type_name *typenametype; struct c_parm *parmtype;
-       struct c_declspecs *dsptype; enum tree_code code;
-       location_t location; }
+       struct c_declspecs *dsptype; struct c_typespec tstype;
+       enum tree_code code; location_t location; }
 
 /* All identifiers that are not reserved words
    and are not declared typedefs in the current block */
@@ -203,9 +202,9 @@ do {                                                                        \
 %type <dsptype> declspecs_ts_nosa declspecs_nots_nosa
 %type <dsptype> declspecs_nosc_ts declspecs_nosc_nots declspecs_nosc declspecs
 %type <dsptype> maybe_type_quals_attrs
-%type <ttype> typespec_nonattr typespec_attr
-%type <ttype> typespec_reserved_nonattr typespec_reserved_attr
-%type <ttype> typespec_nonreserved_nonattr
+%type <tstype> typespec_nonattr typespec_attr
+%type <tstype> typespec_reserved_nonattr typespec_reserved_attr
+%type <tstype> typespec_nonreserved_nonattr
 %type <ttype> offsetof_member_designator
 
 %type <ttype> scspec SCSPEC STATIC TYPESPEC TYPE_QUAL maybe_volatile
@@ -227,7 +226,7 @@ do {                                                                        \
 %type <dtrtype> parm_declarator_starttypename parm_declarator_nostarttypename
 %type <dtrtype> array_declarator
 
-%type <ttype> structsp_attr structsp_nonattr
+%type <tstype> structsp_attr structsp_nonattr
 %type <ttype> component_decl_list component_decl_list2
 %type <ttype> component_decl components components_notype component_declarator
 %type <ttype> component_notype_declarator
@@ -386,7 +385,7 @@ extdefs:
        save_obstack_position { $<dsptype>$ = NULL; } extdef
                { obstack_free (&parser_obstack, $1); }
        | extdefs save_obstack_position
-               { $<dsptype>$ = NULL; ggc_collect(); } extdef
+               { $<dsptype>$ = NULL; ggc_collect (); } extdef
                { obstack_free (&parser_obstack, $2); }
        ;
 
@@ -420,7 +419,7 @@ datadef:
        | declspecs_ts setspecs initdecls ';'
                { POP_DECLSPEC_STACK; }
        | declspecs ';'
-         { shadow_tag ($1); }
+         { shadow_tag (finish_declspecs ($1)); }
        | error ';'
        | error '}'
        | ';'
@@ -430,8 +429,8 @@ datadef:
 \f
 fndef:
          declspecs_ts setspecs declarator
-               { if (! start_function (current_declspecs, $3,
-                                       all_prefix_attributes))
+               { if (!start_function (current_declspecs, $3,
+                                      all_prefix_attributes))
                    YYERROR1;
                }
          old_style_parm_decls save_location
@@ -443,8 +442,8 @@ fndef:
        | declspecs_ts setspecs declarator error
                { POP_DECLSPEC_STACK; }
        | declspecs_nots setspecs notype_declarator
-               { if (! start_function (current_declspecs, $3,
-                                       all_prefix_attributes))
+               { if (!start_function (current_declspecs, $3,
+                                      all_prefix_attributes))
                    YYERROR1;
                }
          old_style_parm_decls save_location
@@ -456,8 +455,8 @@ fndef:
        | declspecs_nots setspecs notype_declarator error
                { POP_DECLSPEC_STACK; }
        | setspecs notype_declarator
-               { if (! start_function (current_declspecs, $2,
-                                       all_prefix_attributes))
+               { if (!start_function (current_declspecs, $2,
+                                      all_prefix_attributes))
                    YYERROR1;
                }
          old_style_parm_decls save_location
@@ -677,6 +676,11 @@ primary:
        | '(' typename ')' '{'
                { start_init (NULL_TREE, NULL, 0);
                  $<ttype>$ = groktypename ($2);
+                 if (C_TYPE_VARIABLE_SIZE ($<ttype>$))
+                   {
+                     error ("compound literal has variable size");
+                     $<ttype>$ = error_mark_node;
+                   }
                  really_start_incremental_init ($<ttype>$); }
          initlist_maybe_comma '}'  %prec UNARY
                { struct c_expr init = pop_init_level (0);
@@ -685,7 +689,7 @@ primary:
                  finish_init ();
                  maybe_warn_string_init (type, init);
 
-                 if (pedantic && ! flag_isoc99)
+                 if (pedantic && !flag_isoc99)
                    pedwarn ("ISO C90 forbids compound literals");
                  $$.value = build_compound_literal (type, constructor);
                  $$.original_code = ERROR_MARK;
@@ -835,7 +839,7 @@ datadecl:
        | declspecs_nots_nosa setspecs notype_initdecls ';'
                { POP_DECLSPEC_STACK; }
        | declspecs_ts_nosa ';'
-               { shadow_tag_warned ($1, 1);
+               { shadow_tag_warned (finish_declspecs ($1), 1);
                  pedwarn ("empty declaration"); }
        | declspecs_nots_nosa ';'
                { pedwarn ("empty declaration"); }
@@ -868,6 +872,7 @@ setspecs: /* empty */
                      prefix_attributes = NULL_TREE;
                      current_declspecs = build_null_declspecs ();
                    }
+                 current_declspecs = finish_declspecs (current_declspecs);
                  all_prefix_attributes = prefix_attributes; }
        ;
 
@@ -888,7 +893,7 @@ decl:
        | declspecs_nots setspecs notype_nested_function
                { POP_DECLSPEC_STACK; }
        | declspecs ';'
-               { shadow_tag ($1); }
+               { shadow_tag (finish_declspecs ($1)); }
        | extension decl
                { RESTORE_EXT_FLAGS ($1); }
        ;
@@ -1257,7 +1262,9 @@ typespec_attr:
 
 typespec_reserved_nonattr:
          TYPESPEC
-               { OBJC_NEED_RAW_IDENTIFIER (1); }
+               { OBJC_NEED_RAW_IDENTIFIER (1);
+                 $$.kind = ctsk_resword;
+                 $$.spec = $1; }
        | structsp_nonattr
        ;
 
@@ -1269,17 +1276,21 @@ typespec_nonreserved_nonattr:
          TYPENAME
                { /* For a typedef name, record the meaning, not the name.
                     In case of `foo foo, bar;'.  */
-                 $$ = lookup_name ($1); }
+                 $$.kind = ctsk_typedef;
+                 $$.spec = lookup_name ($1); }
 @@ifobjc
        | CLASSNAME protocolrefs
-               { $$ = objc_get_protocol_qualified_type ($1, $2); }
+               { $$.kind = ctsk_objc;
+                 $$.spec = objc_get_protocol_qualified_type ($1, $2); }
        | OBJECTNAME protocolrefs
-               { $$ = objc_get_protocol_qualified_type ($1, $2); }
+               { $$.kind = ctsk_objc;
+                 $$.spec = objc_get_protocol_qualified_type ($1, $2); }
 
 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>"
    - nisse@lysator.liu.se */
         | non_empty_protocolrefs
-                { $$ = objc_get_protocol_qualified_type (NULL_TREE, $1); }
+                { $$.kind = ctsk_objc;
+                 $$.spec = objc_get_protocol_qualified_type (NULL_TREE, $1); }
 @@end_ifobjc
        | typeof '(' expr ')'
                { skip_evaluation--;
@@ -1287,11 +1298,17 @@ typespec_nonreserved_nonattr:
                  if (TREE_CODE ($3.value) == COMPONENT_REF
                      && DECL_C_BIT_FIELD (TREE_OPERAND ($3.value, 1)))
                    error ("%<typeof%> applied to a bit-field");
-                 $$ = TREE_TYPE ($3.value);
-                 pop_maybe_used (variably_modified_type_p ($$, NULL_TREE)); }
+                 $$.kind = ctsk_typeof;
+                 $$.spec = TREE_TYPE ($3.value);
+                 pop_maybe_used (variably_modified_type_p ($$.spec,
+                                                           NULL_TREE)); }
        | typeof '(' typename ')'
-               { skip_evaluation--; in_typeof--; $$ = groktypename ($3);
-                 pop_maybe_used (variably_modified_type_p ($$, NULL_TREE)); }
+               { skip_evaluation--;
+                 in_typeof--;
+                 $$.kind = ctsk_typeof;
+                 $$.spec = groktypename ($3);
+                 pop_maybe_used (variably_modified_type_p ($$.spec,
+                                                           NULL_TREE)); }
        ;
 
 /* typespec_nonreserved_attr does not exist.  */
@@ -1427,7 +1444,7 @@ initlist1:
    It may use braces.  */
 initelt:
          designator_list '=' initval
-               { if (pedantic && ! flag_isoc99)
+               { if (pedantic && !flag_isoc99)
                    pedwarn ("ISO C90 forbids specifying subobject to initialize"); }
        | designator initval
                { if (pedantic)
@@ -1473,8 +1490,8 @@ nested_function:
                    pedwarn ("ISO C forbids nested functions");
 
                  push_function_context ();
-                 if (! start_function (current_declspecs, $1,
-                                       all_prefix_attributes))
+                 if (!start_function (current_declspecs, $1,
+                                      all_prefix_attributes))
                    {
                      pop_function_context ();
                      YYERROR1;
@@ -1503,8 +1520,8 @@ notype_nested_function:
                    pedwarn ("ISO C forbids nested functions");
 
                  push_function_context ();
-                 if (! start_function (current_declspecs, $1,
-                                       all_prefix_attributes))
+                 if (!start_function (current_declspecs, $1,
+                                      all_prefix_attributes))
                    {
                      pop_function_context ();
                      YYERROR1;
@@ -1634,47 +1651,55 @@ enum_head:
 
 structsp_attr:
          struct_head identifier '{'
-               { $$ = start_struct (RECORD_TYPE, $2);
+               { $<ttype>$ = start_struct (RECORD_TYPE, $2);
                  /* Start scope of tag before parsing components.  */
                }
          component_decl_list '}' maybe_attribute
-               { $$ = finish_struct ($<ttype>4, nreverse ($5),
-                                     chainon ($1, $7)); }
+               { $$.spec = finish_struct ($<ttype>4, nreverse ($5),
+                                          chainon ($1, $7));
+                 $$.kind = ctsk_tagdef; }
        | struct_head '{' component_decl_list '}' maybe_attribute
-               { $$ = finish_struct (start_struct (RECORD_TYPE, NULL_TREE),
-                                     nreverse ($3), chainon ($1, $5));
+               { $$.spec = finish_struct (start_struct (RECORD_TYPE,
+                                                        NULL_TREE),
+                                          nreverse ($3), chainon ($1, $5));
+                 $$.kind = ctsk_tagdef;
                }
        | union_head identifier '{'
-               { $$ = start_struct (UNION_TYPE, $2); }
+               { $<ttype>$ = start_struct (UNION_TYPE, $2); }
          component_decl_list '}' maybe_attribute
-               { $$ = finish_struct ($<ttype>4, nreverse ($5),
-                                     chainon ($1, $7)); }
+               { $$.spec = finish_struct ($<ttype>4, nreverse ($5),
+                                          chainon ($1, $7));
+                 $$.kind = ctsk_tagdef; }
        | union_head '{' component_decl_list '}' maybe_attribute
-               { $$ = finish_struct (start_struct (UNION_TYPE, NULL_TREE),
-                                     nreverse ($3), chainon ($1, $5));
+               { $$.spec = finish_struct (start_struct (UNION_TYPE,
+                                                        NULL_TREE),
+                                          nreverse ($3), chainon ($1, $5));
+                 $$.kind = ctsk_tagdef;
                }
        | enum_head identifier '{'
-               { $$ = start_enum ($2); }
+               { $<ttype>$ = start_enum ($2); }
          enumlist maybecomma_warn '}' maybe_attribute
-               { $$ = finish_enum ($<ttype>4, nreverse ($5),
-                                   chainon ($1, $8)); }
+               { $$.spec = finish_enum ($<ttype>4, nreverse ($5),
+                                        chainon ($1, $8));
+                 $$.kind = ctsk_tagdef; }
        | enum_head '{'
-               { $$ = start_enum (NULL_TREE); }
+               { $<ttype>$ = start_enum (NULL_TREE); }
          enumlist maybecomma_warn '}' maybe_attribute
-               { $$ = finish_enum ($<ttype>3, nreverse ($4),
-                                   chainon ($1, $7)); }
+               { $$.spec = finish_enum ($<ttype>3, nreverse ($4),
+                                        chainon ($1, $7));
+                 $$.kind = ctsk_tagdef; }
        ;
 
 structsp_nonattr:
          struct_head identifier
-               { $$ = xref_tag (RECORD_TYPE, $2); }
+               { $$ = parser_xref_tag (RECORD_TYPE, $2); }
        | union_head identifier
-               { $$ = xref_tag (UNION_TYPE, $2); }
+               { $$ = parser_xref_tag (UNION_TYPE, $2); }
        | enum_head identifier
-               { $$ = xref_tag (ENUMERAL_TYPE, $2);
+               { $$ = parser_xref_tag (ENUMERAL_TYPE, $2);
                  /* In ISO C, enumerated types can be referred to
                     only if already defined.  */
-                 if (pedantic && !COMPLETE_TYPE_P ($$))
+                 if (pedantic && !COMPLETE_TYPE_P ($$.spec))
                    pedwarn ("ISO C forbids forward references to %<enum%> types"); }
        ;
 
@@ -1686,7 +1711,7 @@ maybecomma:
 maybecomma_warn:
          /* empty */
        | ','
-               { if (pedantic && ! flag_isoc99)
+               { if (pedantic && !flag_isoc99)
                    pedwarn ("comma at end of enumerator list"); }
        ;
 
@@ -1733,9 +1758,6 @@ component_decl:
                  /* Support for unnamed structs or unions as members of
                     structs or unions (which is [a] useful and [b] supports
                     MS P-SDK).  */
-                 if (pedantic)
-                   pedwarn ("ISO C doesn't support unnamed structs/unions");
-
                  $$ = grokfield (build_id_declarator (NULL_TREE),
                                  current_declspecs, NULL_TREE);
                  POP_DECLSPEC_STACK; }
@@ -1745,7 +1767,7 @@ component_decl:
        | declspecs_nosc_nots
                { if (pedantic)
                    pedwarn ("ISO C forbids member declarations with no members");
-                 shadow_tag_warned ($1, pedantic);
+                 shadow_tag_warned (finish_declspecs ($1), pedantic);
                  $$ = NULL_TREE; }
        | error
                { $$ = NULL_TREE; }
@@ -1823,7 +1845,7 @@ enumerator:
 typename:
          declspecs_nosc
                { pending_xref_error ();
-                 $<dsptype>$ = $1; }
+                 $<dsptype>$ = finish_declspecs ($1); }
          absdcl
                { $$ = XOBNEW (&parser_obstack, struct c_type_name);
                  $$->specs = $<dsptype>2;
@@ -2562,7 +2584,7 @@ identifiers_or_typenames:
 
 extension:
        EXTENSION
-               { $$ = SAVE_EXT_FLAGS();
+               { $$ = SAVE_EXT_FLAGS ();
                  pedantic = 0;
                  warn_pointer_arith = 0;
                  warn_traditional = 0;
@@ -3550,4 +3572,21 @@ c_parse_file (void)
     }
 }
 
+#ifdef __XGETTEXT__
+/* Depending on the version of Bison used to compile this grammar,
+   it may issue generic diagnostics spelled "syntax error" or
+   "parse error".  To prevent this from changing the translation
+   template randomly, we list all the variants of this particular
+   diagnostic here.  Translators: there is no fine distinction
+   between diagnostics with "syntax error" in them, and diagnostics
+   with "parse error" in them.  It's okay to give them both the same
+   translation.  */
+const char d1[] = N_("syntax error");
+const char d2[] = N_("parse error");
+const char d3[] = N_("syntax error; also virtual memory exhausted");
+const char d4[] = N_("parse error; also virtual memory exhausted");
+const char d5[] = N_("syntax error: cannot back up");
+const char d6[] = N_("parse error: cannot back up");
+#endif
+
 #include "gt-c-parse.h"