summaryrefslogtreecommitdiff
path: root/gcc/cp/parser.c
diff options
context:
space:
mode:
authornicola <nicola@138bc75d-0d04-0410-961f-82ee72b054a4>2010-10-27 05:23:08 +0000
committernicola <nicola@138bc75d-0d04-0410-961f-82ee72b054a4>2010-10-27 05:23:08 +0000
commit7590f0e5e646477319ef943aa1715eb670aa314e (patch)
treeba6ae21d33b46a8fb8b884194c9eb79ecdd38f48 /gcc/cp/parser.c
parent1d894bcf47c398d81f7ea42eff8a5da823799bf7 (diff)
downloadgcc-7590f0e5e646477319ef943aa1715eb670aa314e.tar.gz
In gcc/:
2010-10-27 Nicola Pero <nicola.pero@meta-innovation.com> * c-parser.c (c_parser_objc_at_property_declaration): Recognize RID_ASSIGN, RID_COPY, RID_RETAIN, RID_READWRITE and RID_NONATOMIC. Do not use objc_set_property_attr, but use local variables instead. Detect repeated usage of setter, getter and ivar attributes. Improved error processing when a setter name does not end in ':'. Do not check for CPP_CLOSE_PAREN after we determined that the token is a keyword. Updated call to objc_add_property_declaration. In gcc/cp/: 2010-10-27 Nicola Pero <nicola.pero@meta-innovation.com> * parser.c (cp_parser_objc_at_property_declaration): Recognize RID_ASSIGN, RID_COPY, RID_RETAIN, RID_READWRITE and RID_NONATOMIC. Do not use objc_set_property_attr, but use local variables instead. Detect repeated usage of setter, getter and ivar attributes. Improved error processing when a setter name does not end in ':'. Do not check for CPP_CLOSE_PAREN after we determined that the token is a keyword. Updated call to objc_add_property_declaration. In gcc/c-family/: 2010-10-27 Nicola Pero <nicola.pero@meta-innovation.com> * c-common.h (enum rid): Added RID_READWRITE, RID_ASSIGN, RID_RETAIN, RID_COPY and RID_NONATOMIC. Updated RID_FIRST_PATTR and RID_LAST_PATTR. (objc_add_property_declaration): Added additional arguments. (objc_property_attribute_kind): Removed. (objc_set_property_attr): Removed. * c-common.c (c_common_reswords): Added readwrite, assign, retain, copy and nonatomic. * stub-objc.c (objc_add_property_declaration): Added additional arguments. (objc_set_property_attr): Removed. In gcc/objc/: 2010-10-27 Nicola Pero <nicola.pero@meta-innovation.com> * objc-act.c (objc_add_property_declaration): Added arguments to pass the various property attributes that were parsed with the property declaration. Process arguments to determine the final property attributes and produce error messages as appropriate. Added temporary code to keep the compiler silent about variables set but not used - for new attributes that are only checked but have no effect yet. (property_readonly): Removed. (property_setter): Removed. (property_getter): Removed. (property_ivar): Removed. (property_copies): Removed. (objc_set_property_attr): Removed. * objc-act.h (enum property_assign_semantics): New. In gcc/testsuite/: 2010-10-27 Nicola Pero <nicola.pero@meta-innovation.com> * obj-c.dg/property/at-property-4.m: New. * obj-c++.dg/property/at-property-4.mm: New. * obj-c++.dg/property/property-neg-5.m: Updated testcase for updates in warning. * obj-c++.dg/property/property-neg-5.mm: Updated testcase for updates in warning. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@165997 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/cp/parser.c')
-rw-r--r--gcc/cp/parser.c106
1 files changed, 65 insertions, 41 deletions
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 95be6d324b9..d0bd6bb5e0b 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -22648,23 +22648,41 @@ cp_parser_objc_struct_declaration (cp_parser *parser)
@property int a, b, c;
PS: This function is identical to
- c_parser_objc_at_property_declaration for C. Keep them in sync.
-
- WORK IN PROGRESS: At the moment, the list of attributes that are
- parsed is different from the above list. It will be updated to use
- the above list at the same time as @synthesize is implemented. */
+ c_parser_objc_at_property_declaration for C. Keep them in sync. */
static void
cp_parser_objc_at_property_declaration (cp_parser *parser)
{
+ /* The following variables hold the attributes of the properties as
+ parsed. They are 'false' or 'NULL_TREE' if the attribute was not
+ seen. When we see an attribute, we set them to 'true' (if they
+ are boolean properties) or to the identifier (if they have an
+ argument, ie, for getter and setter). Note that here we only
+ parse the list of attributes, check the syntax and accumulate the
+ attributes that we find. objc_add_property_declaration() will
+ then process the information. */
+ bool property_assign = false;
+ bool property_copy = false;
+ tree property_getter_ident = NULL_TREE;
+ bool property_nonatomic = false;
+ bool property_readonly = false;
+ bool property_readwrite = false;
+ bool property_retain = false;
+ tree property_setter_ident = NULL_TREE;
+ /* The following two will be removed once @synthesize is
+ implemented. */
+ bool property_copies = false;
+ tree property_ivar_ident = NULL_TREE;
+
+ /* 'properties' is the list of properties that we read. Usually a
+ single one, but maybe more (eg, in "@property int a, b, c;" there
+ are three). */
tree properties;
location_t loc;
+
loc = cp_lexer_peek_token (parser->lexer)->location;
cp_lexer_consume_token (parser->lexer); /* Eat '@property'. */
- /* Initialize attributes to an empty list. */
- objc_set_property_attr (loc, OBJC_PATTR_INIT, NULL_TREE);
-
/* Parse the optional attribute list... */
if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_PAREN))
{
@@ -22683,18 +22701,20 @@ cp_parser_objc_at_property_declaration (cp_parser *parser)
break;
}
keyword = C_RID_CODE (token->u.value);
+ cp_lexer_consume_token (parser->lexer);
switch (keyword)
{
- tree ident;
- objc_property_attribute_kind pkind;
- case RID_READONLY:
- cp_lexer_consume_token (parser->lexer);
- objc_set_property_attr (loc, OBJC_PATTR_READONLY, NULL_TREE);
- break;
+ case RID_ASSIGN: property_assign = true; break;
+ case RID_COPIES: property_copies = true; break;
+ case RID_COPY: property_copy = true; break;
+ case RID_NONATOMIC: property_nonatomic = true; break;
+ case RID_READONLY: property_readonly = true; break;
+ case RID_READWRITE: property_readwrite = true; break;
+ case RID_RETAIN: property_retain = true; break;
+
case RID_GETTER:
case RID_SETTER:
case RID_IVAR:
- cp_lexer_consume_token (parser->lexer);
if (cp_lexer_next_token_is_not (parser->lexer, CPP_EQ))
{
cp_parser_error (parser,
@@ -22709,39 +22729,37 @@ cp_parser_objc_at_property_declaration (cp_parser *parser)
syntax_error = true;
break;
}
- ident = cp_lexer_peek_token (parser->lexer)->u.value;
- cp_lexer_consume_token (parser->lexer);
if (keyword == RID_SETTER)
{
- pkind = OBJC_PATTR_SETTER;
- /* Eat the identifier, and look for the following : */
- if (cp_lexer_next_token_is_not (parser->lexer, CPP_COLON))
- {
- cp_parser_error (parser,
- "setter name must be followed by %<:%>");
- syntax_error = true;
- break;
- }
+ if (property_setter_ident != NULL_TREE)
+ cp_parser_error (parser, "the %<setter%> attribute may only be specified once");
+ else
+ property_setter_ident = cp_lexer_peek_token (parser->lexer)->u.value;
cp_lexer_consume_token (parser->lexer);
+ if (cp_lexer_next_token_is_not (parser->lexer, CPP_COLON))
+ cp_parser_error (parser, "setter name must terminate with %<:%>");
+ else
+ cp_lexer_consume_token (parser->lexer);
}
else if (keyword == RID_GETTER)
- pkind = OBJC_PATTR_GETTER;
- else
- pkind = OBJC_PATTR_IVAR;
- objc_set_property_attr (loc, pkind, ident);
- break;
- case RID_COPIES:
- cp_lexer_consume_token (parser->lexer);
- objc_set_property_attr (loc, OBJC_PATTR_COPIES, NULL_TREE);
- break;
- default:
- if (token->type == CPP_CLOSE_PAREN)
- cp_parser_error (parser, "expected identifier");
- else
{
+ if (property_getter_ident != NULL_TREE)
+ cp_parser_error (parser, "the %<getter%> attribute may only be specified once");
+ else
+ property_getter_ident = cp_lexer_peek_token (parser->lexer)->u.value;
cp_lexer_consume_token (parser->lexer);
- cp_parser_error (parser, "unknown property attribute");
}
+ else /* RID_IVAR, this case will go away. */
+ {
+ if (property_ivar_ident != NULL_TREE)
+ cp_parser_error (parser, "the %<ivar%> attribute may only be specified once");
+ else
+ property_ivar_ident = cp_lexer_peek_token (parser->lexer)->u.value;
+ cp_lexer_consume_token (parser->lexer);
+ }
+ break;
+ default:
+ cp_parser_error (parser, "unknown property attribute");
syntax_error = true;
break;
}
@@ -22785,7 +22803,13 @@ cp_parser_objc_at_property_declaration (cp_parser *parser)
properties = nreverse (properties);
for (; properties; properties = TREE_CHAIN (properties))
- objc_add_property_declaration (loc, copy_node (properties));
+ objc_add_property_declaration (loc, copy_node (properties),
+ property_readonly, property_readwrite,
+ property_assign, property_retain,
+ property_copy, property_nonatomic,
+ property_getter_ident, property_setter_ident,
+ /* The following two will be removed. */
+ property_copies, property_ivar_ident);
}
cp_parser_consume_semicolon_at_end_of_statement (parser);