Commit 42e651a6 by Richard Stallman

(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
parent 3d06b100
...@@ -176,7 +176,7 @@ void yyerror (); ...@@ -176,7 +176,7 @@ void yyerror ();
%type <ttype> declmods typespec typespecqual_reserved %type <ttype> declmods typespec typespecqual_reserved
%type <ttype> SCSPEC TYPESPEC TYPE_QUAL nonempty_type_quals maybe_type_qual %type <ttype> SCSPEC TYPESPEC TYPE_QUAL nonempty_type_quals maybe_type_qual
%type <ttype> initdecls notype_initdecls initdcl notype_initdcl %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> asm_operands nonnull_asm_operands asm_operand asm_clobbers
%type <ttype> maybe_attribute attribute_list attrib %type <ttype> maybe_attribute attribute_list attrib
...@@ -456,9 +456,16 @@ cast_expr: ...@@ -456,9 +456,16 @@ cast_expr:
| '(' typename ')' cast_expr %prec UNARY | '(' typename ')' cast_expr %prec UNARY
{ tree type = groktypename ($2); { tree type = groktypename ($2);
$$ = build_c_cast (type, $4); } $$ = build_c_cast (type, $4); }
| '(' typename ')' '{' initlist maybecomma '}' %prec UNARY | '(' typename ')' '{'
{ tree type = groktypename ($2); { start_init (NULL_TREE, NULL, 0);
char *name; $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) if (pedantic)
pedwarn ("ANSI C forbids constructor expressions"); pedwarn ("ANSI C forbids constructor expressions");
if (TYPE_NAME (type) != 0) if (TYPE_NAME (type) != 0)
...@@ -470,8 +477,7 @@ cast_expr: ...@@ -470,8 +477,7 @@ cast_expr:
} }
else else
name = ""; name = "";
$$ = digest_init (type, build_nt (CONSTRUCTOR, NULL_TREE, nreverse ($5)), $$ = result;
NULL_PTR, 0, 0, name);
if (TREE_CODE (type) == ARRAY_TYPE && TYPE_SIZE (type) == 0) if (TREE_CODE (type) == ARRAY_TYPE && TYPE_SIZE (type) == 0)
{ {
int failure = complete_array_type (type, $$, 1); int failure = complete_array_type (type, $$, 1);
...@@ -1012,10 +1018,12 @@ maybeasm: ...@@ -1012,10 +1018,12 @@ maybeasm:
initdcl: initdcl:
declarator maybeasm maybe_attribute '=' 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 init
/* Note how the declaration of the variable is in effect while its init is parsed! */ /* 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); } finish_decl ($<ttype>5, $6, $2); }
| declarator maybeasm maybe_attribute | declarator maybeasm maybe_attribute
{ tree d = start_decl ($1, current_declspecs, 0); { tree d = start_decl ($1, current_declspecs, 0);
...@@ -1025,10 +1033,12 @@ initdcl: ...@@ -1025,10 +1033,12 @@ initdcl:
notype_initdcl: notype_initdcl:
notype_declarator maybeasm maybe_attribute '=' 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 init
/* Note how the declaration of the variable is in effect while its init is parsed! */ /* 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); } finish_decl ($<ttype>5, $6, $2); }
| notype_declarator maybeasm maybe_attribute | notype_declarator maybeasm maybe_attribute
{ tree d = start_decl ($1, current_declspecs, 0); { tree d = start_decl ($1, current_declspecs, 0);
...@@ -1095,52 +1105,67 @@ attrib ...@@ -1095,52 +1105,67 @@ attrib
NULL_TREE), NULL_TREE),
NULL_TREE); } NULL_TREE); }
; ;
/* Initializers. `init' is the entry point. */
init: init:
expr_no_commas expr_no_commas
| '{' '}' | '{'
{ $$ = build_nt (CONSTRUCTOR, NULL_TREE, NULL_TREE); { really_start_incremental_init (NULL_TREE);
if (pedantic) /* Note that the call to clear_momentary
pedwarn ("ANSI C forbids empty initializer braces"); } is in process_init_element. */
| '{' initlist '}' push_momentary (); }
{ $$ = build_nt (CONSTRUCTOR, NULL_TREE, nreverse ($2)); } initlist_maybe_comma '}'
| '{' initlist ',' '}' { $$ = pop_init_level (0);
{ $$ = build_nt (CONSTRUCTOR, NULL_TREE, nreverse ($2)); } pop_momentary (); }
| error | error
{ $$ = NULL_TREE; } { $$ = error_mark_node;
pop_momentary (); }
; ;
/* This chain is built in reverse order, /* `initlist_maybe_comma' is the guts of an initializer in braces. */
and put in forward order where initlist is used. */ initlist_maybe_comma:
initlist: /* empty */
init { if (pedantic)
{ $$ = build_tree_list (NULL_TREE, $1); } pedwarn ("ANSI C forbids empty initializer braces"); }
| initlist ',' init | initlist1 maybecomma
{ $$ = tree_cons (NULL_TREE, $3, $1); } ;
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 /* These are for labeled elements. The syntax for an array element
initializer conflicts with the syntax for an Objective-C message, initializer conflicts with the syntax for an Objective-C message,
so don't include these productions in the Objective-C grammer. */ so don't include these productions in the Objective-C grammer. */
ifc ifc
| '[' expr_no_commas ELLIPSIS expr_no_commas ']' init | '[' expr_no_commas ELLIPSIS expr_no_commas ']' '='
{ $$ = build_tree_list (tree_cons ($2, NULL_TREE, { set_init_index ($2, $4); }
build_tree_list ($4, NULL_TREE)), initelt
$6); } | '[' expr_no_commas ']' '='
| initlist ',' '[' expr_no_commas ELLIPSIS expr_no_commas ']' init { set_init_index ($2, NULL_TREE); }
{ $$ = tree_cons (tree_cons ($4, NULL_TREE, initelt
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); }
end ifc end ifc
| identifier ':' init | identifier ':'
{ $$ = build_tree_list ($1, $3); } { set_init_label ($1); }
| initlist ',' identifier ':' init initelt
{ $$ = tree_cons ($3, $5, $1); } | '.' identifier '='
{ set_init_label ($2); }
initelt
; ;
nested_function: nested_function:
declarator declarator
{ push_c_function_context (); { push_c_function_context ();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment