From 42e651a63cef14d99224c6ce1bf5dba9fb6d5e7a Mon Sep 17 00:00:00 2001 From: Richard Stallman Date: Fri, 23 Jul 1993 19:19:04 +0000 Subject: [PATCH] (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 --- gcc/c-parse.in | 113 ++++++++++++++++++++++++++++++------------------- 1 file changed, 69 insertions(+), 44 deletions(-) diff --git a/gcc/c-parse.in b/gcc/c-parse.in index a62e29200d1..bae5736185b 100644 --- a/gcc/c-parse.in +++ b/gcc/c-parse.in @@ -176,7 +176,7 @@ void yyerror (); %type declmods typespec typespecqual_reserved %type SCSPEC TYPESPEC TYPE_QUAL nonempty_type_quals maybe_type_qual %type initdecls notype_initdecls initdcl notype_initdcl -%type init initlist maybeasm +%type init maybeasm %type asm_operands nonnull_asm_operands asm_operand asm_clobbers %type 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 '=' - { $$ = start_decl ($1, current_declspecs, 1); } + { $$ = start_decl ($1, current_declspecs, 1); + start_init ($$, $2, global_bindings_p ()); } init /* Note how the declaration of the variable is in effect while its init is parsed! */ - { decl_attributes ($5, $3); + { finish_init (); + decl_attributes ($5, $3); finish_decl ($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 '=' - { $$ = start_decl ($1, current_declspecs, 1); } + { $$ = start_decl ($1, current_declspecs, 1); + start_init ($$, $2, global_bindings_p ()); } init /* Note how the declaration of the variable is in effect while its init is parsed! */ - { decl_attributes ($5, $3); + { finish_init (); + decl_attributes ($5, $3); finish_decl ($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 ();