aboutsummaryrefslogtreecommitdiff
path: root/gcc/c-parse.in
diff options
context:
space:
mode:
authorRichard Stallman <rms@gnu.org>1993-07-23 19:19:04 +0000
committerRichard Stallman <rms@gnu.org>1993-07-23 19:19:04 +0000
commit42e651a63cef14d99224c6ce1bf5dba9fb6d5e7a (patch)
tree52618ce9a4ba955cb560b867b64d54054ce3d3ed /gcc/c-parse.in
parent3d06b1003fd4b4c7a431455e437288c181a36a5c (diff)
downloadgcc-42e651a63cef14d99224c6ce1bf5dba9fb6d5e7a.zip
gcc-42e651a63cef14d99224c6ce1bf5dba9fb6d5e7a.tar.gz
gcc-42e651a63cef14d99224c6ce1bf5dba9fb6d5e7a.tar.bz2
(cast_expr): Use new initializer parsing functions.
(initdcl, notype_initdcl): Likewise. (init): Likewise. (initlist_maybe_comma, initlist1): These replace initlist. (initelt): New nonterminal. Change specified index syntax to `[INDEX]='. Change specified field syntax to `.NAME='. From-SVN: r4977
Diffstat (limited to 'gcc/c-parse.in')
-rw-r--r--gcc/c-parse.in113
1 files changed, 69 insertions, 44 deletions
diff --git a/gcc/c-parse.in b/gcc/c-parse.in
index a62e292..bae5736 100644
--- a/gcc/c-parse.in
+++ b/gcc/c-parse.in
@@ -176,7 +176,7 @@ void yyerror ();
%type <ttype> declmods typespec typespecqual_reserved
%type <ttype> SCSPEC TYPESPEC TYPE_QUAL nonempty_type_quals maybe_type_qual
%type <ttype> initdecls notype_initdecls initdcl notype_initdcl
-%type <ttype> init initlist maybeasm
+%type <ttype> init maybeasm
%type <ttype> asm_operands nonnull_asm_operands asm_operand asm_clobbers
%type <ttype> maybe_attribute attribute_list attrib
@@ -456,9 +456,16 @@ cast_expr:
| '(' typename ')' cast_expr %prec UNARY
{ tree type = groktypename ($2);
$$ = build_c_cast (type, $4); }
- | '(' typename ')' '{' initlist maybecomma '}' %prec UNARY
- { tree type = groktypename ($2);
- char *name;
+ | '(' typename ')' '{'
+ { start_init (NULL_TREE, NULL, 0);
+ $2 = groktypename ($2);
+ really_start_incremental_init ($2); }
+ initlist_maybe_comma '}' %prec UNARY
+ { char *name;
+ tree result = pop_init_level (0);
+ tree type = $2;
+ finish_init ();
+
if (pedantic)
pedwarn ("ANSI C forbids constructor expressions");
if (TYPE_NAME (type) != 0)
@@ -470,8 +477,7 @@ cast_expr:
}
else
name = "";
- $$ = digest_init (type, build_nt (CONSTRUCTOR, NULL_TREE, nreverse ($5)),
- NULL_PTR, 0, 0, name);
+ $$ = result;
if (TREE_CODE (type) == ARRAY_TYPE && TYPE_SIZE (type) == 0)
{
int failure = complete_array_type (type, $$, 1);
@@ -1012,10 +1018,12 @@ maybeasm:
initdcl:
declarator maybeasm maybe_attribute '='
- { $<ttype>$ = start_decl ($1, current_declspecs, 1); }
+ { $<ttype>$ = start_decl ($1, current_declspecs, 1);
+ start_init ($<ttype>$, $2, global_bindings_p ()); }
init
/* Note how the declaration of the variable is in effect while its init is parsed! */
- { decl_attributes ($<ttype>5, $3);
+ { finish_init ();
+ decl_attributes ($<ttype>5, $3);
finish_decl ($<ttype>5, $6, $2); }
| declarator maybeasm maybe_attribute
{ tree d = start_decl ($1, current_declspecs, 0);
@@ -1025,10 +1033,12 @@ initdcl:
notype_initdcl:
notype_declarator maybeasm maybe_attribute '='
- { $<ttype>$ = start_decl ($1, current_declspecs, 1); }
+ { $<ttype>$ = start_decl ($1, current_declspecs, 1);
+ start_init ($<ttype>$, $2, global_bindings_p ()); }
init
/* Note how the declaration of the variable is in effect while its init is parsed! */
- { decl_attributes ($<ttype>5, $3);
+ { finish_init ();
+ decl_attributes ($<ttype>5, $3);
finish_decl ($<ttype>5, $6, $2); }
| notype_declarator maybeasm maybe_attribute
{ tree d = start_decl ($1, current_declspecs, 0);
@@ -1095,52 +1105,67 @@ attrib
NULL_TREE),
NULL_TREE); }
;
+
+/* Initializers. `init' is the entry point. */
init:
expr_no_commas
- | '{' '}'
- { $$ = build_nt (CONSTRUCTOR, NULL_TREE, NULL_TREE);
- if (pedantic)
- pedwarn ("ANSI C forbids empty initializer braces"); }
- | '{' initlist '}'
- { $$ = build_nt (CONSTRUCTOR, NULL_TREE, nreverse ($2)); }
- | '{' initlist ',' '}'
- { $$ = build_nt (CONSTRUCTOR, NULL_TREE, nreverse ($2)); }
+ | '{'
+ { really_start_incremental_init (NULL_TREE);
+ /* Note that the call to clear_momentary
+ is in process_init_element. */
+ push_momentary (); }
+ initlist_maybe_comma '}'
+ { $$ = pop_init_level (0);
+ pop_momentary (); }
+
| error
- { $$ = NULL_TREE; }
+ { $$ = error_mark_node;
+ pop_momentary (); }
;
-/* This chain is built in reverse order,
- and put in forward order where initlist is used. */
-initlist:
- init
- { $$ = build_tree_list (NULL_TREE, $1); }
- | initlist ',' init
- { $$ = tree_cons (NULL_TREE, $3, $1); }
+/* `initlist_maybe_comma' is the guts of an initializer in braces. */
+initlist_maybe_comma:
+ /* empty */
+ { if (pedantic)
+ pedwarn ("ANSI C forbids empty initializer braces"); }
+ | initlist1 maybecomma
+ ;
+
+initlist1:
+ initelt
+ | initlist1 ',' initelt
+ ;
+
+/* `initelt' is a single element of an initializer.
+ It may use braces. */
+initelt:
+ expr_no_commas
+ { process_init_element ($1); }
+ | '{'
+ { push_init_level (0); }
+ initlist_maybe_comma '}'
+ { process_init_element (pop_init_level (0)); }
+ | error
/* These are for labeled elements. The syntax for an array element
initializer conflicts with the syntax for an Objective-C message,
so don't include these productions in the Objective-C grammer. */
ifc
- | '[' expr_no_commas ELLIPSIS expr_no_commas ']' init
- { $$ = build_tree_list (tree_cons ($2, NULL_TREE,
- build_tree_list ($4, NULL_TREE)),
- $6); }
- | initlist ',' '[' expr_no_commas ELLIPSIS expr_no_commas ']' init
- { $$ = tree_cons (tree_cons ($4, NULL_TREE,
- build_tree_list ($6, NULL_TREE)),
- $8,
- $1); }
- | '[' expr_no_commas ']' init
- { $$ = build_tree_list ($2, $4); }
- | initlist ',' '[' expr_no_commas ']' init
- { $$ = tree_cons ($4, $6, $1); }
+ | '[' expr_no_commas ELLIPSIS expr_no_commas ']' '='
+ { set_init_index ($2, $4); }
+ initelt
+ | '[' expr_no_commas ']' '='
+ { set_init_index ($2, NULL_TREE); }
+ initelt
end ifc
- | identifier ':' init
- { $$ = build_tree_list ($1, $3); }
- | initlist ',' identifier ':' init
- { $$ = tree_cons ($3, $5, $1); }
+ | identifier ':'
+ { set_init_label ($1); }
+ initelt
+ | '.' identifier '='
+ { set_init_label ($2); }
+ initelt
;
-
+
nested_function:
declarator
{ push_c_function_context ();