From f6abb50a8a53adba2fdfdee15069890868f0d443 Mon Sep 17 00:00:00 2001 From: Brendan Kehoe Date: Mon, 13 Mar 1995 02:04:52 +0000 Subject: [PATCH] parse.y: New rules to allow attributes in a prefix position. * parse.y: New rules to allow attributes in a prefix position. (prefix_attributes): New variable. Pass it into cplus_decl_attributes. (setattr): New rule. (reserved_declspecs, declmods): Catch attributes here. * decl2.c (cplus_decl_attributes): Add PREFIX_ATTRIBUTES argument. * decl.c (duplicate_decls): Pass DECL_MACHINE_ATTRIBUTES to descendent typedef. (grokdeclarator): Added code to support machine attributes. * Makefile.in (stamp-parse): Expect 5 shift/reduce failures. From-SVN: r9172 --- gcc/cp/ChangeLog | 12 ++++++++++ gcc/cp/cp-tree.h | 1 + gcc/cp/decl.c | 6 +++++ gcc/cp/decl2.c | 6 ++--- gcc/cp/parse.y | 61 +++++++++++++++++++++++++++++------------------- 5 files changed, 59 insertions(+), 27 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 7984637caab..0cbb5de1821 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,15 @@ +Tue Mar 7 10:14:29 1995 Brendan Kehoe (brendan@lisa.cygnus.com) + + * parse.y: New rules to allow attributes in a prefix position. + (prefix_attributes): New variable. Pass it into cplus_decl_attributes. + (setattr): New rule. + (reserved_declspecs, declmods): Catch attributes here. + * decl2.c (cplus_decl_attributes): Add PREFIX_ATTRIBUTES argument. + * decl.c (duplicate_decls): Pass DECL_MACHINE_ATTRIBUTES to + descendent typedef. + (grokdeclarator): Added code to support machine attributes. + * Makefile.in (stamp-parse): Expect 5 shift/reduce failures. + Tue Feb 21 18:43:48 1995 Douglas Rupp (drupp@cs.washington.edu) * Make-lang.in, config-lang.in: ($exeext): New macro. diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index d39a88595a3..766e308e370 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -2011,6 +2011,7 @@ extern tree grokbitfield PROTO((tree, tree, tree)); extern tree groktypefield PROTO((tree, tree)); extern tree grokoptypename PROTO((tree, tree)); extern tree build_push_scope PROTO((tree, tree)); +extern void cplus_decl_attributes PROTO((tree, tree, tree)); extern tree constructor_name_full PROTO((tree)); extern tree constructor_name PROTO((tree)); extern void setup_vtbl_ptr PROTO((void)); diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 01547b0a766..aad3dfb04b0 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -2122,6 +2122,9 @@ duplicate_decls (newdecl, olddecl) int new_defines_function; tree previous_c_decl = NULL_TREE; + if (TREE_CODE_CLASS (TREE_CODE (olddecl)) == 'd') + DECL_MACHINE_ATTRIBUTES (newdecl) = DECL_MACHINE_ATTRIBUTES (olddecl); + types_match = decls_match (newdecl, olddecl); if (TREE_CODE (olddecl) != TREE_LIST) @@ -7157,6 +7160,7 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, raises) enum tree_code innermost_code = ERROR_MARK; int bitfield = 0; int size_varies = 0; + tree decl_machine_attr = NULL_TREE; /* Set this to error_mark_node for FIELD_DECLs we could not handle properly. All FIELD_DECLs we build here have `init' put into their DECL_INITIAL. */ tree init = NULL_TREE; @@ -7530,6 +7534,7 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, raises) else { type = TREE_TYPE (t); + decl_machine_attr = DECL_MACHINE_ATTRIBUTES (id); typedef_decl = t; } } @@ -9001,6 +9006,7 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, raises) decl = grokfndecl (ctype, type, declarator, virtualp, flags, quals, raises, friendp ? -1 : 0, publicp); + decl = build_decl_attribute_variant (decl, decl_machine_attr); if (decl == NULL_TREE) return NULL_TREE; diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index 1da4097c556..b0e5c00c569 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -1921,11 +1921,11 @@ build_push_scope (cname, name) return rval; } -void cplus_decl_attributes (decl, attributes) - tree decl, attributes; +void cplus_decl_attributes (decl, attributes, prefix_attributes) + tree decl, attributes, prefix_attributes; { if (decl && decl != void_type_node) - decl_attributes (decl, attributes, NULL_TREE); + decl_attributes (decl, attributes, prefix_attributes); } /* CONSTRUCTOR_NAME: diff --git a/gcc/cp/parse.y b/gcc/cp/parse.y index b85ffc9d499..c51c756700a 100644 --- a/gcc/cp/parse.y +++ b/gcc/cp/parse.y @@ -287,6 +287,7 @@ empty_parms () %{ /* List of types and structure classes of the current declaration. */ static tree current_declspecs; +static tree prefix_attributes = NULL_TREE; /* When defining an aggregate, this is the most recent one being defined. */ static tree current_aggr; @@ -504,7 +505,7 @@ template_def: momentary = suspend_momentary (); d = start_decl ($2, /*current_declspecs*/NULL_TREE, 0, $3); - cplus_decl_attributes (d, $5); + cplus_decl_attributes (d, $5, prefix_attributes); finish_decl (d, NULL_TREE, $4, 0, 0); end_template_decl ($1, d, 0, def); if (def) @@ -523,7 +524,7 @@ template_def: momentary = suspend_momentary (); d = start_decl ($3, current_declspecs, 0, $4); - cplus_decl_attributes (d, $6); + cplus_decl_attributes (d, $6, prefix_attributes); finish_decl (d, NULL_TREE, $5, 0, 0); end_template_decl ($1, d, 0, def); if (def) @@ -975,7 +976,7 @@ condition: current_declspecs = $1; $6 = suspend_momentary (); $$ = start_decl ($2, current_declspecs, 1, $3); - cplus_decl_attributes ($$, $5); + cplus_decl_attributes ($$, $5, prefix_attributes); } init { @@ -1724,6 +1725,10 @@ object: primary '.' } ; +setattrs: /* empty */ + { prefix_attributes = $0; } + ; + decl: /* Normal case: make this fast. */ typespec declarator ';' @@ -1833,6 +1838,10 @@ reserved_declspecs: warning ("`%s' is not at beginning of declaration", IDENTIFIER_POINTER ($2)); $$ = decl_tree_cons (NULL_TREE, $2, $$); } + | reserved_declspecs attributes setattrs + { $$ = $1; } + | attributes setattrs + { $$ = NULL_TREE; } ; /* List of just storage classes and type modifiers. @@ -1853,6 +1862,10 @@ declmods: IDENTIFIER_POINTER ($2)); $$ = decl_tree_cons (NULL_TREE, $2, $$); TREE_STATIC ($$) = TREE_STATIC ($1); } + | declmods attributes setattrs + { $$ = $1; } + | attributes setattrs + { $$ = NULL_TREE; } ; @@ -1968,7 +1981,7 @@ initdcl0: } $5 = suspend_momentary (); $$ = start_decl ($1, current_declspecs, 1, $2); - cplus_decl_attributes ($$, $4); } + cplus_decl_attributes ($$, $4, prefix_attributes); } init /* Note how the declaration of the variable is in effect while its init is parsed! */ { finish_decl ($6, $7, $3, 0, LOOKUP_ONLYCONVERTING); @@ -1987,20 +2000,20 @@ initdcl0: } $$ = suspend_momentary (); d = start_decl ($1, current_declspecs, 0, $2); - cplus_decl_attributes (d, $4); + cplus_decl_attributes (d, $4, prefix_attributes); finish_decl (d, NULL_TREE, $3, 0, 0); } ; initdcl: declarator exception_specification_opt maybeasm maybe_attribute '=' { $$ = start_decl ($1, current_declspecs, 1, $2); - cplus_decl_attributes ($$, $4); } + cplus_decl_attributes ($$, $4, prefix_attributes); } init /* Note how the declaration of the variable is in effect while its init is parsed! */ { finish_decl ($6, $7, $3, 0, LOOKUP_ONLYCONVERTING); } | declarator exception_specification_opt maybeasm maybe_attribute { $$ = start_decl ($1, current_declspecs, 0, $2); - cplus_decl_attributes ($$, $4); + cplus_decl_attributes ($$, $4, prefix_attributes); finish_decl ($$, NULL_TREE, $3, 0, 0); } ; @@ -2009,7 +2022,7 @@ notype_initdcl0: { current_declspecs = $0; $5 = suspend_momentary (); $$ = start_decl ($1, current_declspecs, 1, $2); - cplus_decl_attributes ($$, $4); } + cplus_decl_attributes ($$, $4, prefix_attributes); } init /* Note how the declaration of the variable is in effect while its init is parsed! */ { finish_decl ($6, $7, $3, 0, LOOKUP_ONLYCONVERTING); @@ -2019,7 +2032,7 @@ notype_initdcl0: current_declspecs = $0; $$ = suspend_momentary (); d = start_decl ($1, current_declspecs, 0, $2); - cplus_decl_attributes (d, $4); + cplus_decl_attributes (d, $4, prefix_attributes); finish_decl (d, NULL_TREE, $3, 0, 0); } ; @@ -2028,7 +2041,7 @@ nomods_initdcl0: { current_declspecs = NULL_TREE; $5 = suspend_momentary (); $$ = start_decl ($1, current_declspecs, 1, $2); - cplus_decl_attributes ($$, $4); } + cplus_decl_attributes ($$, $4, prefix_attributes); } init /* Note how the declaration of the variable is in effect while its init is parsed! */ { finish_decl ($6, $7, $3, 0, LOOKUP_ONLYCONVERTING); @@ -2038,7 +2051,7 @@ nomods_initdcl0: current_declspecs = NULL_TREE; $$ = suspend_momentary (); d = start_decl ($1, current_declspecs, 0, $2); - cplus_decl_attributes (d, $4); + cplus_decl_attributes (d, $4, prefix_attributes); finish_decl (d, NULL_TREE, $3, 0, 0); } ; @@ -2608,7 +2621,7 @@ component_decl_1: } | notype_declarator exception_specification_opt maybeasm maybe_attribute maybe_init { $$ = grokfield ($$, NULL_TREE, $2, $5, $3); - cplus_decl_attributes ($$, $4); } + cplus_decl_attributes ($$, $4, prefix_attributes); } | ':' expr_no_commas { $$ = grokbitfield (NULL_TREE, NULL_TREE, $2); } | error @@ -2626,12 +2639,12 @@ component_decl_1: { $$ = build_parse_node (CALL_EXPR, TREE_VALUE ($1), $3, $5); $$ = grokfield ($$, TREE_CHAIN ($1), $6, $9, $7); - cplus_decl_attributes ($$, $8); } + cplus_decl_attributes ($$, $8, prefix_attributes); } | typed_declspecs LEFT_RIGHT type_quals exception_specification_opt maybeasm maybe_attribute maybe_init { $$ = build_parse_node (CALL_EXPR, TREE_VALUE ($1), empty_parms (), $3); $$ = grokfield ($$, TREE_CHAIN ($1), $4, $7, $5); - cplus_decl_attributes ($$, $6); } + cplus_decl_attributes ($$, $6, prefix_attributes); } | using_decl ; @@ -2680,47 +2693,47 @@ after_type_component_declarator0: after_type_declarator exception_specification_opt maybeasm maybe_attribute maybe_init { current_declspecs = $0; $$ = grokfield ($$, current_declspecs, $2, $5, $3); - cplus_decl_attributes ($$, $4); } + cplus_decl_attributes ($$, $4, prefix_attributes); } | TYPENAME ':' expr_no_commas maybe_attribute { current_declspecs = $0; $$ = grokbitfield ($$, current_declspecs, $3); - cplus_decl_attributes ($$, $4); } + cplus_decl_attributes ($$, $4, prefix_attributes); } ; notype_component_declarator0: notype_declarator exception_specification_opt maybeasm maybe_attribute maybe_init { current_declspecs = $0; $$ = grokfield ($$, current_declspecs, $2, $5, $3); - cplus_decl_attributes ($$, $4); } + cplus_decl_attributes ($$, $4, prefix_attributes); } | IDENTIFIER ':' expr_no_commas maybe_attribute { current_declspecs = $0; $$ = grokbitfield ($$, current_declspecs, $3); - cplus_decl_attributes ($$, $4); } + cplus_decl_attributes ($$, $4, prefix_attributes); } | ':' expr_no_commas maybe_attribute { current_declspecs = $0; $$ = grokbitfield (NULL_TREE, current_declspecs, $2); - cplus_decl_attributes ($$, $3); } + cplus_decl_attributes ($$, $3, prefix_attributes); } ; after_type_component_declarator: after_type_declarator exception_specification_opt maybeasm maybe_attribute maybe_init { $$ = grokfield ($$, current_declspecs, $2, $5, $3); - cplus_decl_attributes ($$, $4); } + cplus_decl_attributes ($$, $4, prefix_attributes); } | TYPENAME ':' expr_no_commas maybe_attribute { $$ = grokbitfield ($$, current_declspecs, $3); - cplus_decl_attributes ($$, $4); } + cplus_decl_attributes ($$, $4, prefix_attributes); } ; notype_component_declarator: notype_declarator exception_specification_opt maybeasm maybe_attribute maybe_init { $$ = grokfield ($$, current_declspecs, $2, $5, $3); - cplus_decl_attributes ($$, $4); } + cplus_decl_attributes ($$, $4, prefix_attributes); } | IDENTIFIER ':' expr_no_commas maybe_attribute { $$ = grokbitfield ($$, current_declspecs, $3); - cplus_decl_attributes ($$, $4); } + cplus_decl_attributes ($$, $4, prefix_attributes); } | ':' expr_no_commas maybe_attribute { $$ = grokbitfield (NULL_TREE, current_declspecs, $2); - cplus_decl_attributes ($$, $3); } + cplus_decl_attributes ($$, $3, prefix_attributes); } ; /* We chain the enumerators in reverse order. -- 2.30.2