Commit f6abb50a by Brendan Kehoe Committed by Brendan Kehoe

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
parent bf6ed040
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) Tue Feb 21 18:43:48 1995 Douglas Rupp (drupp@cs.washington.edu)
* Make-lang.in, config-lang.in: ($exeext): New macro. * Make-lang.in, config-lang.in: ($exeext): New macro.
......
...@@ -2011,6 +2011,7 @@ extern tree grokbitfield PROTO((tree, tree, tree)); ...@@ -2011,6 +2011,7 @@ extern tree grokbitfield PROTO((tree, tree, tree));
extern tree groktypefield PROTO((tree, tree)); extern tree groktypefield PROTO((tree, tree));
extern tree grokoptypename PROTO((tree, tree)); extern tree grokoptypename PROTO((tree, tree));
extern tree build_push_scope 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_full PROTO((tree));
extern tree constructor_name PROTO((tree)); extern tree constructor_name PROTO((tree));
extern void setup_vtbl_ptr PROTO((void)); extern void setup_vtbl_ptr PROTO((void));
......
...@@ -2122,6 +2122,9 @@ duplicate_decls (newdecl, olddecl) ...@@ -2122,6 +2122,9 @@ duplicate_decls (newdecl, olddecl)
int new_defines_function; int new_defines_function;
tree previous_c_decl = NULL_TREE; 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); types_match = decls_match (newdecl, olddecl);
if (TREE_CODE (olddecl) != TREE_LIST) if (TREE_CODE (olddecl) != TREE_LIST)
...@@ -7157,6 +7160,7 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, raises) ...@@ -7157,6 +7160,7 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, raises)
enum tree_code innermost_code = ERROR_MARK; enum tree_code innermost_code = ERROR_MARK;
int bitfield = 0; int bitfield = 0;
int size_varies = 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. /* 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. */ All FIELD_DECLs we build here have `init' put into their DECL_INITIAL. */
tree init = NULL_TREE; tree init = NULL_TREE;
...@@ -7530,6 +7534,7 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, raises) ...@@ -7530,6 +7534,7 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, raises)
else else
{ {
type = TREE_TYPE (t); type = TREE_TYPE (t);
decl_machine_attr = DECL_MACHINE_ATTRIBUTES (id);
typedef_decl = t; typedef_decl = t;
} }
} }
...@@ -9001,6 +9006,7 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, raises) ...@@ -9001,6 +9006,7 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, raises)
decl = grokfndecl (ctype, type, declarator, decl = grokfndecl (ctype, type, declarator,
virtualp, flags, quals, virtualp, flags, quals,
raises, friendp ? -1 : 0, publicp); raises, friendp ? -1 : 0, publicp);
decl = build_decl_attribute_variant (decl, decl_machine_attr);
if (decl == NULL_TREE) if (decl == NULL_TREE)
return NULL_TREE; return NULL_TREE;
......
...@@ -1921,11 +1921,11 @@ build_push_scope (cname, name) ...@@ -1921,11 +1921,11 @@ build_push_scope (cname, name)
return rval; return rval;
} }
void cplus_decl_attributes (decl, attributes) void cplus_decl_attributes (decl, attributes, prefix_attributes)
tree decl, attributes; tree decl, attributes, prefix_attributes;
{ {
if (decl && decl != void_type_node) if (decl && decl != void_type_node)
decl_attributes (decl, attributes, NULL_TREE); decl_attributes (decl, attributes, prefix_attributes);
} }
/* CONSTRUCTOR_NAME: /* CONSTRUCTOR_NAME:
......
...@@ -287,6 +287,7 @@ empty_parms () ...@@ -287,6 +287,7 @@ empty_parms ()
%{ %{
/* List of types and structure classes of the current declaration. */ /* List of types and structure classes of the current declaration. */
static tree current_declspecs; static tree current_declspecs;
static tree prefix_attributes = NULL_TREE;
/* When defining an aggregate, this is the most recent one being defined. */ /* When defining an aggregate, this is the most recent one being defined. */
static tree current_aggr; static tree current_aggr;
...@@ -504,7 +505,7 @@ template_def: ...@@ -504,7 +505,7 @@ template_def:
momentary = suspend_momentary (); momentary = suspend_momentary ();
d = start_decl ($<ttype>2, /*current_declspecs*/NULL_TREE, 0, d = start_decl ($<ttype>2, /*current_declspecs*/NULL_TREE, 0,
$3); $3);
cplus_decl_attributes (d, $5); cplus_decl_attributes (d, $5, prefix_attributes);
finish_decl (d, NULL_TREE, $4, 0, 0); finish_decl (d, NULL_TREE, $4, 0, 0);
end_template_decl ($1, d, 0, def); end_template_decl ($1, d, 0, def);
if (def) if (def)
...@@ -523,7 +524,7 @@ template_def: ...@@ -523,7 +524,7 @@ template_def:
momentary = suspend_momentary (); momentary = suspend_momentary ();
d = start_decl ($<ttype>3, current_declspecs, d = start_decl ($<ttype>3, current_declspecs,
0, $<ttype>4); 0, $<ttype>4);
cplus_decl_attributes (d, $6); cplus_decl_attributes (d, $6, prefix_attributes);
finish_decl (d, NULL_TREE, $5, 0, 0); finish_decl (d, NULL_TREE, $5, 0, 0);
end_template_decl ($1, d, 0, def); end_template_decl ($1, d, 0, def);
if (def) if (def)
...@@ -975,7 +976,7 @@ condition: ...@@ -975,7 +976,7 @@ condition:
current_declspecs = $1; current_declspecs = $1;
$<itype>6 = suspend_momentary (); $<itype>6 = suspend_momentary ();
$<ttype>$ = start_decl ($<ttype>2, current_declspecs, 1, $3); $<ttype>$ = start_decl ($<ttype>2, current_declspecs, 1, $3);
cplus_decl_attributes ($<ttype>$, $5); cplus_decl_attributes ($<ttype>$, $5, prefix_attributes);
} }
init init
{ {
...@@ -1724,6 +1725,10 @@ object: primary '.' ...@@ -1724,6 +1725,10 @@ object: primary '.'
} }
; ;
setattrs: /* empty */
{ prefix_attributes = $<ttype>0; }
;
decl: decl:
/* Normal case: make this fast. */ /* Normal case: make this fast. */
typespec declarator ';' typespec declarator ';'
...@@ -1833,6 +1838,10 @@ reserved_declspecs: ...@@ -1833,6 +1838,10 @@ reserved_declspecs:
warning ("`%s' is not at beginning of declaration", warning ("`%s' is not at beginning of declaration",
IDENTIFIER_POINTER ($2)); IDENTIFIER_POINTER ($2));
$$ = decl_tree_cons (NULL_TREE, $2, $$); } $$ = decl_tree_cons (NULL_TREE, $2, $$); }
| reserved_declspecs attributes setattrs
{ $$ = $1; }
| attributes setattrs
{ $$ = NULL_TREE; }
; ;
/* List of just storage classes and type modifiers. /* List of just storage classes and type modifiers.
...@@ -1853,6 +1862,10 @@ declmods: ...@@ -1853,6 +1862,10 @@ declmods:
IDENTIFIER_POINTER ($2)); IDENTIFIER_POINTER ($2));
$$ = decl_tree_cons (NULL_TREE, $2, $$); $$ = decl_tree_cons (NULL_TREE, $2, $$);
TREE_STATIC ($$) = TREE_STATIC ($1); } TREE_STATIC ($$) = TREE_STATIC ($1); }
| declmods attributes setattrs
{ $$ = $1; }
| attributes setattrs
{ $$ = NULL_TREE; }
; ;
...@@ -1968,7 +1981,7 @@ initdcl0: ...@@ -1968,7 +1981,7 @@ initdcl0:
} }
$<itype>5 = suspend_momentary (); $<itype>5 = suspend_momentary ();
$<ttype>$ = start_decl ($<ttype>1, current_declspecs, 1, $2); $<ttype>$ = start_decl ($<ttype>1, current_declspecs, 1, $2);
cplus_decl_attributes ($<ttype>$, $4); } cplus_decl_attributes ($<ttype>$, $4, prefix_attributes); }
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! */
{ finish_decl ($<ttype>6, $7, $3, 0, LOOKUP_ONLYCONVERTING); { finish_decl ($<ttype>6, $7, $3, 0, LOOKUP_ONLYCONVERTING);
...@@ -1987,20 +2000,20 @@ initdcl0: ...@@ -1987,20 +2000,20 @@ initdcl0:
} }
$$ = suspend_momentary (); $$ = suspend_momentary ();
d = start_decl ($<ttype>1, current_declspecs, 0, $2); d = start_decl ($<ttype>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); } finish_decl (d, NULL_TREE, $3, 0, 0); }
; ;
initdcl: initdcl:
declarator exception_specification_opt maybeasm maybe_attribute '=' declarator exception_specification_opt maybeasm maybe_attribute '='
{ $<ttype>$ = start_decl ($<ttype>1, current_declspecs, 1, $2); { $<ttype>$ = start_decl ($<ttype>1, current_declspecs, 1, $2);
cplus_decl_attributes ($<ttype>$, $4); } cplus_decl_attributes ($<ttype>$, $4, prefix_attributes); }
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! */
{ finish_decl ($<ttype>6, $7, $3, 0, LOOKUP_ONLYCONVERTING); } { finish_decl ($<ttype>6, $7, $3, 0, LOOKUP_ONLYCONVERTING); }
| declarator exception_specification_opt maybeasm maybe_attribute | declarator exception_specification_opt maybeasm maybe_attribute
{ $<ttype>$ = start_decl ($<ttype>1, current_declspecs, 0, $2); { $<ttype>$ = start_decl ($<ttype>1, current_declspecs, 0, $2);
cplus_decl_attributes ($<ttype>$, $4); cplus_decl_attributes ($<ttype>$, $4, prefix_attributes);
finish_decl ($<ttype>$, NULL_TREE, $3, 0, 0); } finish_decl ($<ttype>$, NULL_TREE, $3, 0, 0); }
; ;
...@@ -2009,7 +2022,7 @@ notype_initdcl0: ...@@ -2009,7 +2022,7 @@ notype_initdcl0:
{ current_declspecs = $<ttype>0; { current_declspecs = $<ttype>0;
$<itype>5 = suspend_momentary (); $<itype>5 = suspend_momentary ();
$<ttype>$ = start_decl ($<ttype>1, current_declspecs, 1, $2); $<ttype>$ = start_decl ($<ttype>1, current_declspecs, 1, $2);
cplus_decl_attributes ($<ttype>$, $4); } cplus_decl_attributes ($<ttype>$, $4, prefix_attributes); }
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! */
{ finish_decl ($<ttype>6, $7, $3, 0, LOOKUP_ONLYCONVERTING); { finish_decl ($<ttype>6, $7, $3, 0, LOOKUP_ONLYCONVERTING);
...@@ -2019,7 +2032,7 @@ notype_initdcl0: ...@@ -2019,7 +2032,7 @@ notype_initdcl0:
current_declspecs = $<ttype>0; current_declspecs = $<ttype>0;
$$ = suspend_momentary (); $$ = suspend_momentary ();
d = start_decl ($<ttype>1, current_declspecs, 0, $2); d = start_decl ($<ttype>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); } finish_decl (d, NULL_TREE, $3, 0, 0); }
; ;
...@@ -2028,7 +2041,7 @@ nomods_initdcl0: ...@@ -2028,7 +2041,7 @@ nomods_initdcl0:
{ current_declspecs = NULL_TREE; { current_declspecs = NULL_TREE;
$<itype>5 = suspend_momentary (); $<itype>5 = suspend_momentary ();
$<ttype>$ = start_decl ($1, current_declspecs, 1, $2); $<ttype>$ = start_decl ($1, current_declspecs, 1, $2);
cplus_decl_attributes ($<ttype>$, $4); } cplus_decl_attributes ($<ttype>$, $4, prefix_attributes); }
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! */
{ finish_decl ($<ttype>6, $7, $3, 0, LOOKUP_ONLYCONVERTING); { finish_decl ($<ttype>6, $7, $3, 0, LOOKUP_ONLYCONVERTING);
...@@ -2038,7 +2051,7 @@ nomods_initdcl0: ...@@ -2038,7 +2051,7 @@ nomods_initdcl0:
current_declspecs = NULL_TREE; current_declspecs = NULL_TREE;
$$ = suspend_momentary (); $$ = suspend_momentary ();
d = start_decl ($1, current_declspecs, 0, $2); 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); } finish_decl (d, NULL_TREE, $3, 0, 0); }
; ;
...@@ -2608,7 +2621,7 @@ component_decl_1: ...@@ -2608,7 +2621,7 @@ component_decl_1:
} }
| notype_declarator exception_specification_opt maybeasm maybe_attribute maybe_init | notype_declarator exception_specification_opt maybeasm maybe_attribute maybe_init
{ $$ = grokfield ($$, NULL_TREE, $2, $5, $3); { $$ = grokfield ($$, NULL_TREE, $2, $5, $3);
cplus_decl_attributes ($$, $4); } cplus_decl_attributes ($$, $4, prefix_attributes); }
| ':' expr_no_commas | ':' expr_no_commas
{ $$ = grokbitfield (NULL_TREE, NULL_TREE, $2); } { $$ = grokbitfield (NULL_TREE, NULL_TREE, $2); }
| error | error
...@@ -2626,12 +2639,12 @@ component_decl_1: ...@@ -2626,12 +2639,12 @@ component_decl_1:
{ $$ = build_parse_node (CALL_EXPR, TREE_VALUE ($1), { $$ = build_parse_node (CALL_EXPR, TREE_VALUE ($1),
$3, $5); $3, $5);
$$ = grokfield ($$, TREE_CHAIN ($1), $6, $9, $7); $$ = 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 | typed_declspecs LEFT_RIGHT type_quals exception_specification_opt maybeasm maybe_attribute maybe_init
{ $$ = build_parse_node (CALL_EXPR, TREE_VALUE ($1), { $$ = build_parse_node (CALL_EXPR, TREE_VALUE ($1),
empty_parms (), $3); empty_parms (), $3);
$$ = grokfield ($$, TREE_CHAIN ($1), $4, $7, $5); $$ = grokfield ($$, TREE_CHAIN ($1), $4, $7, $5);
cplus_decl_attributes ($$, $6); } cplus_decl_attributes ($$, $6, prefix_attributes); }
| using_decl | using_decl
; ;
...@@ -2680,47 +2693,47 @@ after_type_component_declarator0: ...@@ -2680,47 +2693,47 @@ after_type_component_declarator0:
after_type_declarator exception_specification_opt maybeasm maybe_attribute maybe_init after_type_declarator exception_specification_opt maybeasm maybe_attribute maybe_init
{ current_declspecs = $<ttype>0; { current_declspecs = $<ttype>0;
$$ = grokfield ($$, current_declspecs, $2, $5, $3); $$ = grokfield ($$, current_declspecs, $2, $5, $3);
cplus_decl_attributes ($$, $4); } cplus_decl_attributes ($$, $4, prefix_attributes); }
| TYPENAME ':' expr_no_commas maybe_attribute | TYPENAME ':' expr_no_commas maybe_attribute
{ current_declspecs = $<ttype>0; { current_declspecs = $<ttype>0;
$$ = grokbitfield ($$, current_declspecs, $3); $$ = grokbitfield ($$, current_declspecs, $3);
cplus_decl_attributes ($$, $4); } cplus_decl_attributes ($$, $4, prefix_attributes); }
; ;
notype_component_declarator0: notype_component_declarator0:
notype_declarator exception_specification_opt maybeasm maybe_attribute maybe_init notype_declarator exception_specification_opt maybeasm maybe_attribute maybe_init
{ current_declspecs = $<ttype>0; { current_declspecs = $<ttype>0;
$$ = grokfield ($$, current_declspecs, $2, $5, $3); $$ = grokfield ($$, current_declspecs, $2, $5, $3);
cplus_decl_attributes ($$, $4); } cplus_decl_attributes ($$, $4, prefix_attributes); }
| IDENTIFIER ':' expr_no_commas maybe_attribute | IDENTIFIER ':' expr_no_commas maybe_attribute
{ current_declspecs = $<ttype>0; { current_declspecs = $<ttype>0;
$$ = grokbitfield ($$, current_declspecs, $3); $$ = grokbitfield ($$, current_declspecs, $3);
cplus_decl_attributes ($$, $4); } cplus_decl_attributes ($$, $4, prefix_attributes); }
| ':' expr_no_commas maybe_attribute | ':' expr_no_commas maybe_attribute
{ current_declspecs = $<ttype>0; { current_declspecs = $<ttype>0;
$$ = grokbitfield (NULL_TREE, current_declspecs, $2); $$ = grokbitfield (NULL_TREE, current_declspecs, $2);
cplus_decl_attributes ($$, $3); } cplus_decl_attributes ($$, $3, prefix_attributes); }
; ;
after_type_component_declarator: after_type_component_declarator:
after_type_declarator exception_specification_opt maybeasm maybe_attribute maybe_init after_type_declarator exception_specification_opt maybeasm maybe_attribute maybe_init
{ $$ = grokfield ($$, current_declspecs, $2, $5, $3); { $$ = grokfield ($$, current_declspecs, $2, $5, $3);
cplus_decl_attributes ($$, $4); } cplus_decl_attributes ($$, $4, prefix_attributes); }
| TYPENAME ':' expr_no_commas maybe_attribute | TYPENAME ':' expr_no_commas maybe_attribute
{ $$ = grokbitfield ($$, current_declspecs, $3); { $$ = grokbitfield ($$, current_declspecs, $3);
cplus_decl_attributes ($$, $4); } cplus_decl_attributes ($$, $4, prefix_attributes); }
; ;
notype_component_declarator: notype_component_declarator:
notype_declarator exception_specification_opt maybeasm maybe_attribute maybe_init notype_declarator exception_specification_opt maybeasm maybe_attribute maybe_init
{ $$ = grokfield ($$, current_declspecs, $2, $5, $3); { $$ = grokfield ($$, current_declspecs, $2, $5, $3);
cplus_decl_attributes ($$, $4); } cplus_decl_attributes ($$, $4, prefix_attributes); }
| IDENTIFIER ':' expr_no_commas maybe_attribute | IDENTIFIER ':' expr_no_commas maybe_attribute
{ $$ = grokbitfield ($$, current_declspecs, $3); { $$ = grokbitfield ($$, current_declspecs, $3);
cplus_decl_attributes ($$, $4); } cplus_decl_attributes ($$, $4, prefix_attributes); }
| ':' expr_no_commas maybe_attribute | ':' expr_no_commas maybe_attribute
{ $$ = grokbitfield (NULL_TREE, current_declspecs, $2); { $$ = grokbitfield (NULL_TREE, current_declspecs, $2);
cplus_decl_attributes ($$, $3); } cplus_decl_attributes ($$, $3, prefix_attributes); }
; ;
/* We chain the enumerators in reverse order. /* We chain the enumerators in reverse order.
......
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