blob: 05cbabd67c5afd3a81eb2543526ab54aa6af463a [file] [log] [blame]
Chris Lattner4b009652007-07-25 00:24:17 +00001//===--- ParseObjc.cpp - Objective C Parsing ------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by Steve Naroff and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the Objective-C portions of the Parser interface.
11//
12//===----------------------------------------------------------------------===//
13
14#include "clang/Parse/Parser.h"
Steve Naroff09a0c4c2007-08-22 18:35:33 +000015#include "clang/Parse/DeclSpec.h"
Fariborz Jahanian06798362007-11-01 23:59:59 +000016#include "clang/Parse/Scope.h"
Chris Lattner4b009652007-07-25 00:24:17 +000017#include "clang/Basic/Diagnostic.h"
18#include "llvm/ADT/SmallVector.h"
19using namespace clang;
20
21
22/// ParseExternalDeclaration:
23/// external-declaration: [C99 6.9]
24/// [OBJC] objc-class-definition
Steve Naroff5b96e2e2007-10-29 21:39:29 +000025/// [OBJC] objc-class-declaration
26/// [OBJC] objc-alias-declaration
27/// [OBJC] objc-protocol-definition
28/// [OBJC] objc-method-definition
29/// [OBJC] '@' 'end'
Steve Narofffb367882007-08-20 21:31:48 +000030Parser::DeclTy *Parser::ParseObjCAtDirectives() {
Chris Lattner4b009652007-07-25 00:24:17 +000031 SourceLocation AtLoc = ConsumeToken(); // the "@"
32
Steve Naroff87c329f2007-08-23 18:16:40 +000033 switch (Tok.getObjCKeywordID()) {
Chris Lattner4b009652007-07-25 00:24:17 +000034 case tok::objc_class:
35 return ParseObjCAtClassDeclaration(AtLoc);
36 case tok::objc_interface:
Steve Narofffb367882007-08-20 21:31:48 +000037 return ParseObjCAtInterfaceDeclaration(AtLoc);
Chris Lattner4b009652007-07-25 00:24:17 +000038 case tok::objc_protocol:
Steve Naroff72f17fb2007-08-22 22:17:26 +000039 return ParseObjCAtProtocolDeclaration(AtLoc);
Chris Lattner4b009652007-07-25 00:24:17 +000040 case tok::objc_implementation:
Fariborz Jahanian83ddf822007-11-10 20:59:13 +000041 return ParseObjCAtImplementationDeclaration(AtLoc);
Chris Lattner4b009652007-07-25 00:24:17 +000042 case tok::objc_end:
Fariborz Jahanian027c23b2007-09-01 00:26:16 +000043 return ParseObjCAtEndDeclaration(AtLoc);
Chris Lattner4b009652007-07-25 00:24:17 +000044 case tok::objc_compatibility_alias:
Fariborz Jahanianb62aff32007-09-04 19:26:51 +000045 return ParseObjCAtAliasDeclaration(AtLoc);
Fariborz Jahanian027c23b2007-09-01 00:26:16 +000046 case tok::objc_synthesize:
47 return ParseObjCPropertySynthesize(AtLoc);
48 case tok::objc_dynamic:
49 return ParseObjCPropertyDynamic(AtLoc);
Chris Lattner4b009652007-07-25 00:24:17 +000050 default:
51 Diag(AtLoc, diag::err_unexpected_at);
52 SkipUntil(tok::semi);
Steve Narofffb367882007-08-20 21:31:48 +000053 return 0;
Chris Lattner4b009652007-07-25 00:24:17 +000054 }
55}
56
57///
58/// objc-class-declaration:
59/// '@' 'class' identifier-list ';'
60///
Steve Narofffb367882007-08-20 21:31:48 +000061Parser::DeclTy *Parser::ParseObjCAtClassDeclaration(SourceLocation atLoc) {
Chris Lattner4b009652007-07-25 00:24:17 +000062 ConsumeToken(); // the identifier "class"
63 llvm::SmallVector<IdentifierInfo *, 8> ClassNames;
64
65 while (1) {
Chris Lattnera1d2bb72007-10-09 17:51:17 +000066 if (Tok.isNot(tok::identifier)) {
Chris Lattner4b009652007-07-25 00:24:17 +000067 Diag(Tok, diag::err_expected_ident);
68 SkipUntil(tok::semi);
Steve Narofffb367882007-08-20 21:31:48 +000069 return 0;
Chris Lattner4b009652007-07-25 00:24:17 +000070 }
Chris Lattner4b009652007-07-25 00:24:17 +000071 ClassNames.push_back(Tok.getIdentifierInfo());
72 ConsumeToken();
73
Chris Lattnera1d2bb72007-10-09 17:51:17 +000074 if (Tok.isNot(tok::comma))
Chris Lattner4b009652007-07-25 00:24:17 +000075 break;
76
77 ConsumeToken();
78 }
79
80 // Consume the ';'.
81 if (ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@class"))
Steve Narofffb367882007-08-20 21:31:48 +000082 return 0;
Chris Lattner4b009652007-07-25 00:24:17 +000083
Steve Naroff415c1832007-10-10 17:32:04 +000084 return Actions.ActOnForwardClassDeclaration(atLoc,
Steve Naroff81f1bba2007-09-06 21:24:23 +000085 &ClassNames[0], ClassNames.size());
Chris Lattner4b009652007-07-25 00:24:17 +000086}
87
Steve Narofffb367882007-08-20 21:31:48 +000088///
89/// objc-interface:
90/// objc-class-interface-attributes[opt] objc-class-interface
91/// objc-category-interface
92///
93/// objc-class-interface:
94/// '@' 'interface' identifier objc-superclass[opt]
95/// objc-protocol-refs[opt]
96/// objc-class-instance-variables[opt]
97/// objc-interface-decl-list
98/// @end
99///
100/// objc-category-interface:
101/// '@' 'interface' identifier '(' identifier[opt] ')'
102/// objc-protocol-refs[opt]
103/// objc-interface-decl-list
104/// @end
105///
106/// objc-superclass:
107/// ':' identifier
108///
109/// objc-class-interface-attributes:
110/// __attribute__((visibility("default")))
111/// __attribute__((visibility("hidden")))
112/// __attribute__((deprecated))
113/// __attribute__((unavailable))
114/// __attribute__((objc_exception)) - used by NSException on 64-bit
115///
116Parser::DeclTy *Parser::ParseObjCAtInterfaceDeclaration(
117 SourceLocation atLoc, AttributeList *attrList) {
Steve Naroff87c329f2007-08-23 18:16:40 +0000118 assert(Tok.isObjCAtKeyword(tok::objc_interface) &&
Steve Narofffb367882007-08-20 21:31:48 +0000119 "ParseObjCAtInterfaceDeclaration(): Expected @interface");
120 ConsumeToken(); // the "interface" identifier
121
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000122 if (Tok.isNot(tok::identifier)) {
Steve Narofffb367882007-08-20 21:31:48 +0000123 Diag(Tok, diag::err_expected_ident); // missing class or category name.
124 return 0;
125 }
126 // We have a class or category name - consume it.
Steve Naroff72f17fb2007-08-22 22:17:26 +0000127 IdentifierInfo *nameId = Tok.getIdentifierInfo();
Steve Narofffb367882007-08-20 21:31:48 +0000128 SourceLocation nameLoc = ConsumeToken();
129
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000130 if (Tok.is(tok::l_paren)) { // we have a category.
Steve Narofffb367882007-08-20 21:31:48 +0000131 SourceLocation lparenLoc = ConsumeParen();
132 SourceLocation categoryLoc, rparenLoc;
133 IdentifierInfo *categoryId = 0;
Fariborz Jahanianf25220e2007-09-18 20:26:58 +0000134 llvm::SmallVector<IdentifierInfo *, 8> ProtocolRefs;
Steve Narofffb367882007-08-20 21:31:48 +0000135
Steve Naroffa7f62782007-08-23 19:56:30 +0000136 // For ObjC2, the category name is optional (not an error).
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000137 if (Tok.is(tok::identifier)) {
Steve Narofffb367882007-08-20 21:31:48 +0000138 categoryId = Tok.getIdentifierInfo();
139 categoryLoc = ConsumeToken();
Steve Naroffa7f62782007-08-23 19:56:30 +0000140 } else if (!getLang().ObjC2) {
141 Diag(Tok, diag::err_expected_ident); // missing category name.
142 return 0;
Steve Narofffb367882007-08-20 21:31:48 +0000143 }
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000144 if (Tok.isNot(tok::r_paren)) {
Steve Narofffb367882007-08-20 21:31:48 +0000145 Diag(Tok, diag::err_expected_rparen);
146 SkipUntil(tok::r_paren, false); // don't stop at ';'
147 return 0;
148 }
149 rparenLoc = ConsumeParen();
Steve Naroffef20ed32007-10-30 02:23:23 +0000150 SourceLocation endProtoLoc;
Steve Narofffb367882007-08-20 21:31:48 +0000151 // Next, we need to check for any protocol references.
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000152 if (Tok.is(tok::less)) {
Steve Naroffef20ed32007-10-30 02:23:23 +0000153 if (ParseObjCProtocolReferences(ProtocolRefs, endProtoLoc))
Steve Narofffb367882007-08-20 21:31:48 +0000154 return 0;
155 }
156 if (attrList) // categories don't support attributes.
157 Diag(Tok, diag::err_objc_no_attributes_on_category);
158
Steve Naroff415c1832007-10-10 17:32:04 +0000159 DeclTy *CategoryType = Actions.ActOnStartCategoryInterface(atLoc,
Steve Naroff25aace82007-10-03 21:00:46 +0000160 nameId, nameLoc, categoryId, categoryLoc,
Steve Naroff667f1682007-10-30 13:30:57 +0000161 &ProtocolRefs[0], ProtocolRefs.size(),
162 endProtoLoc);
Fariborz Jahanianf25220e2007-09-18 20:26:58 +0000163
164 ParseObjCInterfaceDeclList(CategoryType, tok::objc_not_keyword);
Steve Narofffb367882007-08-20 21:31:48 +0000165
Steve Naroff0bbffd82007-08-22 16:35:03 +0000166 // The @ sign was already consumed by ParseObjCInterfaceDeclList().
Steve Naroff87c329f2007-08-23 18:16:40 +0000167 if (Tok.isObjCAtKeyword(tok::objc_end)) {
Steve Naroff0bbffd82007-08-22 16:35:03 +0000168 ConsumeToken(); // the "end" identifier
Fariborz Jahanianac20be22007-10-08 18:53:38 +0000169 return CategoryType;
Steve Narofffb367882007-08-20 21:31:48 +0000170 }
Steve Naroff0bbffd82007-08-22 16:35:03 +0000171 Diag(Tok, diag::err_objc_missing_end);
Steve Narofffb367882007-08-20 21:31:48 +0000172 return 0;
173 }
174 // Parse a class interface.
175 IdentifierInfo *superClassId = 0;
176 SourceLocation superClassLoc;
Steve Naroff72f17fb2007-08-22 22:17:26 +0000177
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000178 if (Tok.is(tok::colon)) { // a super class is specified.
Steve Narofffb367882007-08-20 21:31:48 +0000179 ConsumeToken();
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000180 if (Tok.isNot(tok::identifier)) {
Steve Narofffb367882007-08-20 21:31:48 +0000181 Diag(Tok, diag::err_expected_ident); // missing super class name.
182 return 0;
183 }
184 superClassId = Tok.getIdentifierInfo();
185 superClassLoc = ConsumeToken();
186 }
187 // Next, we need to check for any protocol references.
Steve Naroff304ed392007-09-05 23:30:30 +0000188 llvm::SmallVector<IdentifierInfo *, 8> ProtocolRefs;
Steve Naroffef20ed32007-10-30 02:23:23 +0000189 SourceLocation endProtoLoc;
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000190 if (Tok.is(tok::less)) {
Steve Naroffef20ed32007-10-30 02:23:23 +0000191 if (ParseObjCProtocolReferences(ProtocolRefs, endProtoLoc))
Steve Narofffb367882007-08-20 21:31:48 +0000192 return 0;
193 }
Steve Naroff415c1832007-10-10 17:32:04 +0000194 DeclTy *ClsType = Actions.ActOnStartClassInterface(
Fariborz Jahanianc091b5d2007-09-25 18:38:09 +0000195 atLoc, nameId, nameLoc,
Steve Naroff304ed392007-09-05 23:30:30 +0000196 superClassId, superClassLoc, &ProtocolRefs[0],
Steve Naroffef20ed32007-10-30 02:23:23 +0000197 ProtocolRefs.size(), endProtoLoc, attrList);
Steve Naroff304ed392007-09-05 23:30:30 +0000198
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000199 if (Tok.is(tok::l_brace))
Steve Naroff1a7fa7b2007-10-29 21:38:07 +0000200 ParseObjCClassInstanceVariables(ClsType, atLoc);
Steve Narofffb367882007-08-20 21:31:48 +0000201
Fariborz Jahanian63ca8ae2007-09-17 21:07:36 +0000202 ParseObjCInterfaceDeclList(ClsType, tok::objc_interface);
Steve Naroff0bbffd82007-08-22 16:35:03 +0000203
204 // The @ sign was already consumed by ParseObjCInterfaceDeclList().
Steve Naroff87c329f2007-08-23 18:16:40 +0000205 if (Tok.isObjCAtKeyword(tok::objc_end)) {
Steve Naroff0bbffd82007-08-22 16:35:03 +0000206 ConsumeToken(); // the "end" identifier
Steve Narofffaed3bf2007-09-10 20:51:04 +0000207 return ClsType;
Steve Narofffb367882007-08-20 21:31:48 +0000208 }
Steve Naroff0bbffd82007-08-22 16:35:03 +0000209 Diag(Tok, diag::err_objc_missing_end);
Steve Narofffb367882007-08-20 21:31:48 +0000210 return 0;
211}
212
213/// objc-interface-decl-list:
214/// empty
Steve Narofffb367882007-08-20 21:31:48 +0000215/// objc-interface-decl-list objc-property-decl [OBJC2]
Steve Naroff0bbffd82007-08-22 16:35:03 +0000216/// objc-interface-decl-list objc-method-requirement [OBJC2]
Steve Naroff81f1bba2007-09-06 21:24:23 +0000217/// objc-interface-decl-list objc-method-proto ';'
Steve Narofffb367882007-08-20 21:31:48 +0000218/// objc-interface-decl-list declaration
219/// objc-interface-decl-list ';'
220///
Steve Naroff0bbffd82007-08-22 16:35:03 +0000221/// objc-method-requirement: [OBJC2]
222/// @required
223/// @optional
224///
Fariborz Jahanian63ca8ae2007-09-17 21:07:36 +0000225void Parser::ParseObjCInterfaceDeclList(DeclTy *interfaceDecl,
226 tok::ObjCKeywordKind contextKey) {
Fariborz Jahanian3dc7cbc2007-09-10 20:33:04 +0000227 llvm::SmallVector<DeclTy*, 32> allMethods;
Fariborz Jahaniand8df6d82007-11-06 22:01:00 +0000228 llvm::SmallVector<DeclTy*, 16> allProperties;
Fariborz Jahanian8b5ab6f2007-09-18 00:25:23 +0000229 tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword;
Steve Naroff1a7fa7b2007-10-29 21:38:07 +0000230 SourceLocation AtEndLoc;
231
Steve Naroff0bbffd82007-08-22 16:35:03 +0000232 while (1) {
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000233 if (Tok.is(tok::at)) {
Steve Naroff0bbffd82007-08-22 16:35:03 +0000234 SourceLocation AtLoc = ConsumeToken(); // the "@"
Steve Naroff87c329f2007-08-23 18:16:40 +0000235 tok::ObjCKeywordKind ocKind = Tok.getObjCKeywordID();
Steve Naroff0bbffd82007-08-22 16:35:03 +0000236
237 if (ocKind == tok::objc_end) { // terminate list
Steve Naroff1a7fa7b2007-10-29 21:38:07 +0000238 AtEndLoc = AtLoc;
Fariborz Jahanian3dc7cbc2007-09-10 20:33:04 +0000239 break;
Steve Naroff0bbffd82007-08-22 16:35:03 +0000240 } else if (ocKind == tok::objc_required) { // protocols only
241 ConsumeToken();
Fariborz Jahanian8b5ab6f2007-09-18 00:25:23 +0000242 MethodImplKind = ocKind;
Fariborz Jahanian63ca8ae2007-09-17 21:07:36 +0000243 if (contextKey != tok::objc_protocol)
244 Diag(AtLoc, diag::err_objc_protocol_required);
Steve Naroff0bbffd82007-08-22 16:35:03 +0000245 } else if (ocKind == tok::objc_optional) { // protocols only
246 ConsumeToken();
Fariborz Jahanian8b5ab6f2007-09-18 00:25:23 +0000247 MethodImplKind = ocKind;
Fariborz Jahanian63ca8ae2007-09-17 21:07:36 +0000248 if (contextKey != tok::objc_protocol)
249 Diag(AtLoc, diag::err_objc_protocol_optional);
Steve Naroff0bbffd82007-08-22 16:35:03 +0000250 } else if (ocKind == tok::objc_property) {
Fariborz Jahaniand8df6d82007-11-06 22:01:00 +0000251 allProperties.push_back(ParseObjCPropertyDecl(interfaceDecl, AtLoc));
Steve Naroff0bbffd82007-08-22 16:35:03 +0000252 continue;
253 } else {
254 Diag(Tok, diag::err_objc_illegal_interface_qual);
255 ConsumeToken();
256 }
257 }
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000258 if (Tok.is(tok::minus) || Tok.is(tok::plus)) {
259 DeclTy *methodPrototype =
260 ParseObjCMethodPrototype(interfaceDecl, MethodImplKind);
Fariborz Jahanian63ca8ae2007-09-17 21:07:36 +0000261 allMethods.push_back(methodPrototype);
Steve Naroff81f1bba2007-09-06 21:24:23 +0000262 // Consume the ';' here, since ParseObjCMethodPrototype() is re-used for
263 // method definitions.
Steve Naroffaa1b6d42007-09-17 15:07:43 +0000264 ExpectAndConsume(tok::semi, diag::err_expected_semi_after,"method proto");
Steve Naroff0bbffd82007-08-22 16:35:03 +0000265 continue;
266 }
Fariborz Jahanian5d175c32007-12-11 18:34:51 +0000267 else if (Tok.is(tok::at))
268 continue;
269
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000270 if (Tok.is(tok::semi))
Steve Naroff0bbffd82007-08-22 16:35:03 +0000271 ConsumeToken();
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000272 else if (Tok.is(tok::eof))
Fariborz Jahanian3dc7cbc2007-09-10 20:33:04 +0000273 break;
Steve Naroff304ed392007-09-05 23:30:30 +0000274 else {
Steve Naroff09a0c4c2007-08-22 18:35:33 +0000275 // FIXME: as the name implies, this rule allows function definitions.
276 // We could pass a flag or check for functions during semantic analysis.
Steve Naroff81f1bba2007-09-06 21:24:23 +0000277 ParseDeclarationOrFunctionDefinition();
Steve Naroff304ed392007-09-05 23:30:30 +0000278 }
Steve Naroff0bbffd82007-08-22 16:35:03 +0000279 }
Steve Naroff1ccf4632007-10-30 03:43:13 +0000280 /// Insert collected methods declarations into the @interface object.
Steve Naroffb82c50f2007-11-11 17:19:15 +0000281 Actions.ActOnAtEnd(AtEndLoc, interfaceDecl, &allMethods[0], allMethods.size(),
282 &allProperties[0], allProperties.size());
Steve Naroff0bbffd82007-08-22 16:35:03 +0000283}
284
Fariborz Jahanian6668b8c2007-08-31 16:11:31 +0000285/// Parse property attribute declarations.
286///
287/// property-attr-decl: '(' property-attrlist ')'
288/// property-attrlist:
289/// property-attribute
290/// property-attrlist ',' property-attribute
291/// property-attribute:
292/// getter '=' identifier
293/// setter '=' identifier ':'
294/// readonly
295/// readwrite
296/// assign
297/// retain
298/// copy
299/// nonatomic
300///
Fariborz Jahaniand8df6d82007-11-06 22:01:00 +0000301void Parser::ParseObjCPropertyAttribute (ObjcDeclSpec &DS) {
Fariborz Jahanian6668b8c2007-08-31 16:11:31 +0000302 SourceLocation loc = ConsumeParen(); // consume '('
303 while (isObjCPropertyAttribute()) {
304 const IdentifierInfo *II = Tok.getIdentifierInfo();
305 // getter/setter require extra treatment.
306 if (II == ObjcPropertyAttrs[objc_getter] ||
307 II == ObjcPropertyAttrs[objc_setter]) {
308 // skip getter/setter part.
309 SourceLocation loc = ConsumeToken();
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000310 if (Tok.is(tok::equal)) {
Fariborz Jahanian6668b8c2007-08-31 16:11:31 +0000311 loc = ConsumeToken();
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000312 if (Tok.is(tok::identifier)) {
Fariborz Jahanian6668b8c2007-08-31 16:11:31 +0000313 if (II == ObjcPropertyAttrs[objc_setter]) {
Fariborz Jahaniand8df6d82007-11-06 22:01:00 +0000314 DS.setPropertyAttributes(ObjcDeclSpec::DQ_PR_setter);
315 DS.setSetterName(Tok.getIdentifierInfo());
Fariborz Jahanian6668b8c2007-08-31 16:11:31 +0000316 loc = ConsumeToken(); // consume method name
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000317 if (Tok.isNot(tok::colon)) {
Fariborz Jahanian6668b8c2007-08-31 16:11:31 +0000318 Diag(loc, diag::err_expected_colon);
319 SkipUntil(tok::r_paren,true,true);
320 break;
321 }
322 }
Fariborz Jahaniand8df6d82007-11-06 22:01:00 +0000323 else {
324 DS.setPropertyAttributes(ObjcDeclSpec::DQ_PR_getter);
325 DS.setGetterName(Tok.getIdentifierInfo());
326 }
Fariborz Jahanian6668b8c2007-08-31 16:11:31 +0000327 }
328 else {
329 Diag(loc, diag::err_expected_ident);
330 SkipUntil(tok::r_paren,true,true);
331 break;
332 }
333 }
334 else {
335 Diag(loc, diag::err_objc_expected_equal);
336 SkipUntil(tok::r_paren,true,true);
337 break;
338 }
339 }
Fariborz Jahaniand8df6d82007-11-06 22:01:00 +0000340
341 else if (II == ObjcPropertyAttrs[objc_readonly])
342 DS.setPropertyAttributes(ObjcDeclSpec::DQ_PR_readonly);
343 else if (II == ObjcPropertyAttrs[objc_assign])
344 DS.setPropertyAttributes(ObjcDeclSpec::DQ_PR_assign);
345 else if (II == ObjcPropertyAttrs[objc_readwrite])
346 DS.setPropertyAttributes(ObjcDeclSpec::DQ_PR_readwrite);
347 else if (II == ObjcPropertyAttrs[objc_retain])
348 DS.setPropertyAttributes(ObjcDeclSpec::DQ_PR_retain);
349 else if (II == ObjcPropertyAttrs[objc_copy])
350 DS.setPropertyAttributes(ObjcDeclSpec::DQ_PR_copy);
351 else if (II == ObjcPropertyAttrs[objc_nonatomic])
352 DS.setPropertyAttributes(ObjcDeclSpec::DQ_PR_nonatomic);
353
Fariborz Jahanian6668b8c2007-08-31 16:11:31 +0000354 ConsumeToken(); // consume last attribute token
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000355 if (Tok.is(tok::comma)) {
Fariborz Jahanian6668b8c2007-08-31 16:11:31 +0000356 loc = ConsumeToken();
357 continue;
358 }
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000359 if (Tok.is(tok::r_paren))
Fariborz Jahanian6668b8c2007-08-31 16:11:31 +0000360 break;
361 Diag(loc, diag::err_expected_rparen);
362 SkipUntil(tok::semi);
363 return;
364 }
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000365 if (Tok.is(tok::r_paren))
Fariborz Jahanian6668b8c2007-08-31 16:11:31 +0000366 ConsumeParen();
367 else {
368 Diag(loc, diag::err_objc_expected_property_attr);
369 SkipUntil(tok::r_paren); // recover from error inside attribute list
370 }
371}
372
373/// Main routine to parse property declaration.
374///
375/// @property property-attr-decl[opt] property-component-decl ';'
376///
Fariborz Jahaniand8df6d82007-11-06 22:01:00 +0000377Parser::DeclTy *Parser::ParseObjCPropertyDecl(DeclTy *interfaceDecl,
378 SourceLocation AtLoc) {
Fariborz Jahanian6668b8c2007-08-31 16:11:31 +0000379 assert(Tok.isObjCAtKeyword(tok::objc_property) &&
380 "ParseObjCPropertyDecl(): Expected @property");
Fariborz Jahaniand8df6d82007-11-06 22:01:00 +0000381 ObjcDeclSpec DS;
Fariborz Jahanian6668b8c2007-08-31 16:11:31 +0000382 ConsumeToken(); // the "property" identifier
383 // Parse property attribute list, if any.
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000384 if (Tok.is(tok::l_paren)) {
Fariborz Jahanian6668b8c2007-08-31 16:11:31 +0000385 // property has attribute list.
Fariborz Jahaniand8df6d82007-11-06 22:01:00 +0000386 ParseObjCPropertyAttribute(DS);
Fariborz Jahanian6668b8c2007-08-31 16:11:31 +0000387 }
388 // Parse declaration portion of @property.
Fariborz Jahaniand8df6d82007-11-06 22:01:00 +0000389 llvm::SmallVector<DeclTy*, 8> PropertyDecls;
Fariborz Jahanian6668b8c2007-08-31 16:11:31 +0000390 ParseStructDeclaration(interfaceDecl, PropertyDecls);
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000391 if (Tok.is(tok::semi))
Fariborz Jahanian6668b8c2007-08-31 16:11:31 +0000392 ConsumeToken();
393 else {
394 Diag(Tok, diag::err_expected_semi_decl_list);
395 SkipUntil(tok::r_brace, true, true);
396 }
Fariborz Jahaniand8df6d82007-11-06 22:01:00 +0000397 return Actions.ActOnAddObjcProperties(AtLoc,
398 &PropertyDecls[0], PropertyDecls.size(), DS);
Chris Lattner4b009652007-07-25 00:24:17 +0000399}
Steve Narofffb367882007-08-20 21:31:48 +0000400
Steve Naroff81f1bba2007-09-06 21:24:23 +0000401/// objc-method-proto:
Fariborz Jahanian027c23b2007-09-01 00:26:16 +0000402/// objc-instance-method objc-method-decl objc-method-attributes[opt]
Steve Naroff81f1bba2007-09-06 21:24:23 +0000403/// objc-class-method objc-method-decl objc-method-attributes[opt]
Steve Naroff0bbffd82007-08-22 16:35:03 +0000404///
405/// objc-instance-method: '-'
406/// objc-class-method: '+'
407///
Steve Naroff09a0c4c2007-08-22 18:35:33 +0000408/// objc-method-attributes: [OBJC2]
409/// __attribute__((deprecated))
410///
Fariborz Jahanian8b5ab6f2007-09-18 00:25:23 +0000411Parser::DeclTy *Parser::ParseObjCMethodPrototype(DeclTy *IDecl,
412 tok::ObjCKeywordKind MethodImplKind) {
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000413 assert((Tok.is(tok::minus) || Tok.is(tok::plus)) && "expected +/-");
Steve Naroff0bbffd82007-08-22 16:35:03 +0000414
415 tok::TokenKind methodType = Tok.getKind();
Steve Naroff3774dd92007-10-26 20:53:56 +0000416 SourceLocation mLoc = ConsumeToken();
Steve Naroff0bbffd82007-08-22 16:35:03 +0000417
Fariborz Jahanian8473b222007-11-09 19:52:12 +0000418 DeclTy *MDecl = ParseObjCMethodDecl(mLoc, methodType, IDecl, MethodImplKind);
Steve Naroff81f1bba2007-09-06 21:24:23 +0000419 // Since this rule is used for both method declarations and definitions,
Steve Narofffaed3bf2007-09-10 20:51:04 +0000420 // the caller is (optionally) responsible for consuming the ';'.
Steve Naroff304ed392007-09-05 23:30:30 +0000421 return MDecl;
Steve Naroff0bbffd82007-08-22 16:35:03 +0000422}
423
424/// objc-selector:
425/// identifier
426/// one of
427/// enum struct union if else while do for switch case default
428/// break continue return goto asm sizeof typeof __alignof
429/// unsigned long const short volatile signed restrict _Complex
430/// in out inout bycopy byref oneway int char float double void _Bool
431///
Fariborz Jahanian91193f62007-10-11 00:55:41 +0000432IdentifierInfo *Parser::ParseObjCSelector(SourceLocation &SelectorLoc) {
Chris Lattnerd031a452007-10-07 02:00:24 +0000433 switch (Tok.getKind()) {
434 default:
435 return 0;
436 case tok::identifier:
437 case tok::kw_typeof:
438 case tok::kw___alignof:
439 case tok::kw_auto:
440 case tok::kw_break:
441 case tok::kw_case:
442 case tok::kw_char:
443 case tok::kw_const:
444 case tok::kw_continue:
445 case tok::kw_default:
446 case tok::kw_do:
447 case tok::kw_double:
448 case tok::kw_else:
449 case tok::kw_enum:
450 case tok::kw_extern:
451 case tok::kw_float:
452 case tok::kw_for:
453 case tok::kw_goto:
454 case tok::kw_if:
455 case tok::kw_inline:
456 case tok::kw_int:
457 case tok::kw_long:
458 case tok::kw_register:
459 case tok::kw_restrict:
460 case tok::kw_return:
461 case tok::kw_short:
462 case tok::kw_signed:
463 case tok::kw_sizeof:
464 case tok::kw_static:
465 case tok::kw_struct:
466 case tok::kw_switch:
467 case tok::kw_typedef:
468 case tok::kw_union:
469 case tok::kw_unsigned:
470 case tok::kw_void:
471 case tok::kw_volatile:
472 case tok::kw_while:
Chris Lattner2baef2e2007-11-15 05:25:19 +0000473 case tok::kw_bool:
Chris Lattnerd031a452007-10-07 02:00:24 +0000474 case tok::kw__Bool:
475 case tok::kw__Complex:
476 IdentifierInfo *II = Tok.getIdentifierInfo();
Fariborz Jahanian91193f62007-10-11 00:55:41 +0000477 SelectorLoc = ConsumeToken();
Chris Lattnerd031a452007-10-07 02:00:24 +0000478 return II;
Fariborz Jahanian171ceb52007-09-27 19:52:15 +0000479 }
Steve Naroff0bbffd82007-08-22 16:35:03 +0000480}
481
Fariborz Jahanian6668b8c2007-08-31 16:11:31 +0000482/// property-attrlist: one of
483/// readonly getter setter assign retain copy nonatomic
484///
485bool Parser::isObjCPropertyAttribute() {
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000486 if (Tok.is(tok::identifier)) {
Fariborz Jahanian6668b8c2007-08-31 16:11:31 +0000487 const IdentifierInfo *II = Tok.getIdentifierInfo();
488 for (unsigned i = 0; i < objc_NumAttrs; ++i)
489 if (II == ObjcPropertyAttrs[i]) return true;
490 }
491 return false;
492}
493
Steve Naroff0bbffd82007-08-22 16:35:03 +0000494/// objc-type-name:
495/// '(' objc-type-qualifiers[opt] type-name ')'
496/// '(' objc-type-qualifiers[opt] ')'
497///
498/// objc-type-qualifiers:
499/// objc-type-qualifier
500/// objc-type-qualifiers objc-type-qualifier
501///
Fariborz Jahanian2fd0daa2007-10-31 23:53:01 +0000502Parser::TypeTy *Parser::ParseObjCTypeName(ObjcDeclSpec &DS) {
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000503 assert(Tok.is(tok::l_paren) && "expected (");
Steve Naroff0bbffd82007-08-22 16:35:03 +0000504
505 SourceLocation LParenLoc = ConsumeParen(), RParenLoc;
Chris Lattner265c8172007-09-27 15:15:46 +0000506 TypeTy *Ty = 0;
Steve Naroff0bbffd82007-08-22 16:35:03 +0000507
Fariborz Jahanian6dab49b2007-10-31 21:59:43 +0000508 // Parse type qualifiers, in, inout, etc.
Fariborz Jahanian6dab49b2007-10-31 21:59:43 +0000509 ParseObjcTypeQualifierList(DS);
Steve Naroffa8ee2262007-08-22 23:18:22 +0000510
Steve Naroff0bbffd82007-08-22 16:35:03 +0000511 if (isTypeSpecifierQualifier()) {
Steve Naroff304ed392007-09-05 23:30:30 +0000512 Ty = ParseTypeName();
513 // FIXME: back when Sema support is in place...
514 // assert(Ty && "Parser::ParseObjCTypeName(): missing type");
Steve Naroff0bbffd82007-08-22 16:35:03 +0000515 }
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000516 if (Tok.isNot(tok::r_paren)) {
Steve Naroff0bbffd82007-08-22 16:35:03 +0000517 MatchRHSPunctuation(tok::r_paren, LParenLoc);
Steve Naroff304ed392007-09-05 23:30:30 +0000518 return 0; // FIXME: decide how we want to handle this error...
Steve Naroff0bbffd82007-08-22 16:35:03 +0000519 }
520 RParenLoc = ConsumeParen();
Steve Naroff304ed392007-09-05 23:30:30 +0000521 return Ty;
Steve Naroff0bbffd82007-08-22 16:35:03 +0000522}
523
524/// objc-method-decl:
525/// objc-selector
Steve Naroff09a0c4c2007-08-22 18:35:33 +0000526/// objc-keyword-selector objc-parmlist[opt]
Steve Naroff0bbffd82007-08-22 16:35:03 +0000527/// objc-type-name objc-selector
Steve Naroff09a0c4c2007-08-22 18:35:33 +0000528/// objc-type-name objc-keyword-selector objc-parmlist[opt]
Steve Naroff0bbffd82007-08-22 16:35:03 +0000529///
530/// objc-keyword-selector:
Steve Naroff72f17fb2007-08-22 22:17:26 +0000531/// objc-keyword-decl
Steve Naroff0bbffd82007-08-22 16:35:03 +0000532/// objc-keyword-selector objc-keyword-decl
533///
534/// objc-keyword-decl:
Steve Naroff72f17fb2007-08-22 22:17:26 +0000535/// objc-selector ':' objc-type-name objc-keyword-attributes[opt] identifier
536/// objc-selector ':' objc-keyword-attributes[opt] identifier
537/// ':' objc-type-name objc-keyword-attributes[opt] identifier
538/// ':' objc-keyword-attributes[opt] identifier
Steve Naroff0bbffd82007-08-22 16:35:03 +0000539///
Steve Naroff09a0c4c2007-08-22 18:35:33 +0000540/// objc-parmlist:
541/// objc-parms objc-ellipsis[opt]
Steve Naroff0bbffd82007-08-22 16:35:03 +0000542///
Steve Naroff09a0c4c2007-08-22 18:35:33 +0000543/// objc-parms:
544/// objc-parms , parameter-declaration
Steve Naroff0bbffd82007-08-22 16:35:03 +0000545///
Steve Naroff09a0c4c2007-08-22 18:35:33 +0000546/// objc-ellipsis:
Steve Naroff0bbffd82007-08-22 16:35:03 +0000547/// , ...
548///
Steve Naroff72f17fb2007-08-22 22:17:26 +0000549/// objc-keyword-attributes: [OBJC2]
550/// __attribute__((unused))
551///
Steve Naroff3774dd92007-10-26 20:53:56 +0000552Parser::DeclTy *Parser::ParseObjCMethodDecl(SourceLocation mLoc,
Fariborz Jahanian8473b222007-11-09 19:52:12 +0000553 tok::TokenKind mType,
554 DeclTy *IDecl,
Steve Naroff4ed9d662007-09-27 14:38:14 +0000555 tok::ObjCKeywordKind MethodImplKind)
556{
Steve Naroff09a0c4c2007-08-22 18:35:33 +0000557 // Parse the return type.
Chris Lattnerd031a452007-10-07 02:00:24 +0000558 TypeTy *ReturnType = 0;
Fariborz Jahanian2fd0daa2007-10-31 23:53:01 +0000559 ObjcDeclSpec DSRet;
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000560 if (Tok.is(tok::l_paren))
Fariborz Jahanian2fd0daa2007-10-31 23:53:01 +0000561 ReturnType = ParseObjCTypeName(DSRet);
Steve Naroff3774dd92007-10-26 20:53:56 +0000562 SourceLocation selLoc;
563 IdentifierInfo *SelIdent = ParseObjCSelector(selLoc);
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000564 if (Tok.isNot(tok::colon)) {
Chris Lattnerd031a452007-10-07 02:00:24 +0000565 if (!SelIdent) {
566 Diag(Tok, diag::err_expected_ident); // missing selector name.
567 // FIXME: this creates a unary selector with a null identifier, is this
568 // ok?? Maybe we should skip to the next semicolon or something.
569 }
570
571 // If attributes exist after the method, parse them.
572 AttributeList *MethodAttrs = 0;
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000573 if (getLang().ObjC2 && Tok.is(tok::kw___attribute))
Chris Lattnerd031a452007-10-07 02:00:24 +0000574 MethodAttrs = ParseAttributes();
575
576 Selector Sel = PP.getSelectorTable().getNullarySelector(SelIdent);
Steve Naroff3774dd92007-10-26 20:53:56 +0000577 return Actions.ActOnMethodDeclaration(mLoc, Tok.getLocation(),
Fariborz Jahanian8473b222007-11-09 19:52:12 +0000578 mType, IDecl, DSRet, ReturnType, Sel,
Fariborz Jahanian2fd0daa2007-10-31 23:53:01 +0000579 0, 0, 0, MethodAttrs, MethodImplKind);
Chris Lattnerd031a452007-10-07 02:00:24 +0000580 }
Steve Naroff304ed392007-09-05 23:30:30 +0000581
Steve Naroff4ed9d662007-09-27 14:38:14 +0000582 llvm::SmallVector<IdentifierInfo *, 12> KeyIdents;
583 llvm::SmallVector<Action::TypeTy *, 12> KeyTypes;
Fariborz Jahanian2fd0daa2007-10-31 23:53:01 +0000584 llvm::SmallVector<ObjcDeclSpec, 12> ArgTypeQuals;
Steve Naroff4ed9d662007-09-27 14:38:14 +0000585 llvm::SmallVector<IdentifierInfo *, 12> ArgNames;
Chris Lattnerd031a452007-10-07 02:00:24 +0000586
587 Action::TypeTy *TypeInfo;
588 while (1) {
589 KeyIdents.push_back(SelIdent);
Steve Naroff4ed9d662007-09-27 14:38:14 +0000590
Chris Lattnerd031a452007-10-07 02:00:24 +0000591 // Each iteration parses a single keyword argument.
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000592 if (Tok.isNot(tok::colon)) {
Chris Lattnerd031a452007-10-07 02:00:24 +0000593 Diag(Tok, diag::err_expected_colon);
594 break;
595 }
596 ConsumeToken(); // Eat the ':'.
Fariborz Jahanian2fd0daa2007-10-31 23:53:01 +0000597 ObjcDeclSpec DSType;
598 if (Tok.is(tok::l_paren)) { // Parse the argument type.
599 TypeInfo = ParseObjCTypeName(DSType);
600 }
Chris Lattnerd031a452007-10-07 02:00:24 +0000601 else
602 TypeInfo = 0;
603 KeyTypes.push_back(TypeInfo);
Fariborz Jahanian2fd0daa2007-10-31 23:53:01 +0000604 ArgTypeQuals.push_back(DSType);
Steve Naroff304ed392007-09-05 23:30:30 +0000605
Chris Lattnerd031a452007-10-07 02:00:24 +0000606 // If attributes exist before the argument name, parse them.
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000607 if (getLang().ObjC2 && Tok.is(tok::kw___attribute))
Chris Lattnerd031a452007-10-07 02:00:24 +0000608 ParseAttributes(); // FIXME: pass attributes through.
Steve Naroff72f17fb2007-08-22 22:17:26 +0000609
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000610 if (Tok.isNot(tok::identifier)) {
Chris Lattnerd031a452007-10-07 02:00:24 +0000611 Diag(Tok, diag::err_expected_ident); // missing argument name.
612 break;
Steve Naroff09a0c4c2007-08-22 18:35:33 +0000613 }
Chris Lattnerd031a452007-10-07 02:00:24 +0000614 ArgNames.push_back(Tok.getIdentifierInfo());
615 ConsumeToken(); // Eat the identifier.
Steve Narofff9e80db2007-10-05 18:42:47 +0000616
Chris Lattnerd031a452007-10-07 02:00:24 +0000617 // Check for another keyword selector.
Fariborz Jahanian91193f62007-10-11 00:55:41 +0000618 SourceLocation Loc;
619 SelIdent = ParseObjCSelector(Loc);
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000620 if (!SelIdent && Tok.isNot(tok::colon))
Chris Lattnerd031a452007-10-07 02:00:24 +0000621 break;
622 // We have a selector or a colon, continue parsing.
Steve Naroff09a0c4c2007-08-22 18:35:33 +0000623 }
Chris Lattnerd031a452007-10-07 02:00:24 +0000624
Steve Naroff29fe7462007-11-15 12:35:21 +0000625 bool isVariadic = false;
626
Chris Lattnerd031a452007-10-07 02:00:24 +0000627 // Parse the (optional) parameter list.
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000628 while (Tok.is(tok::comma)) {
Chris Lattnerd031a452007-10-07 02:00:24 +0000629 ConsumeToken();
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000630 if (Tok.is(tok::ellipsis)) {
Steve Naroff29fe7462007-11-15 12:35:21 +0000631 isVariadic = true;
Chris Lattnerd031a452007-10-07 02:00:24 +0000632 ConsumeToken();
633 break;
634 }
Steve Naroff29fe7462007-11-15 12:35:21 +0000635 // FIXME: implement this...
Chris Lattnerd031a452007-10-07 02:00:24 +0000636 // Parse the c-style argument declaration-specifier.
637 DeclSpec DS;
638 ParseDeclarationSpecifiers(DS);
639 // Parse the declarator.
640 Declarator ParmDecl(DS, Declarator::PrototypeContext);
641 ParseDeclarator(ParmDecl);
642 }
643
644 // FIXME: Add support for optional parmameter list...
Fariborz Jahanian3dc7cbc2007-09-10 20:33:04 +0000645 // If attributes exist after the method, parse them.
Chris Lattnerd031a452007-10-07 02:00:24 +0000646 AttributeList *MethodAttrs = 0;
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000647 if (getLang().ObjC2 && Tok.is(tok::kw___attribute))
Chris Lattnerd031a452007-10-07 02:00:24 +0000648 MethodAttrs = ParseAttributes();
649
650 Selector Sel = PP.getSelectorTable().getSelector(KeyIdents.size(),
651 &KeyIdents[0]);
Steve Naroff3774dd92007-10-26 20:53:56 +0000652 return Actions.ActOnMethodDeclaration(mLoc, Tok.getLocation(),
Fariborz Jahanian8473b222007-11-09 19:52:12 +0000653 mType, IDecl, DSRet, ReturnType, Sel,
Fariborz Jahanian2fd0daa2007-10-31 23:53:01 +0000654 &ArgTypeQuals[0], &KeyTypes[0],
Steve Naroff29fe7462007-11-15 12:35:21 +0000655 &ArgNames[0], MethodAttrs,
656 MethodImplKind, isVariadic);
Steve Naroff0bbffd82007-08-22 16:35:03 +0000657}
658
Fariborz Jahanianc04aff12007-10-08 23:06:41 +0000659/// CmpProtocolVals - Comparison predicate for sorting protocols.
660static bool CmpProtocolVals(const IdentifierInfo* const& lhs,
661 const IdentifierInfo* const& rhs) {
662 return strcmp(lhs->getName(), rhs->getName()) < 0;
663}
664
Steve Narofffb367882007-08-20 21:31:48 +0000665/// objc-protocol-refs:
666/// '<' identifier-list '>'
667///
Steve Naroff304ed392007-09-05 23:30:30 +0000668bool Parser::ParseObjCProtocolReferences(
Steve Naroffef20ed32007-10-30 02:23:23 +0000669 llvm::SmallVectorImpl<IdentifierInfo*> &ProtocolRefs, SourceLocation &endLoc)
670{
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000671 assert(Tok.is(tok::less) && "expected <");
Steve Narofffb367882007-08-20 21:31:48 +0000672
673 ConsumeToken(); // the "<"
Steve Narofffb367882007-08-20 21:31:48 +0000674
675 while (1) {
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000676 if (Tok.isNot(tok::identifier)) {
Steve Narofffb367882007-08-20 21:31:48 +0000677 Diag(Tok, diag::err_expected_ident);
678 SkipUntil(tok::greater);
679 return true;
680 }
681 ProtocolRefs.push_back(Tok.getIdentifierInfo());
682 ConsumeToken();
683
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000684 if (Tok.isNot(tok::comma))
Steve Narofffb367882007-08-20 21:31:48 +0000685 break;
686 ConsumeToken();
687 }
Fariborz Jahanianc04aff12007-10-08 23:06:41 +0000688
689 // Sort protocols, keyed by name.
690 // Later on, we remove duplicates.
691 std::stable_sort(ProtocolRefs.begin(), ProtocolRefs.end(), CmpProtocolVals);
692
693 // Make protocol names unique.
694 ProtocolRefs.erase(std::unique(ProtocolRefs.begin(), ProtocolRefs.end()),
695 ProtocolRefs.end());
Steve Narofffb367882007-08-20 21:31:48 +0000696 // Consume the '>'.
Steve Naroffef20ed32007-10-30 02:23:23 +0000697 if (Tok.is(tok::greater)) {
698 endLoc = ConsumeAnyToken();
699 return false;
700 }
701 Diag(Tok, diag::err_expected_greater);
702 return true;
Steve Narofffb367882007-08-20 21:31:48 +0000703}
704
705/// objc-class-instance-variables:
706/// '{' objc-instance-variable-decl-list[opt] '}'
707///
708/// objc-instance-variable-decl-list:
709/// objc-visibility-spec
710/// objc-instance-variable-decl ';'
711/// ';'
712/// objc-instance-variable-decl-list objc-visibility-spec
713/// objc-instance-variable-decl-list objc-instance-variable-decl ';'
714/// objc-instance-variable-decl-list ';'
715///
716/// objc-visibility-spec:
717/// @private
718/// @protected
719/// @public
Steve Naroffc4474992007-08-21 21:17:12 +0000720/// @package [OBJC2]
Steve Narofffb367882007-08-20 21:31:48 +0000721///
722/// objc-instance-variable-decl:
723/// struct-declaration
724///
Steve Naroff1a7fa7b2007-10-29 21:38:07 +0000725void Parser::ParseObjCClassInstanceVariables(DeclTy *interfaceDecl,
726 SourceLocation atLoc) {
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000727 assert(Tok.is(tok::l_brace) && "expected {");
Steve Naroff81f1bba2007-09-06 21:24:23 +0000728 llvm::SmallVector<DeclTy*, 16> IvarDecls;
Fariborz Jahanian3957dae2007-09-13 20:56:13 +0000729 llvm::SmallVector<DeclTy*, 32> AllIvarDecls;
730 llvm::SmallVector<tok::ObjCKeywordKind, 32> AllVisibilities;
Steve Naroffc4474992007-08-21 21:17:12 +0000731
732 SourceLocation LBraceLoc = ConsumeBrace(); // the "{"
Steve Naroffc4474992007-08-21 21:17:12 +0000733
Fariborz Jahanian3957dae2007-09-13 20:56:13 +0000734 tok::ObjCKeywordKind visibility = tok::objc_private;
Steve Naroffc4474992007-08-21 21:17:12 +0000735 // While we still have something to read, read the instance variables.
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000736 while (Tok.isNot(tok::r_brace) && Tok.isNot(tok::eof)) {
Steve Naroffc4474992007-08-21 21:17:12 +0000737 // Each iteration of this loop reads one objc-instance-variable-decl.
738
739 // Check for extraneous top-level semicolon.
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000740 if (Tok.is(tok::semi)) {
Steve Naroffc4474992007-08-21 21:17:12 +0000741 Diag(Tok, diag::ext_extra_struct_semi);
742 ConsumeToken();
743 continue;
744 }
745 // Set the default visibility to private.
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000746 if (Tok.is(tok::at)) { // parse objc-visibility-spec
Steve Naroffc4474992007-08-21 21:17:12 +0000747 ConsumeToken(); // eat the @ sign
Steve Naroff87c329f2007-08-23 18:16:40 +0000748 switch (Tok.getObjCKeywordID()) {
Steve Naroffc4474992007-08-21 21:17:12 +0000749 case tok::objc_private:
750 case tok::objc_public:
751 case tok::objc_protected:
752 case tok::objc_package:
Steve Naroff87c329f2007-08-23 18:16:40 +0000753 visibility = Tok.getObjCKeywordID();
Steve Naroffc4474992007-08-21 21:17:12 +0000754 ConsumeToken();
755 continue;
756 default:
757 Diag(Tok, diag::err_objc_illegal_visibility_spec);
758 ConsumeToken();
759 continue;
760 }
761 }
762 ParseStructDeclaration(interfaceDecl, IvarDecls);
Fariborz Jahanian3957dae2007-09-13 20:56:13 +0000763 for (unsigned i = 0; i < IvarDecls.size(); i++) {
764 AllIvarDecls.push_back(IvarDecls[i]);
765 AllVisibilities.push_back(visibility);
766 }
Steve Naroff81f1bba2007-09-06 21:24:23 +0000767 IvarDecls.clear();
768
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000769 if (Tok.is(tok::semi)) {
Steve Naroffc4474992007-08-21 21:17:12 +0000770 ConsumeToken();
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000771 } else if (Tok.is(tok::r_brace)) {
Steve Naroffc4474992007-08-21 21:17:12 +0000772 Diag(Tok.getLocation(), diag::ext_expected_semi_decl_list);
773 break;
774 } else {
775 Diag(Tok, diag::err_expected_semi_decl_list);
776 // Skip to end of block or statement
777 SkipUntil(tok::r_brace, true, true);
778 }
779 }
Steve Naroff1a7fa7b2007-10-29 21:38:07 +0000780 SourceLocation RBraceLoc = MatchRHSPunctuation(tok::r_brace, LBraceLoc);
Steve Naroff809b4f02007-10-31 22:11:35 +0000781 // Call ActOnFields() even if we don't have any decls. This is useful
782 // for code rewriting tools that need to be aware of the empty list.
783 Actions.ActOnFields(CurScope, atLoc, interfaceDecl,
784 &AllIvarDecls[0], AllIvarDecls.size(),
785 LBraceLoc, RBraceLoc, &AllVisibilities[0]);
Steve Naroffc4474992007-08-21 21:17:12 +0000786 return;
Chris Lattner4b009652007-07-25 00:24:17 +0000787}
Steve Narofffb367882007-08-20 21:31:48 +0000788
789/// objc-protocol-declaration:
790/// objc-protocol-definition
791/// objc-protocol-forward-reference
792///
793/// objc-protocol-definition:
794/// @protocol identifier
795/// objc-protocol-refs[opt]
Steve Naroff81f1bba2007-09-06 21:24:23 +0000796/// objc-interface-decl-list
Steve Narofffb367882007-08-20 21:31:48 +0000797/// @end
798///
799/// objc-protocol-forward-reference:
800/// @protocol identifier-list ';'
801///
802/// "@protocol identifier ;" should be resolved as "@protocol
Steve Naroff81f1bba2007-09-06 21:24:23 +0000803/// identifier-list ;": objc-interface-decl-list may not start with a
Steve Narofffb367882007-08-20 21:31:48 +0000804/// semicolon in the first alternative if objc-protocol-refs are omitted.
805
Steve Naroff72f17fb2007-08-22 22:17:26 +0000806Parser::DeclTy *Parser::ParseObjCAtProtocolDeclaration(SourceLocation AtLoc) {
Steve Naroff87c329f2007-08-23 18:16:40 +0000807 assert(Tok.isObjCAtKeyword(tok::objc_protocol) &&
Steve Naroff72f17fb2007-08-22 22:17:26 +0000808 "ParseObjCAtProtocolDeclaration(): Expected @protocol");
809 ConsumeToken(); // the "protocol" identifier
810
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000811 if (Tok.isNot(tok::identifier)) {
Steve Naroff72f17fb2007-08-22 22:17:26 +0000812 Diag(Tok, diag::err_expected_ident); // missing protocol name.
813 return 0;
814 }
815 // Save the protocol name, then consume it.
816 IdentifierInfo *protocolName = Tok.getIdentifierInfo();
817 SourceLocation nameLoc = ConsumeToken();
818
Fariborz Jahanianc716c942007-09-21 15:40:54 +0000819 llvm::SmallVector<IdentifierInfo *, 8> ProtocolRefs;
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000820 if (Tok.is(tok::semi)) { // forward declaration of one protocol.
Steve Naroff72f17fb2007-08-22 22:17:26 +0000821 ConsumeToken();
Fariborz Jahanianc716c942007-09-21 15:40:54 +0000822 ProtocolRefs.push_back(protocolName);
Steve Naroff72f17fb2007-08-22 22:17:26 +0000823 }
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000824 if (Tok.is(tok::comma)) { // list of forward declarations.
Steve Naroff72f17fb2007-08-22 22:17:26 +0000825 // Parse the list of forward declarations.
Steve Naroff72f17fb2007-08-22 22:17:26 +0000826 ProtocolRefs.push_back(protocolName);
827
828 while (1) {
829 ConsumeToken(); // the ','
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000830 if (Tok.isNot(tok::identifier)) {
Steve Naroff72f17fb2007-08-22 22:17:26 +0000831 Diag(Tok, diag::err_expected_ident);
832 SkipUntil(tok::semi);
833 return 0;
834 }
835 ProtocolRefs.push_back(Tok.getIdentifierInfo());
836 ConsumeToken(); // the identifier
837
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000838 if (Tok.isNot(tok::comma))
Steve Naroff72f17fb2007-08-22 22:17:26 +0000839 break;
840 }
841 // Consume the ';'.
842 if (ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@protocol"))
843 return 0;
Steve Naroff72f17fb2007-08-22 22:17:26 +0000844 }
Fariborz Jahanianc716c942007-09-21 15:40:54 +0000845 if (ProtocolRefs.size() > 0)
Steve Naroff415c1832007-10-10 17:32:04 +0000846 return Actions.ActOnForwardProtocolDeclaration(AtLoc,
Steve Naroffb4dfe362007-10-02 22:39:18 +0000847 &ProtocolRefs[0],
848 ProtocolRefs.size());
Steve Naroff72f17fb2007-08-22 22:17:26 +0000849 // Last, and definitely not least, parse a protocol declaration.
Steve Naroffef20ed32007-10-30 02:23:23 +0000850 SourceLocation endProtoLoc;
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000851 if (Tok.is(tok::less)) {
Steve Naroffef20ed32007-10-30 02:23:23 +0000852 if (ParseObjCProtocolReferences(ProtocolRefs, endProtoLoc))
Steve Naroff72f17fb2007-08-22 22:17:26 +0000853 return 0;
854 }
Fariborz Jahanian63ca8ae2007-09-17 21:07:36 +0000855
Steve Naroff415c1832007-10-10 17:32:04 +0000856 DeclTy *ProtoType = Actions.ActOnStartProtocolInterface(AtLoc,
Fariborz Jahanian63ca8ae2007-09-17 21:07:36 +0000857 protocolName, nameLoc,
858 &ProtocolRefs[0],
Steve Naroffef20ed32007-10-30 02:23:23 +0000859 ProtocolRefs.size(), endProtoLoc);
Fariborz Jahanian63ca8ae2007-09-17 21:07:36 +0000860 ParseObjCInterfaceDeclList(ProtoType, tok::objc_protocol);
Steve Naroff72f17fb2007-08-22 22:17:26 +0000861
862 // The @ sign was already consumed by ParseObjCInterfaceDeclList().
Steve Naroff87c329f2007-08-23 18:16:40 +0000863 if (Tok.isObjCAtKeyword(tok::objc_end)) {
Steve Naroff72f17fb2007-08-22 22:17:26 +0000864 ConsumeToken(); // the "end" identifier
Fariborz Jahanianac20be22007-10-08 18:53:38 +0000865 return ProtoType;
Steve Naroff72f17fb2007-08-22 22:17:26 +0000866 }
867 Diag(Tok, diag::err_objc_missing_end);
Steve Narofffb367882007-08-20 21:31:48 +0000868 return 0;
Chris Lattner4b009652007-07-25 00:24:17 +0000869}
Steve Narofffb367882007-08-20 21:31:48 +0000870
871/// objc-implementation:
872/// objc-class-implementation-prologue
873/// objc-category-implementation-prologue
874///
875/// objc-class-implementation-prologue:
876/// @implementation identifier objc-superclass[opt]
877/// objc-class-instance-variables[opt]
878///
879/// objc-category-implementation-prologue:
880/// @implementation identifier ( identifier )
881
Fariborz Jahanian027c23b2007-09-01 00:26:16 +0000882Parser::DeclTy *Parser::ParseObjCAtImplementationDeclaration(
883 SourceLocation atLoc) {
884 assert(Tok.isObjCAtKeyword(tok::objc_implementation) &&
885 "ParseObjCAtImplementationDeclaration(): Expected @implementation");
886 ConsumeToken(); // the "implementation" identifier
887
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000888 if (Tok.isNot(tok::identifier)) {
Fariborz Jahanian027c23b2007-09-01 00:26:16 +0000889 Diag(Tok, diag::err_expected_ident); // missing class or category name.
890 return 0;
891 }
892 // We have a class or category name - consume it.
Fariborz Jahanianc091b5d2007-09-25 18:38:09 +0000893 IdentifierInfo *nameId = Tok.getIdentifierInfo();
Fariborz Jahanian027c23b2007-09-01 00:26:16 +0000894 SourceLocation nameLoc = ConsumeToken(); // consume class or category name
895
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000896 if (Tok.is(tok::l_paren)) {
Fariborz Jahanian027c23b2007-09-01 00:26:16 +0000897 // we have a category implementation.
898 SourceLocation lparenLoc = ConsumeParen();
899 SourceLocation categoryLoc, rparenLoc;
900 IdentifierInfo *categoryId = 0;
901
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000902 if (Tok.is(tok::identifier)) {
Fariborz Jahanian027c23b2007-09-01 00:26:16 +0000903 categoryId = Tok.getIdentifierInfo();
904 categoryLoc = ConsumeToken();
905 } else {
906 Diag(Tok, diag::err_expected_ident); // missing category name.
907 return 0;
908 }
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000909 if (Tok.isNot(tok::r_paren)) {
Fariborz Jahanian027c23b2007-09-01 00:26:16 +0000910 Diag(Tok, diag::err_expected_rparen);
911 SkipUntil(tok::r_paren, false); // don't stop at ';'
912 return 0;
913 }
914 rparenLoc = ConsumeParen();
Steve Naroff415c1832007-10-10 17:32:04 +0000915 DeclTy *ImplCatType = Actions.ActOnStartCategoryImplementation(
Fariborz Jahaniana91aa322007-10-02 16:38:50 +0000916 atLoc, nameId, nameLoc, categoryId,
917 categoryLoc);
Fariborz Jahanian83ddf822007-11-10 20:59:13 +0000918 ObjcImpDecl = ImplCatType;
919 return 0;
Fariborz Jahanian027c23b2007-09-01 00:26:16 +0000920 }
921 // We have a class implementation
Fariborz Jahanianc091b5d2007-09-25 18:38:09 +0000922 SourceLocation superClassLoc;
923 IdentifierInfo *superClassId = 0;
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000924 if (Tok.is(tok::colon)) {
Fariborz Jahanian027c23b2007-09-01 00:26:16 +0000925 // We have a super class
926 ConsumeToken();
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000927 if (Tok.isNot(tok::identifier)) {
Fariborz Jahanian027c23b2007-09-01 00:26:16 +0000928 Diag(Tok, diag::err_expected_ident); // missing super class name.
929 return 0;
930 }
Fariborz Jahanianc091b5d2007-09-25 18:38:09 +0000931 superClassId = Tok.getIdentifierInfo();
932 superClassLoc = ConsumeToken(); // Consume super class name
Fariborz Jahanian027c23b2007-09-01 00:26:16 +0000933 }
Steve Naroff415c1832007-10-10 17:32:04 +0000934 DeclTy *ImplClsType = Actions.ActOnStartClassImplementation(
Steve Naroff25aace82007-10-03 21:00:46 +0000935 atLoc, nameId, nameLoc,
Fariborz Jahanianc091b5d2007-09-25 18:38:09 +0000936 superClassId, superClassLoc);
937
Steve Naroff1a7fa7b2007-10-29 21:38:07 +0000938 if (Tok.is(tok::l_brace)) // we have ivars
939 ParseObjCClassInstanceVariables(ImplClsType/*FIXME*/, atLoc);
Fariborz Jahanian83ddf822007-11-10 20:59:13 +0000940 ObjcImpDecl = ImplClsType;
Fariborz Jahanian027c23b2007-09-01 00:26:16 +0000941
Fariborz Jahanian83ddf822007-11-10 20:59:13 +0000942 return 0;
Chris Lattner4b009652007-07-25 00:24:17 +0000943}
Steve Naroff1a7fa7b2007-10-29 21:38:07 +0000944
Fariborz Jahanian027c23b2007-09-01 00:26:16 +0000945Parser::DeclTy *Parser::ParseObjCAtEndDeclaration(SourceLocation atLoc) {
946 assert(Tok.isObjCAtKeyword(tok::objc_end) &&
947 "ParseObjCAtEndDeclaration(): Expected @end");
948 ConsumeToken(); // the "end" identifier
Fariborz Jahanian1e4e82f2007-09-27 18:57:03 +0000949 if (ObjcImpDecl) {
950 // Checking is not necessary except that a parse error might have caused
951 // @implementation not to have been parsed to completion and ObjcImpDecl
952 // could be 0.
Steve Naroffb82c50f2007-11-11 17:19:15 +0000953 Actions.ActOnAtEnd(atLoc, ObjcImpDecl);
Fariborz Jahanian1e4e82f2007-09-27 18:57:03 +0000954 }
Fariborz Jahanian027c23b2007-09-01 00:26:16 +0000955
Fariborz Jahanian83ddf822007-11-10 20:59:13 +0000956 return ObjcImpDecl;
Steve Narofffb367882007-08-20 21:31:48 +0000957}
Fariborz Jahanianb62aff32007-09-04 19:26:51 +0000958
959/// compatibility-alias-decl:
960/// @compatibility_alias alias-name class-name ';'
961///
962Parser::DeclTy *Parser::ParseObjCAtAliasDeclaration(SourceLocation atLoc) {
963 assert(Tok.isObjCAtKeyword(tok::objc_compatibility_alias) &&
964 "ParseObjCAtAliasDeclaration(): Expected @compatibility_alias");
965 ConsumeToken(); // consume compatibility_alias
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000966 if (Tok.isNot(tok::identifier)) {
Fariborz Jahanianb62aff32007-09-04 19:26:51 +0000967 Diag(Tok, diag::err_expected_ident);
968 return 0;
969 }
Fariborz Jahanian05d212a2007-10-11 23:42:27 +0000970 IdentifierInfo *aliasId = Tok.getIdentifierInfo();
971 SourceLocation aliasLoc = ConsumeToken(); // consume alias-name
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000972 if (Tok.isNot(tok::identifier)) {
Fariborz Jahanianb62aff32007-09-04 19:26:51 +0000973 Diag(Tok, diag::err_expected_ident);
974 return 0;
975 }
Fariborz Jahanian05d212a2007-10-11 23:42:27 +0000976 IdentifierInfo *classId = Tok.getIdentifierInfo();
977 SourceLocation classLoc = ConsumeToken(); // consume class-name;
978 if (Tok.isNot(tok::semi)) {
Fariborz Jahanian6c30fa62007-09-04 21:42:12 +0000979 Diag(Tok, diag::err_expected_semi_after, "@compatibility_alias");
Fariborz Jahanian05d212a2007-10-11 23:42:27 +0000980 return 0;
981 }
982 DeclTy *ClsType = Actions.ActOnCompatiblityAlias(atLoc,
983 aliasId, aliasLoc,
984 classId, classLoc);
985 return ClsType;
Chris Lattner4b009652007-07-25 00:24:17 +0000986}
987
Fariborz Jahanian027c23b2007-09-01 00:26:16 +0000988/// property-synthesis:
989/// @synthesize property-ivar-list ';'
990///
991/// property-ivar-list:
992/// property-ivar
993/// property-ivar-list ',' property-ivar
994///
995/// property-ivar:
996/// identifier
997/// identifier '=' identifier
998///
999Parser::DeclTy *Parser::ParseObjCPropertySynthesize(SourceLocation atLoc) {
1000 assert(Tok.isObjCAtKeyword(tok::objc_synthesize) &&
1001 "ParseObjCPropertyDynamic(): Expected '@synthesize'");
1002 SourceLocation loc = ConsumeToken(); // consume dynamic
Chris Lattnera1d2bb72007-10-09 17:51:17 +00001003 if (Tok.isNot(tok::identifier)) {
Fariborz Jahanian027c23b2007-09-01 00:26:16 +00001004 Diag(Tok, diag::err_expected_ident);
1005 return 0;
1006 }
Chris Lattnera1d2bb72007-10-09 17:51:17 +00001007 while (Tok.is(tok::identifier)) {
Fariborz Jahanian027c23b2007-09-01 00:26:16 +00001008 ConsumeToken(); // consume property name
Chris Lattnera1d2bb72007-10-09 17:51:17 +00001009 if (Tok.is(tok::equal)) {
Fariborz Jahanian027c23b2007-09-01 00:26:16 +00001010 // property '=' ivar-name
1011 ConsumeToken(); // consume '='
Chris Lattnera1d2bb72007-10-09 17:51:17 +00001012 if (Tok.isNot(tok::identifier)) {
Fariborz Jahanian027c23b2007-09-01 00:26:16 +00001013 Diag(Tok, diag::err_expected_ident);
1014 break;
1015 }
1016 ConsumeToken(); // consume ivar-name
1017 }
Chris Lattnera1d2bb72007-10-09 17:51:17 +00001018 if (Tok.isNot(tok::comma))
Fariborz Jahanian027c23b2007-09-01 00:26:16 +00001019 break;
1020 ConsumeToken(); // consume ','
1021 }
Chris Lattnera1d2bb72007-10-09 17:51:17 +00001022 if (Tok.isNot(tok::semi))
Fariborz Jahanian027c23b2007-09-01 00:26:16 +00001023 Diag(Tok, diag::err_expected_semi_after, "@synthesize");
1024 return 0;
Chris Lattner4b009652007-07-25 00:24:17 +00001025}
1026
Fariborz Jahanian027c23b2007-09-01 00:26:16 +00001027/// property-dynamic:
1028/// @dynamic property-list
1029///
1030/// property-list:
1031/// identifier
1032/// property-list ',' identifier
1033///
1034Parser::DeclTy *Parser::ParseObjCPropertyDynamic(SourceLocation atLoc) {
1035 assert(Tok.isObjCAtKeyword(tok::objc_dynamic) &&
1036 "ParseObjCPropertyDynamic(): Expected '@dynamic'");
1037 SourceLocation loc = ConsumeToken(); // consume dynamic
Chris Lattnera1d2bb72007-10-09 17:51:17 +00001038 if (Tok.isNot(tok::identifier)) {
Fariborz Jahanian027c23b2007-09-01 00:26:16 +00001039 Diag(Tok, diag::err_expected_ident);
1040 return 0;
1041 }
Chris Lattnera1d2bb72007-10-09 17:51:17 +00001042 while (Tok.is(tok::identifier)) {
Fariborz Jahanian027c23b2007-09-01 00:26:16 +00001043 ConsumeToken(); // consume property name
Chris Lattnera1d2bb72007-10-09 17:51:17 +00001044 if (Tok.isNot(tok::comma))
Fariborz Jahanian027c23b2007-09-01 00:26:16 +00001045 break;
1046 ConsumeToken(); // consume ','
1047 }
Chris Lattnera1d2bb72007-10-09 17:51:17 +00001048 if (Tok.isNot(tok::semi))
Fariborz Jahanian027c23b2007-09-01 00:26:16 +00001049 Diag(Tok, diag::err_expected_semi_after, "@dynamic");
1050 return 0;
1051}
Fariborz Jahanian64b864e2007-09-19 19:14:32 +00001052
1053/// objc-throw-statement:
1054/// throw expression[opt];
1055///
Fariborz Jahanian08df2c62007-11-07 02:00:49 +00001056Parser::StmtResult Parser::ParseObjCThrowStmt(SourceLocation atLoc) {
1057 ExprResult Res;
Fariborz Jahanian64b864e2007-09-19 19:14:32 +00001058 ConsumeToken(); // consume throw
Chris Lattnera1d2bb72007-10-09 17:51:17 +00001059 if (Tok.isNot(tok::semi)) {
Fariborz Jahanian08df2c62007-11-07 02:00:49 +00001060 Res = ParseExpression();
Fariborz Jahanian64b864e2007-09-19 19:14:32 +00001061 if (Res.isInvalid) {
1062 SkipUntil(tok::semi);
Fariborz Jahanian08df2c62007-11-07 02:00:49 +00001063 return true;
Fariborz Jahanian64b864e2007-09-19 19:14:32 +00001064 }
1065 }
Fariborz Jahanian08df2c62007-11-07 02:00:49 +00001066 ConsumeToken(); // consume ';'
1067 return Actions.ActOnObjcAtThrowStmt(atLoc, Res.Val);
Fariborz Jahanian64b864e2007-09-19 19:14:32 +00001068}
1069
1070/// objc-try-catch-statement:
1071/// @try compound-statement objc-catch-list[opt]
1072/// @try compound-statement objc-catch-list[opt] @finally compound-statement
1073///
1074/// objc-catch-list:
1075/// @catch ( parameter-declaration ) compound-statement
1076/// objc-catch-list @catch ( catch-parameter-declaration ) compound-statement
1077/// catch-parameter-declaration:
1078/// parameter-declaration
1079/// '...' [OBJC2]
1080///
Fariborz Jahanian70952482007-11-01 21:12:44 +00001081Parser::StmtResult Parser::ParseObjCTryStmt(SourceLocation atLoc) {
Fariborz Jahanian64b864e2007-09-19 19:14:32 +00001082 bool catch_or_finally_seen = false;
1083 ConsumeToken(); // consume try
Chris Lattnera1d2bb72007-10-09 17:51:17 +00001084 if (Tok.isNot(tok::l_brace)) {
Fariborz Jahanian64b864e2007-09-19 19:14:32 +00001085 Diag (Tok, diag::err_expected_lbrace);
Fariborz Jahanian70952482007-11-01 21:12:44 +00001086 return true;
Fariborz Jahanian64b864e2007-09-19 19:14:32 +00001087 }
Fariborz Jahanian06798362007-11-01 23:59:59 +00001088 StmtResult CatchStmts;
Fariborz Jahaniande3abf82007-11-02 00:18:53 +00001089 StmtResult FinallyStmt;
Fariborz Jahanian64b864e2007-09-19 19:14:32 +00001090 StmtResult TryBody = ParseCompoundStatementBody();
Fariborz Jahanianb8bf6072007-11-02 15:39:31 +00001091 if (TryBody.isInvalid)
1092 TryBody = Actions.ActOnNullStmt(Tok.getLocation());
Chris Lattnera1d2bb72007-10-09 17:51:17 +00001093 while (Tok.is(tok::at)) {
Fariborz Jahaniande3abf82007-11-02 00:18:53 +00001094 SourceLocation AtCatchFinallyLoc = ConsumeToken();
Fariborz Jahanian64b864e2007-09-19 19:14:32 +00001095 if (Tok.getIdentifierInfo()->getObjCKeywordID() == tok::objc_catch) {
Fariborz Jahanian06798362007-11-01 23:59:59 +00001096 StmtTy *FirstPart = 0;
1097 ConsumeToken(); // consume catch
Chris Lattnera1d2bb72007-10-09 17:51:17 +00001098 if (Tok.is(tok::l_paren)) {
Fariborz Jahanian64b864e2007-09-19 19:14:32 +00001099 ConsumeParen();
Fariborz Jahanian06798362007-11-01 23:59:59 +00001100 EnterScope(Scope::DeclScope);
Chris Lattnera1d2bb72007-10-09 17:51:17 +00001101 if (Tok.isNot(tok::ellipsis)) {
Fariborz Jahanian64b864e2007-09-19 19:14:32 +00001102 DeclSpec DS;
1103 ParseDeclarationSpecifiers(DS);
Fariborz Jahanian06798362007-11-01 23:59:59 +00001104 // FIXME: Is BlockContext right?
1105 Declarator DeclaratorInfo(DS, Declarator::BlockContext);
1106 ParseDeclarator(DeclaratorInfo);
Fariborz Jahanian59e9e042007-11-02 18:16:07 +00001107 DeclTy * aBlockVarDecl = Actions.ActOnDeclarator(CurScope,
1108 DeclaratorInfo, 0);
1109 StmtResult stmtResult = Actions.ActOnDeclStmt(aBlockVarDecl);
Fariborz Jahanian06798362007-11-01 23:59:59 +00001110 FirstPart = stmtResult.isInvalid ? 0 : stmtResult.Val;
Fariborz Jahanian64b864e2007-09-19 19:14:32 +00001111 }
1112 else
1113 ConsumeToken(); // consume '...'
Fariborz Jahanian06798362007-11-01 23:59:59 +00001114 SourceLocation RParenLoc = ConsumeParen();
Fariborz Jahanian70952482007-11-01 21:12:44 +00001115 StmtResult CatchBody = ParseCompoundStatementBody();
Fariborz Jahanian06798362007-11-01 23:59:59 +00001116 if (CatchBody.isInvalid)
1117 CatchBody = Actions.ActOnNullStmt(Tok.getLocation());
Fariborz Jahaniande3abf82007-11-02 00:18:53 +00001118 CatchStmts = Actions.ActOnObjcAtCatchStmt(AtCatchFinallyLoc, RParenLoc,
Fariborz Jahanian06798362007-11-01 23:59:59 +00001119 FirstPart, CatchBody.Val, CatchStmts.Val);
1120 ExitScope();
Fariborz Jahanian64b864e2007-09-19 19:14:32 +00001121 }
1122 else {
Fariborz Jahaniande3abf82007-11-02 00:18:53 +00001123 Diag(AtCatchFinallyLoc, diag::err_expected_lparen_after,
1124 "@catch clause");
Fariborz Jahanian70952482007-11-01 21:12:44 +00001125 return true;
Fariborz Jahanian64b864e2007-09-19 19:14:32 +00001126 }
1127 catch_or_finally_seen = true;
1128 }
1129 else if (Tok.getIdentifierInfo()->getObjCKeywordID() == tok::objc_finally) {
1130 ConsumeToken(); // consume finally
1131 StmtResult FinallyBody = ParseCompoundStatementBody();
Fariborz Jahaniande3abf82007-11-02 00:18:53 +00001132 if (FinallyBody.isInvalid)
1133 FinallyBody = Actions.ActOnNullStmt(Tok.getLocation());
1134 FinallyStmt = Actions.ActOnObjcAtFinallyStmt(AtCatchFinallyLoc,
1135 FinallyBody.Val);
Fariborz Jahanian64b864e2007-09-19 19:14:32 +00001136 catch_or_finally_seen = true;
1137 break;
1138 }
1139 }
Fariborz Jahanianb8bf6072007-11-02 15:39:31 +00001140 if (!catch_or_finally_seen) {
Fariborz Jahanian64b864e2007-09-19 19:14:32 +00001141 Diag(atLoc, diag::err_missing_catch_finally);
Fariborz Jahanianb8bf6072007-11-02 15:39:31 +00001142 return true;
1143 }
1144 return Actions.ActOnObjcAtTryStmt(atLoc, TryBody.Val, CatchStmts.Val,
1145 FinallyStmt.Val);
Fariborz Jahanian64b864e2007-09-19 19:14:32 +00001146}
Fariborz Jahanian027c23b2007-09-01 00:26:16 +00001147
Steve Naroff81f1bba2007-09-06 21:24:23 +00001148/// objc-method-def: objc-method-proto ';'[opt] '{' body '}'
Fariborz Jahanian027c23b2007-09-01 00:26:16 +00001149///
Steve Naroff18c83382007-11-13 23:01:27 +00001150Parser::DeclTy *Parser::ParseObjCMethodDefinition() {
Fariborz Jahaniandfb1c372007-11-08 23:49:49 +00001151 DeclTy *MDecl = ParseObjCMethodPrototype(ObjcImpDecl);
Fariborz Jahanian027c23b2007-09-01 00:26:16 +00001152 // parse optional ';'
Chris Lattnera1d2bb72007-10-09 17:51:17 +00001153 if (Tok.is(tok::semi))
Fariborz Jahanian027c23b2007-09-01 00:26:16 +00001154 ConsumeToken();
1155
Steve Naroff9191a9e82007-11-11 19:54:21 +00001156 // We should have an opening brace now.
Chris Lattnera1d2bb72007-10-09 17:51:17 +00001157 if (Tok.isNot(tok::l_brace)) {
Steve Naroff9191a9e82007-11-11 19:54:21 +00001158 Diag(Tok, diag::err_expected_fn_body);
1159
1160 // Skip over garbage, until we get to '{'. Don't eat the '{'.
1161 SkipUntil(tok::l_brace, true, true);
1162
1163 // If we didn't find the '{', bail out.
1164 if (Tok.isNot(tok::l_brace))
Steve Naroff18c83382007-11-13 23:01:27 +00001165 return 0;
Fariborz Jahanian027c23b2007-09-01 00:26:16 +00001166 }
Steve Naroff9191a9e82007-11-11 19:54:21 +00001167 SourceLocation BraceLoc = Tok.getLocation();
1168
1169 // Enter a scope for the method body.
1170 EnterScope(Scope::FnScope|Scope::DeclScope);
1171
1172 // Tell the actions module that we have entered a method definition with the
1173 // specified Declarator for the method.
1174 Actions.ObjcActOnStartOfMethodDef(CurScope, MDecl);
1175
1176 StmtResult FnBody = ParseCompoundStatementBody();
1177
1178 // If the function body could not be parsed, make a bogus compoundstmt.
1179 if (FnBody.isInvalid)
1180 FnBody = Actions.ActOnCompoundStmt(BraceLoc, BraceLoc, 0, 0, false);
1181
1182 // Leave the function body scope.
1183 ExitScope();
1184
1185 // TODO: Pass argument information.
Steve Naroff99ee4302007-11-11 23:20:51 +00001186 Actions.ActOnFinishFunctionBody(MDecl, FnBody.Val);
Steve Naroff18c83382007-11-13 23:01:27 +00001187 return MDecl;
Chris Lattner4b009652007-07-25 00:24:17 +00001188}
Anders Carlssona66cad42007-08-21 17:43:55 +00001189
Steve Narofffb9dd752007-10-15 20:55:58 +00001190Parser::ExprResult Parser::ParseObjCAtExpression(SourceLocation AtLoc) {
Anders Carlssona66cad42007-08-21 17:43:55 +00001191
1192 switch (Tok.getKind()) {
1193 case tok::string_literal: // primary-expression: string-literal
1194 case tok::wide_string_literal:
Steve Naroff0add5d22007-11-03 11:27:19 +00001195 return ParsePostfixExpressionSuffix(ParseObjCStringLiteral(AtLoc));
Anders Carlsson2996b4e2007-08-23 15:25:28 +00001196 default:
1197 break;
1198 }
1199
1200 switch (Tok.getIdentifierInfo()->getObjCKeywordID()) {
Chris Lattnercfd61c82007-10-16 22:51:17 +00001201 case tok::objc_encode:
1202 return ParsePostfixExpressionSuffix(ParseObjCEncodeExpression(AtLoc));
1203 case tok::objc_protocol:
Fariborz Jahanian957448a2007-10-16 23:21:02 +00001204 return ParsePostfixExpressionSuffix(ParseObjCProtocolExpression(AtLoc));
Chris Lattnercfd61c82007-10-16 22:51:17 +00001205 case tok::objc_selector:
Fariborz Jahanian957448a2007-10-16 23:21:02 +00001206 return ParsePostfixExpressionSuffix(ParseObjCSelectorExpression(AtLoc));
Chris Lattnercfd61c82007-10-16 22:51:17 +00001207 default:
1208 Diag(AtLoc, diag::err_unexpected_at);
1209 SkipUntil(tok::semi);
1210 break;
Anders Carlssona66cad42007-08-21 17:43:55 +00001211 }
1212
1213 return 0;
1214}
1215
Fariborz Jahanian1e534dc2007-09-05 19:52:07 +00001216/// objc-message-expr:
1217/// '[' objc-receiver objc-message-args ']'
1218///
1219/// objc-receiver:
1220/// expression
1221/// class-name
1222/// type-name
1223///
1224/// objc-message-args:
1225/// objc-selector
1226/// objc-keywordarg-list
1227///
1228/// objc-keywordarg-list:
1229/// objc-keywordarg
1230/// objc-keywordarg-list objc-keywordarg
1231///
1232/// objc-keywordarg:
1233/// selector-name[opt] ':' objc-keywordexpr
1234///
1235/// objc-keywordexpr:
1236/// nonempty-expr-list
1237///
1238/// nonempty-expr-list:
1239/// assignment-expression
1240/// nonempty-expr-list , assignment-expression
1241///
1242Parser::ExprResult Parser::ParseObjCMessageExpression() {
Chris Lattnera1d2bb72007-10-09 17:51:17 +00001243 assert(Tok.is(tok::l_square) && "'[' expected");
Steve Naroffc39ca262007-09-18 23:55:05 +00001244 SourceLocation LBracloc = ConsumeBracket(); // consume '['
Steve Naroff253118b2007-09-17 20:25:27 +00001245 IdentifierInfo *ReceiverName = 0;
1246 ExprTy *ReceiverExpr = 0;
Fariborz Jahaniand4462f92007-09-05 23:08:20 +00001247 // Parse receiver
Chris Lattnera1d2bb72007-10-09 17:51:17 +00001248 if (Tok.is(tok::identifier) &&
Fariborz Jahanian2ce5dc52007-11-12 20:13:27 +00001249 (Actions.isTypeName(*Tok.getIdentifierInfo(), CurScope)
1250 || !strcmp(Tok.getIdentifierInfo()->getName(), "super"))) {
Steve Naroff253118b2007-09-17 20:25:27 +00001251 ReceiverName = Tok.getIdentifierInfo();
Steve Narofff0c31dd2007-09-16 16:16:00 +00001252 ConsumeToken();
Steve Naroff253118b2007-09-17 20:25:27 +00001253 } else {
1254 ExprResult Res = ParseAssignmentExpression();
1255 if (Res.isInvalid) {
Steve Naroffe015e9c2007-11-12 19:18:37 +00001256 Diag(Tok, diag::err_invalid_receiver_to_message);
Steve Naroff253118b2007-09-17 20:25:27 +00001257 SkipUntil(tok::identifier);
1258 return Res;
1259 }
1260 ReceiverExpr = Res.Val;
1261 }
Fariborz Jahaniand4462f92007-09-05 23:08:20 +00001262 // Parse objc-selector
Fariborz Jahanian91193f62007-10-11 00:55:41 +00001263 SourceLocation Loc;
1264 IdentifierInfo *selIdent = ParseObjCSelector(Loc);
Steve Naroff4ed9d662007-09-27 14:38:14 +00001265
1266 llvm::SmallVector<IdentifierInfo *, 12> KeyIdents;
1267 llvm::SmallVector<Action::ExprTy *, 12> KeyExprs;
1268
Chris Lattnera1d2bb72007-10-09 17:51:17 +00001269 if (Tok.is(tok::colon)) {
Fariborz Jahaniand4462f92007-09-05 23:08:20 +00001270 while (1) {
1271 // Each iteration parses a single keyword argument.
Steve Naroff4ed9d662007-09-27 14:38:14 +00001272 KeyIdents.push_back(selIdent);
Steve Naroff253118b2007-09-17 20:25:27 +00001273
Chris Lattnera1d2bb72007-10-09 17:51:17 +00001274 if (Tok.isNot(tok::colon)) {
Fariborz Jahaniand4462f92007-09-05 23:08:20 +00001275 Diag(Tok, diag::err_expected_colon);
1276 SkipUntil(tok::semi);
Steve Naroff253118b2007-09-17 20:25:27 +00001277 return true;
Fariborz Jahaniand4462f92007-09-05 23:08:20 +00001278 }
Steve Naroff4ed9d662007-09-27 14:38:14 +00001279 ConsumeToken(); // Eat the ':'.
Fariborz Jahaniand4462f92007-09-05 23:08:20 +00001280 /// Parse the expression after ':'
Steve Naroff253118b2007-09-17 20:25:27 +00001281 ExprResult Res = ParseAssignmentExpression();
1282 if (Res.isInvalid) {
1283 SkipUntil(tok::identifier);
1284 return Res;
1285 }
1286 // We have a valid expression.
Steve Naroff4ed9d662007-09-27 14:38:14 +00001287 KeyExprs.push_back(Res.Val);
Steve Naroff253118b2007-09-17 20:25:27 +00001288
1289 // Check for another keyword selector.
Fariborz Jahanian91193f62007-10-11 00:55:41 +00001290 selIdent = ParseObjCSelector(Loc);
Chris Lattnera1d2bb72007-10-09 17:51:17 +00001291 if (!selIdent && Tok.isNot(tok::colon))
Fariborz Jahaniand4462f92007-09-05 23:08:20 +00001292 break;
1293 // We have a selector or a colon, continue parsing.
1294 }
1295 // Parse the, optional, argument list, comma separated.
Chris Lattnera1d2bb72007-10-09 17:51:17 +00001296 while (Tok.is(tok::comma)) {
Steve Naroff9f176d12007-11-15 13:05:42 +00001297 ConsumeToken(); // Eat the ','.
1298 /// Parse the expression after ','
1299 ExprResult Res = ParseAssignmentExpression();
1300 if (Res.isInvalid) {
1301 SkipUntil(tok::identifier);
1302 return Res;
1303 }
1304 // We have a valid expression.
1305 KeyExprs.push_back(Res.Val);
Fariborz Jahaniand4462f92007-09-05 23:08:20 +00001306 }
1307 } else if (!selIdent) {
1308 Diag(Tok, diag::err_expected_ident); // missing selector name.
1309 SkipUntil(tok::semi);
1310 return 0;
1311 }
Chris Lattnerd031a452007-10-07 02:00:24 +00001312
Chris Lattnera1d2bb72007-10-09 17:51:17 +00001313 if (Tok.isNot(tok::r_square)) {
Fariborz Jahaniand4462f92007-09-05 23:08:20 +00001314 Diag(Tok, diag::err_expected_rsquare);
1315 SkipUntil(tok::semi);
1316 return 0;
1317 }
Steve Naroffc39ca262007-09-18 23:55:05 +00001318 SourceLocation RBracloc = ConsumeBracket(); // consume ']'
Steve Naroff253118b2007-09-17 20:25:27 +00001319
Steve Narofff9e80db2007-10-05 18:42:47 +00001320 unsigned nKeys = KeyIdents.size();
Chris Lattnerd031a452007-10-07 02:00:24 +00001321 if (nKeys == 0)
1322 KeyIdents.push_back(selIdent);
1323 Selector Sel = PP.getSelectorTable().getSelector(nKeys, &KeyIdents[0]);
1324
1325 // We've just parsed a keyword message.
Steve Naroff253118b2007-09-17 20:25:27 +00001326 if (ReceiverName)
Fariborz Jahanian2ce5dc52007-11-12 20:13:27 +00001327 return Actions.ActOnClassMessage(CurScope,
1328 ReceiverName, Sel, LBracloc, RBracloc,
Steve Naroff9f176d12007-11-15 13:05:42 +00001329 &KeyExprs[0], KeyExprs.size());
Chris Lattnerd031a452007-10-07 02:00:24 +00001330 return Actions.ActOnInstanceMessage(ReceiverExpr, Sel, LBracloc, RBracloc,
Steve Naroff9f176d12007-11-15 13:05:42 +00001331 &KeyExprs[0], KeyExprs.size());
Fariborz Jahanian1e534dc2007-09-05 19:52:07 +00001332}
1333
Steve Naroff0add5d22007-11-03 11:27:19 +00001334Parser::ExprResult Parser::ParseObjCStringLiteral(SourceLocation AtLoc) {
Anders Carlssona66cad42007-08-21 17:43:55 +00001335 ExprResult Res = ParseStringLiteralExpression();
1336
1337 if (Res.isInvalid) return Res;
1338
Steve Naroff0add5d22007-11-03 11:27:19 +00001339 return Actions.ParseObjCStringLiteral(AtLoc, Res.Val);
Anders Carlssona66cad42007-08-21 17:43:55 +00001340}
Anders Carlsson8be1d402007-08-22 15:14:15 +00001341
1342/// objc-encode-expression:
1343/// @encode ( type-name )
Chris Lattnercfd61c82007-10-16 22:51:17 +00001344Parser::ExprResult Parser::ParseObjCEncodeExpression(SourceLocation AtLoc) {
Steve Naroff87c329f2007-08-23 18:16:40 +00001345 assert(Tok.isObjCAtKeyword(tok::objc_encode) && "Not an @encode expression!");
Anders Carlsson8be1d402007-08-22 15:14:15 +00001346
1347 SourceLocation EncLoc = ConsumeToken();
1348
Chris Lattnera1d2bb72007-10-09 17:51:17 +00001349 if (Tok.isNot(tok::l_paren)) {
Anders Carlsson8be1d402007-08-22 15:14:15 +00001350 Diag(Tok, diag::err_expected_lparen_after, "@encode");
1351 return true;
1352 }
1353
1354 SourceLocation LParenLoc = ConsumeParen();
1355
1356 TypeTy *Ty = ParseTypeName();
1357
Anders Carlsson92faeb82007-08-23 15:31:37 +00001358 SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc);
Anders Carlsson8be1d402007-08-22 15:14:15 +00001359
Chris Lattnercfd61c82007-10-16 22:51:17 +00001360 return Actions.ParseObjCEncodeExpression(AtLoc, EncLoc, LParenLoc, Ty,
Anders Carlsson92faeb82007-08-23 15:31:37 +00001361 RParenLoc);
Anders Carlsson8be1d402007-08-22 15:14:15 +00001362}
Anders Carlsson2996b4e2007-08-23 15:25:28 +00001363
1364/// objc-protocol-expression
1365/// @protocol ( protocol-name )
1366
Fariborz Jahanian957448a2007-10-16 23:21:02 +00001367Parser::ExprResult Parser::ParseObjCProtocolExpression(SourceLocation AtLoc)
Anders Carlsson2996b4e2007-08-23 15:25:28 +00001368{
1369 SourceLocation ProtoLoc = ConsumeToken();
1370
Chris Lattnera1d2bb72007-10-09 17:51:17 +00001371 if (Tok.isNot(tok::l_paren)) {
Anders Carlsson2996b4e2007-08-23 15:25:28 +00001372 Diag(Tok, diag::err_expected_lparen_after, "@protocol");
1373 return true;
1374 }
1375
1376 SourceLocation LParenLoc = ConsumeParen();
1377
Chris Lattnera1d2bb72007-10-09 17:51:17 +00001378 if (Tok.isNot(tok::identifier)) {
Anders Carlsson2996b4e2007-08-23 15:25:28 +00001379 Diag(Tok, diag::err_expected_ident);
1380 return true;
1381 }
Fariborz Jahanianb391e6e2007-10-17 16:58:11 +00001382 IdentifierInfo *protocolId = Tok.getIdentifierInfo();
Anders Carlsson2996b4e2007-08-23 15:25:28 +00001383 ConsumeToken();
1384
Anders Carlsson92faeb82007-08-23 15:31:37 +00001385 SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc);
Anders Carlsson2996b4e2007-08-23 15:25:28 +00001386
Fariborz Jahanianb391e6e2007-10-17 16:58:11 +00001387 return Actions.ParseObjCProtocolExpression(protocolId, AtLoc, ProtoLoc,
1388 LParenLoc, RParenLoc);
Anders Carlsson2996b4e2007-08-23 15:25:28 +00001389}
Fariborz Jahanian056c6b02007-10-15 23:39:13 +00001390
1391/// objc-selector-expression
1392/// @selector '(' objc-keyword-selector ')'
Fariborz Jahanian957448a2007-10-16 23:21:02 +00001393Parser::ExprResult Parser::ParseObjCSelectorExpression(SourceLocation AtLoc)
Fariborz Jahanian056c6b02007-10-15 23:39:13 +00001394{
1395 SourceLocation SelectorLoc = ConsumeToken();
1396
1397 if (Tok.isNot(tok::l_paren)) {
1398 Diag(Tok, diag::err_expected_lparen_after, "@selector");
1399 return 0;
1400 }
1401
Fariborz Jahanianf807c202007-10-16 20:40:23 +00001402 llvm::SmallVector<IdentifierInfo *, 12> KeyIdents;
Fariborz Jahanian056c6b02007-10-15 23:39:13 +00001403 SourceLocation LParenLoc = ConsumeParen();
1404 SourceLocation sLoc;
1405 IdentifierInfo *SelIdent = ParseObjCSelector(sLoc);
1406 if (!SelIdent && Tok.isNot(tok::colon)) {
Fariborz Jahanian056c6b02007-10-15 23:39:13 +00001407 Diag(Tok, diag::err_expected_ident); // missing selector name.
1408 return 0;
1409 }
Fariborz Jahanianf807c202007-10-16 20:40:23 +00001410 KeyIdents.push_back(SelIdent);
Steve Naroff6fd89272007-12-05 22:21:29 +00001411 unsigned nColons = 0;
1412 if (Tok.isNot(tok::r_paren)) {
Fariborz Jahanian056c6b02007-10-15 23:39:13 +00001413 while (1) {
1414 if (Tok.isNot(tok::colon)) {
1415 Diag(Tok, diag::err_expected_colon);
1416 break;
1417 }
Steve Naroff6fd89272007-12-05 22:21:29 +00001418 nColons++;
Fariborz Jahanian056c6b02007-10-15 23:39:13 +00001419 ConsumeToken(); // Eat the ':'.
1420 if (Tok.is(tok::r_paren))
1421 break;
1422 // Check for another keyword selector.
1423 SourceLocation Loc;
1424 SelIdent = ParseObjCSelector(Loc);
Fariborz Jahanianf807c202007-10-16 20:40:23 +00001425 KeyIdents.push_back(SelIdent);
Fariborz Jahanian056c6b02007-10-15 23:39:13 +00001426 if (!SelIdent && Tok.isNot(tok::colon))
1427 break;
1428 }
Steve Naroff6fd89272007-12-05 22:21:29 +00001429 }
Fariborz Jahanian056c6b02007-10-15 23:39:13 +00001430 SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc);
Steve Naroff6fd89272007-12-05 22:21:29 +00001431 Selector Sel = PP.getSelectorTable().getSelector(nColons, &KeyIdents[0]);
Fariborz Jahanian957448a2007-10-16 23:21:02 +00001432 return Actions.ParseObjCSelectorExpression(Sel, AtLoc, SelectorLoc, LParenLoc,
Fariborz Jahanianf807c202007-10-16 20:40:23 +00001433 RParenLoc);
Gabor Greifa823dd12007-10-19 15:38:32 +00001434 }