#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 */
%token BREAK CONTINUE RETURN GOTO ASM_KEYWORD TYPEOF ALIGNOF
%token ATTRIBUTE EXTENSION LABEL
%token REALPART IMAGPART VA_ARG CHOOSE_EXPR TYPES_COMPATIBLE_P
-%token PTR_VALUE PTR_BASE PTR_EXTENT
%token FUNC_NAME OFFSETOF
/* Add precedence rules to solve dangling else s/r conflict */
Objective C, so that the token codes are the same in both. */
%token AT_INTERFACE AT_IMPLEMENTATION AT_END AT_SELECTOR AT_DEFS AT_ENCODE
%token CLASSNAME AT_PUBLIC AT_PRIVATE AT_PROTECTED AT_PROTOCOL
-%token OBJECTNAME AT_CLASS AT_ALIAS
+%token AT_CLASS AT_ALIAS
%token AT_THROW AT_TRY AT_CATCH AT_FINALLY AT_SYNCHRONIZED
%token OBJC_STRING
%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
%type <ttype> selectorarg keywordnamelist keywordname objcencodeexpr
%type <ttype> non_empty_protocolrefs protocolrefs identifier_list objcprotocolexpr
-%type <ttype> CLASSNAME OBJECTNAME OBJC_STRING OBJC_TYPE_QUAL
+%type <ttype> CLASSNAME OBJC_STRING OBJC_TYPE_QUAL
%type <ttype> superclass objc_quals objc_qual objc_typename
%type <itype> objc_try_catch_stmt optellipsis
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); }
;
datadef:
setspecs notype_initdecls ';'
- { if (pedantic)
- error ("ISO C forbids data definition with no type or storage class");
- else
- warning ("data definition has no type or storage class");
-
+ { pedwarn ("data definition has no type or storage class");
POP_DECLSPEC_STACK; }
| declspecs_nots setspecs notype_initdecls ';'
{ POP_DECLSPEC_STACK; }
\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
IDENTIFIER
| TYPENAME
@@ifobjc
- | OBJECTNAME
| CLASSNAME
@@end_ifobjc
;
| '(' 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;
c = fold ($3.value);
STRIP_NOPS (c);
if (TREE_CODE (c) != INTEGER_CST)
- error ("first argument to __builtin_choose_expr not"
+ error ("first argument to %<__builtin_choose_expr%> not"
" a constant");
$$ = integer_zerop (c) ? $7 : $5;
}
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); }
- | OBJECTNAME protocolrefs
- { $$ = objc_get_protocol_qualified_type ($1, $2); }
+ { $$.kind = ctsk_objc;
+ $$.spec = objc_get_protocol_qualified_type ($1, $2); }
+ | TYPENAME non_empty_protocolrefs
+ { $$.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
+ | array_designator initval
{ if (pedantic)
pedwarn ("obsolete use of designated initializer without %<=%>"); }
| identifier ':'
designator:
'.' identifier
{ set_init_label ($2); }
- | '[' expr_no_commas ELLIPSIS expr_no_commas ']'
+ | array_designator
+ ;
+
+array_designator:
+ '[' expr_no_commas ELLIPSIS expr_no_commas ']'
{ set_init_index ($2.value, $4.value);
if (pedantic)
pedwarn ("ISO C forbids specifying range of elements to initialize"); }
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;
{ $$ = make_pointer_declarator ($2, $3); }
| TYPENAME
{ $$ = build_id_declarator ($1); }
-@@ifobjc
- | OBJECTNAME
- { $$ = build_id_declarator ($1); }
-@@end_ifobjc
;
/* Kinds of declarator that can appear in a parameter list
{ $$ = set_array_declarator_inner ($2, $1, false); }
| TYPENAME
{ $$ = build_id_declarator ($1); }
-@@ifobjc
- | OBJECTNAME
- { $$ = build_id_declarator ($1); }
-@@end_ifobjc
;
parm_declarator_nostarttypename:
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; }
compstmt_primary_start:
'(' '{'
- { if (current_function_decl == 0)
+ { if (cur_stmt_list == NULL)
{
error ("braced-group within expression allowed "
"only inside a function");
extension:
EXTENSION
- { $$ = SAVE_EXT_FLAGS();
+ { $$ = SAVE_EXT_FLAGS ();
pedantic = 0;
warn_pointer_arith = 0;
warn_traditional = 0;
IDENTIFIER
| TYPENAME
| CLASSNAME
- | OBJECTNAME
| reservedwords
;
ENUM | STRUCT | UNION | IF | ELSE | WHILE | DO | FOR
| SWITCH | CASE | DEFAULT | BREAK | CONTINUE | RETURN
| GOTO | ASM_KEYWORD | SIZEOF | TYPEOF | ALIGNOF
- | TYPESPEC | TYPE_QUAL
+ | TYPESPEC | TYPE_QUAL | OBJC_TYPE_QUAL
;
objc_qual:
{ "__inline", RID_INLINE, 0 },
{ "__inline__", RID_INLINE, 0 },
{ "__label__", RID_LABEL, 0 },
- { "__ptrbase", RID_PTRBASE, 0 },
- { "__ptrbase__", RID_PTRBASE, 0 },
- { "__ptrextent", RID_PTREXTENT, 0 },
- { "__ptrextent__", RID_PTREXTENT, 0 },
- { "__ptrvalue", RID_PTRVALUE, 0 },
- { "__ptrvalue__", RID_PTRVALUE, 0 },
{ "__real", RID_REALPART, 0 },
{ "__real__", RID_REALPART, 0 },
{ "__restrict", RID_RESTRICT, 0 },
{ "while", RID_WHILE, 0 },
@@ifobjc
- { "id", RID_ID, D_OBJC },
/* These objc keywords are recognized only immediately after
an '@'. */
/* RID_IMAGPART */ IMAGPART,
/* RID_REALPART */ REALPART,
/* RID_LABEL */ LABEL,
- /* RID_PTRBASE */ PTR_BASE,
- /* RID_PTREXTENT */ PTR_EXTENT,
- /* RID_PTRVALUE */ PTR_VALUE,
/* RID_CHOOSE_EXPR */ CHOOSE_EXPR,
/* RID_TYPES_COMPATIBLE_P */ TYPES_COMPATIBLE_P,
/* RID_STATCAST */ 0,
/* Objective C */
- /* RID_ID */ OBJECTNAME,
/* RID_AT_ENCODE */ AT_ENCODE,
/* RID_AT_END */ AT_END,
/* RID_AT_CLASS */ AT_CLASS,
enum rid rid_code = C_RID_CODE (yylval.ttype);
@@ifobjc
- /* Turn non-typedefed refs to "id" into plain identifiers; this
- allows constructs like "void foo(id id);" to work. */
- if (rid_code == RID_ID)
- {
- decl = lookup_name (yylval.ttype);
- if (decl == NULL_TREE || TREE_CODE (decl) != TYPE_DECL)
- return IDENTIFIER;
- }
-
if (!OBJC_IS_AT_KEYWORD (rid_code)
&& (!OBJC_IS_PQ_KEYWORD (rid_code) || objc_pq_context))
@@end_ifobjc
{
case IDENTIFIER:
case TYPENAME:
- case OBJECTNAME:
case TYPESPEC:
case TYPE_QUAL:
case SCSPEC:
}
}
+#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"