aboutsummaryrefslogtreecommitdiff
path: root/gcc/c-parser.c
diff options
context:
space:
mode:
authorNicola Pero <nicola.pero@meta-innovation.com>2010-10-18 23:28:20 +0000
committerNicola Pero <nicola@gcc.gnu.org>2010-10-18 23:28:20 +0000
commitda57d1b98f8ca9d1304fe66ff14315f12ce2a14f (patch)
tree59330bf1f36ce8580abaac8db170b72523706080 /gcc/c-parser.c
parent0069111f9c747028548f8c5dd7b91c4e5358039d (diff)
downloadgcc-da57d1b98f8ca9d1304fe66ff14315f12ce2a14f.zip
gcc-da57d1b98f8ca9d1304fe66ff14315f12ce2a14f.tar.gz
gcc-da57d1b98f8ca9d1304fe66ff14315f12ce2a14f.tar.bz2
In gcc/: 2010-10-18 Nicola Pero <nicola.pero@meta-innovation.com>
In gcc/: 2010-10-18 Nicola Pero <nicola.pero@meta-innovation.com> Implemented parsing @synthesize and @dynamic for Objective-C. * c-parser.c (c_parser_external_declaration): Recognize RID_AT_SYNTHESIZE and RID_AT_DYNAMIC. (c_parser_objc_at_synthesize_declaration): New. (c_parser_objc_at_dynamic_declaration): New. 2010-10-18 Nicola Pero <nicola.pero@meta-innovation.com> * c-parser.c (c_parser_objc_class_declaration): After finding an error, parse the whole declaration then reset parser->error. In gcc/cp/: 2010-10-18 Nicola Pero <nicola.pero@meta-innovation.com> Implemented parsing @synthesize and @dynamic for Objective-C++. * parser.c (cp_parser_objc_method_definition_list): Recognize RID_AT_SYNTHESIZE and RID_AT_DYNAMIC. (cp_parser_objc_at_dynamic_declaration): New. (cp_parser_objc_at_synthesize_declaration): New. 2010-10-18 Nicola Pero <nicola.pero@meta-innovation.com> * parser.c (cp_parser_objc_identifier_list): Check the return value of cp_parser_identifier and react if it is error_mark_node. In gcc/objc/: 2010-10-18 Nicola Pero <nicola.pero@meta-innovation.com> Implemented parsing @synthesize and @dynamic for Objective-C/Objective-C++. * objc-act.c (objc_add_synthesize_declaration): New. (objc_add_dynamic_declaration): New. 2010-10-18 Nicola Pero <nicola.pero@meta-innovation.com> * objc-act.c (lookup_and_install_protocols): Return NULL if passed error_mark_node. In gcc/testsuite/: 2010-10-18 Nicola Pero <nicola.pero@meta-innovation.com> Implemented parsing @synthesize and @dynamic for Objective-C/Objective-C++. * objc.dg/property/dynamic-1.m: New. * objc.dg/property/synthesize-1.m: New. * obj-c++.dg/property/dynamic-1.mm: New. * obj-c++.dg/property/synthesize-1.mm: New. 2010-10-18 Nicola Pero <nicola.pero@meta-innovation.com> * objc.dg/at-class-1.m: New. * objc.dg/at-class-1.mm: New. From-SVN: r165667
Diffstat (limited to 'gcc/c-parser.c')
-rw-r--r--gcc/c-parser.c127
1 files changed, 126 insertions, 1 deletions
diff --git a/gcc/c-parser.c b/gcc/c-parser.c
index 6a7d7c6..d234218 100644
--- a/gcc/c-parser.c
+++ b/gcc/c-parser.c
@@ -1082,6 +1082,8 @@ static tree c_parser_objc_receiver (c_parser *);
static tree c_parser_objc_message_args (c_parser *);
static tree c_parser_objc_keywordexpr (c_parser *);
static void c_parser_objc_at_property (c_parser *) ;
+static void c_parser_objc_at_synthesize_declaration (c_parser *);
+static void c_parser_objc_at_dynamic_declaration (c_parser *);
static bool c_parser_objc_diagnose_bad_element_prefix
(c_parser *, struct c_declspecs *);
@@ -1185,6 +1187,14 @@ c_parser_external_declaration (c_parser *parser)
gcc_assert (c_dialect_objc ());
c_parser_objc_at_property (parser);
break;
+ case RID_AT_SYNTHESIZE:
+ gcc_assert (c_dialect_objc ());
+ c_parser_objc_at_synthesize_declaration (parser);
+ break;
+ case RID_AT_DYNAMIC:
+ gcc_assert (c_dialect_objc ());
+ c_parser_objc_at_dynamic_declaration (parser);
+ break;
case RID_AT_END:
gcc_assert (c_dialect_objc ());
c_parser_consume_token (parser);
@@ -6763,7 +6773,9 @@ c_parser_objc_class_declaration (c_parser *parser)
if (c_parser_next_token_is_not (parser, CPP_NAME))
{
c_parser_error (parser, "expected identifier");
- break;
+ c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
+ parser->error = false;
+ return;
}
id = c_parser_peek_token (parser)->value;
list = chainon (list, build_tree_list (NULL_TREE, id));
@@ -7689,6 +7701,119 @@ c_parser_objc_at_property (c_parser *parser)
c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
}
+/* Parse an Objective-C @synthesize declaration. The syntax is:
+
+ objc-synthesize-declaration:
+ @synthesize objc-synthesize-identifier-list ;
+
+ objc-synthesize-identifier-list:
+ objc-synthesize-identifier
+ objc-synthesize-identifier-list, objc-synthesize-identifier
+
+ objc-synthesize-identifier
+ identifier
+ identifier = identifier
+
+ For example:
+ @synthesize MyProperty;
+ @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty;
+
+ PS: This function is identical to cp_parser_objc_at_synthesize_declaration
+ for C++. Keep them in sync.
+*/
+static void
+c_parser_objc_at_synthesize_declaration (c_parser *parser)
+{
+ tree list = NULL_TREE;
+ location_t loc;
+ gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNTHESIZE));
+ loc = c_parser_peek_token (parser)->location;
+
+ c_parser_consume_token (parser);
+ while (true)
+ {
+ tree property, ivar;
+ if (c_parser_next_token_is_not (parser, CPP_NAME))
+ {
+ c_parser_error (parser, "expected identifier");
+ c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
+ /* Once we find the semicolon, we can resume normal parsing.
+ We have to reset parser->error manually because
+ c_parser_skip_until_found() won't reset it for us if the
+ next token is precisely a semicolon. */
+ parser->error = false;
+ return;
+ }
+ property = c_parser_peek_token (parser)->value;
+ c_parser_consume_token (parser);
+ if (c_parser_next_token_is (parser, CPP_EQ))
+ {
+ c_parser_consume_token (parser);
+ if (c_parser_next_token_is_not (parser, CPP_NAME))
+ {
+ c_parser_error (parser, "expected identifier");
+ c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
+ parser->error = false;
+ return;
+ }
+ ivar = c_parser_peek_token (parser)->value;
+ c_parser_consume_token (parser);
+ }
+ else
+ ivar = NULL_TREE;
+ list = chainon (list, build_tree_list (ivar, property));
+ if (c_parser_next_token_is (parser, CPP_COMMA))
+ c_parser_consume_token (parser);
+ else
+ break;
+ }
+ c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
+ objc_add_synthesize_declaration (loc, list);
+}
+
+/* Parse an Objective-C @dynamic declaration. The syntax is:
+
+ objc-dynamic-declaration:
+ @dynamic identifier-list ;
+
+ For example:
+ @dynamic MyProperty;
+ @dynamic MyProperty, AnotherProperty;
+
+ PS: This function is identical to cp_parser_objc_at_dynamic_declaration
+ for C++. Keep them in sync.
+*/
+static void
+c_parser_objc_at_dynamic_declaration (c_parser *parser)
+{
+ tree list = NULL_TREE;
+ location_t loc;
+ gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_DYNAMIC));
+ loc = c_parser_peek_token (parser)->location;
+
+ c_parser_consume_token (parser);
+ while (true)
+ {
+ tree property;
+ if (c_parser_next_token_is_not (parser, CPP_NAME))
+ {
+ c_parser_error (parser, "expected identifier");
+ c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
+ parser->error = false;
+ return;
+ }
+ property = c_parser_peek_token (parser)->value;
+ list = chainon (list, build_tree_list (NULL_TREE, property));
+ c_parser_consume_token (parser);
+ if (c_parser_next_token_is (parser, CPP_COMMA))
+ c_parser_consume_token (parser);
+ else
+ break;
+ }
+ c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
+ objc_add_dynamic_declaration (loc, list);
+}
+
/* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
should be considered, statements. ALLOW_STMT is true if we're within