#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,
%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 */
%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
%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
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); }
;
| declspecs_ts setspecs initdecls ';'
{ POP_DECLSPEC_STACK; }
| declspecs ';'
- { shadow_tag ($1); }
+ { shadow_tag (finish_declspecs ($1)); }
| error ';'
| error '}'
| ';'
\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
| 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
| 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
| '(' 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);
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;
| 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"); }
prefix_attributes = NULL_TREE;
current_declspecs = build_null_declspecs ();
}
+ current_declspecs = finish_declspecs (current_declspecs);
all_prefix_attributes = prefix_attributes; }
;
| declspecs_nots setspecs notype_nested_function
{ POP_DECLSPEC_STACK; }
| declspecs ';'
- { shadow_tag ($1); }
+ { shadow_tag (finish_declspecs ($1)); }
| extension decl
{ RESTORE_EXT_FLAGS ($1); }
;
typespec_reserved_nonattr:
TYPESPEC
- { OBJC_NEED_RAW_IDENTIFIER (1); }
+ { OBJC_NEED_RAW_IDENTIFIER (1);
+ $$.kind = ctsk_resword;
+ $$.spec = $1; }
| structsp_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--;
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. */
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)
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;
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;
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"); }
;
maybecomma_warn:
/* empty */
| ','
- { if (pedantic && ! flag_isoc99)
+ { if (pedantic && !flag_isoc99)
pedwarn ("comma at end of enumerator list"); }
;
/* 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; }
| 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; }
typename:
declspecs_nosc
{ pending_xref_error ();
- $<dsptype>$ = $1; }
+ $<dsptype>$ = finish_declspecs ($1); }
absdcl
{ $$ = XOBNEW (&parser_obstack, struct c_type_name);
$$->specs = $<dsptype>2;
extension:
EXTENSION
- { $$ = SAVE_EXT_FLAGS();
+ { $$ = SAVE_EXT_FLAGS ();
pedantic = 0;
warn_pointer_arith = 0;
warn_traditional = 0;
}
}
+#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"