blob: 9904a2ca85dc886779d9d52c5d4ebdf72e2bee79 [file] [log] [blame]
Ted Kremeneka526c5c2008-01-07 19:49:32 +00001//===--- ParseObjC.cpp - Objective C Parsing ------------------------------===//
Reid Spencer5f016e22007-07-11 17:01:13 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner0bc735f2007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Reid Spencer5f016e22007-07-11 17:01:13 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the Objective-C portions of the Parser interface.
11//
12//===----------------------------------------------------------------------===//
13
14#include "clang/Parse/Parser.h"
Steve Naroff4985ace2007-08-22 18:35:33 +000015#include "clang/Parse/DeclSpec.h"
Fariborz Jahanian3b1191d2007-11-01 23:59:59 +000016#include "clang/Parse/Scope.h"
Chris Lattner500d3292009-01-29 05:15:15 +000017#include "clang/Parse/ParseDiagnostic.h"
Reid Spencer5f016e22007-07-11 17:01:13 +000018#include "llvm/ADT/SmallVector.h"
19using namespace clang;
20
21
Chris Lattner891dca62008-12-08 21:53:24 +000022/// ParseObjCAtDirectives - Handle parts of the external-declaration production:
Reid Spencer5f016e22007-07-11 17:01:13 +000023/// external-declaration: [C99 6.9]
24/// [OBJC] objc-class-definition
Steve Naroff91fa0b72007-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'
Chris Lattnerb28317a2009-03-28 19:18:32 +000030Parser::DeclPtrTy Parser::ParseObjCAtDirectives() {
Reid Spencer5f016e22007-07-11 17:01:13 +000031 SourceLocation AtLoc = ConsumeToken(); // the "@"
Mike Stump1eb44332009-09-09 15:08:12 +000032
Douglas Gregorc464ae82009-12-07 09:27:33 +000033 if (Tok.is(tok::code_completion)) {
34 Actions.CodeCompleteObjCAtDirective(CurScope, ObjCImpDecl, false);
35 ConsumeToken();
36 }
37
Steve Naroff861cf3e2007-08-23 18:16:40 +000038 switch (Tok.getObjCKeywordID()) {
Chris Lattner5ffb14b2008-08-23 02:02:23 +000039 case tok::objc_class:
40 return ParseObjCAtClassDeclaration(AtLoc);
41 case tok::objc_interface:
42 return ParseObjCAtInterfaceDeclaration(AtLoc);
43 case tok::objc_protocol:
44 return ParseObjCAtProtocolDeclaration(AtLoc);
45 case tok::objc_implementation:
46 return ParseObjCAtImplementationDeclaration(AtLoc);
47 case tok::objc_end:
48 return ParseObjCAtEndDeclaration(AtLoc);
49 case tok::objc_compatibility_alias:
50 return ParseObjCAtAliasDeclaration(AtLoc);
51 case tok::objc_synthesize:
52 return ParseObjCPropertySynthesize(AtLoc);
53 case tok::objc_dynamic:
54 return ParseObjCPropertyDynamic(AtLoc);
55 default:
56 Diag(AtLoc, diag::err_unexpected_at);
57 SkipUntil(tok::semi);
Chris Lattnerb28317a2009-03-28 19:18:32 +000058 return DeclPtrTy();
Reid Spencer5f016e22007-07-11 17:01:13 +000059 }
60}
61
62///
Mike Stump1eb44332009-09-09 15:08:12 +000063/// objc-class-declaration:
Reid Spencer5f016e22007-07-11 17:01:13 +000064/// '@' 'class' identifier-list ';'
Mike Stump1eb44332009-09-09 15:08:12 +000065///
Chris Lattnerb28317a2009-03-28 19:18:32 +000066Parser::DeclPtrTy Parser::ParseObjCAtClassDeclaration(SourceLocation atLoc) {
Reid Spencer5f016e22007-07-11 17:01:13 +000067 ConsumeToken(); // the identifier "class"
68 llvm::SmallVector<IdentifierInfo *, 8> ClassNames;
Ted Kremenekc09cba62009-11-17 23:12:20 +000069 llvm::SmallVector<SourceLocation, 8> ClassLocs;
70
Mike Stump1eb44332009-09-09 15:08:12 +000071
Reid Spencer5f016e22007-07-11 17:01:13 +000072 while (1) {
Chris Lattnerdf195262007-10-09 17:51:17 +000073 if (Tok.isNot(tok::identifier)) {
Reid Spencer5f016e22007-07-11 17:01:13 +000074 Diag(Tok, diag::err_expected_ident);
75 SkipUntil(tok::semi);
Chris Lattnerb28317a2009-03-28 19:18:32 +000076 return DeclPtrTy();
Reid Spencer5f016e22007-07-11 17:01:13 +000077 }
Reid Spencer5f016e22007-07-11 17:01:13 +000078 ClassNames.push_back(Tok.getIdentifierInfo());
Ted Kremenekc09cba62009-11-17 23:12:20 +000079 ClassLocs.push_back(Tok.getLocation());
Reid Spencer5f016e22007-07-11 17:01:13 +000080 ConsumeToken();
Mike Stump1eb44332009-09-09 15:08:12 +000081
Chris Lattnerdf195262007-10-09 17:51:17 +000082 if (Tok.isNot(tok::comma))
Reid Spencer5f016e22007-07-11 17:01:13 +000083 break;
Mike Stump1eb44332009-09-09 15:08:12 +000084
Reid Spencer5f016e22007-07-11 17:01:13 +000085 ConsumeToken();
86 }
Mike Stump1eb44332009-09-09 15:08:12 +000087
Reid Spencer5f016e22007-07-11 17:01:13 +000088 // Consume the ';'.
89 if (ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@class"))
Chris Lattnerb28317a2009-03-28 19:18:32 +000090 return DeclPtrTy();
Mike Stump1eb44332009-09-09 15:08:12 +000091
Ted Kremenekc09cba62009-11-17 23:12:20 +000092 return Actions.ActOnForwardClassDeclaration(atLoc, ClassNames.data(),
93 ClassLocs.data(),
94 ClassNames.size());
Reid Spencer5f016e22007-07-11 17:01:13 +000095}
96
Steve Naroffdac269b2007-08-20 21:31:48 +000097///
98/// objc-interface:
99/// objc-class-interface-attributes[opt] objc-class-interface
100/// objc-category-interface
101///
102/// objc-class-interface:
Mike Stump1eb44332009-09-09 15:08:12 +0000103/// '@' 'interface' identifier objc-superclass[opt]
Steve Naroffdac269b2007-08-20 21:31:48 +0000104/// objc-protocol-refs[opt]
Mike Stump1eb44332009-09-09 15:08:12 +0000105/// objc-class-instance-variables[opt]
Steve Naroffdac269b2007-08-20 21:31:48 +0000106/// objc-interface-decl-list
107/// @end
108///
109/// objc-category-interface:
Mike Stump1eb44332009-09-09 15:08:12 +0000110/// '@' 'interface' identifier '(' identifier[opt] ')'
Steve Naroffdac269b2007-08-20 21:31:48 +0000111/// objc-protocol-refs[opt]
112/// objc-interface-decl-list
113/// @end
114///
115/// objc-superclass:
116/// ':' identifier
117///
118/// objc-class-interface-attributes:
119/// __attribute__((visibility("default")))
120/// __attribute__((visibility("hidden")))
121/// __attribute__((deprecated))
122/// __attribute__((unavailable))
123/// __attribute__((objc_exception)) - used by NSException on 64-bit
124///
Chris Lattnerb28317a2009-03-28 19:18:32 +0000125Parser::DeclPtrTy Parser::ParseObjCAtInterfaceDeclaration(
Steve Naroffdac269b2007-08-20 21:31:48 +0000126 SourceLocation atLoc, AttributeList *attrList) {
Steve Naroff861cf3e2007-08-23 18:16:40 +0000127 assert(Tok.isObjCAtKeyword(tok::objc_interface) &&
Steve Naroffdac269b2007-08-20 21:31:48 +0000128 "ParseObjCAtInterfaceDeclaration(): Expected @interface");
129 ConsumeToken(); // the "interface" identifier
Mike Stump1eb44332009-09-09 15:08:12 +0000130
Douglas Gregor3b49aca2009-11-18 16:26:39 +0000131 // Code completion after '@interface'.
132 if (Tok.is(tok::code_completion)) {
133 Actions.CodeCompleteObjCInterfaceDecl(CurScope);
134 ConsumeToken();
135 }
136
Chris Lattnerdf195262007-10-09 17:51:17 +0000137 if (Tok.isNot(tok::identifier)) {
Steve Naroffdac269b2007-08-20 21:31:48 +0000138 Diag(Tok, diag::err_expected_ident); // missing class or category name.
Chris Lattnerb28317a2009-03-28 19:18:32 +0000139 return DeclPtrTy();
Steve Naroffdac269b2007-08-20 21:31:48 +0000140 }
Fariborz Jahanian63e963c2009-11-16 18:57:01 +0000141
Steve Naroffdac269b2007-08-20 21:31:48 +0000142 // We have a class or category name - consume it.
Steve Naroff7ef58fd2007-08-22 22:17:26 +0000143 IdentifierInfo *nameId = Tok.getIdentifierInfo();
Steve Naroffdac269b2007-08-20 21:31:48 +0000144 SourceLocation nameLoc = ConsumeToken();
Mike Stump1eb44332009-09-09 15:08:12 +0000145
Chris Lattnerdf195262007-10-09 17:51:17 +0000146 if (Tok.is(tok::l_paren)) { // we have a category.
Steve Naroffdac269b2007-08-20 21:31:48 +0000147 SourceLocation lparenLoc = ConsumeParen();
148 SourceLocation categoryLoc, rparenLoc;
149 IdentifierInfo *categoryId = 0;
Mike Stump1eb44332009-09-09 15:08:12 +0000150
Douglas Gregor33ced0b2009-11-18 19:08:43 +0000151 if (Tok.is(tok::code_completion)) {
152 Actions.CodeCompleteObjCInterfaceCategory(CurScope, nameId);
153 ConsumeToken();
154 }
155
Steve Naroff527fe232007-08-23 19:56:30 +0000156 // For ObjC2, the category name is optional (not an error).
Chris Lattnerdf195262007-10-09 17:51:17 +0000157 if (Tok.is(tok::identifier)) {
Steve Naroffdac269b2007-08-20 21:31:48 +0000158 categoryId = Tok.getIdentifierInfo();
159 categoryLoc = ConsumeToken();
Steve Naroff527fe232007-08-23 19:56:30 +0000160 } else if (!getLang().ObjC2) {
161 Diag(Tok, diag::err_expected_ident); // missing category name.
Chris Lattnerb28317a2009-03-28 19:18:32 +0000162 return DeclPtrTy();
Steve Naroffdac269b2007-08-20 21:31:48 +0000163 }
Chris Lattnerdf195262007-10-09 17:51:17 +0000164 if (Tok.isNot(tok::r_paren)) {
Steve Naroffdac269b2007-08-20 21:31:48 +0000165 Diag(Tok, diag::err_expected_rparen);
166 SkipUntil(tok::r_paren, false); // don't stop at ';'
Chris Lattnerb28317a2009-03-28 19:18:32 +0000167 return DeclPtrTy();
Steve Naroffdac269b2007-08-20 21:31:48 +0000168 }
169 rparenLoc = ConsumeParen();
Mike Stump1eb44332009-09-09 15:08:12 +0000170
Steve Naroffdac269b2007-08-20 21:31:48 +0000171 // Next, we need to check for any protocol references.
Argyrios Kyrtzidis71b0add2009-09-29 19:41:44 +0000172 SourceLocation LAngleLoc, EndProtoLoc;
Chris Lattnerb28317a2009-03-28 19:18:32 +0000173 llvm::SmallVector<DeclPtrTy, 8> ProtocolRefs;
Argyrios Kyrtzidis71b0add2009-09-29 19:41:44 +0000174 llvm::SmallVector<SourceLocation, 8> ProtocolLocs;
Chris Lattner6bd6d0b2008-07-26 04:07:02 +0000175 if (Tok.is(tok::less) &&
Argyrios Kyrtzidis71b0add2009-09-29 19:41:44 +0000176 ParseObjCProtocolReferences(ProtocolRefs, ProtocolLocs, true,
177 LAngleLoc, EndProtoLoc))
Chris Lattnerb28317a2009-03-28 19:18:32 +0000178 return DeclPtrTy();
Mike Stump1eb44332009-09-09 15:08:12 +0000179
Steve Naroffdac269b2007-08-20 21:31:48 +0000180 if (attrList) // categories don't support attributes.
181 Diag(Tok, diag::err_objc_no_attributes_on_category);
Mike Stump1eb44332009-09-09 15:08:12 +0000182
Jay Foadbeaaccd2009-05-21 09:52:38 +0000183 DeclPtrTy CategoryType =
Mike Stump1eb44332009-09-09 15:08:12 +0000184 Actions.ActOnStartCategoryInterface(atLoc,
Jay Foadbeaaccd2009-05-21 09:52:38 +0000185 nameId, nameLoc,
186 categoryId, categoryLoc,
187 ProtocolRefs.data(),
188 ProtocolRefs.size(),
189 EndProtoLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000190
Fariborz Jahanianfd225cc2007-09-18 20:26:58 +0000191 ParseObjCInterfaceDeclList(CategoryType, tok::objc_not_keyword);
Chris Lattnerbc662af2008-10-20 06:10:06 +0000192 return CategoryType;
Steve Naroffdac269b2007-08-20 21:31:48 +0000193 }
194 // Parse a class interface.
195 IdentifierInfo *superClassId = 0;
196 SourceLocation superClassLoc;
Steve Naroff7ef58fd2007-08-22 22:17:26 +0000197
Chris Lattnerdf195262007-10-09 17:51:17 +0000198 if (Tok.is(tok::colon)) { // a super class is specified.
Steve Naroffdac269b2007-08-20 21:31:48 +0000199 ConsumeToken();
Douglas Gregor3b49aca2009-11-18 16:26:39 +0000200
201 // Code completion of superclass names.
202 if (Tok.is(tok::code_completion)) {
203 Actions.CodeCompleteObjCSuperclass(CurScope, nameId);
204 ConsumeToken();
205 }
206
Chris Lattnerdf195262007-10-09 17:51:17 +0000207 if (Tok.isNot(tok::identifier)) {
Steve Naroffdac269b2007-08-20 21:31:48 +0000208 Diag(Tok, diag::err_expected_ident); // missing super class name.
Chris Lattnerb28317a2009-03-28 19:18:32 +0000209 return DeclPtrTy();
Steve Naroffdac269b2007-08-20 21:31:48 +0000210 }
211 superClassId = Tok.getIdentifierInfo();
212 superClassLoc = ConsumeToken();
213 }
214 // Next, we need to check for any protocol references.
Chris Lattnerb28317a2009-03-28 19:18:32 +0000215 llvm::SmallVector<Action::DeclPtrTy, 8> ProtocolRefs;
Argyrios Kyrtzidis71b0add2009-09-29 19:41:44 +0000216 llvm::SmallVector<SourceLocation, 8> ProtocolLocs;
217 SourceLocation LAngleLoc, EndProtoLoc;
Chris Lattner06036d32008-07-26 04:13:19 +0000218 if (Tok.is(tok::less) &&
Argyrios Kyrtzidis71b0add2009-09-29 19:41:44 +0000219 ParseObjCProtocolReferences(ProtocolRefs, ProtocolLocs, true,
220 LAngleLoc, EndProtoLoc))
Chris Lattnerb28317a2009-03-28 19:18:32 +0000221 return DeclPtrTy();
Mike Stump1eb44332009-09-09 15:08:12 +0000222
223 DeclPtrTy ClsType =
224 Actions.ActOnStartClassInterface(atLoc, nameId, nameLoc,
Chris Lattner06036d32008-07-26 04:13:19 +0000225 superClassId, superClassLoc,
Jay Foadbeaaccd2009-05-21 09:52:38 +0000226 ProtocolRefs.data(), ProtocolRefs.size(),
Chris Lattner06036d32008-07-26 04:13:19 +0000227 EndProtoLoc, attrList);
Mike Stump1eb44332009-09-09 15:08:12 +0000228
Chris Lattnerdf195262007-10-09 17:51:17 +0000229 if (Tok.is(tok::l_brace))
Steve Naroff60fccee2007-10-29 21:38:07 +0000230 ParseObjCClassInstanceVariables(ClsType, atLoc);
Steve Naroffdac269b2007-08-20 21:31:48 +0000231
Fariborz Jahanian25e077d2007-09-17 21:07:36 +0000232 ParseObjCInterfaceDeclList(ClsType, tok::objc_interface);
Chris Lattnerbc662af2008-10-20 06:10:06 +0000233 return ClsType;
Steve Naroffdac269b2007-08-20 21:31:48 +0000234}
235
John McCalld0014542009-12-03 22:31:13 +0000236/// The Objective-C property callback. This should be defined where
237/// it's used, but instead it's been lifted to here to support VS2005.
238struct Parser::ObjCPropertyCallback : FieldCallback {
239 Parser &P;
240 DeclPtrTy IDecl;
241 llvm::SmallVectorImpl<DeclPtrTy> &Props;
242 ObjCDeclSpec &OCDS;
243 SourceLocation AtLoc;
244 tok::ObjCKeywordKind MethodImplKind;
245
246 ObjCPropertyCallback(Parser &P, DeclPtrTy IDecl,
247 llvm::SmallVectorImpl<DeclPtrTy> &Props,
248 ObjCDeclSpec &OCDS, SourceLocation AtLoc,
249 tok::ObjCKeywordKind MethodImplKind) :
250 P(P), IDecl(IDecl), Props(Props), OCDS(OCDS), AtLoc(AtLoc),
251 MethodImplKind(MethodImplKind) {
252 }
253
254 DeclPtrTy invoke(FieldDeclarator &FD) {
255 if (FD.D.getIdentifier() == 0) {
256 P.Diag(AtLoc, diag::err_objc_property_requires_field_name)
257 << FD.D.getSourceRange();
258 return DeclPtrTy();
259 }
260 if (FD.BitfieldSize) {
261 P.Diag(AtLoc, diag::err_objc_property_bitfield)
262 << FD.D.getSourceRange();
263 return DeclPtrTy();
264 }
265
266 // Install the property declarator into interfaceDecl.
267 IdentifierInfo *SelName =
268 OCDS.getGetterName() ? OCDS.getGetterName() : FD.D.getIdentifier();
269
270 Selector GetterSel =
271 P.PP.getSelectorTable().getNullarySelector(SelName);
272 IdentifierInfo *SetterName = OCDS.getSetterName();
273 Selector SetterSel;
274 if (SetterName)
275 SetterSel = P.PP.getSelectorTable().getSelector(1, &SetterName);
276 else
277 SetterSel = SelectorTable::constructSetterName(P.PP.getIdentifierTable(),
278 P.PP.getSelectorTable(),
279 FD.D.getIdentifier());
280 bool isOverridingProperty = false;
281 DeclPtrTy Property =
282 P.Actions.ActOnProperty(P.CurScope, AtLoc, FD, OCDS,
283 GetterSel, SetterSel, IDecl,
284 &isOverridingProperty,
285 MethodImplKind);
286 if (!isOverridingProperty)
287 Props.push_back(Property);
288
289 return Property;
290 }
291};
292
Steve Naroffdac269b2007-08-20 21:31:48 +0000293/// objc-interface-decl-list:
294/// empty
Steve Naroffdac269b2007-08-20 21:31:48 +0000295/// objc-interface-decl-list objc-property-decl [OBJC2]
Steve Naroff294494e2007-08-22 16:35:03 +0000296/// objc-interface-decl-list objc-method-requirement [OBJC2]
Steve Naroff3536b442007-09-06 21:24:23 +0000297/// objc-interface-decl-list objc-method-proto ';'
Steve Naroffdac269b2007-08-20 21:31:48 +0000298/// objc-interface-decl-list declaration
299/// objc-interface-decl-list ';'
300///
Steve Naroff294494e2007-08-22 16:35:03 +0000301/// objc-method-requirement: [OBJC2]
302/// @required
303/// @optional
304///
Chris Lattnerb28317a2009-03-28 19:18:32 +0000305void Parser::ParseObjCInterfaceDeclList(DeclPtrTy interfaceDecl,
Chris Lattnercb53b362007-12-27 19:57:00 +0000306 tok::ObjCKeywordKind contextKey) {
Chris Lattnerb28317a2009-03-28 19:18:32 +0000307 llvm::SmallVector<DeclPtrTy, 32> allMethods;
308 llvm::SmallVector<DeclPtrTy, 16> allProperties;
Chris Lattner682bf922009-03-29 16:50:03 +0000309 llvm::SmallVector<DeclGroupPtrTy, 8> allTUVariables;
Fariborz Jahanian00933592007-09-18 00:25:23 +0000310 tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword;
Mike Stump1eb44332009-09-09 15:08:12 +0000311
Chris Lattnerbc662af2008-10-20 06:10:06 +0000312 SourceLocation AtEndLoc;
313
Steve Naroff294494e2007-08-22 16:35:03 +0000314 while (1) {
Chris Lattnere82a10f2008-10-20 05:46:22 +0000315 // If this is a method prototype, parse it.
Chris Lattnerdf195262007-10-09 17:51:17 +0000316 if (Tok.is(tok::minus) || Tok.is(tok::plus)) {
Mike Stump1eb44332009-09-09 15:08:12 +0000317 DeclPtrTy methodPrototype =
Chris Lattnerdf195262007-10-09 17:51:17 +0000318 ParseObjCMethodPrototype(interfaceDecl, MethodImplKind);
Fariborz Jahanian25e077d2007-09-17 21:07:36 +0000319 allMethods.push_back(methodPrototype);
Steve Naroff3536b442007-09-06 21:24:23 +0000320 // Consume the ';' here, since ParseObjCMethodPrototype() is re-used for
321 // method definitions.
Chris Lattnerb6d74a12009-02-15 22:24:30 +0000322 ExpectAndConsume(tok::semi, diag::err_expected_semi_after_method_proto,
323 "", tok::semi);
Steve Naroff294494e2007-08-22 16:35:03 +0000324 continue;
325 }
Mike Stump1eb44332009-09-09 15:08:12 +0000326
Chris Lattnere82a10f2008-10-20 05:46:22 +0000327 // Ignore excess semicolons.
328 if (Tok.is(tok::semi)) {
Steve Naroff294494e2007-08-22 16:35:03 +0000329 ConsumeToken();
Chris Lattnere82a10f2008-10-20 05:46:22 +0000330 continue;
331 }
Mike Stump1eb44332009-09-09 15:08:12 +0000332
Chris Lattnerbc662af2008-10-20 06:10:06 +0000333 // If we got to the end of the file, exit the loop.
Chris Lattnere82a10f2008-10-20 05:46:22 +0000334 if (Tok.is(tok::eof))
Fariborz Jahaniane3a2ca72007-09-10 20:33:04 +0000335 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000336
Chris Lattnere82a10f2008-10-20 05:46:22 +0000337 // If we don't have an @ directive, parse it as a function definition.
338 if (Tok.isNot(tok::at)) {
Chris Lattner1fd80112009-01-09 04:34:13 +0000339 // The code below does not consume '}'s because it is afraid of eating the
340 // end of a namespace. Because of the way this code is structured, an
341 // erroneous r_brace would cause an infinite loop if not handled here.
342 if (Tok.is(tok::r_brace))
343 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000344
Steve Naroff4985ace2007-08-22 18:35:33 +0000345 // FIXME: as the name implies, this rule allows function definitions.
346 // We could pass a flag or check for functions during semantic analysis.
Sean Huntbbd37c62009-11-21 08:43:09 +0000347 allTUVariables.push_back(ParseDeclarationOrFunctionDefinition(0));
Chris Lattnere82a10f2008-10-20 05:46:22 +0000348 continue;
349 }
Mike Stump1eb44332009-09-09 15:08:12 +0000350
Chris Lattnere82a10f2008-10-20 05:46:22 +0000351 // Otherwise, we have an @ directive, eat the @.
352 SourceLocation AtLoc = ConsumeToken(); // the "@"
Douglas Gregorc464ae82009-12-07 09:27:33 +0000353 if (Tok.is(tok::code_completion)) {
354 Actions.CodeCompleteObjCAtDirective(CurScope, ObjCImpDecl, true);
355 ConsumeToken();
356 break;
357 }
358
Chris Lattnera2449b22008-10-20 05:57:40 +0000359 tok::ObjCKeywordKind DirectiveKind = Tok.getObjCKeywordID();
Mike Stump1eb44332009-09-09 15:08:12 +0000360
Chris Lattnera2449b22008-10-20 05:57:40 +0000361 if (DirectiveKind == tok::objc_end) { // @end -> terminate list
Chris Lattnere82a10f2008-10-20 05:46:22 +0000362 AtEndLoc = AtLoc;
363 break;
Chris Lattnerbc662af2008-10-20 06:10:06 +0000364 }
Mike Stump1eb44332009-09-09 15:08:12 +0000365
Chris Lattnerbc662af2008-10-20 06:10:06 +0000366 // Eat the identifier.
367 ConsumeToken();
368
Chris Lattnera2449b22008-10-20 05:57:40 +0000369 switch (DirectiveKind) {
370 default:
Chris Lattnerbc662af2008-10-20 06:10:06 +0000371 // FIXME: If someone forgets an @end on a protocol, this loop will
372 // continue to eat up tons of stuff and spew lots of nonsense errors. It
373 // would probably be better to bail out if we saw an @class or @interface
374 // or something like that.
Chris Lattnerf6ed8552008-10-20 07:22:18 +0000375 Diag(AtLoc, diag::err_objc_illegal_interface_qual);
Chris Lattnerbc662af2008-10-20 06:10:06 +0000376 // Skip until we see an '@' or '}' or ';'.
Chris Lattnera2449b22008-10-20 05:57:40 +0000377 SkipUntil(tok::r_brace, tok::at);
378 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000379
Chris Lattnera2449b22008-10-20 05:57:40 +0000380 case tok::objc_required:
Chris Lattnera2449b22008-10-20 05:57:40 +0000381 case tok::objc_optional:
Chris Lattnera2449b22008-10-20 05:57:40 +0000382 // This is only valid on protocols.
Chris Lattnerbc662af2008-10-20 06:10:06 +0000383 // FIXME: Should this check for ObjC2 being enabled?
Chris Lattnere82a10f2008-10-20 05:46:22 +0000384 if (contextKey != tok::objc_protocol)
Chris Lattnerbc662af2008-10-20 06:10:06 +0000385 Diag(AtLoc, diag::err_objc_directive_only_in_protocol);
Chris Lattnera2449b22008-10-20 05:57:40 +0000386 else
Chris Lattnerbc662af2008-10-20 06:10:06 +0000387 MethodImplKind = DirectiveKind;
Chris Lattnera2449b22008-10-20 05:57:40 +0000388 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000389
Chris Lattnera2449b22008-10-20 05:57:40 +0000390 case tok::objc_property:
Chris Lattnerf6ed8552008-10-20 07:22:18 +0000391 if (!getLang().ObjC2)
392 Diag(AtLoc, diag::err_objc_propertoes_require_objc2);
393
Chris Lattnere82a10f2008-10-20 05:46:22 +0000394 ObjCDeclSpec OCDS;
Mike Stump1eb44332009-09-09 15:08:12 +0000395 // Parse property attribute list, if any.
Chris Lattner8ca329c2008-10-20 07:24:39 +0000396 if (Tok.is(tok::l_paren))
Douglas Gregor4ad96852009-11-19 07:41:15 +0000397 ParseObjCPropertyAttribute(OCDS, interfaceDecl,
398 allMethods.data(), allMethods.size());
Mike Stump1eb44332009-09-09 15:08:12 +0000399
John McCalld0014542009-12-03 22:31:13 +0000400 ObjCPropertyCallback Callback(*this, interfaceDecl, allProperties,
401 OCDS, AtLoc, MethodImplKind);
John McCallbdd563e2009-11-03 02:38:08 +0000402
Chris Lattnere82a10f2008-10-20 05:46:22 +0000403 // Parse all the comma separated declarators.
404 DeclSpec DS;
John McCallbdd563e2009-11-03 02:38:08 +0000405 ParseStructDeclaration(DS, Callback);
Mike Stump1eb44332009-09-09 15:08:12 +0000406
Chris Lattnera1fed7e2008-10-20 06:15:13 +0000407 ExpectAndConsume(tok::semi, diag::err_expected_semi_decl_list, "",
408 tok::at);
Chris Lattnera2449b22008-10-20 05:57:40 +0000409 break;
Steve Narofff28b2642007-09-05 23:30:30 +0000410 }
Steve Naroff294494e2007-08-22 16:35:03 +0000411 }
Chris Lattnerbc662af2008-10-20 06:10:06 +0000412
413 // We break out of the big loop in two cases: when we see @end or when we see
414 // EOF. In the former case, eat the @end. In the later case, emit an error.
Douglas Gregorc464ae82009-12-07 09:27:33 +0000415 if (Tok.is(tok::code_completion)) {
416 Actions.CodeCompleteObjCAtDirective(CurScope, ObjCImpDecl, true);
417 ConsumeToken();
418 } else if (Tok.isObjCAtKeyword(tok::objc_end))
Chris Lattnerbc662af2008-10-20 06:10:06 +0000419 ConsumeToken(); // the "end" identifier
420 else
421 Diag(Tok, diag::err_objc_missing_end);
Mike Stump1eb44332009-09-09 15:08:12 +0000422
Chris Lattnera2449b22008-10-20 05:57:40 +0000423 // Insert collected methods declarations into the @interface object.
Chris Lattnerbc662af2008-10-20 06:10:06 +0000424 // This passes in an invalid SourceLocation for AtEndLoc when EOF is hit.
Ted Kremenek8a779312008-06-06 16:45:15 +0000425 Actions.ActOnAtEnd(AtEndLoc, interfaceDecl,
Mike Stump1eb44332009-09-09 15:08:12 +0000426 allMethods.data(), allMethods.size(),
Jay Foadbeaaccd2009-05-21 09:52:38 +0000427 allProperties.data(), allProperties.size(),
428 allTUVariables.data(), allTUVariables.size());
Steve Naroff294494e2007-08-22 16:35:03 +0000429}
430
Fariborz Jahaniand0f97d12007-08-31 16:11:31 +0000431/// Parse property attribute declarations.
432///
433/// property-attr-decl: '(' property-attrlist ')'
434/// property-attrlist:
435/// property-attribute
436/// property-attrlist ',' property-attribute
437/// property-attribute:
438/// getter '=' identifier
439/// setter '=' identifier ':'
440/// readonly
441/// readwrite
442/// assign
443/// retain
444/// copy
445/// nonatomic
446///
Douglas Gregor4ad96852009-11-19 07:41:15 +0000447void Parser::ParseObjCPropertyAttribute(ObjCDeclSpec &DS, DeclPtrTy ClassDecl,
448 DeclPtrTy *Methods,
449 unsigned NumMethods) {
Chris Lattner8ca329c2008-10-20 07:24:39 +0000450 assert(Tok.getKind() == tok::l_paren);
Chris Lattnerdd5b5f22008-10-20 07:00:43 +0000451 SourceLocation LHSLoc = ConsumeParen(); // consume '('
Mike Stump1eb44332009-09-09 15:08:12 +0000452
Chris Lattnercd9f4b32008-10-20 07:15:22 +0000453 while (1) {
Steve Naroffece8e712009-10-08 21:55:05 +0000454 if (Tok.is(tok::code_completion)) {
Douglas Gregora93b1082009-11-18 23:08:07 +0000455 Actions.CodeCompleteObjCPropertyFlags(CurScope, DS);
Steve Naroffece8e712009-10-08 21:55:05 +0000456 ConsumeToken();
457 }
Fariborz Jahaniand0f97d12007-08-31 16:11:31 +0000458 const IdentifierInfo *II = Tok.getIdentifierInfo();
Mike Stump1eb44332009-09-09 15:08:12 +0000459
Chris Lattnerf6ed8552008-10-20 07:22:18 +0000460 // If this is not an identifier at all, bail out early.
461 if (II == 0) {
462 MatchRHSPunctuation(tok::r_paren, LHSLoc);
463 return;
464 }
Mike Stump1eb44332009-09-09 15:08:12 +0000465
Chris Lattner156b0612008-10-20 07:37:22 +0000466 SourceLocation AttrName = ConsumeToken(); // consume last attribute name
Mike Stump1eb44332009-09-09 15:08:12 +0000467
Chris Lattner92e62b02008-11-20 04:42:34 +0000468 if (II->isStr("readonly"))
Chris Lattnere00da7c2008-10-20 07:39:53 +0000469 DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_readonly);
Chris Lattner92e62b02008-11-20 04:42:34 +0000470 else if (II->isStr("assign"))
Chris Lattnere00da7c2008-10-20 07:39:53 +0000471 DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_assign);
Chris Lattner92e62b02008-11-20 04:42:34 +0000472 else if (II->isStr("readwrite"))
Chris Lattnere00da7c2008-10-20 07:39:53 +0000473 DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_readwrite);
Chris Lattner92e62b02008-11-20 04:42:34 +0000474 else if (II->isStr("retain"))
Chris Lattnere00da7c2008-10-20 07:39:53 +0000475 DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_retain);
Chris Lattner92e62b02008-11-20 04:42:34 +0000476 else if (II->isStr("copy"))
Chris Lattnere00da7c2008-10-20 07:39:53 +0000477 DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_copy);
Chris Lattner92e62b02008-11-20 04:42:34 +0000478 else if (II->isStr("nonatomic"))
Chris Lattnere00da7c2008-10-20 07:39:53 +0000479 DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_nonatomic);
Chris Lattner92e62b02008-11-20 04:42:34 +0000480 else if (II->isStr("getter") || II->isStr("setter")) {
Chris Lattnere00da7c2008-10-20 07:39:53 +0000481 // getter/setter require extra treatment.
Chris Lattner156b0612008-10-20 07:37:22 +0000482 if (ExpectAndConsume(tok::equal, diag::err_objc_expected_equal, "",
483 tok::r_paren))
Chris Lattnerdd5b5f22008-10-20 07:00:43 +0000484 return;
Mike Stump1eb44332009-09-09 15:08:12 +0000485
Douglas Gregor4ad96852009-11-19 07:41:15 +0000486 if (Tok.is(tok::code_completion)) {
487 if (II->getNameStart()[0] == 's')
488 Actions.CodeCompleteObjCPropertySetter(CurScope, ClassDecl,
489 Methods, NumMethods);
490 else
491 Actions.CodeCompleteObjCPropertyGetter(CurScope, ClassDecl,
492 Methods, NumMethods);
493 ConsumeToken();
494 }
495
Chris Lattner8ca329c2008-10-20 07:24:39 +0000496 if (Tok.isNot(tok::identifier)) {
Chris Lattner1ab3b962008-11-18 07:48:38 +0000497 Diag(Tok, diag::err_expected_ident);
Chris Lattner8ca329c2008-10-20 07:24:39 +0000498 SkipUntil(tok::r_paren);
499 return;
500 }
Mike Stump1eb44332009-09-09 15:08:12 +0000501
Daniel Dunbare013d682009-10-18 20:26:12 +0000502 if (II->getNameStart()[0] == 's') {
Chris Lattner8ca329c2008-10-20 07:24:39 +0000503 DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_setter);
504 DS.setSetterName(Tok.getIdentifierInfo());
Chris Lattner156b0612008-10-20 07:37:22 +0000505 ConsumeToken(); // consume method name
Mike Stump1eb44332009-09-09 15:08:12 +0000506
Chris Lattner156b0612008-10-20 07:37:22 +0000507 if (ExpectAndConsume(tok::colon, diag::err_expected_colon, "",
508 tok::r_paren))
Chris Lattner8ca329c2008-10-20 07:24:39 +0000509 return;
Chris Lattner8ca329c2008-10-20 07:24:39 +0000510 } else {
511 DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_getter);
512 DS.setGetterName(Tok.getIdentifierInfo());
Chris Lattner156b0612008-10-20 07:37:22 +0000513 ConsumeToken(); // consume method name
Chris Lattner8ca329c2008-10-20 07:24:39 +0000514 }
Chris Lattnere00da7c2008-10-20 07:39:53 +0000515 } else {
Chris Lattnera9500f02008-11-19 07:49:38 +0000516 Diag(AttrName, diag::err_objc_expected_property_attr) << II;
Chris Lattnercd9f4b32008-10-20 07:15:22 +0000517 SkipUntil(tok::r_paren);
518 return;
Chris Lattnercd9f4b32008-10-20 07:15:22 +0000519 }
Mike Stump1eb44332009-09-09 15:08:12 +0000520
Chris Lattner156b0612008-10-20 07:37:22 +0000521 if (Tok.isNot(tok::comma))
522 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000523
Chris Lattner156b0612008-10-20 07:37:22 +0000524 ConsumeToken();
Fariborz Jahaniand0f97d12007-08-31 16:11:31 +0000525 }
Mike Stump1eb44332009-09-09 15:08:12 +0000526
Chris Lattner156b0612008-10-20 07:37:22 +0000527 MatchRHSPunctuation(tok::r_paren, LHSLoc);
Fariborz Jahaniand0f97d12007-08-31 16:11:31 +0000528}
529
Steve Naroff3536b442007-09-06 21:24:23 +0000530/// objc-method-proto:
Mike Stump1eb44332009-09-09 15:08:12 +0000531/// objc-instance-method objc-method-decl objc-method-attributes[opt]
Steve Naroff3536b442007-09-06 21:24:23 +0000532/// objc-class-method objc-method-decl objc-method-attributes[opt]
Steve Naroff294494e2007-08-22 16:35:03 +0000533///
534/// objc-instance-method: '-'
535/// objc-class-method: '+'
536///
Steve Naroff4985ace2007-08-22 18:35:33 +0000537/// objc-method-attributes: [OBJC2]
538/// __attribute__((deprecated))
539///
Mike Stump1eb44332009-09-09 15:08:12 +0000540Parser::DeclPtrTy Parser::ParseObjCMethodPrototype(DeclPtrTy IDecl,
Chris Lattnerb28317a2009-03-28 19:18:32 +0000541 tok::ObjCKeywordKind MethodImplKind) {
Chris Lattnerdf195262007-10-09 17:51:17 +0000542 assert((Tok.is(tok::minus) || Tok.is(tok::plus)) && "expected +/-");
Steve Naroff294494e2007-08-22 16:35:03 +0000543
Mike Stump1eb44332009-09-09 15:08:12 +0000544 tok::TokenKind methodType = Tok.getKind();
Steve Naroffbef11852007-10-26 20:53:56 +0000545 SourceLocation mLoc = ConsumeToken();
Mike Stump1eb44332009-09-09 15:08:12 +0000546
Chris Lattnerb28317a2009-03-28 19:18:32 +0000547 DeclPtrTy MDecl = ParseObjCMethodDecl(mLoc, methodType, IDecl,MethodImplKind);
Steve Naroff3536b442007-09-06 21:24:23 +0000548 // Since this rule is used for both method declarations and definitions,
Steve Naroff2bd42fa2007-09-10 20:51:04 +0000549 // the caller is (optionally) responsible for consuming the ';'.
Steve Narofff28b2642007-09-05 23:30:30 +0000550 return MDecl;
Steve Naroff294494e2007-08-22 16:35:03 +0000551}
552
553/// objc-selector:
554/// identifier
555/// one of
556/// enum struct union if else while do for switch case default
557/// break continue return goto asm sizeof typeof __alignof
558/// unsigned long const short volatile signed restrict _Complex
559/// in out inout bycopy byref oneway int char float double void _Bool
560///
Chris Lattner2fc5c242009-04-11 18:13:45 +0000561IdentifierInfo *Parser::ParseObjCSelectorPiece(SourceLocation &SelectorLoc) {
Chris Lattnerff384912007-10-07 02:00:24 +0000562 switch (Tok.getKind()) {
563 default:
564 return 0;
565 case tok::identifier:
Anders Carlssonef048ef2008-08-23 21:00:01 +0000566 case tok::kw_asm:
Chris Lattnerff384912007-10-07 02:00:24 +0000567 case tok::kw_auto:
Chris Lattner9298d962007-11-15 05:25:19 +0000568 case tok::kw_bool:
Anders Carlssonef048ef2008-08-23 21:00:01 +0000569 case tok::kw_break:
570 case tok::kw_case:
571 case tok::kw_catch:
572 case tok::kw_char:
573 case tok::kw_class:
574 case tok::kw_const:
575 case tok::kw_const_cast:
576 case tok::kw_continue:
577 case tok::kw_default:
578 case tok::kw_delete:
579 case tok::kw_do:
580 case tok::kw_double:
581 case tok::kw_dynamic_cast:
582 case tok::kw_else:
583 case tok::kw_enum:
584 case tok::kw_explicit:
585 case tok::kw_export:
586 case tok::kw_extern:
587 case tok::kw_false:
588 case tok::kw_float:
589 case tok::kw_for:
590 case tok::kw_friend:
591 case tok::kw_goto:
592 case tok::kw_if:
593 case tok::kw_inline:
594 case tok::kw_int:
595 case tok::kw_long:
596 case tok::kw_mutable:
597 case tok::kw_namespace:
598 case tok::kw_new:
599 case tok::kw_operator:
600 case tok::kw_private:
601 case tok::kw_protected:
602 case tok::kw_public:
603 case tok::kw_register:
604 case tok::kw_reinterpret_cast:
605 case tok::kw_restrict:
606 case tok::kw_return:
607 case tok::kw_short:
608 case tok::kw_signed:
609 case tok::kw_sizeof:
610 case tok::kw_static:
611 case tok::kw_static_cast:
612 case tok::kw_struct:
613 case tok::kw_switch:
614 case tok::kw_template:
615 case tok::kw_this:
616 case tok::kw_throw:
617 case tok::kw_true:
618 case tok::kw_try:
619 case tok::kw_typedef:
620 case tok::kw_typeid:
621 case tok::kw_typename:
622 case tok::kw_typeof:
623 case tok::kw_union:
624 case tok::kw_unsigned:
625 case tok::kw_using:
626 case tok::kw_virtual:
627 case tok::kw_void:
628 case tok::kw_volatile:
629 case tok::kw_wchar_t:
630 case tok::kw_while:
Chris Lattnerff384912007-10-07 02:00:24 +0000631 case tok::kw__Bool:
632 case tok::kw__Complex:
Anders Carlssonef048ef2008-08-23 21:00:01 +0000633 case tok::kw___alignof:
Chris Lattnerff384912007-10-07 02:00:24 +0000634 IdentifierInfo *II = Tok.getIdentifierInfo();
Fariborz Jahanian4b6c9052007-10-11 00:55:41 +0000635 SelectorLoc = ConsumeToken();
Chris Lattnerff384912007-10-07 02:00:24 +0000636 return II;
Fariborz Jahaniand0649512007-09-27 19:52:15 +0000637 }
Steve Naroff294494e2007-08-22 16:35:03 +0000638}
639
Fariborz Jahanian0196cab2008-01-02 22:54:34 +0000640/// objc-for-collection-in: 'in'
641///
Fariborz Jahanian335a2d42008-01-04 23:04:08 +0000642bool Parser::isTokIdentifier_in() const {
Fariborz Jahanian3ba5a0f2008-01-03 17:55:25 +0000643 // FIXME: May have to do additional look-ahead to only allow for
644 // valid tokens following an 'in'; such as an identifier, unary operators,
645 // '[' etc.
Mike Stump1eb44332009-09-09 15:08:12 +0000646 return (getLang().ObjC2 && Tok.is(tok::identifier) &&
Chris Lattner5ffb14b2008-08-23 02:02:23 +0000647 Tok.getIdentifierInfo() == ObjCTypeQuals[objc_in]);
Fariborz Jahanian0196cab2008-01-02 22:54:34 +0000648}
649
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000650/// ParseObjCTypeQualifierList - This routine parses the objective-c's type
Chris Lattnere8b724d2007-12-12 06:56:32 +0000651/// qualifier list and builds their bitmask representation in the input
652/// argument.
Steve Naroff294494e2007-08-22 16:35:03 +0000653///
654/// objc-type-qualifiers:
655/// objc-type-qualifier
656/// objc-type-qualifiers objc-type-qualifier
657///
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000658void Parser::ParseObjCTypeQualifierList(ObjCDeclSpec &DS) {
Chris Lattnere8b724d2007-12-12 06:56:32 +0000659 while (1) {
Chris Lattnercb53b362007-12-27 19:57:00 +0000660 if (Tok.isNot(tok::identifier))
Chris Lattnere8b724d2007-12-12 06:56:32 +0000661 return;
Mike Stump1eb44332009-09-09 15:08:12 +0000662
Chris Lattnere8b724d2007-12-12 06:56:32 +0000663 const IdentifierInfo *II = Tok.getIdentifierInfo();
664 for (unsigned i = 0; i != objc_NumQuals; ++i) {
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000665 if (II != ObjCTypeQuals[i])
Chris Lattnere8b724d2007-12-12 06:56:32 +0000666 continue;
Mike Stump1eb44332009-09-09 15:08:12 +0000667
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000668 ObjCDeclSpec::ObjCDeclQualifier Qual;
Chris Lattnere8b724d2007-12-12 06:56:32 +0000669 switch (i) {
670 default: assert(0 && "Unknown decl qualifier");
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000671 case objc_in: Qual = ObjCDeclSpec::DQ_In; break;
672 case objc_out: Qual = ObjCDeclSpec::DQ_Out; break;
673 case objc_inout: Qual = ObjCDeclSpec::DQ_Inout; break;
674 case objc_oneway: Qual = ObjCDeclSpec::DQ_Oneway; break;
675 case objc_bycopy: Qual = ObjCDeclSpec::DQ_Bycopy; break;
676 case objc_byref: Qual = ObjCDeclSpec::DQ_Byref; break;
Chris Lattnere8b724d2007-12-12 06:56:32 +0000677 }
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000678 DS.setObjCDeclQualifier(Qual);
Chris Lattnere8b724d2007-12-12 06:56:32 +0000679 ConsumeToken();
680 II = 0;
681 break;
682 }
Mike Stump1eb44332009-09-09 15:08:12 +0000683
Chris Lattnere8b724d2007-12-12 06:56:32 +0000684 // If this wasn't a recognized qualifier, bail out.
685 if (II) return;
686 }
687}
688
689/// objc-type-name:
690/// '(' objc-type-qualifiers[opt] type-name ')'
691/// '(' objc-type-qualifiers[opt] ')'
692///
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000693Parser::TypeTy *Parser::ParseObjCTypeName(ObjCDeclSpec &DS) {
Chris Lattnerdf195262007-10-09 17:51:17 +0000694 assert(Tok.is(tok::l_paren) && "expected (");
Mike Stump1eb44332009-09-09 15:08:12 +0000695
Chris Lattner4a76b292008-10-22 03:52:06 +0000696 SourceLocation LParenLoc = ConsumeParen();
Chris Lattnere8904e92008-08-23 01:48:03 +0000697 SourceLocation TypeStartLoc = Tok.getLocation();
Mike Stump1eb44332009-09-09 15:08:12 +0000698
Fariborz Jahanian19d74e12007-10-31 21:59:43 +0000699 // Parse type qualifiers, in, inout, etc.
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000700 ParseObjCTypeQualifierList(DS);
Steve Naroff4fa7afd2007-08-22 23:18:22 +0000701
Chris Lattner4a76b292008-10-22 03:52:06 +0000702 TypeTy *Ty = 0;
Douglas Gregor809070a2009-02-18 17:45:20 +0000703 if (isTypeSpecifierQualifier()) {
704 TypeResult TypeSpec = ParseTypeName();
705 if (!TypeSpec.isInvalid())
706 Ty = TypeSpec.get();
707 }
Mike Stump1eb44332009-09-09 15:08:12 +0000708
Steve Naroffd7333c22008-10-21 14:15:04 +0000709 if (Tok.is(tok::r_paren))
Chris Lattner4a76b292008-10-22 03:52:06 +0000710 ConsumeParen();
711 else if (Tok.getLocation() == TypeStartLoc) {
712 // If we didn't eat any tokens, then this isn't a type.
Chris Lattner1ab3b962008-11-18 07:48:38 +0000713 Diag(Tok, diag::err_expected_type);
Chris Lattner4a76b292008-10-22 03:52:06 +0000714 SkipUntil(tok::r_paren);
715 } else {
716 // Otherwise, we found *something*, but didn't get a ')' in the right
717 // place. Emit an error then return what we have as the type.
718 MatchRHSPunctuation(tok::r_paren, LParenLoc);
719 }
Steve Narofff28b2642007-09-05 23:30:30 +0000720 return Ty;
Steve Naroff294494e2007-08-22 16:35:03 +0000721}
722
723/// objc-method-decl:
724/// objc-selector
Steve Naroff4985ace2007-08-22 18:35:33 +0000725/// objc-keyword-selector objc-parmlist[opt]
Steve Naroff294494e2007-08-22 16:35:03 +0000726/// objc-type-name objc-selector
Steve Naroff4985ace2007-08-22 18:35:33 +0000727/// objc-type-name objc-keyword-selector objc-parmlist[opt]
Steve Naroff294494e2007-08-22 16:35:03 +0000728///
729/// objc-keyword-selector:
Mike Stump1eb44332009-09-09 15:08:12 +0000730/// objc-keyword-decl
Steve Naroff294494e2007-08-22 16:35:03 +0000731/// objc-keyword-selector objc-keyword-decl
732///
733/// objc-keyword-decl:
Steve Naroff7ef58fd2007-08-22 22:17:26 +0000734/// objc-selector ':' objc-type-name objc-keyword-attributes[opt] identifier
735/// objc-selector ':' objc-keyword-attributes[opt] identifier
736/// ':' objc-type-name objc-keyword-attributes[opt] identifier
737/// ':' objc-keyword-attributes[opt] identifier
Steve Naroff294494e2007-08-22 16:35:03 +0000738///
Steve Naroff4985ace2007-08-22 18:35:33 +0000739/// objc-parmlist:
740/// objc-parms objc-ellipsis[opt]
Steve Naroff294494e2007-08-22 16:35:03 +0000741///
Steve Naroff4985ace2007-08-22 18:35:33 +0000742/// objc-parms:
743/// objc-parms , parameter-declaration
Steve Naroff294494e2007-08-22 16:35:03 +0000744///
Steve Naroff4985ace2007-08-22 18:35:33 +0000745/// objc-ellipsis:
Steve Naroff294494e2007-08-22 16:35:03 +0000746/// , ...
747///
Steve Naroff7ef58fd2007-08-22 22:17:26 +0000748/// objc-keyword-attributes: [OBJC2]
749/// __attribute__((unused))
750///
Chris Lattnerb28317a2009-03-28 19:18:32 +0000751Parser::DeclPtrTy Parser::ParseObjCMethodDecl(SourceLocation mLoc,
752 tok::TokenKind mType,
753 DeclPtrTy IDecl,
754 tok::ObjCKeywordKind MethodImplKind) {
John McCall54abf7d2009-11-04 02:18:39 +0000755 ParsingDeclRAIIObject PD(*this);
756
Chris Lattnere8904e92008-08-23 01:48:03 +0000757 // Parse the return type if present.
Chris Lattnerff384912007-10-07 02:00:24 +0000758 TypeTy *ReturnType = 0;
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000759 ObjCDeclSpec DSRet;
Chris Lattnerdf195262007-10-09 17:51:17 +0000760 if (Tok.is(tok::l_paren))
Fariborz Jahanianf1de0ca2007-10-31 23:53:01 +0000761 ReturnType = ParseObjCTypeName(DSRet);
Mike Stump1eb44332009-09-09 15:08:12 +0000762
Steve Naroffbef11852007-10-26 20:53:56 +0000763 SourceLocation selLoc;
Chris Lattner2fc5c242009-04-11 18:13:45 +0000764 IdentifierInfo *SelIdent = ParseObjCSelectorPiece(selLoc);
Chris Lattnere8904e92008-08-23 01:48:03 +0000765
Steve Naroff84c43102009-02-11 20:43:13 +0000766 // An unnamed colon is valid.
767 if (!SelIdent && Tok.isNot(tok::colon)) { // missing selector name.
Chris Lattner1ab3b962008-11-18 07:48:38 +0000768 Diag(Tok, diag::err_expected_selector_for_method)
769 << SourceRange(mLoc, Tok.getLocation());
Chris Lattnere8904e92008-08-23 01:48:03 +0000770 // Skip until we get a ; or {}.
771 SkipUntil(tok::r_brace);
Chris Lattnerb28317a2009-03-28 19:18:32 +0000772 return DeclPtrTy();
Chris Lattnere8904e92008-08-23 01:48:03 +0000773 }
Mike Stump1eb44332009-09-09 15:08:12 +0000774
Fariborz Jahanian439c6582009-01-09 00:38:19 +0000775 llvm::SmallVector<Declarator, 8> CargNames;
Chris Lattnerdf195262007-10-09 17:51:17 +0000776 if (Tok.isNot(tok::colon)) {
Chris Lattnerff384912007-10-07 02:00:24 +0000777 // If attributes exist after the method, parse them.
778 AttributeList *MethodAttrs = 0;
Mike Stump1eb44332009-09-09 15:08:12 +0000779 if (getLang().ObjC2 && Tok.is(tok::kw___attribute))
Sean Huntbbd37c62009-11-21 08:43:09 +0000780 MethodAttrs = ParseGNUAttributes();
Mike Stump1eb44332009-09-09 15:08:12 +0000781
Chris Lattnerff384912007-10-07 02:00:24 +0000782 Selector Sel = PP.getSelectorTable().getNullarySelector(SelIdent);
John McCall54abf7d2009-11-04 02:18:39 +0000783 DeclPtrTy Result
784 = Actions.ActOnMethodDeclaration(mLoc, Tok.getLocation(),
Fariborz Jahanian1f7b6f82007-11-09 19:52:12 +0000785 mType, IDecl, DSRet, ReturnType, Sel,
Ted Kremenek1c6a3cc2009-05-04 17:04:30 +0000786 0, CargNames, MethodAttrs,
787 MethodImplKind);
John McCall54abf7d2009-11-04 02:18:39 +0000788 PD.complete(Result);
789 return Result;
Chris Lattnerff384912007-10-07 02:00:24 +0000790 }
Steve Narofff28b2642007-09-05 23:30:30 +0000791
Steve Naroff68d331a2007-09-27 14:38:14 +0000792 llvm::SmallVector<IdentifierInfo *, 12> KeyIdents;
Chris Lattnere294d3f2009-04-11 18:57:04 +0000793 llvm::SmallVector<Action::ObjCArgInfo, 12> ArgInfos;
Mike Stump1eb44332009-09-09 15:08:12 +0000794
Chris Lattnerff384912007-10-07 02:00:24 +0000795 while (1) {
Chris Lattnere294d3f2009-04-11 18:57:04 +0000796 Action::ObjCArgInfo ArgInfo;
Mike Stump1eb44332009-09-09 15:08:12 +0000797
Chris Lattnerff384912007-10-07 02:00:24 +0000798 // Each iteration parses a single keyword argument.
Chris Lattnerdf195262007-10-09 17:51:17 +0000799 if (Tok.isNot(tok::colon)) {
Chris Lattnerff384912007-10-07 02:00:24 +0000800 Diag(Tok, diag::err_expected_colon);
801 break;
802 }
803 ConsumeToken(); // Eat the ':'.
Mike Stump1eb44332009-09-09 15:08:12 +0000804
Chris Lattnere294d3f2009-04-11 18:57:04 +0000805 ArgInfo.Type = 0;
806 if (Tok.is(tok::l_paren)) // Parse the argument type if present.
807 ArgInfo.Type = ParseObjCTypeName(ArgInfo.DeclSpec);
808
Chris Lattnerff384912007-10-07 02:00:24 +0000809 // If attributes exist before the argument name, parse them.
Chris Lattnere294d3f2009-04-11 18:57:04 +0000810 ArgInfo.ArgAttrs = 0;
Chris Lattnerdf195262007-10-09 17:51:17 +0000811 if (getLang().ObjC2 && Tok.is(tok::kw___attribute))
Sean Huntbbd37c62009-11-21 08:43:09 +0000812 ArgInfo.ArgAttrs = ParseGNUAttributes();
Steve Naroff7ef58fd2007-08-22 22:17:26 +0000813
Chris Lattnerdf195262007-10-09 17:51:17 +0000814 if (Tok.isNot(tok::identifier)) {
Chris Lattnerff384912007-10-07 02:00:24 +0000815 Diag(Tok, diag::err_expected_ident); // missing argument name.
816 break;
Steve Naroff4985ace2007-08-22 18:35:33 +0000817 }
Mike Stump1eb44332009-09-09 15:08:12 +0000818
Chris Lattnere294d3f2009-04-11 18:57:04 +0000819 ArgInfo.Name = Tok.getIdentifierInfo();
820 ArgInfo.NameLoc = Tok.getLocation();
Chris Lattnerff384912007-10-07 02:00:24 +0000821 ConsumeToken(); // Eat the identifier.
Mike Stump1eb44332009-09-09 15:08:12 +0000822
Chris Lattnere294d3f2009-04-11 18:57:04 +0000823 ArgInfos.push_back(ArgInfo);
824 KeyIdents.push_back(SelIdent);
825
Chris Lattnerff384912007-10-07 02:00:24 +0000826 // Check for another keyword selector.
Fariborz Jahanian4b6c9052007-10-11 00:55:41 +0000827 SourceLocation Loc;
Chris Lattner2fc5c242009-04-11 18:13:45 +0000828 SelIdent = ParseObjCSelectorPiece(Loc);
Chris Lattnerdf195262007-10-09 17:51:17 +0000829 if (!SelIdent && Tok.isNot(tok::colon))
Chris Lattnerff384912007-10-07 02:00:24 +0000830 break;
831 // We have a selector or a colon, continue parsing.
Steve Naroff4985ace2007-08-22 18:35:33 +0000832 }
Mike Stump1eb44332009-09-09 15:08:12 +0000833
Steve Naroff335eafa2007-11-15 12:35:21 +0000834 bool isVariadic = false;
Mike Stump1eb44332009-09-09 15:08:12 +0000835
Chris Lattnerff384912007-10-07 02:00:24 +0000836 // Parse the (optional) parameter list.
Chris Lattnerdf195262007-10-09 17:51:17 +0000837 while (Tok.is(tok::comma)) {
Chris Lattnerff384912007-10-07 02:00:24 +0000838 ConsumeToken();
Chris Lattnerdf195262007-10-09 17:51:17 +0000839 if (Tok.is(tok::ellipsis)) {
Steve Naroff335eafa2007-11-15 12:35:21 +0000840 isVariadic = true;
Chris Lattnerff384912007-10-07 02:00:24 +0000841 ConsumeToken();
842 break;
843 }
Chris Lattnerff384912007-10-07 02:00:24 +0000844 DeclSpec DS;
845 ParseDeclarationSpecifiers(DS);
Mike Stump1eb44332009-09-09 15:08:12 +0000846 // Parse the declarator.
Chris Lattnerff384912007-10-07 02:00:24 +0000847 Declarator ParmDecl(DS, Declarator::PrototypeContext);
848 ParseDeclarator(ParmDecl);
Fariborz Jahanian439c6582009-01-09 00:38:19 +0000849 CargNames.push_back(ParmDecl);
Chris Lattnerff384912007-10-07 02:00:24 +0000850 }
Mike Stump1eb44332009-09-09 15:08:12 +0000851
Chris Lattnerff384912007-10-07 02:00:24 +0000852 // FIXME: Add support for optional parmameter list...
Fariborz Jahaniane3a2ca72007-09-10 20:33:04 +0000853 // If attributes exist after the method, parse them.
Chris Lattnerff384912007-10-07 02:00:24 +0000854 AttributeList *MethodAttrs = 0;
Mike Stump1eb44332009-09-09 15:08:12 +0000855 if (getLang().ObjC2 && Tok.is(tok::kw___attribute))
Sean Huntbbd37c62009-11-21 08:43:09 +0000856 MethodAttrs = ParseGNUAttributes();
Mike Stump1eb44332009-09-09 15:08:12 +0000857
Fariborz Jahanian3688fc62009-06-24 17:00:18 +0000858 if (KeyIdents.size() == 0)
859 return DeclPtrTy();
Chris Lattnerff384912007-10-07 02:00:24 +0000860 Selector Sel = PP.getSelectorTable().getSelector(KeyIdents.size(),
861 &KeyIdents[0]);
John McCall54abf7d2009-11-04 02:18:39 +0000862 DeclPtrTy Result
863 = Actions.ActOnMethodDeclaration(mLoc, Tok.getLocation(),
Fariborz Jahanian3688fc62009-06-24 17:00:18 +0000864 mType, IDecl, DSRet, ReturnType, Sel,
Ted Kremenek1c6a3cc2009-05-04 17:04:30 +0000865 &ArgInfos[0], CargNames, MethodAttrs,
Steve Naroff335eafa2007-11-15 12:35:21 +0000866 MethodImplKind, isVariadic);
John McCall54abf7d2009-11-04 02:18:39 +0000867 PD.complete(Result);
868 return Result;
Steve Naroff294494e2007-08-22 16:35:03 +0000869}
870
Steve Naroffdac269b2007-08-20 21:31:48 +0000871/// objc-protocol-refs:
872/// '<' identifier-list '>'
873///
Chris Lattner7caeabd2008-07-21 22:17:28 +0000874bool Parser::
Chris Lattnerb28317a2009-03-28 19:18:32 +0000875ParseObjCProtocolReferences(llvm::SmallVectorImpl<Action::DeclPtrTy> &Protocols,
Argyrios Kyrtzidis71b0add2009-09-29 19:41:44 +0000876 llvm::SmallVectorImpl<SourceLocation> &ProtocolLocs,
877 bool WarnOnDeclarations,
878 SourceLocation &LAngleLoc, SourceLocation &EndLoc) {
Chris Lattnere13b9592008-07-26 04:03:38 +0000879 assert(Tok.is(tok::less) && "expected <");
Mike Stump1eb44332009-09-09 15:08:12 +0000880
Argyrios Kyrtzidis71b0add2009-09-29 19:41:44 +0000881 LAngleLoc = ConsumeToken(); // the "<"
Mike Stump1eb44332009-09-09 15:08:12 +0000882
Chris Lattnere13b9592008-07-26 04:03:38 +0000883 llvm::SmallVector<IdentifierLocPair, 8> ProtocolIdents;
Mike Stump1eb44332009-09-09 15:08:12 +0000884
Chris Lattnere13b9592008-07-26 04:03:38 +0000885 while (1) {
Douglas Gregor55385fe2009-11-18 04:19:12 +0000886 if (Tok.is(tok::code_completion)) {
887 Actions.CodeCompleteObjCProtocolReferences(ProtocolIdents.data(),
888 ProtocolIdents.size());
889 ConsumeToken();
890 }
891
Chris Lattnere13b9592008-07-26 04:03:38 +0000892 if (Tok.isNot(tok::identifier)) {
893 Diag(Tok, diag::err_expected_ident);
894 SkipUntil(tok::greater);
895 return true;
896 }
897 ProtocolIdents.push_back(std::make_pair(Tok.getIdentifierInfo(),
898 Tok.getLocation()));
Argyrios Kyrtzidis71b0add2009-09-29 19:41:44 +0000899 ProtocolLocs.push_back(Tok.getLocation());
Chris Lattnere13b9592008-07-26 04:03:38 +0000900 ConsumeToken();
Mike Stump1eb44332009-09-09 15:08:12 +0000901
Chris Lattnere13b9592008-07-26 04:03:38 +0000902 if (Tok.isNot(tok::comma))
903 break;
904 ConsumeToken();
905 }
Mike Stump1eb44332009-09-09 15:08:12 +0000906
Chris Lattnere13b9592008-07-26 04:03:38 +0000907 // Consume the '>'.
908 if (Tok.isNot(tok::greater)) {
909 Diag(Tok, diag::err_expected_greater);
910 return true;
911 }
Mike Stump1eb44332009-09-09 15:08:12 +0000912
Chris Lattnere13b9592008-07-26 04:03:38 +0000913 EndLoc = ConsumeAnyToken();
Mike Stump1eb44332009-09-09 15:08:12 +0000914
Chris Lattnere13b9592008-07-26 04:03:38 +0000915 // Convert the list of protocols identifiers into a list of protocol decls.
916 Actions.FindProtocolDeclaration(WarnOnDeclarations,
917 &ProtocolIdents[0], ProtocolIdents.size(),
918 Protocols);
919 return false;
920}
921
Steve Naroffdac269b2007-08-20 21:31:48 +0000922/// objc-class-instance-variables:
923/// '{' objc-instance-variable-decl-list[opt] '}'
924///
925/// objc-instance-variable-decl-list:
926/// objc-visibility-spec
927/// objc-instance-variable-decl ';'
928/// ';'
929/// objc-instance-variable-decl-list objc-visibility-spec
930/// objc-instance-variable-decl-list objc-instance-variable-decl ';'
931/// objc-instance-variable-decl-list ';'
932///
933/// objc-visibility-spec:
934/// @private
935/// @protected
936/// @public
Steve Naroffddbff782007-08-21 21:17:12 +0000937/// @package [OBJC2]
Steve Naroffdac269b2007-08-20 21:31:48 +0000938///
939/// objc-instance-variable-decl:
Mike Stump1eb44332009-09-09 15:08:12 +0000940/// struct-declaration
Steve Naroffdac269b2007-08-20 21:31:48 +0000941///
Chris Lattnerb28317a2009-03-28 19:18:32 +0000942void Parser::ParseObjCClassInstanceVariables(DeclPtrTy interfaceDecl,
Steve Naroff60fccee2007-10-29 21:38:07 +0000943 SourceLocation atLoc) {
Chris Lattnerdf195262007-10-09 17:51:17 +0000944 assert(Tok.is(tok::l_brace) && "expected {");
Chris Lattnerb28317a2009-03-28 19:18:32 +0000945 llvm::SmallVector<DeclPtrTy, 32> AllIvarDecls;
Chris Lattnere1359422008-04-10 06:46:29 +0000946
Douglas Gregor1a0d31a2009-01-12 18:45:55 +0000947 ParseScope ClassScope(this, Scope::DeclScope|Scope::ClassScope);
Douglas Gregor72de6672009-01-08 20:45:30 +0000948
Steve Naroffddbff782007-08-21 21:17:12 +0000949 SourceLocation LBraceLoc = ConsumeBrace(); // the "{"
Mike Stump1eb44332009-09-09 15:08:12 +0000950
Fariborz Jahanianaa847fe2008-04-29 23:03:51 +0000951 tok::ObjCKeywordKind visibility = tok::objc_protected;
Steve Naroffddbff782007-08-21 21:17:12 +0000952 // While we still have something to read, read the instance variables.
Chris Lattnerdf195262007-10-09 17:51:17 +0000953 while (Tok.isNot(tok::r_brace) && Tok.isNot(tok::eof)) {
Steve Naroffddbff782007-08-21 21:17:12 +0000954 // Each iteration of this loop reads one objc-instance-variable-decl.
Mike Stump1eb44332009-09-09 15:08:12 +0000955
Steve Naroffddbff782007-08-21 21:17:12 +0000956 // Check for extraneous top-level semicolon.
Chris Lattnerdf195262007-10-09 17:51:17 +0000957 if (Tok.is(tok::semi)) {
Chris Lattnerc2253f52009-11-06 06:40:12 +0000958 Diag(Tok, diag::ext_extra_struct_semi)
Chris Lattner29d9c1a2009-12-06 17:36:05 +0000959 << CodeModificationHint::CreateRemoval(Tok.getLocation());
Steve Naroffddbff782007-08-21 21:17:12 +0000960 ConsumeToken();
961 continue;
962 }
Mike Stump1eb44332009-09-09 15:08:12 +0000963
Steve Naroffddbff782007-08-21 21:17:12 +0000964 // Set the default visibility to private.
Chris Lattnerdf195262007-10-09 17:51:17 +0000965 if (Tok.is(tok::at)) { // parse objc-visibility-spec
Steve Naroffddbff782007-08-21 21:17:12 +0000966 ConsumeToken(); // eat the @ sign
Steve Naroff861cf3e2007-08-23 18:16:40 +0000967 switch (Tok.getObjCKeywordID()) {
Steve Naroffddbff782007-08-21 21:17:12 +0000968 case tok::objc_private:
969 case tok::objc_public:
970 case tok::objc_protected:
971 case tok::objc_package:
Steve Naroff861cf3e2007-08-23 18:16:40 +0000972 visibility = Tok.getObjCKeywordID();
Steve Naroffddbff782007-08-21 21:17:12 +0000973 ConsumeToken();
Mike Stump1eb44332009-09-09 15:08:12 +0000974 continue;
Steve Naroffddbff782007-08-21 21:17:12 +0000975 default:
976 Diag(Tok, diag::err_objc_illegal_visibility_spec);
Steve Naroffddbff782007-08-21 21:17:12 +0000977 continue;
978 }
979 }
Mike Stump1eb44332009-09-09 15:08:12 +0000980
John McCallbdd563e2009-11-03 02:38:08 +0000981 struct ObjCIvarCallback : FieldCallback {
982 Parser &P;
983 DeclPtrTy IDecl;
984 tok::ObjCKeywordKind visibility;
985 llvm::SmallVectorImpl<DeclPtrTy> &AllIvarDecls;
986
987 ObjCIvarCallback(Parser &P, DeclPtrTy IDecl, tok::ObjCKeywordKind V,
988 llvm::SmallVectorImpl<DeclPtrTy> &AllIvarDecls) :
989 P(P), IDecl(IDecl), visibility(V), AllIvarDecls(AllIvarDecls) {
990 }
991
992 DeclPtrTy invoke(FieldDeclarator &FD) {
993 // Install the declarator into the interface decl.
994 DeclPtrTy Field
995 = P.Actions.ActOnIvar(P.CurScope,
996 FD.D.getDeclSpec().getSourceRange().getBegin(),
997 IDecl, FD.D, FD.BitfieldSize, visibility);
998 AllIvarDecls.push_back(Field);
999 return Field;
1000 }
1001 } Callback(*this, interfaceDecl, visibility, AllIvarDecls);
1002
Chris Lattnere1359422008-04-10 06:46:29 +00001003 // Parse all the comma separated declarators.
1004 DeclSpec DS;
John McCallbdd563e2009-11-03 02:38:08 +00001005 ParseStructDeclaration(DS, Callback);
Mike Stump1eb44332009-09-09 15:08:12 +00001006
Chris Lattnerdf195262007-10-09 17:51:17 +00001007 if (Tok.is(tok::semi)) {
Steve Naroffddbff782007-08-21 21:17:12 +00001008 ConsumeToken();
Steve Naroffddbff782007-08-21 21:17:12 +00001009 } else {
1010 Diag(Tok, diag::err_expected_semi_decl_list);
1011 // Skip to end of block or statement
1012 SkipUntil(tok::r_brace, true, true);
1013 }
1014 }
Steve Naroff60fccee2007-10-29 21:38:07 +00001015 SourceLocation RBraceLoc = MatchRHSPunctuation(tok::r_brace, LBraceLoc);
Steve Naroff8749be52007-10-31 22:11:35 +00001016 // Call ActOnFields() even if we don't have any decls. This is useful
1017 // for code rewriting tools that need to be aware of the empty list.
1018 Actions.ActOnFields(CurScope, atLoc, interfaceDecl,
Jay Foadbeaaccd2009-05-21 09:52:38 +00001019 AllIvarDecls.data(), AllIvarDecls.size(),
Daniel Dunbar1bfe1c22008-10-03 02:03:53 +00001020 LBraceLoc, RBraceLoc, 0);
Steve Naroffddbff782007-08-21 21:17:12 +00001021 return;
Reid Spencer5f016e22007-07-11 17:01:13 +00001022}
Steve Naroffdac269b2007-08-20 21:31:48 +00001023
1024/// objc-protocol-declaration:
1025/// objc-protocol-definition
1026/// objc-protocol-forward-reference
1027///
1028/// objc-protocol-definition:
Mike Stump1eb44332009-09-09 15:08:12 +00001029/// @protocol identifier
1030/// objc-protocol-refs[opt]
1031/// objc-interface-decl-list
Steve Naroffdac269b2007-08-20 21:31:48 +00001032/// @end
1033///
1034/// objc-protocol-forward-reference:
1035/// @protocol identifier-list ';'
1036///
1037/// "@protocol identifier ;" should be resolved as "@protocol
Steve Naroff3536b442007-09-06 21:24:23 +00001038/// identifier-list ;": objc-interface-decl-list may not start with a
Steve Naroffdac269b2007-08-20 21:31:48 +00001039/// semicolon in the first alternative if objc-protocol-refs are omitted.
Chris Lattnerb28317a2009-03-28 19:18:32 +00001040Parser::DeclPtrTy Parser::ParseObjCAtProtocolDeclaration(SourceLocation AtLoc,
1041 AttributeList *attrList) {
Steve Naroff861cf3e2007-08-23 18:16:40 +00001042 assert(Tok.isObjCAtKeyword(tok::objc_protocol) &&
Steve Naroff7ef58fd2007-08-22 22:17:26 +00001043 "ParseObjCAtProtocolDeclaration(): Expected @protocol");
1044 ConsumeToken(); // the "protocol" identifier
Mike Stump1eb44332009-09-09 15:08:12 +00001045
Douglas Gregor083128f2009-11-18 04:49:41 +00001046 if (Tok.is(tok::code_completion)) {
1047 Actions.CodeCompleteObjCProtocolDecl(CurScope);
1048 ConsumeToken();
1049 }
1050
Chris Lattnerdf195262007-10-09 17:51:17 +00001051 if (Tok.isNot(tok::identifier)) {
Steve Naroff7ef58fd2007-08-22 22:17:26 +00001052 Diag(Tok, diag::err_expected_ident); // missing protocol name.
Chris Lattnerb28317a2009-03-28 19:18:32 +00001053 return DeclPtrTy();
Steve Naroff7ef58fd2007-08-22 22:17:26 +00001054 }
1055 // Save the protocol name, then consume it.
1056 IdentifierInfo *protocolName = Tok.getIdentifierInfo();
1057 SourceLocation nameLoc = ConsumeToken();
Mike Stump1eb44332009-09-09 15:08:12 +00001058
Chris Lattnerdf195262007-10-09 17:51:17 +00001059 if (Tok.is(tok::semi)) { // forward declaration of one protocol.
Chris Lattner7caeabd2008-07-21 22:17:28 +00001060 IdentifierLocPair ProtoInfo(protocolName, nameLoc);
Steve Naroff7ef58fd2007-08-22 22:17:26 +00001061 ConsumeToken();
Mike Stump1eb44332009-09-09 15:08:12 +00001062 return Actions.ActOnForwardProtocolDeclaration(AtLoc, &ProtoInfo, 1,
Fariborz Jahanianbc1c8772008-12-17 01:07:27 +00001063 attrList);
Steve Naroff7ef58fd2007-08-22 22:17:26 +00001064 }
Mike Stump1eb44332009-09-09 15:08:12 +00001065
Chris Lattnerdf195262007-10-09 17:51:17 +00001066 if (Tok.is(tok::comma)) { // list of forward declarations.
Chris Lattner7caeabd2008-07-21 22:17:28 +00001067 llvm::SmallVector<IdentifierLocPair, 8> ProtocolRefs;
1068 ProtocolRefs.push_back(std::make_pair(protocolName, nameLoc));
1069
Steve Naroff7ef58fd2007-08-22 22:17:26 +00001070 // Parse the list of forward declarations.
Steve Naroff7ef58fd2007-08-22 22:17:26 +00001071 while (1) {
1072 ConsumeToken(); // the ','
Chris Lattnerdf195262007-10-09 17:51:17 +00001073 if (Tok.isNot(tok::identifier)) {
Steve Naroff7ef58fd2007-08-22 22:17:26 +00001074 Diag(Tok, diag::err_expected_ident);
1075 SkipUntil(tok::semi);
Chris Lattnerb28317a2009-03-28 19:18:32 +00001076 return DeclPtrTy();
Steve Naroff7ef58fd2007-08-22 22:17:26 +00001077 }
Chris Lattner7caeabd2008-07-21 22:17:28 +00001078 ProtocolRefs.push_back(IdentifierLocPair(Tok.getIdentifierInfo(),
1079 Tok.getLocation()));
Steve Naroff7ef58fd2007-08-22 22:17:26 +00001080 ConsumeToken(); // the identifier
Mike Stump1eb44332009-09-09 15:08:12 +00001081
Chris Lattnerdf195262007-10-09 17:51:17 +00001082 if (Tok.isNot(tok::comma))
Steve Naroff7ef58fd2007-08-22 22:17:26 +00001083 break;
1084 }
1085 // Consume the ';'.
1086 if (ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@protocol"))
Chris Lattnerb28317a2009-03-28 19:18:32 +00001087 return DeclPtrTy();
Mike Stump1eb44332009-09-09 15:08:12 +00001088
Steve Naroffe440eb82007-10-10 17:32:04 +00001089 return Actions.ActOnForwardProtocolDeclaration(AtLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001090 &ProtocolRefs[0],
Fariborz Jahanianbc1c8772008-12-17 01:07:27 +00001091 ProtocolRefs.size(),
1092 attrList);
Chris Lattner7caeabd2008-07-21 22:17:28 +00001093 }
Mike Stump1eb44332009-09-09 15:08:12 +00001094
Steve Naroff7ef58fd2007-08-22 22:17:26 +00001095 // Last, and definitely not least, parse a protocol declaration.
Argyrios Kyrtzidis71b0add2009-09-29 19:41:44 +00001096 SourceLocation LAngleLoc, EndProtoLoc;
Chris Lattner7caeabd2008-07-21 22:17:28 +00001097
Chris Lattnerb28317a2009-03-28 19:18:32 +00001098 llvm::SmallVector<DeclPtrTy, 8> ProtocolRefs;
Argyrios Kyrtzidis71b0add2009-09-29 19:41:44 +00001099 llvm::SmallVector<SourceLocation, 8> ProtocolLocs;
Chris Lattner7caeabd2008-07-21 22:17:28 +00001100 if (Tok.is(tok::less) &&
Argyrios Kyrtzidis71b0add2009-09-29 19:41:44 +00001101 ParseObjCProtocolReferences(ProtocolRefs, ProtocolLocs, false,
1102 LAngleLoc, EndProtoLoc))
Chris Lattnerb28317a2009-03-28 19:18:32 +00001103 return DeclPtrTy();
Mike Stump1eb44332009-09-09 15:08:12 +00001104
Chris Lattnerb28317a2009-03-28 19:18:32 +00001105 DeclPtrTy ProtoType =
Chris Lattnere13b9592008-07-26 04:03:38 +00001106 Actions.ActOnStartProtocolInterface(AtLoc, protocolName, nameLoc,
Jay Foadbeaaccd2009-05-21 09:52:38 +00001107 ProtocolRefs.data(),
1108 ProtocolRefs.size(),
Daniel Dunbar246e70f2008-09-26 04:48:09 +00001109 EndProtoLoc, attrList);
Fariborz Jahanian25e077d2007-09-17 21:07:36 +00001110 ParseObjCInterfaceDeclList(ProtoType, tok::objc_protocol);
Chris Lattnerbc662af2008-10-20 06:10:06 +00001111 return ProtoType;
Reid Spencer5f016e22007-07-11 17:01:13 +00001112}
Steve Naroffdac269b2007-08-20 21:31:48 +00001113
1114/// objc-implementation:
1115/// objc-class-implementation-prologue
1116/// objc-category-implementation-prologue
1117///
1118/// objc-class-implementation-prologue:
1119/// @implementation identifier objc-superclass[opt]
1120/// objc-class-instance-variables[opt]
1121///
1122/// objc-category-implementation-prologue:
1123/// @implementation identifier ( identifier )
Chris Lattnerb28317a2009-03-28 19:18:32 +00001124Parser::DeclPtrTy Parser::ParseObjCAtImplementationDeclaration(
Fariborz Jahanianac00b7f2007-09-01 00:26:16 +00001125 SourceLocation atLoc) {
1126 assert(Tok.isObjCAtKeyword(tok::objc_implementation) &&
1127 "ParseObjCAtImplementationDeclaration(): Expected @implementation");
1128 ConsumeToken(); // the "implementation" identifier
Mike Stump1eb44332009-09-09 15:08:12 +00001129
Douglas Gregor3b49aca2009-11-18 16:26:39 +00001130 // Code completion after '@implementation'.
1131 if (Tok.is(tok::code_completion)) {
1132 Actions.CodeCompleteObjCImplementationDecl(CurScope);
1133 ConsumeToken();
1134 }
1135
Chris Lattnerdf195262007-10-09 17:51:17 +00001136 if (Tok.isNot(tok::identifier)) {
Fariborz Jahanianac00b7f2007-09-01 00:26:16 +00001137 Diag(Tok, diag::err_expected_ident); // missing class or category name.
Chris Lattnerb28317a2009-03-28 19:18:32 +00001138 return DeclPtrTy();
Fariborz Jahanianac00b7f2007-09-01 00:26:16 +00001139 }
1140 // We have a class or category name - consume it.
Fariborz Jahanianccb4f312007-09-25 18:38:09 +00001141 IdentifierInfo *nameId = Tok.getIdentifierInfo();
Fariborz Jahanianac00b7f2007-09-01 00:26:16 +00001142 SourceLocation nameLoc = ConsumeToken(); // consume class or category name
Mike Stump1eb44332009-09-09 15:08:12 +00001143
1144 if (Tok.is(tok::l_paren)) {
Fariborz Jahanianac00b7f2007-09-01 00:26:16 +00001145 // we have a category implementation.
1146 SourceLocation lparenLoc = ConsumeParen();
1147 SourceLocation categoryLoc, rparenLoc;
1148 IdentifierInfo *categoryId = 0;
Mike Stump1eb44332009-09-09 15:08:12 +00001149
Douglas Gregor33ced0b2009-11-18 19:08:43 +00001150 if (Tok.is(tok::code_completion)) {
1151 Actions.CodeCompleteObjCImplementationCategory(CurScope, nameId);
1152 ConsumeToken();
1153 }
1154
Chris Lattnerdf195262007-10-09 17:51:17 +00001155 if (Tok.is(tok::identifier)) {
Fariborz Jahanianac00b7f2007-09-01 00:26:16 +00001156 categoryId = Tok.getIdentifierInfo();
1157 categoryLoc = ConsumeToken();
1158 } else {
1159 Diag(Tok, diag::err_expected_ident); // missing category name.
Chris Lattnerb28317a2009-03-28 19:18:32 +00001160 return DeclPtrTy();
Mike Stump1eb44332009-09-09 15:08:12 +00001161 }
Chris Lattnerdf195262007-10-09 17:51:17 +00001162 if (Tok.isNot(tok::r_paren)) {
Fariborz Jahanianac00b7f2007-09-01 00:26:16 +00001163 Diag(Tok, diag::err_expected_rparen);
1164 SkipUntil(tok::r_paren, false); // don't stop at ';'
Chris Lattnerb28317a2009-03-28 19:18:32 +00001165 return DeclPtrTy();
Fariborz Jahanianac00b7f2007-09-01 00:26:16 +00001166 }
1167 rparenLoc = ConsumeParen();
Chris Lattnerb28317a2009-03-28 19:18:32 +00001168 DeclPtrTy ImplCatType = Actions.ActOnStartCategoryImplementation(
Mike Stump1eb44332009-09-09 15:08:12 +00001169 atLoc, nameId, nameLoc, categoryId,
Fariborz Jahanian8f3fde02007-10-02 16:38:50 +00001170 categoryLoc);
Ted Kremeneka526c5c2008-01-07 19:49:32 +00001171 ObjCImpDecl = ImplCatType;
Fariborz Jahanian63e963c2009-11-16 18:57:01 +00001172 PendingObjCImpDecl.push_back(ObjCImpDecl);
Chris Lattnerb28317a2009-03-28 19:18:32 +00001173 return DeclPtrTy();
Fariborz Jahanianac00b7f2007-09-01 00:26:16 +00001174 }
1175 // We have a class implementation
Fariborz Jahanianccb4f312007-09-25 18:38:09 +00001176 SourceLocation superClassLoc;
1177 IdentifierInfo *superClassId = 0;
Chris Lattnerdf195262007-10-09 17:51:17 +00001178 if (Tok.is(tok::colon)) {
Fariborz Jahanianac00b7f2007-09-01 00:26:16 +00001179 // We have a super class
1180 ConsumeToken();
Chris Lattnerdf195262007-10-09 17:51:17 +00001181 if (Tok.isNot(tok::identifier)) {
Fariborz Jahanianac00b7f2007-09-01 00:26:16 +00001182 Diag(Tok, diag::err_expected_ident); // missing super class name.
Chris Lattnerb28317a2009-03-28 19:18:32 +00001183 return DeclPtrTy();
Fariborz Jahanianac00b7f2007-09-01 00:26:16 +00001184 }
Fariborz Jahanianccb4f312007-09-25 18:38:09 +00001185 superClassId = Tok.getIdentifierInfo();
1186 superClassLoc = ConsumeToken(); // Consume super class name
Fariborz Jahanianac00b7f2007-09-01 00:26:16 +00001187 }
Chris Lattnerb28317a2009-03-28 19:18:32 +00001188 DeclPtrTy ImplClsType = Actions.ActOnStartClassImplementation(
Chris Lattnercb53b362007-12-27 19:57:00 +00001189 atLoc, nameId, nameLoc,
Fariborz Jahanianccb4f312007-09-25 18:38:09 +00001190 superClassId, superClassLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001191
Steve Naroff60fccee2007-10-29 21:38:07 +00001192 if (Tok.is(tok::l_brace)) // we have ivars
1193 ParseObjCClassInstanceVariables(ImplClsType/*FIXME*/, atLoc);
Ted Kremeneka526c5c2008-01-07 19:49:32 +00001194 ObjCImpDecl = ImplClsType;
Fariborz Jahanian63e963c2009-11-16 18:57:01 +00001195 PendingObjCImpDecl.push_back(ObjCImpDecl);
1196
Chris Lattnerb28317a2009-03-28 19:18:32 +00001197 return DeclPtrTy();
Reid Spencer5f016e22007-07-11 17:01:13 +00001198}
Steve Naroff60fccee2007-10-29 21:38:07 +00001199
Chris Lattnerb28317a2009-03-28 19:18:32 +00001200Parser::DeclPtrTy Parser::ParseObjCAtEndDeclaration(SourceLocation atLoc) {
Fariborz Jahanianac00b7f2007-09-01 00:26:16 +00001201 assert(Tok.isObjCAtKeyword(tok::objc_end) &&
1202 "ParseObjCAtEndDeclaration(): Expected @end");
Chris Lattnerb28317a2009-03-28 19:18:32 +00001203 DeclPtrTy Result = ObjCImpDecl;
Fariborz Jahanianac00b7f2007-09-01 00:26:16 +00001204 ConsumeToken(); // the "end" identifier
Fariborz Jahaniana6e3ac52009-03-04 22:30:12 +00001205 if (ObjCImpDecl) {
Ted Kremeneka526c5c2008-01-07 19:49:32 +00001206 Actions.ActOnAtEnd(atLoc, ObjCImpDecl);
Chris Lattnerb28317a2009-03-28 19:18:32 +00001207 ObjCImpDecl = DeclPtrTy();
Fariborz Jahanian63e963c2009-11-16 18:57:01 +00001208 PendingObjCImpDecl.pop_back();
Fariborz Jahaniana6e3ac52009-03-04 22:30:12 +00001209 }
Fariborz Jahanian94cdb252008-01-10 17:58:07 +00001210 else
1211 Diag(atLoc, diag::warn_expected_implementation); // missing @implementation
Fariborz Jahaniana6e3ac52009-03-04 22:30:12 +00001212 return Result;
Steve Naroffdac269b2007-08-20 21:31:48 +00001213}
Fariborz Jahaniane992af02007-09-04 19:26:51 +00001214
Fariborz Jahanian1ac71042009-11-17 17:15:16 +00001215Parser::DeclGroupPtrTy Parser::RetrievePendingObjCImpDecl() {
Fariborz Jahanian63e963c2009-11-16 18:57:01 +00001216 if (PendingObjCImpDecl.empty())
1217 return Actions.ConvertDeclToDeclGroup(DeclPtrTy());
1218 DeclPtrTy ImpDecl = PendingObjCImpDecl.pop_back_val();
1219 Actions.ActOnAtEnd(SourceLocation(), ImpDecl);
1220 return Actions.ConvertDeclToDeclGroup(ImpDecl);
1221}
1222
Fariborz Jahaniane992af02007-09-04 19:26:51 +00001223/// compatibility-alias-decl:
1224/// @compatibility_alias alias-name class-name ';'
1225///
Chris Lattnerb28317a2009-03-28 19:18:32 +00001226Parser::DeclPtrTy Parser::ParseObjCAtAliasDeclaration(SourceLocation atLoc) {
Fariborz Jahaniane992af02007-09-04 19:26:51 +00001227 assert(Tok.isObjCAtKeyword(tok::objc_compatibility_alias) &&
1228 "ParseObjCAtAliasDeclaration(): Expected @compatibility_alias");
1229 ConsumeToken(); // consume compatibility_alias
Chris Lattnerdf195262007-10-09 17:51:17 +00001230 if (Tok.isNot(tok::identifier)) {
Fariborz Jahaniane992af02007-09-04 19:26:51 +00001231 Diag(Tok, diag::err_expected_ident);
Chris Lattnerb28317a2009-03-28 19:18:32 +00001232 return DeclPtrTy();
Fariborz Jahaniane992af02007-09-04 19:26:51 +00001233 }
Fariborz Jahanian243b64b2007-10-11 23:42:27 +00001234 IdentifierInfo *aliasId = Tok.getIdentifierInfo();
1235 SourceLocation aliasLoc = ConsumeToken(); // consume alias-name
Chris Lattnerdf195262007-10-09 17:51:17 +00001236 if (Tok.isNot(tok::identifier)) {
Fariborz Jahaniane992af02007-09-04 19:26:51 +00001237 Diag(Tok, diag::err_expected_ident);
Chris Lattnerb28317a2009-03-28 19:18:32 +00001238 return DeclPtrTy();
Fariborz Jahaniane992af02007-09-04 19:26:51 +00001239 }
Fariborz Jahanian243b64b2007-10-11 23:42:27 +00001240 IdentifierInfo *classId = Tok.getIdentifierInfo();
1241 SourceLocation classLoc = ConsumeToken(); // consume class-name;
1242 if (Tok.isNot(tok::semi)) {
Chris Lattner1ab3b962008-11-18 07:48:38 +00001243 Diag(Tok, diag::err_expected_semi_after) << "@compatibility_alias";
Chris Lattnerb28317a2009-03-28 19:18:32 +00001244 return DeclPtrTy();
Fariborz Jahanian243b64b2007-10-11 23:42:27 +00001245 }
Chris Lattnerb28317a2009-03-28 19:18:32 +00001246 return Actions.ActOnCompatiblityAlias(atLoc, aliasId, aliasLoc,
1247 classId, classLoc);
Reid Spencer5f016e22007-07-11 17:01:13 +00001248}
1249
Fariborz Jahanianac00b7f2007-09-01 00:26:16 +00001250/// property-synthesis:
1251/// @synthesize property-ivar-list ';'
1252///
1253/// property-ivar-list:
1254/// property-ivar
1255/// property-ivar-list ',' property-ivar
1256///
1257/// property-ivar:
1258/// identifier
1259/// identifier '=' identifier
1260///
Chris Lattnerb28317a2009-03-28 19:18:32 +00001261Parser::DeclPtrTy Parser::ParseObjCPropertySynthesize(SourceLocation atLoc) {
Fariborz Jahanianac00b7f2007-09-01 00:26:16 +00001262 assert(Tok.isObjCAtKeyword(tok::objc_synthesize) &&
1263 "ParseObjCPropertyDynamic(): Expected '@synthesize'");
Fariborz Jahanianf624f812008-04-18 00:19:30 +00001264 SourceLocation loc = ConsumeToken(); // consume synthesize
Mike Stump1eb44332009-09-09 15:08:12 +00001265
Douglas Gregorb328c422009-11-18 19:45:45 +00001266 while (true) {
Douglas Gregor322328b2009-11-18 22:32:06 +00001267 if (Tok.is(tok::code_completion)) {
Douglas Gregor424b2a52009-11-18 22:56:13 +00001268 Actions.CodeCompleteObjCPropertyDefinition(CurScope, ObjCImpDecl);
Douglas Gregor322328b2009-11-18 22:32:06 +00001269 ConsumeToken();
1270 }
1271
Douglas Gregorb328c422009-11-18 19:45:45 +00001272 if (Tok.isNot(tok::identifier)) {
1273 Diag(Tok, diag::err_synthesized_property_name);
1274 SkipUntil(tok::semi);
1275 return DeclPtrTy();
1276 }
1277
Fariborz Jahanianf624f812008-04-18 00:19:30 +00001278 IdentifierInfo *propertyIvar = 0;
1279 IdentifierInfo *propertyId = Tok.getIdentifierInfo();
1280 SourceLocation propertyLoc = ConsumeToken(); // consume property name
Chris Lattnerdf195262007-10-09 17:51:17 +00001281 if (Tok.is(tok::equal)) {
Fariborz Jahanianac00b7f2007-09-01 00:26:16 +00001282 // property '=' ivar-name
1283 ConsumeToken(); // consume '='
Douglas Gregor322328b2009-11-18 22:32:06 +00001284
1285 if (Tok.is(tok::code_completion)) {
1286 Actions.CodeCompleteObjCPropertySynthesizeIvar(CurScope, propertyId,
1287 ObjCImpDecl);
1288 ConsumeToken();
1289 }
1290
Chris Lattnerdf195262007-10-09 17:51:17 +00001291 if (Tok.isNot(tok::identifier)) {
Fariborz Jahanianac00b7f2007-09-01 00:26:16 +00001292 Diag(Tok, diag::err_expected_ident);
1293 break;
1294 }
Fariborz Jahanianf624f812008-04-18 00:19:30 +00001295 propertyIvar = Tok.getIdentifierInfo();
Fariborz Jahanianac00b7f2007-09-01 00:26:16 +00001296 ConsumeToken(); // consume ivar-name
1297 }
Fariborz Jahanianf624f812008-04-18 00:19:30 +00001298 Actions.ActOnPropertyImplDecl(atLoc, propertyLoc, true, ObjCImpDecl,
1299 propertyId, propertyIvar);
Chris Lattnerdf195262007-10-09 17:51:17 +00001300 if (Tok.isNot(tok::comma))
Fariborz Jahanianac00b7f2007-09-01 00:26:16 +00001301 break;
1302 ConsumeToken(); // consume ','
1303 }
Douglas Gregorb328c422009-11-18 19:45:45 +00001304 if (Tok.isNot(tok::semi)) {
Chris Lattner1ab3b962008-11-18 07:48:38 +00001305 Diag(Tok, diag::err_expected_semi_after) << "@synthesize";
Douglas Gregorb328c422009-11-18 19:45:45 +00001306 SkipUntil(tok::semi);
1307 }
Fariborz Jahaniand3fdcb52009-11-06 21:48:47 +00001308 else
1309 ConsumeToken(); // consume ';'
Chris Lattnerb28317a2009-03-28 19:18:32 +00001310 return DeclPtrTy();
Reid Spencer5f016e22007-07-11 17:01:13 +00001311}
1312
Fariborz Jahanianac00b7f2007-09-01 00:26:16 +00001313/// property-dynamic:
1314/// @dynamic property-list
1315///
1316/// property-list:
1317/// identifier
1318/// property-list ',' identifier
1319///
Chris Lattnerb28317a2009-03-28 19:18:32 +00001320Parser::DeclPtrTy Parser::ParseObjCPropertyDynamic(SourceLocation atLoc) {
Fariborz Jahanianac00b7f2007-09-01 00:26:16 +00001321 assert(Tok.isObjCAtKeyword(tok::objc_dynamic) &&
1322 "ParseObjCPropertyDynamic(): Expected '@dynamic'");
1323 SourceLocation loc = ConsumeToken(); // consume dynamic
Douglas Gregor424b2a52009-11-18 22:56:13 +00001324 while (true) {
1325 if (Tok.is(tok::code_completion)) {
1326 Actions.CodeCompleteObjCPropertyDefinition(CurScope, ObjCImpDecl);
1327 ConsumeToken();
1328 }
1329
1330 if (Tok.isNot(tok::identifier)) {
1331 Diag(Tok, diag::err_expected_ident);
1332 SkipUntil(tok::semi);
1333 return DeclPtrTy();
1334 }
1335
Fariborz Jahanianc35b9e42008-04-21 21:05:54 +00001336 IdentifierInfo *propertyId = Tok.getIdentifierInfo();
1337 SourceLocation propertyLoc = ConsumeToken(); // consume property name
1338 Actions.ActOnPropertyImplDecl(atLoc, propertyLoc, false, ObjCImpDecl,
1339 propertyId, 0);
1340
Chris Lattnerdf195262007-10-09 17:51:17 +00001341 if (Tok.isNot(tok::comma))
Fariborz Jahanianac00b7f2007-09-01 00:26:16 +00001342 break;
1343 ConsumeToken(); // consume ','
1344 }
Chris Lattnerdf195262007-10-09 17:51:17 +00001345 if (Tok.isNot(tok::semi))
Chris Lattner1ab3b962008-11-18 07:48:38 +00001346 Diag(Tok, diag::err_expected_semi_after) << "@dynamic";
Chris Lattnerb28317a2009-03-28 19:18:32 +00001347 return DeclPtrTy();
Fariborz Jahanianac00b7f2007-09-01 00:26:16 +00001348}
Mike Stump1eb44332009-09-09 15:08:12 +00001349
Fariborz Jahanian397fcc12007-09-19 19:14:32 +00001350/// objc-throw-statement:
1351/// throw expression[opt];
1352///
Sebastian Redl43bc2a02008-12-11 20:12:42 +00001353Parser::OwningStmtResult Parser::ParseObjCThrowStmt(SourceLocation atLoc) {
Sebastian Redl15faa7f2008-12-09 20:22:58 +00001354 OwningExprResult Res(Actions);
Fariborz Jahanian397fcc12007-09-19 19:14:32 +00001355 ConsumeToken(); // consume throw
Chris Lattnerdf195262007-10-09 17:51:17 +00001356 if (Tok.isNot(tok::semi)) {
Fariborz Jahanian39f8f152007-11-07 02:00:49 +00001357 Res = ParseExpression();
Sebastian Redl0e9eabc2008-12-09 13:15:23 +00001358 if (Res.isInvalid()) {
Fariborz Jahanian397fcc12007-09-19 19:14:32 +00001359 SkipUntil(tok::semi);
Sebastian Redl43bc2a02008-12-11 20:12:42 +00001360 return StmtError();
Fariborz Jahanian397fcc12007-09-19 19:14:32 +00001361 }
1362 }
Fariborz Jahanian39f8f152007-11-07 02:00:49 +00001363 ConsumeToken(); // consume ';'
Steve Naroffe21dd6f2009-02-11 20:05:44 +00001364 return Actions.ActOnObjCAtThrowStmt(atLoc, move(Res), CurScope);
Fariborz Jahanian397fcc12007-09-19 19:14:32 +00001365}
1366
Fariborz Jahanianc385c902008-01-29 18:21:32 +00001367/// objc-synchronized-statement:
Fariborz Jahanian78a677b2008-01-30 17:38:29 +00001368/// @synchronized '(' expression ')' compound-statement
Fariborz Jahanianc385c902008-01-29 18:21:32 +00001369///
Sebastian Redl43bc2a02008-12-11 20:12:42 +00001370Parser::OwningStmtResult
1371Parser::ParseObjCSynchronizedStmt(SourceLocation atLoc) {
Fariborz Jahanianfa3ee8e2008-01-29 19:14:59 +00001372 ConsumeToken(); // consume synchronized
1373 if (Tok.isNot(tok::l_paren)) {
Chris Lattner1ab3b962008-11-18 07:48:38 +00001374 Diag(Tok, diag::err_expected_lparen_after) << "@synchronized";
Sebastian Redl43bc2a02008-12-11 20:12:42 +00001375 return StmtError();
Fariborz Jahanianfa3ee8e2008-01-29 19:14:59 +00001376 }
1377 ConsumeParen(); // '('
Sebastian Redl2f7ece72008-12-11 21:36:32 +00001378 OwningExprResult Res(ParseExpression());
Sebastian Redl0e9eabc2008-12-09 13:15:23 +00001379 if (Res.isInvalid()) {
Fariborz Jahanianfa3ee8e2008-01-29 19:14:59 +00001380 SkipUntil(tok::semi);
Sebastian Redl43bc2a02008-12-11 20:12:42 +00001381 return StmtError();
Fariborz Jahanianfa3ee8e2008-01-29 19:14:59 +00001382 }
1383 if (Tok.isNot(tok::r_paren)) {
Chris Lattner1ab3b962008-11-18 07:48:38 +00001384 Diag(Tok, diag::err_expected_lbrace);
Sebastian Redl43bc2a02008-12-11 20:12:42 +00001385 return StmtError();
Fariborz Jahanianfa3ee8e2008-01-29 19:14:59 +00001386 }
1387 ConsumeParen(); // ')'
Fariborz Jahanian78a677b2008-01-30 17:38:29 +00001388 if (Tok.isNot(tok::l_brace)) {
Chris Lattner1ab3b962008-11-18 07:48:38 +00001389 Diag(Tok, diag::err_expected_lbrace);
Sebastian Redl43bc2a02008-12-11 20:12:42 +00001390 return StmtError();
Fariborz Jahanian78a677b2008-01-30 17:38:29 +00001391 }
Steve Naroff3ac438c2008-06-04 20:36:13 +00001392 // Enter a scope to hold everything within the compound stmt. Compound
1393 // statements can always hold declarations.
Douglas Gregor8935b8b2008-12-10 06:34:36 +00001394 ParseScope BodyScope(this, Scope::DeclScope);
Steve Naroff3ac438c2008-06-04 20:36:13 +00001395
Sebastian Redl61364dd2008-12-11 19:30:53 +00001396 OwningStmtResult SynchBody(ParseCompoundStatementBody());
Sebastian Redl0e9eabc2008-12-09 13:15:23 +00001397
Douglas Gregor8935b8b2008-12-10 06:34:36 +00001398 BodyScope.Exit();
Sebastian Redl0e9eabc2008-12-09 13:15:23 +00001399 if (SynchBody.isInvalid())
Fariborz Jahanianfa3ee8e2008-01-29 19:14:59 +00001400 SynchBody = Actions.ActOnNullStmt(Tok.getLocation());
Sebastian Redl76ad2e82009-02-05 15:02:23 +00001401 return Actions.ActOnObjCAtSynchronizedStmt(atLoc, move(Res), move(SynchBody));
Fariborz Jahanianc385c902008-01-29 18:21:32 +00001402}
1403
Fariborz Jahanian397fcc12007-09-19 19:14:32 +00001404/// objc-try-catch-statement:
1405/// @try compound-statement objc-catch-list[opt]
1406/// @try compound-statement objc-catch-list[opt] @finally compound-statement
1407///
1408/// objc-catch-list:
1409/// @catch ( parameter-declaration ) compound-statement
1410/// objc-catch-list @catch ( catch-parameter-declaration ) compound-statement
1411/// catch-parameter-declaration:
1412/// parameter-declaration
1413/// '...' [OBJC2]
1414///
Sebastian Redl43bc2a02008-12-11 20:12:42 +00001415Parser::OwningStmtResult Parser::ParseObjCTryStmt(SourceLocation atLoc) {
Fariborz Jahanian397fcc12007-09-19 19:14:32 +00001416 bool catch_or_finally_seen = false;
Sebastian Redl43bc2a02008-12-11 20:12:42 +00001417
Fariborz Jahanian397fcc12007-09-19 19:14:32 +00001418 ConsumeToken(); // consume try
Chris Lattnerdf195262007-10-09 17:51:17 +00001419 if (Tok.isNot(tok::l_brace)) {
Chris Lattner1ab3b962008-11-18 07:48:38 +00001420 Diag(Tok, diag::err_expected_lbrace);
Sebastian Redl43bc2a02008-12-11 20:12:42 +00001421 return StmtError();
Fariborz Jahanian397fcc12007-09-19 19:14:32 +00001422 }
Sebastian Redl15faa7f2008-12-09 20:22:58 +00001423 OwningStmtResult CatchStmts(Actions);
1424 OwningStmtResult FinallyStmt(Actions);
Douglas Gregor8935b8b2008-12-10 06:34:36 +00001425 ParseScope TryScope(this, Scope::DeclScope);
Sebastian Redl61364dd2008-12-11 19:30:53 +00001426 OwningStmtResult TryBody(ParseCompoundStatementBody());
Douglas Gregor8935b8b2008-12-10 06:34:36 +00001427 TryScope.Exit();
Sebastian Redl0e9eabc2008-12-09 13:15:23 +00001428 if (TryBody.isInvalid())
Fariborz Jahanianbd49a642007-11-02 15:39:31 +00001429 TryBody = Actions.ActOnNullStmt(Tok.getLocation());
Sebastian Redla55e52c2008-11-25 22:21:31 +00001430
Chris Lattnerdf195262007-10-09 17:51:17 +00001431 while (Tok.is(tok::at)) {
Chris Lattner6b884502008-03-10 06:06:04 +00001432 // At this point, we need to lookahead to determine if this @ is the start
1433 // of an @catch or @finally. We don't want to consume the @ token if this
1434 // is an @try or @encode or something else.
1435 Token AfterAt = GetLookAheadToken(1);
1436 if (!AfterAt.isObjCAtKeyword(tok::objc_catch) &&
1437 !AfterAt.isObjCAtKeyword(tok::objc_finally))
1438 break;
Sebastian Redl0e9eabc2008-12-09 13:15:23 +00001439
Fariborz Jahanian161a9c52007-11-02 00:18:53 +00001440 SourceLocation AtCatchFinallyLoc = ConsumeToken();
Chris Lattnercb53b362007-12-27 19:57:00 +00001441 if (Tok.isObjCAtKeyword(tok::objc_catch)) {
Chris Lattnerb28317a2009-03-28 19:18:32 +00001442 DeclPtrTy FirstPart;
Fariborz Jahanian3b1191d2007-11-01 23:59:59 +00001443 ConsumeToken(); // consume catch
Chris Lattnerdf195262007-10-09 17:51:17 +00001444 if (Tok.is(tok::l_paren)) {
Fariborz Jahanian397fcc12007-09-19 19:14:32 +00001445 ConsumeParen();
Steve Naroffe21dd6f2009-02-11 20:05:44 +00001446 ParseScope CatchScope(this, Scope::DeclScope|Scope::AtCatchScope);
Chris Lattnerdf195262007-10-09 17:51:17 +00001447 if (Tok.isNot(tok::ellipsis)) {
Fariborz Jahanian397fcc12007-09-19 19:14:32 +00001448 DeclSpec DS;
1449 ParseDeclarationSpecifiers(DS);
Sebastian Redl43bc2a02008-12-11 20:12:42 +00001450 // For some odd reason, the name of the exception variable is
Mike Stump1eb44332009-09-09 15:08:12 +00001451 // optional. As a result, we need to use "PrototypeContext", because
Steve Naroff7ba138a2009-03-03 19:52:17 +00001452 // we must accept either 'declarator' or 'abstract-declarator' here.
1453 Declarator ParmDecl(DS, Declarator::PrototypeContext);
1454 ParseDeclarator(ParmDecl);
1455
1456 // Inform the actions module about the parameter declarator, so it
1457 // gets added to the current scope.
1458 FirstPart = Actions.ActOnParamDeclarator(CurScope, ParmDecl);
Steve Naroff64515f32008-02-05 21:27:35 +00001459 } else
Fariborz Jahanian397fcc12007-09-19 19:14:32 +00001460 ConsumeToken(); // consume '...'
Mike Stump1eb44332009-09-09 15:08:12 +00001461
Steve Naroff93a25952009-04-07 22:56:58 +00001462 SourceLocation RParenLoc;
Mike Stump1eb44332009-09-09 15:08:12 +00001463
Steve Naroff93a25952009-04-07 22:56:58 +00001464 if (Tok.is(tok::r_paren))
1465 RParenLoc = ConsumeParen();
1466 else // Skip over garbage, until we get to ')'. Eat the ')'.
1467 SkipUntil(tok::r_paren, true, false);
1468
Sebastian Redl15faa7f2008-12-09 20:22:58 +00001469 OwningStmtResult CatchBody(Actions, true);
Chris Lattnerc1b3ba52008-02-14 19:27:54 +00001470 if (Tok.is(tok::l_brace))
1471 CatchBody = ParseCompoundStatementBody();
1472 else
1473 Diag(Tok, diag::err_expected_lbrace);
Sebastian Redl0e9eabc2008-12-09 13:15:23 +00001474 if (CatchBody.isInvalid())
Fariborz Jahanian3b1191d2007-11-01 23:59:59 +00001475 CatchBody = Actions.ActOnNullStmt(Tok.getLocation());
Sebastian Redl0e9eabc2008-12-09 13:15:23 +00001476 CatchStmts = Actions.ActOnObjCAtCatchStmt(AtCatchFinallyLoc,
Steve Naroff7ba138a2009-03-03 19:52:17 +00001477 RParenLoc, FirstPart, move(CatchBody),
Sebastian Redl76ad2e82009-02-05 15:02:23 +00001478 move(CatchStmts));
Steve Naroff64515f32008-02-05 21:27:35 +00001479 } else {
Chris Lattner1ab3b962008-11-18 07:48:38 +00001480 Diag(AtCatchFinallyLoc, diag::err_expected_lparen_after)
1481 << "@catch clause";
Sebastian Redl43bc2a02008-12-11 20:12:42 +00001482 return StmtError();
Fariborz Jahanian397fcc12007-09-19 19:14:32 +00001483 }
1484 catch_or_finally_seen = true;
Chris Lattner6b884502008-03-10 06:06:04 +00001485 } else {
1486 assert(Tok.isObjCAtKeyword(tok::objc_finally) && "Lookahead confused?");
Steve Naroff64515f32008-02-05 21:27:35 +00001487 ConsumeToken(); // consume finally
Douglas Gregor8935b8b2008-12-10 06:34:36 +00001488 ParseScope FinallyScope(this, Scope::DeclScope);
Sebastian Redl0e9eabc2008-12-09 13:15:23 +00001489
Sebastian Redl15faa7f2008-12-09 20:22:58 +00001490 OwningStmtResult FinallyBody(Actions, true);
Chris Lattnerc1b3ba52008-02-14 19:27:54 +00001491 if (Tok.is(tok::l_brace))
1492 FinallyBody = ParseCompoundStatementBody();
1493 else
1494 Diag(Tok, diag::err_expected_lbrace);
Sebastian Redl0e9eabc2008-12-09 13:15:23 +00001495 if (FinallyBody.isInvalid())
Fariborz Jahanian161a9c52007-11-02 00:18:53 +00001496 FinallyBody = Actions.ActOnNullStmt(Tok.getLocation());
Sebastian Redl0e9eabc2008-12-09 13:15:23 +00001497 FinallyStmt = Actions.ActOnObjCAtFinallyStmt(AtCatchFinallyLoc,
Sebastian Redl76ad2e82009-02-05 15:02:23 +00001498 move(FinallyBody));
Fariborz Jahanian397fcc12007-09-19 19:14:32 +00001499 catch_or_finally_seen = true;
1500 break;
1501 }
1502 }
Fariborz Jahanianbd49a642007-11-02 15:39:31 +00001503 if (!catch_or_finally_seen) {
Fariborz Jahanian397fcc12007-09-19 19:14:32 +00001504 Diag(atLoc, diag::err_missing_catch_finally);
Sebastian Redl43bc2a02008-12-11 20:12:42 +00001505 return StmtError();
Fariborz Jahanianbd49a642007-11-02 15:39:31 +00001506 }
Sebastian Redl76ad2e82009-02-05 15:02:23 +00001507 return Actions.ActOnObjCAtTryStmt(atLoc, move(TryBody), move(CatchStmts),
1508 move(FinallyStmt));
Fariborz Jahanian397fcc12007-09-19 19:14:32 +00001509}
Fariborz Jahanianac00b7f2007-09-01 00:26:16 +00001510
Steve Naroff3536b442007-09-06 21:24:23 +00001511/// objc-method-def: objc-method-proto ';'[opt] '{' body '}'
Fariborz Jahanianac00b7f2007-09-01 00:26:16 +00001512///
Chris Lattnerb28317a2009-03-28 19:18:32 +00001513Parser::DeclPtrTy Parser::ParseObjCMethodDefinition() {
1514 DeclPtrTy MDecl = ParseObjCMethodPrototype(ObjCImpDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00001515
Chris Lattner49f28ca2009-03-05 08:00:35 +00001516 PrettyStackTraceActionsDecl CrashInfo(MDecl, Tok.getLocation(), Actions,
1517 PP.getSourceManager(),
1518 "parsing Objective-C method");
Mike Stump1eb44332009-09-09 15:08:12 +00001519
Fariborz Jahanianac00b7f2007-09-01 00:26:16 +00001520 // parse optional ';'
Fariborz Jahanian209a8c22009-10-20 16:39:13 +00001521 if (Tok.is(tok::semi)) {
Ted Kremenek496e45e2009-11-10 22:55:49 +00001522 if (ObjCImpDecl) {
1523 Diag(Tok, diag::warn_semicolon_before_method_body)
Chris Lattner29d9c1a2009-12-06 17:36:05 +00001524 << CodeModificationHint::CreateRemoval(Tok.getLocation());
Ted Kremenek496e45e2009-11-10 22:55:49 +00001525 }
Fariborz Jahanianac00b7f2007-09-01 00:26:16 +00001526 ConsumeToken();
Fariborz Jahanian209a8c22009-10-20 16:39:13 +00001527 }
Fariborz Jahanianac00b7f2007-09-01 00:26:16 +00001528
Steve Naroff409be832007-11-11 19:54:21 +00001529 // We should have an opening brace now.
Chris Lattnerdf195262007-10-09 17:51:17 +00001530 if (Tok.isNot(tok::l_brace)) {
Steve Naroffda323ad2008-02-29 21:48:07 +00001531 Diag(Tok, diag::err_expected_method_body);
Mike Stump1eb44332009-09-09 15:08:12 +00001532
Steve Naroff409be832007-11-11 19:54:21 +00001533 // Skip over garbage, until we get to '{'. Don't eat the '{'.
1534 SkipUntil(tok::l_brace, true, true);
Mike Stump1eb44332009-09-09 15:08:12 +00001535
Steve Naroff409be832007-11-11 19:54:21 +00001536 // If we didn't find the '{', bail out.
1537 if (Tok.isNot(tok::l_brace))
Chris Lattnerb28317a2009-03-28 19:18:32 +00001538 return DeclPtrTy();
Fariborz Jahanianac00b7f2007-09-01 00:26:16 +00001539 }
Steve Naroff409be832007-11-11 19:54:21 +00001540 SourceLocation BraceLoc = Tok.getLocation();
Mike Stump1eb44332009-09-09 15:08:12 +00001541
Steve Naroff409be832007-11-11 19:54:21 +00001542 // Enter a scope for the method body.
Douglas Gregor8935b8b2008-12-10 06:34:36 +00001543 ParseScope BodyScope(this, Scope::FnScope|Scope::DeclScope);
Mike Stump1eb44332009-09-09 15:08:12 +00001544
Steve Naroff409be832007-11-11 19:54:21 +00001545 // Tell the actions module that we have entered a method definition with the
Steve Naroff394f3f42008-07-25 17:57:26 +00001546 // specified Declarator for the method.
Steve Naroffebf64432009-02-28 16:59:13 +00001547 Actions.ActOnStartOfObjCMethodDef(CurScope, MDecl);
Sebastian Redl61364dd2008-12-11 19:30:53 +00001548
1549 OwningStmtResult FnBody(ParseCompoundStatementBody());
1550
Steve Naroff409be832007-11-11 19:54:21 +00001551 // If the function body could not be parsed, make a bogus compoundstmt.
Sebastian Redl0e9eabc2008-12-09 13:15:23 +00001552 if (FnBody.isInvalid())
Sebastian Redla60528c2008-12-21 12:04:03 +00001553 FnBody = Actions.ActOnCompoundStmt(BraceLoc, BraceLoc,
1554 MultiStmtArg(Actions), false);
Sebastian Redl798d1192008-12-13 16:23:55 +00001555
Steve Naroff32ce8372009-03-02 22:00:56 +00001556 // TODO: Pass argument information.
1557 Actions.ActOnFinishFunctionBody(MDecl, move(FnBody));
Mike Stump1eb44332009-09-09 15:08:12 +00001558
Steve Naroff409be832007-11-11 19:54:21 +00001559 // Leave the function body scope.
Douglas Gregor8935b8b2008-12-10 06:34:36 +00001560 BodyScope.Exit();
Sebastian Redl798d1192008-12-13 16:23:55 +00001561
Steve Naroff71c0a952007-11-13 23:01:27 +00001562 return MDecl;
Reid Spencer5f016e22007-07-11 17:01:13 +00001563}
Anders Carlsson55085182007-08-21 17:43:55 +00001564
Sebastian Redl43bc2a02008-12-11 20:12:42 +00001565Parser::OwningStmtResult Parser::ParseObjCAtStatement(SourceLocation AtLoc) {
Douglas Gregor9a0c85e2009-12-07 09:51:25 +00001566 if (Tok.is(tok::code_completion)) {
1567 Actions.CodeCompleteObjCAtStatement(CurScope);
1568 ConsumeToken();
1569 return StmtError();
Chris Lattner5d803162009-12-07 16:33:19 +00001570 }
1571
1572 if (Tok.isObjCAtKeyword(tok::objc_try))
Chris Lattner6b884502008-03-10 06:06:04 +00001573 return ParseObjCTryStmt(AtLoc);
Chris Lattner5d803162009-12-07 16:33:19 +00001574
1575 if (Tok.isObjCAtKeyword(tok::objc_throw))
Steve Naroff64515f32008-02-05 21:27:35 +00001576 return ParseObjCThrowStmt(AtLoc);
Chris Lattner5d803162009-12-07 16:33:19 +00001577
1578 if (Tok.isObjCAtKeyword(tok::objc_synchronized))
Steve Naroff64515f32008-02-05 21:27:35 +00001579 return ParseObjCSynchronizedStmt(AtLoc);
Chris Lattner5d803162009-12-07 16:33:19 +00001580
Sebastian Redld8c4e152008-12-11 22:33:27 +00001581 OwningExprResult Res(ParseExpressionWithLeadingAt(AtLoc));
Sebastian Redl0e9eabc2008-12-09 13:15:23 +00001582 if (Res.isInvalid()) {
Steve Naroff64515f32008-02-05 21:27:35 +00001583 // If the expression is invalid, skip ahead to the next semicolon. Not
1584 // doing this opens us up to the possibility of infinite loops if
1585 // ParseExpression does not consume any tokens.
1586 SkipUntil(tok::semi);
Sebastian Redl43bc2a02008-12-11 20:12:42 +00001587 return StmtError();
Steve Naroff64515f32008-02-05 21:27:35 +00001588 }
Chris Lattner5d803162009-12-07 16:33:19 +00001589
Steve Naroff64515f32008-02-05 21:27:35 +00001590 // Otherwise, eat the semicolon.
1591 ExpectAndConsume(tok::semi, diag::err_expected_semi_after_expr);
Anders Carlsson5ee56e92009-12-16 02:09:40 +00001592 return Actions.ActOnExprStmt(Actions.MakeFullExpr(Res));
Steve Naroff64515f32008-02-05 21:27:35 +00001593}
1594
Sebastian Redl1d922962008-12-13 15:32:12 +00001595Parser::OwningExprResult Parser::ParseObjCAtExpression(SourceLocation AtLoc) {
Anders Carlsson55085182007-08-21 17:43:55 +00001596 switch (Tok.getKind()) {
Douglas Gregor9a0c85e2009-12-07 09:51:25 +00001597 case tok::code_completion:
1598 Actions.CodeCompleteObjCAtExpression(CurScope);
1599 ConsumeToken();
1600 return ExprError();
1601
Chris Lattnerb3a99cd2007-12-12 01:04:12 +00001602 case tok::string_literal: // primary-expression: string-literal
1603 case tok::wide_string_literal:
Sebastian Redl1d922962008-12-13 15:32:12 +00001604 return ParsePostfixExpressionSuffix(ParseObjCStringLiteral(AtLoc));
Chris Lattnerb3a99cd2007-12-12 01:04:12 +00001605 default:
Chris Lattner4fef81d2008-08-05 06:19:09 +00001606 if (Tok.getIdentifierInfo() == 0)
Sebastian Redl1d922962008-12-13 15:32:12 +00001607 return ExprError(Diag(AtLoc, diag::err_unexpected_at));
Sebastian Redl2f7ece72008-12-11 21:36:32 +00001608
Chris Lattner4fef81d2008-08-05 06:19:09 +00001609 switch (Tok.getIdentifierInfo()->getObjCKeywordID()) {
1610 case tok::objc_encode:
Sebastian Redl1d922962008-12-13 15:32:12 +00001611 return ParsePostfixExpressionSuffix(ParseObjCEncodeExpression(AtLoc));
Chris Lattner4fef81d2008-08-05 06:19:09 +00001612 case tok::objc_protocol:
Sebastian Redl1d922962008-12-13 15:32:12 +00001613 return ParsePostfixExpressionSuffix(ParseObjCProtocolExpression(AtLoc));
Chris Lattner4fef81d2008-08-05 06:19:09 +00001614 case tok::objc_selector:
Sebastian Redl1d922962008-12-13 15:32:12 +00001615 return ParsePostfixExpressionSuffix(ParseObjCSelectorExpression(AtLoc));
Chris Lattner4fef81d2008-08-05 06:19:09 +00001616 default:
Sebastian Redl1d922962008-12-13 15:32:12 +00001617 return ExprError(Diag(AtLoc, diag::err_unexpected_at));
Chris Lattner4fef81d2008-08-05 06:19:09 +00001618 }
Anders Carlsson55085182007-08-21 17:43:55 +00001619 }
Anders Carlsson55085182007-08-21 17:43:55 +00001620}
1621
Mike Stump1eb44332009-09-09 15:08:12 +00001622/// objc-message-expr:
Fariborz Jahanian0ccb27d2007-09-05 19:52:07 +00001623/// '[' objc-receiver objc-message-args ']'
1624///
1625/// objc-receiver:
1626/// expression
1627/// class-name
1628/// type-name
Sebastian Redl1d922962008-12-13 15:32:12 +00001629Parser::OwningExprResult Parser::ParseObjCMessageExpression() {
Chris Lattner699b6612008-01-25 18:59:06 +00001630 assert(Tok.is(tok::l_square) && "'[' expected");
1631 SourceLocation LBracLoc = ConsumeBracket(); // consume '['
1632
1633 // Parse receiver
Chris Lattner14dd98a2008-01-25 19:25:00 +00001634 if (isTokObjCMessageIdentifierReceiver()) {
Chris Lattner699b6612008-01-25 18:59:06 +00001635 IdentifierInfo *ReceiverName = Tok.getIdentifierInfo();
Fariborz Jahaniand2869922009-04-08 19:50:10 +00001636 if (ReceiverName != Ident_super || GetLookAheadToken(1).isNot(tok::period)) {
1637 SourceLocation NameLoc = ConsumeToken();
1638 return ParseObjCMessageExpressionBody(LBracLoc, NameLoc, ReceiverName,
1639 ExprArg(Actions));
1640 }
Chris Lattner699b6612008-01-25 18:59:06 +00001641 }
1642
Sebastian Redl2f7ece72008-12-11 21:36:32 +00001643 OwningExprResult Res(ParseExpression());
Sebastian Redl0e9eabc2008-12-09 13:15:23 +00001644 if (Res.isInvalid()) {
Chris Lattner5c749422008-01-25 19:43:26 +00001645 SkipUntil(tok::r_square);
Sebastian Redl1d922962008-12-13 15:32:12 +00001646 return move(Res);
Chris Lattner699b6612008-01-25 18:59:06 +00001647 }
Sebastian Redl1d922962008-12-13 15:32:12 +00001648
Sebastian Redl0e9eabc2008-12-09 13:15:23 +00001649 return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(),
Sebastian Redl76ad2e82009-02-05 15:02:23 +00001650 0, move(Res));
Chris Lattner699b6612008-01-25 18:59:06 +00001651}
Sebastian Redl1d922962008-12-13 15:32:12 +00001652
Chris Lattner699b6612008-01-25 18:59:06 +00001653/// ParseObjCMessageExpressionBody - Having parsed "'[' objc-receiver", parse
1654/// the rest of a message expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001655///
Fariborz Jahanian0ccb27d2007-09-05 19:52:07 +00001656/// objc-message-args:
1657/// objc-selector
1658/// objc-keywordarg-list
1659///
1660/// objc-keywordarg-list:
1661/// objc-keywordarg
1662/// objc-keywordarg-list objc-keywordarg
1663///
Mike Stump1eb44332009-09-09 15:08:12 +00001664/// objc-keywordarg:
Fariborz Jahanian0ccb27d2007-09-05 19:52:07 +00001665/// selector-name[opt] ':' objc-keywordexpr
1666///
1667/// objc-keywordexpr:
1668/// nonempty-expr-list
1669///
1670/// nonempty-expr-list:
1671/// assignment-expression
1672/// nonempty-expr-list , assignment-expression
Sebastian Redl1d922962008-12-13 15:32:12 +00001673///
1674Parser::OwningExprResult
Chris Lattner699b6612008-01-25 18:59:06 +00001675Parser::ParseObjCMessageExpressionBody(SourceLocation LBracLoc,
Steve Naroff5cb93b82008-11-19 15:54:23 +00001676 SourceLocation NameLoc,
Chris Lattner699b6612008-01-25 18:59:06 +00001677 IdentifierInfo *ReceiverName,
Sebastian Redl1d922962008-12-13 15:32:12 +00001678 ExprArg ReceiverExpr) {
Steve Naroffc4df6d22009-11-07 02:08:14 +00001679 if (Tok.is(tok::code_completion)) {
1680 if (ReceiverName)
Douglas Gregord3c68542009-11-19 01:08:35 +00001681 Actions.CodeCompleteObjCClassMessage(CurScope, ReceiverName, NameLoc,
1682 0, 0);
Steve Naroffc4df6d22009-11-07 02:08:14 +00001683 else
Douglas Gregord3c68542009-11-19 01:08:35 +00001684 Actions.CodeCompleteObjCInstanceMessage(CurScope, ReceiverExpr.get(),
1685 0, 0);
Steve Naroffc4df6d22009-11-07 02:08:14 +00001686 ConsumeToken();
1687 }
Douglas Gregord3c68542009-11-19 01:08:35 +00001688
Fariborz Jahaniana65ff6c2007-09-05 23:08:20 +00001689 // Parse objc-selector
Fariborz Jahanian4b6c9052007-10-11 00:55:41 +00001690 SourceLocation Loc;
Chris Lattner2fc5c242009-04-11 18:13:45 +00001691 IdentifierInfo *selIdent = ParseObjCSelectorPiece(Loc);
Steve Naroff68d331a2007-09-27 14:38:14 +00001692
Anders Carlssonff975cf2009-02-14 18:21:46 +00001693 SourceLocation SelectorLoc = Loc;
Mike Stump1eb44332009-09-09 15:08:12 +00001694
Steve Naroff68d331a2007-09-27 14:38:14 +00001695 llvm::SmallVector<IdentifierInfo *, 12> KeyIdents;
Sebastian Redla55e52c2008-11-25 22:21:31 +00001696 ExprVector KeyExprs(Actions);
Steve Naroff68d331a2007-09-27 14:38:14 +00001697
Chris Lattnerdf195262007-10-09 17:51:17 +00001698 if (Tok.is(tok::colon)) {
Fariborz Jahaniana65ff6c2007-09-05 23:08:20 +00001699 while (1) {
1700 // Each iteration parses a single keyword argument.
Steve Naroff68d331a2007-09-27 14:38:14 +00001701 KeyIdents.push_back(selIdent);
Steve Naroff37387c92007-09-17 20:25:27 +00001702
Chris Lattnerdf195262007-10-09 17:51:17 +00001703 if (Tok.isNot(tok::colon)) {
Fariborz Jahaniana65ff6c2007-09-05 23:08:20 +00001704 Diag(Tok, diag::err_expected_colon);
Chris Lattner4fef81d2008-08-05 06:19:09 +00001705 // We must manually skip to a ']', otherwise the expression skipper will
1706 // stop at the ']' when it skips to the ';'. We want it to skip beyond
1707 // the enclosing expression.
1708 SkipUntil(tok::r_square);
Sebastian Redl1d922962008-12-13 15:32:12 +00001709 return ExprError();
Fariborz Jahaniana65ff6c2007-09-05 23:08:20 +00001710 }
Sebastian Redl1d922962008-12-13 15:32:12 +00001711
Steve Naroff68d331a2007-09-27 14:38:14 +00001712 ConsumeToken(); // Eat the ':'.
Mike Stump1eb44332009-09-09 15:08:12 +00001713 /// Parse the expression after ':'
Sebastian Redl2f7ece72008-12-11 21:36:32 +00001714 OwningExprResult Res(ParseAssignmentExpression());
Sebastian Redl0e9eabc2008-12-09 13:15:23 +00001715 if (Res.isInvalid()) {
Chris Lattner4fef81d2008-08-05 06:19:09 +00001716 // We must manually skip to a ']', otherwise the expression skipper will
1717 // stop at the ']' when it skips to the ';'. We want it to skip beyond
1718 // the enclosing expression.
1719 SkipUntil(tok::r_square);
Sebastian Redl1d922962008-12-13 15:32:12 +00001720 return move(Res);
Steve Naroff37387c92007-09-17 20:25:27 +00001721 }
Sebastian Redl1d922962008-12-13 15:32:12 +00001722
Steve Naroff37387c92007-09-17 20:25:27 +00001723 // We have a valid expression.
Sebastian Redleffa8d12008-12-10 00:02:53 +00001724 KeyExprs.push_back(Res.release());
Sebastian Redl1d922962008-12-13 15:32:12 +00001725
Douglas Gregord3c68542009-11-19 01:08:35 +00001726 // Code completion after each argument.
1727 if (Tok.is(tok::code_completion)) {
1728 if (ReceiverName)
1729 Actions.CodeCompleteObjCClassMessage(CurScope, ReceiverName, NameLoc,
1730 KeyIdents.data(),
1731 KeyIdents.size());
1732 else
1733 Actions.CodeCompleteObjCInstanceMessage(CurScope, ReceiverExpr.get(),
1734 KeyIdents.data(),
1735 KeyIdents.size());
1736 ConsumeToken();
1737 }
1738
Steve Naroff37387c92007-09-17 20:25:27 +00001739 // Check for another keyword selector.
Chris Lattner2fc5c242009-04-11 18:13:45 +00001740 selIdent = ParseObjCSelectorPiece(Loc);
Chris Lattnerdf195262007-10-09 17:51:17 +00001741 if (!selIdent && Tok.isNot(tok::colon))
Fariborz Jahaniana65ff6c2007-09-05 23:08:20 +00001742 break;
1743 // We have a selector or a colon, continue parsing.
1744 }
1745 // Parse the, optional, argument list, comma separated.
Chris Lattnerdf195262007-10-09 17:51:17 +00001746 while (Tok.is(tok::comma)) {
Steve Naroff49f109c2007-11-15 13:05:42 +00001747 ConsumeToken(); // Eat the ','.
Mike Stump1eb44332009-09-09 15:08:12 +00001748 /// Parse the expression after ','
Sebastian Redl2f7ece72008-12-11 21:36:32 +00001749 OwningExprResult Res(ParseAssignmentExpression());
Sebastian Redl0e9eabc2008-12-09 13:15:23 +00001750 if (Res.isInvalid()) {
Chris Lattner4fef81d2008-08-05 06:19:09 +00001751 // We must manually skip to a ']', otherwise the expression skipper will
1752 // stop at the ']' when it skips to the ';'. We want it to skip beyond
1753 // the enclosing expression.
1754 SkipUntil(tok::r_square);
Sebastian Redl1d922962008-12-13 15:32:12 +00001755 return move(Res);
Steve Naroff49f109c2007-11-15 13:05:42 +00001756 }
Sebastian Redl0e9eabc2008-12-09 13:15:23 +00001757
Steve Naroff49f109c2007-11-15 13:05:42 +00001758 // We have a valid expression.
Sebastian Redleffa8d12008-12-10 00:02:53 +00001759 KeyExprs.push_back(Res.release());
Fariborz Jahaniana65ff6c2007-09-05 23:08:20 +00001760 }
1761 } else if (!selIdent) {
1762 Diag(Tok, diag::err_expected_ident); // missing selector name.
Sebastian Redl1d922962008-12-13 15:32:12 +00001763
Chris Lattner4fef81d2008-08-05 06:19:09 +00001764 // We must manually skip to a ']', otherwise the expression skipper will
1765 // stop at the ']' when it skips to the ';'. We want it to skip beyond
1766 // the enclosing expression.
1767 SkipUntil(tok::r_square);
Sebastian Redl1d922962008-12-13 15:32:12 +00001768 return ExprError();
Fariborz Jahaniana65ff6c2007-09-05 23:08:20 +00001769 }
Sebastian Redl1d922962008-12-13 15:32:12 +00001770
Chris Lattnerdf195262007-10-09 17:51:17 +00001771 if (Tok.isNot(tok::r_square)) {
Fariborz Jahaniana65ff6c2007-09-05 23:08:20 +00001772 Diag(Tok, diag::err_expected_rsquare);
Chris Lattner4fef81d2008-08-05 06:19:09 +00001773 // We must manually skip to a ']', otherwise the expression skipper will
1774 // stop at the ']' when it skips to the ';'. We want it to skip beyond
1775 // the enclosing expression.
1776 SkipUntil(tok::r_square);
Sebastian Redl1d922962008-12-13 15:32:12 +00001777 return ExprError();
Fariborz Jahaniana65ff6c2007-09-05 23:08:20 +00001778 }
Sebastian Redl1d922962008-12-13 15:32:12 +00001779
Chris Lattner699b6612008-01-25 18:59:06 +00001780 SourceLocation RBracLoc = ConsumeBracket(); // consume ']'
Sebastian Redl1d922962008-12-13 15:32:12 +00001781
Steve Naroff29238a02007-10-05 18:42:47 +00001782 unsigned nKeys = KeyIdents.size();
Chris Lattnerff384912007-10-07 02:00:24 +00001783 if (nKeys == 0)
1784 KeyIdents.push_back(selIdent);
1785 Selector Sel = PP.getSelectorTable().getSelector(nKeys, &KeyIdents[0]);
Sebastian Redl1d922962008-12-13 15:32:12 +00001786
Chris Lattnerff384912007-10-07 02:00:24 +00001787 // We've just parsed a keyword message.
Sebastian Redl1d922962008-12-13 15:32:12 +00001788 if (ReceiverName)
1789 return Owned(Actions.ActOnClassMessage(CurScope, ReceiverName, Sel,
Mike Stump1eb44332009-09-09 15:08:12 +00001790 LBracLoc, NameLoc, SelectorLoc,
Anders Carlssonff975cf2009-02-14 18:21:46 +00001791 RBracLoc,
Sebastian Redl1d922962008-12-13 15:32:12 +00001792 KeyExprs.take(), KeyExprs.size()));
1793 return Owned(Actions.ActOnInstanceMessage(ReceiverExpr.release(), Sel,
Anders Carlssonff975cf2009-02-14 18:21:46 +00001794 LBracLoc, SelectorLoc, RBracLoc,
Sebastian Redl1d922962008-12-13 15:32:12 +00001795 KeyExprs.take(), KeyExprs.size()));
Fariborz Jahanian0ccb27d2007-09-05 19:52:07 +00001796}
1797
Sebastian Redl1d922962008-12-13 15:32:12 +00001798Parser::OwningExprResult Parser::ParseObjCStringLiteral(SourceLocation AtLoc) {
Sebastian Redl20df9b72008-12-11 22:51:44 +00001799 OwningExprResult Res(ParseStringLiteralExpression());
Sebastian Redl1d922962008-12-13 15:32:12 +00001800 if (Res.isInvalid()) return move(Res);
1801
Chris Lattnerb3a99cd2007-12-12 01:04:12 +00001802 // @"foo" @"bar" is a valid concatenated string. Eat any subsequent string
1803 // expressions. At this point, we know that the only valid thing that starts
1804 // with '@' is an @"".
1805 llvm::SmallVector<SourceLocation, 4> AtLocs;
Sebastian Redla55e52c2008-11-25 22:21:31 +00001806 ExprVector AtStrings(Actions);
Chris Lattnerb3a99cd2007-12-12 01:04:12 +00001807 AtLocs.push_back(AtLoc);
Sebastian Redleffa8d12008-12-10 00:02:53 +00001808 AtStrings.push_back(Res.release());
Sebastian Redl0e9eabc2008-12-09 13:15:23 +00001809
Chris Lattnerb3a99cd2007-12-12 01:04:12 +00001810 while (Tok.is(tok::at)) {
1811 AtLocs.push_back(ConsumeToken()); // eat the @.
Anders Carlsson55085182007-08-21 17:43:55 +00001812
Sebastian Redl15faa7f2008-12-09 20:22:58 +00001813 // Invalid unless there is a string literal.
Chris Lattner97cf6eb2009-02-18 05:56:09 +00001814 if (!isTokenStringLiteral())
1815 return ExprError(Diag(Tok, diag::err_objc_concat_string));
Chris Lattnerb3a99cd2007-12-12 01:04:12 +00001816
Chris Lattner97cf6eb2009-02-18 05:56:09 +00001817 OwningExprResult Lit(ParseStringLiteralExpression());
Sebastian Redl0e9eabc2008-12-09 13:15:23 +00001818 if (Lit.isInvalid())
Sebastian Redl1d922962008-12-13 15:32:12 +00001819 return move(Lit);
Sebastian Redl0e9eabc2008-12-09 13:15:23 +00001820
Sebastian Redleffa8d12008-12-10 00:02:53 +00001821 AtStrings.push_back(Lit.release());
Chris Lattnerb3a99cd2007-12-12 01:04:12 +00001822 }
Sebastian Redl1d922962008-12-13 15:32:12 +00001823
1824 return Owned(Actions.ParseObjCStringLiteral(&AtLocs[0], AtStrings.take(),
1825 AtStrings.size()));
Anders Carlsson55085182007-08-21 17:43:55 +00001826}
Anders Carlssonf9bcf012007-08-22 15:14:15 +00001827
1828/// objc-encode-expression:
1829/// @encode ( type-name )
Sebastian Redl1d922962008-12-13 15:32:12 +00001830Parser::OwningExprResult
1831Parser::ParseObjCEncodeExpression(SourceLocation AtLoc) {
Steve Naroff861cf3e2007-08-23 18:16:40 +00001832 assert(Tok.isObjCAtKeyword(tok::objc_encode) && "Not an @encode expression!");
Sebastian Redl1d922962008-12-13 15:32:12 +00001833
Anders Carlssonf9bcf012007-08-22 15:14:15 +00001834 SourceLocation EncLoc = ConsumeToken();
Sebastian Redl1d922962008-12-13 15:32:12 +00001835
Chris Lattner4fef81d2008-08-05 06:19:09 +00001836 if (Tok.isNot(tok::l_paren))
Sebastian Redl1d922962008-12-13 15:32:12 +00001837 return ExprError(Diag(Tok, diag::err_expected_lparen_after) << "@encode");
1838
Anders Carlssonf9bcf012007-08-22 15:14:15 +00001839 SourceLocation LParenLoc = ConsumeParen();
Sebastian Redl1d922962008-12-13 15:32:12 +00001840
Douglas Gregor809070a2009-02-18 17:45:20 +00001841 TypeResult Ty = ParseTypeName();
Sebastian Redl1d922962008-12-13 15:32:12 +00001842
Anders Carlsson4988ae32007-08-23 15:31:37 +00001843 SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc);
Sebastian Redl1d922962008-12-13 15:32:12 +00001844
Douglas Gregor809070a2009-02-18 17:45:20 +00001845 if (Ty.isInvalid())
1846 return ExprError();
1847
Mike Stump1eb44332009-09-09 15:08:12 +00001848 return Owned(Actions.ParseObjCEncodeExpression(AtLoc, EncLoc, LParenLoc,
Douglas Gregor809070a2009-02-18 17:45:20 +00001849 Ty.get(), RParenLoc));
Anders Carlssonf9bcf012007-08-22 15:14:15 +00001850}
Anders Carlsson29b2cb12007-08-23 15:25:28 +00001851
1852/// objc-protocol-expression
1853/// @protocol ( protocol-name )
Sebastian Redl1d922962008-12-13 15:32:12 +00001854Parser::OwningExprResult
1855Parser::ParseObjCProtocolExpression(SourceLocation AtLoc) {
Anders Carlsson29b2cb12007-08-23 15:25:28 +00001856 SourceLocation ProtoLoc = ConsumeToken();
Sebastian Redl1d922962008-12-13 15:32:12 +00001857
Chris Lattner4fef81d2008-08-05 06:19:09 +00001858 if (Tok.isNot(tok::l_paren))
Sebastian Redl1d922962008-12-13 15:32:12 +00001859 return ExprError(Diag(Tok, diag::err_expected_lparen_after) << "@protocol");
1860
Anders Carlsson29b2cb12007-08-23 15:25:28 +00001861 SourceLocation LParenLoc = ConsumeParen();
Sebastian Redl1d922962008-12-13 15:32:12 +00001862
Chris Lattner4fef81d2008-08-05 06:19:09 +00001863 if (Tok.isNot(tok::identifier))
Sebastian Redl1d922962008-12-13 15:32:12 +00001864 return ExprError(Diag(Tok, diag::err_expected_ident));
1865
Fariborz Jahanian390d50a2007-10-17 16:58:11 +00001866 IdentifierInfo *protocolId = Tok.getIdentifierInfo();
Anders Carlsson29b2cb12007-08-23 15:25:28 +00001867 ConsumeToken();
Sebastian Redl1d922962008-12-13 15:32:12 +00001868
Anders Carlsson4988ae32007-08-23 15:31:37 +00001869 SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc);
Anders Carlsson29b2cb12007-08-23 15:25:28 +00001870
Sebastian Redl1d922962008-12-13 15:32:12 +00001871 return Owned(Actions.ParseObjCProtocolExpression(protocolId, AtLoc, ProtoLoc,
1872 LParenLoc, RParenLoc));
Anders Carlsson29b2cb12007-08-23 15:25:28 +00001873}
Fariborz Jahaniana0818e32007-10-15 23:39:13 +00001874
1875/// objc-selector-expression
1876/// @selector '(' objc-keyword-selector ')'
Sebastian Redl1d922962008-12-13 15:32:12 +00001877Parser::OwningExprResult
1878Parser::ParseObjCSelectorExpression(SourceLocation AtLoc) {
Fariborz Jahaniana0818e32007-10-15 23:39:13 +00001879 SourceLocation SelectorLoc = ConsumeToken();
Sebastian Redl1d922962008-12-13 15:32:12 +00001880
Chris Lattner4fef81d2008-08-05 06:19:09 +00001881 if (Tok.isNot(tok::l_paren))
Sebastian Redl1d922962008-12-13 15:32:12 +00001882 return ExprError(Diag(Tok, diag::err_expected_lparen_after) << "@selector");
1883
Fariborz Jahanianb62f6812007-10-16 20:40:23 +00001884 llvm::SmallVector<IdentifierInfo *, 12> KeyIdents;
Fariborz Jahaniana0818e32007-10-15 23:39:13 +00001885 SourceLocation LParenLoc = ConsumeParen();
1886 SourceLocation sLoc;
Chris Lattner2fc5c242009-04-11 18:13:45 +00001887 IdentifierInfo *SelIdent = ParseObjCSelectorPiece(sLoc);
Sebastian Redl1d922962008-12-13 15:32:12 +00001888 if (!SelIdent && Tok.isNot(tok::colon)) // missing selector name.
1889 return ExprError(Diag(Tok, diag::err_expected_ident));
1890
Fariborz Jahanianb62f6812007-10-16 20:40:23 +00001891 KeyIdents.push_back(SelIdent);
Steve Naroff887407e2007-12-05 22:21:29 +00001892 unsigned nColons = 0;
1893 if (Tok.isNot(tok::r_paren)) {
Fariborz Jahaniana0818e32007-10-15 23:39:13 +00001894 while (1) {
Chris Lattner4fef81d2008-08-05 06:19:09 +00001895 if (Tok.isNot(tok::colon))
Sebastian Redl1d922962008-12-13 15:32:12 +00001896 return ExprError(Diag(Tok, diag::err_expected_colon));
1897
Chris Lattnercb53b362007-12-27 19:57:00 +00001898 nColons++;
Fariborz Jahaniana0818e32007-10-15 23:39:13 +00001899 ConsumeToken(); // Eat the ':'.
1900 if (Tok.is(tok::r_paren))
1901 break;
1902 // Check for another keyword selector.
1903 SourceLocation Loc;
Chris Lattner2fc5c242009-04-11 18:13:45 +00001904 SelIdent = ParseObjCSelectorPiece(Loc);
Fariborz Jahanianb62f6812007-10-16 20:40:23 +00001905 KeyIdents.push_back(SelIdent);
Fariborz Jahaniana0818e32007-10-15 23:39:13 +00001906 if (!SelIdent && Tok.isNot(tok::colon))
1907 break;
1908 }
Steve Naroff887407e2007-12-05 22:21:29 +00001909 }
Fariborz Jahaniana0818e32007-10-15 23:39:13 +00001910 SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc);
Steve Naroff887407e2007-12-05 22:21:29 +00001911 Selector Sel = PP.getSelectorTable().getSelector(nColons, &KeyIdents[0]);
Sebastian Redl1d922962008-12-13 15:32:12 +00001912 return Owned(Actions.ParseObjCSelectorExpression(Sel, AtLoc, SelectorLoc,
1913 LParenLoc, RParenLoc));
Gabor Greif58065b22007-10-19 15:38:32 +00001914 }