blob: 1b09b1fe8448cfbde6f818bd5fa093fbea146b46 [file] [log] [blame]
Ted Kremenek1b0ea822008-01-07 19:49:32 +00001//===--- ParseObjC.cpp - Objective C Parsing ------------------------------===//
Chris Lattnerda59c2f2006-11-05 02:08:13 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner5b12ab82007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattnerda59c2f2006-11-05 02:08:13 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the Objective-C portions of the Parser interface.
11//
12//===----------------------------------------------------------------------===//
13
Chris Lattner60f36222009-01-29 05:15:15 +000014#include "clang/Parse/ParseDiagnostic.h"
John McCall8b0666c2010-08-20 18:27:03 +000015#include "clang/Parse/Parser.h"
16#include "clang/Sema/DeclSpec.h"
17#include "clang/Sema/Scope.h"
Chris Lattnerda59c2f2006-11-05 02:08:13 +000018#include "llvm/ADT/SmallVector.h"
Chris Lattnerda59c2f2006-11-05 02:08:13 +000019using namespace clang;
20
21
Chris Lattner3a907162008-12-08 21:53:24 +000022/// ParseObjCAtDirectives - Handle parts of the external-declaration production:
Chris Lattnerda59c2f2006-11-05 02:08:13 +000023/// external-declaration: [C99 6.9]
24/// [OBJC] objc-class-definition
Steve Naroffe0933392007-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'
John McCall48871652010-08-21 09:40:31 +000030Decl *Parser::ParseObjCAtDirectives() {
Chris Lattnerda59c2f2006-11-05 02:08:13 +000031 SourceLocation AtLoc = ConsumeToken(); // the "@"
Mike Stump11289f42009-09-09 15:08:12 +000032
Douglas Gregorf48706c2009-12-07 09:27:33 +000033 if (Tok.is(tok::code_completion)) {
Douglas Gregor0be31a22010-07-02 17:43:08 +000034 Actions.CodeCompleteObjCAtDirective(getCurScope(), ObjCImpDecl, false);
Douglas Gregor6da3db42010-05-25 05:58:43 +000035 ConsumeCodeCompletionToken();
Douglas Gregorf48706c2009-12-07 09:27:33 +000036 }
37
Steve Naroff7c348172007-08-23 18:16:40 +000038 switch (Tok.getObjCKeywordID()) {
Chris Lattnerce90ef52008-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);
John McCall48871652010-08-21 09:40:31 +000058 return 0;
Chris Lattnerda59c2f2006-11-05 02:08:13 +000059 }
60}
61
62///
Mike Stump11289f42009-09-09 15:08:12 +000063/// objc-class-declaration:
Chris Lattnerda59c2f2006-11-05 02:08:13 +000064/// '@' 'class' identifier-list ';'
Mike Stump11289f42009-09-09 15:08:12 +000065///
John McCall48871652010-08-21 09:40:31 +000066Decl *Parser::ParseObjCAtClassDeclaration(SourceLocation atLoc) {
Chris Lattnerda59c2f2006-11-05 02:08:13 +000067 ConsumeToken(); // the identifier "class"
Chris Lattner23b7eb62007-06-15 23:05:46 +000068 llvm::SmallVector<IdentifierInfo *, 8> ClassNames;
Ted Kremeneka26da852009-11-17 23:12:20 +000069 llvm::SmallVector<SourceLocation, 8> ClassLocs;
70
Mike Stump11289f42009-09-09 15:08:12 +000071
Chris Lattnerda59c2f2006-11-05 02:08:13 +000072 while (1) {
Chris Lattner0ef13522007-10-09 17:51:17 +000073 if (Tok.isNot(tok::identifier)) {
Chris Lattnerbd638922006-11-10 05:19:25 +000074 Diag(Tok, diag::err_expected_ident);
Chris Lattnerda59c2f2006-11-05 02:08:13 +000075 SkipUntil(tok::semi);
John McCall48871652010-08-21 09:40:31 +000076 return 0;
Chris Lattnerda59c2f2006-11-05 02:08:13 +000077 }
Chris Lattnerda59c2f2006-11-05 02:08:13 +000078 ClassNames.push_back(Tok.getIdentifierInfo());
Ted Kremeneka26da852009-11-17 23:12:20 +000079 ClassLocs.push_back(Tok.getLocation());
Chris Lattnerda59c2f2006-11-05 02:08:13 +000080 ConsumeToken();
Mike Stump11289f42009-09-09 15:08:12 +000081
Chris Lattner0ef13522007-10-09 17:51:17 +000082 if (Tok.isNot(tok::comma))
Chris Lattnerda59c2f2006-11-05 02:08:13 +000083 break;
Mike Stump11289f42009-09-09 15:08:12 +000084
Chris Lattnerda59c2f2006-11-05 02:08:13 +000085 ConsumeToken();
86 }
Mike Stump11289f42009-09-09 15:08:12 +000087
Chris Lattnerda59c2f2006-11-05 02:08:13 +000088 // Consume the ';'.
89 if (ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@class"))
John McCall48871652010-08-21 09:40:31 +000090 return 0;
Mike Stump11289f42009-09-09 15:08:12 +000091
Ted Kremeneka26da852009-11-17 23:12:20 +000092 return Actions.ActOnForwardClassDeclaration(atLoc, ClassNames.data(),
93 ClassLocs.data(),
94 ClassNames.size());
Chris Lattnerda59c2f2006-11-05 02:08:13 +000095}
96
Steve Naroff1eb1ad62007-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 Stump11289f42009-09-09 15:08:12 +0000103/// '@' 'interface' identifier objc-superclass[opt]
Steve Naroff1eb1ad62007-08-20 21:31:48 +0000104/// objc-protocol-refs[opt]
Mike Stump11289f42009-09-09 15:08:12 +0000105/// objc-class-instance-variables[opt]
Steve Naroff1eb1ad62007-08-20 21:31:48 +0000106/// objc-interface-decl-list
107/// @end
108///
109/// objc-category-interface:
Mike Stump11289f42009-09-09 15:08:12 +0000110/// '@' 'interface' identifier '(' identifier[opt] ')'
Steve Naroff1eb1ad62007-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///
John McCall48871652010-08-21 09:40:31 +0000125Decl *Parser::ParseObjCAtInterfaceDeclaration(
Steve Naroff1eb1ad62007-08-20 21:31:48 +0000126 SourceLocation atLoc, AttributeList *attrList) {
Steve Naroff7c348172007-08-23 18:16:40 +0000127 assert(Tok.isObjCAtKeyword(tok::objc_interface) &&
Steve Naroff1eb1ad62007-08-20 21:31:48 +0000128 "ParseObjCAtInterfaceDeclaration(): Expected @interface");
129 ConsumeToken(); // the "interface" identifier
Mike Stump11289f42009-09-09 15:08:12 +0000130
Douglas Gregor49c22a72009-11-18 16:26:39 +0000131 // Code completion after '@interface'.
132 if (Tok.is(tok::code_completion)) {
Douglas Gregor0be31a22010-07-02 17:43:08 +0000133 Actions.CodeCompleteObjCInterfaceDecl(getCurScope());
Douglas Gregor6da3db42010-05-25 05:58:43 +0000134 ConsumeCodeCompletionToken();
Douglas Gregor49c22a72009-11-18 16:26:39 +0000135 }
136
Chris Lattner0ef13522007-10-09 17:51:17 +0000137 if (Tok.isNot(tok::identifier)) {
Steve Naroff1eb1ad62007-08-20 21:31:48 +0000138 Diag(Tok, diag::err_expected_ident); // missing class or category name.
John McCall48871652010-08-21 09:40:31 +0000139 return 0;
Steve Naroff1eb1ad62007-08-20 21:31:48 +0000140 }
Fariborz Jahanian9290ede2009-11-16 18:57:01 +0000141
Steve Naroff1eb1ad62007-08-20 21:31:48 +0000142 // We have a class or category name - consume it.
Steve Naroff0b6a01a2007-08-22 22:17:26 +0000143 IdentifierInfo *nameId = Tok.getIdentifierInfo();
Steve Naroff1eb1ad62007-08-20 21:31:48 +0000144 SourceLocation nameLoc = ConsumeToken();
Fariborz Jahanian65654df2010-04-26 21:18:08 +0000145 if (Tok.is(tok::l_paren) &&
146 !isKnownToBeTypeSpecifier(GetLookAheadToken(1))) { // we have a category.
Steve Naroff1eb1ad62007-08-20 21:31:48 +0000147 SourceLocation lparenLoc = ConsumeParen();
148 SourceLocation categoryLoc, rparenLoc;
149 IdentifierInfo *categoryId = 0;
Douglas Gregor5d34fd32009-11-18 19:08:43 +0000150 if (Tok.is(tok::code_completion)) {
Douglas Gregor0be31a22010-07-02 17:43:08 +0000151 Actions.CodeCompleteObjCInterfaceCategory(getCurScope(), nameId, nameLoc);
Douglas Gregor6da3db42010-05-25 05:58:43 +0000152 ConsumeCodeCompletionToken();
Douglas Gregor5d34fd32009-11-18 19:08:43 +0000153 }
154
Steve Naroff4e1f80d2007-08-23 19:56:30 +0000155 // For ObjC2, the category name is optional (not an error).
Chris Lattner0ef13522007-10-09 17:51:17 +0000156 if (Tok.is(tok::identifier)) {
Steve Naroff1eb1ad62007-08-20 21:31:48 +0000157 categoryId = Tok.getIdentifierInfo();
158 categoryLoc = ConsumeToken();
Fariborz Jahaniand077f712010-04-02 23:15:40 +0000159 }
Fariborz Jahaniand077f712010-04-02 23:15:40 +0000160 else if (!getLang().ObjC2) {
Steve Naroff4e1f80d2007-08-23 19:56:30 +0000161 Diag(Tok, diag::err_expected_ident); // missing category name.
John McCall48871652010-08-21 09:40:31 +0000162 return 0;
Steve Naroff1eb1ad62007-08-20 21:31:48 +0000163 }
Chris Lattner0ef13522007-10-09 17:51:17 +0000164 if (Tok.isNot(tok::r_paren)) {
Steve Naroff1eb1ad62007-08-20 21:31:48 +0000165 Diag(Tok, diag::err_expected_rparen);
166 SkipUntil(tok::r_paren, false); // don't stop at ';'
John McCall48871652010-08-21 09:40:31 +0000167 return 0;
Steve Naroff1eb1ad62007-08-20 21:31:48 +0000168 }
169 rparenLoc = ConsumeParen();
Fariborz Jahanian65654df2010-04-26 21:18:08 +0000170 // Next, we need to check for any protocol references.
171 SourceLocation LAngleLoc, EndProtoLoc;
John McCall48871652010-08-21 09:40:31 +0000172 llvm::SmallVector<Decl *, 8> ProtocolRefs;
Fariborz Jahanian65654df2010-04-26 21:18:08 +0000173 llvm::SmallVector<SourceLocation, 8> ProtocolLocs;
174 if (Tok.is(tok::less) &&
175 ParseObjCProtocolReferences(ProtocolRefs, ProtocolLocs, true,
Argyrios Kyrtzidisfc1f9e42009-09-29 19:41:44 +0000176 LAngleLoc, EndProtoLoc))
John McCall48871652010-08-21 09:40:31 +0000177 return 0;
Mike Stump11289f42009-09-09 15:08:12 +0000178
Fariborz Jahanian65654df2010-04-26 21:18:08 +0000179 if (attrList) // categories don't support attributes.
180 Diag(Tok, diag::err_objc_no_attributes_on_category);
Mike Stump11289f42009-09-09 15:08:12 +0000181
John McCall48871652010-08-21 09:40:31 +0000182 Decl *CategoryType =
Fariborz Jahanian65654df2010-04-26 21:18:08 +0000183 Actions.ActOnStartCategoryInterface(atLoc,
184 nameId, nameLoc,
185 categoryId, categoryLoc,
186 ProtocolRefs.data(),
187 ProtocolRefs.size(),
188 ProtocolLocs.data(),
189 EndProtoLoc);
190 if (Tok.is(tok::l_brace))
Fariborz Jahanian4c172c62010-02-22 23:04:20 +0000191 ParseObjCClassInstanceVariables(CategoryType, tok::objc_private,
192 atLoc);
193
Fariborz Jahanian65654df2010-04-26 21:18:08 +0000194 ParseObjCInterfaceDeclList(CategoryType, tok::objc_not_keyword);
195 return CategoryType;
Steve Naroff1eb1ad62007-08-20 21:31:48 +0000196 }
197 // Parse a class interface.
198 IdentifierInfo *superClassId = 0;
199 SourceLocation superClassLoc;
Steve Naroff0b6a01a2007-08-22 22:17:26 +0000200
Chris Lattner0ef13522007-10-09 17:51:17 +0000201 if (Tok.is(tok::colon)) { // a super class is specified.
Steve Naroff1eb1ad62007-08-20 21:31:48 +0000202 ConsumeToken();
Douglas Gregor49c22a72009-11-18 16:26:39 +0000203
204 // Code completion of superclass names.
205 if (Tok.is(tok::code_completion)) {
Douglas Gregor0be31a22010-07-02 17:43:08 +0000206 Actions.CodeCompleteObjCSuperclass(getCurScope(), nameId, nameLoc);
Douglas Gregor6da3db42010-05-25 05:58:43 +0000207 ConsumeCodeCompletionToken();
Douglas Gregor49c22a72009-11-18 16:26:39 +0000208 }
209
Chris Lattner0ef13522007-10-09 17:51:17 +0000210 if (Tok.isNot(tok::identifier)) {
Steve Naroff1eb1ad62007-08-20 21:31:48 +0000211 Diag(Tok, diag::err_expected_ident); // missing super class name.
John McCall48871652010-08-21 09:40:31 +0000212 return 0;
Steve Naroff1eb1ad62007-08-20 21:31:48 +0000213 }
214 superClassId = Tok.getIdentifierInfo();
215 superClassLoc = ConsumeToken();
216 }
217 // Next, we need to check for any protocol references.
John McCall48871652010-08-21 09:40:31 +0000218 llvm::SmallVector<Decl *, 8> ProtocolRefs;
Argyrios Kyrtzidisfc1f9e42009-09-29 19:41:44 +0000219 llvm::SmallVector<SourceLocation, 8> ProtocolLocs;
220 SourceLocation LAngleLoc, EndProtoLoc;
Chris Lattnerdf59f5a2008-07-26 04:13:19 +0000221 if (Tok.is(tok::less) &&
Argyrios Kyrtzidisfc1f9e42009-09-29 19:41:44 +0000222 ParseObjCProtocolReferences(ProtocolRefs, ProtocolLocs, true,
223 LAngleLoc, EndProtoLoc))
John McCall48871652010-08-21 09:40:31 +0000224 return 0;
Mike Stump11289f42009-09-09 15:08:12 +0000225
John McCall48871652010-08-21 09:40:31 +0000226 Decl *ClsType =
Mike Stump11289f42009-09-09 15:08:12 +0000227 Actions.ActOnStartClassInterface(atLoc, nameId, nameLoc,
Chris Lattnerdf59f5a2008-07-26 04:13:19 +0000228 superClassId, superClassLoc,
Jay Foad7d0479f2009-05-21 09:52:38 +0000229 ProtocolRefs.data(), ProtocolRefs.size(),
Douglas Gregor002b6712010-01-16 15:02:53 +0000230 ProtocolLocs.data(),
Chris Lattnerdf59f5a2008-07-26 04:13:19 +0000231 EndProtoLoc, attrList);
Mike Stump11289f42009-09-09 15:08:12 +0000232
Chris Lattner0ef13522007-10-09 17:51:17 +0000233 if (Tok.is(tok::l_brace))
Fariborz Jahanian4c172c62010-02-22 23:04:20 +0000234 ParseObjCClassInstanceVariables(ClsType, tok::objc_protected, atLoc);
Steve Naroff1eb1ad62007-08-20 21:31:48 +0000235
Fariborz Jahanian39d641f2007-09-17 21:07:36 +0000236 ParseObjCInterfaceDeclList(ClsType, tok::objc_interface);
Fariborz Jahanian65654df2010-04-26 21:18:08 +0000237 return ClsType;
Steve Naroff1eb1ad62007-08-20 21:31:48 +0000238}
239
John McCall064d77b2009-12-03 22:31:13 +0000240/// The Objective-C property callback. This should be defined where
241/// it's used, but instead it's been lifted to here to support VS2005.
242struct Parser::ObjCPropertyCallback : FieldCallback {
243 Parser &P;
John McCall48871652010-08-21 09:40:31 +0000244 Decl *IDecl;
245 llvm::SmallVectorImpl<Decl *> &Props;
John McCall064d77b2009-12-03 22:31:13 +0000246 ObjCDeclSpec &OCDS;
247 SourceLocation AtLoc;
248 tok::ObjCKeywordKind MethodImplKind;
249
John McCall48871652010-08-21 09:40:31 +0000250 ObjCPropertyCallback(Parser &P, Decl *IDecl,
251 llvm::SmallVectorImpl<Decl *> &Props,
John McCall064d77b2009-12-03 22:31:13 +0000252 ObjCDeclSpec &OCDS, SourceLocation AtLoc,
253 tok::ObjCKeywordKind MethodImplKind) :
254 P(P), IDecl(IDecl), Props(Props), OCDS(OCDS), AtLoc(AtLoc),
255 MethodImplKind(MethodImplKind) {
256 }
257
John McCall48871652010-08-21 09:40:31 +0000258 Decl *invoke(FieldDeclarator &FD) {
John McCall064d77b2009-12-03 22:31:13 +0000259 if (FD.D.getIdentifier() == 0) {
260 P.Diag(AtLoc, diag::err_objc_property_requires_field_name)
261 << FD.D.getSourceRange();
John McCall48871652010-08-21 09:40:31 +0000262 return 0;
John McCall064d77b2009-12-03 22:31:13 +0000263 }
264 if (FD.BitfieldSize) {
265 P.Diag(AtLoc, diag::err_objc_property_bitfield)
266 << FD.D.getSourceRange();
John McCall48871652010-08-21 09:40:31 +0000267 return 0;
John McCall064d77b2009-12-03 22:31:13 +0000268 }
269
270 // Install the property declarator into interfaceDecl.
271 IdentifierInfo *SelName =
272 OCDS.getGetterName() ? OCDS.getGetterName() : FD.D.getIdentifier();
273
274 Selector GetterSel =
275 P.PP.getSelectorTable().getNullarySelector(SelName);
276 IdentifierInfo *SetterName = OCDS.getSetterName();
277 Selector SetterSel;
278 if (SetterName)
279 SetterSel = P.PP.getSelectorTable().getSelector(1, &SetterName);
280 else
281 SetterSel = SelectorTable::constructSetterName(P.PP.getIdentifierTable(),
282 P.PP.getSelectorTable(),
283 FD.D.getIdentifier());
284 bool isOverridingProperty = false;
John McCall48871652010-08-21 09:40:31 +0000285 Decl *Property =
Douglas Gregor0be31a22010-07-02 17:43:08 +0000286 P.Actions.ActOnProperty(P.getCurScope(), AtLoc, FD, OCDS,
John McCall064d77b2009-12-03 22:31:13 +0000287 GetterSel, SetterSel, IDecl,
288 &isOverridingProperty,
289 MethodImplKind);
290 if (!isOverridingProperty)
291 Props.push_back(Property);
292
293 return Property;
294 }
295};
296
Steve Naroff1eb1ad62007-08-20 21:31:48 +0000297/// objc-interface-decl-list:
298/// empty
Steve Naroff1eb1ad62007-08-20 21:31:48 +0000299/// objc-interface-decl-list objc-property-decl [OBJC2]
Steve Naroff99264b42007-08-22 16:35:03 +0000300/// objc-interface-decl-list objc-method-requirement [OBJC2]
Steve Naroff09bf8152007-09-06 21:24:23 +0000301/// objc-interface-decl-list objc-method-proto ';'
Steve Naroff1eb1ad62007-08-20 21:31:48 +0000302/// objc-interface-decl-list declaration
303/// objc-interface-decl-list ';'
304///
Steve Naroff99264b42007-08-22 16:35:03 +0000305/// objc-method-requirement: [OBJC2]
306/// @required
307/// @optional
308///
John McCall48871652010-08-21 09:40:31 +0000309void Parser::ParseObjCInterfaceDeclList(Decl *interfaceDecl,
Chris Lattner5e530bc2007-12-27 19:57:00 +0000310 tok::ObjCKeywordKind contextKey) {
John McCall48871652010-08-21 09:40:31 +0000311 llvm::SmallVector<Decl *, 32> allMethods;
312 llvm::SmallVector<Decl *, 16> allProperties;
Chris Lattner5bbb3c82009-03-29 16:50:03 +0000313 llvm::SmallVector<DeclGroupPtrTy, 8> allTUVariables;
Fariborz Jahanian0c74e9d2007-09-18 00:25:23 +0000314 tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword;
Mike Stump11289f42009-09-09 15:08:12 +0000315
Ted Kremenekc7c64312010-01-07 01:20:12 +0000316 SourceRange AtEnd;
Chris Lattnerda9fb152008-10-20 06:10:06 +0000317
Steve Naroff99264b42007-08-22 16:35:03 +0000318 while (1) {
Chris Lattner038a3e32008-10-20 05:46:22 +0000319 // If this is a method prototype, parse it.
Chris Lattner0ef13522007-10-09 17:51:17 +0000320 if (Tok.is(tok::minus) || Tok.is(tok::plus)) {
John McCall48871652010-08-21 09:40:31 +0000321 Decl *methodPrototype =
Chris Lattner0ef13522007-10-09 17:51:17 +0000322 ParseObjCMethodPrototype(interfaceDecl, MethodImplKind);
Fariborz Jahanian39d641f2007-09-17 21:07:36 +0000323 allMethods.push_back(methodPrototype);
Steve Naroff09bf8152007-09-06 21:24:23 +0000324 // Consume the ';' here, since ParseObjCMethodPrototype() is re-used for
325 // method definitions.
Chris Lattner8510b902009-02-15 22:24:30 +0000326 ExpectAndConsume(tok::semi, diag::err_expected_semi_after_method_proto,
327 "", tok::semi);
Steve Naroff99264b42007-08-22 16:35:03 +0000328 continue;
329 }
Fariborz Jahaniand077f712010-04-02 23:15:40 +0000330 if (Tok.is(tok::l_paren)) {
331 Diag(Tok, diag::err_expected_minus_or_plus);
John McCall48871652010-08-21 09:40:31 +0000332 ParseObjCMethodDecl(Tok.getLocation(),
333 tok::minus,
334 interfaceDecl,
335 MethodImplKind);
Fariborz Jahaniand077f712010-04-02 23:15:40 +0000336 continue;
337 }
Chris Lattner038a3e32008-10-20 05:46:22 +0000338 // Ignore excess semicolons.
339 if (Tok.is(tok::semi)) {
Steve Naroff99264b42007-08-22 16:35:03 +0000340 ConsumeToken();
Chris Lattner038a3e32008-10-20 05:46:22 +0000341 continue;
342 }
Mike Stump11289f42009-09-09 15:08:12 +0000343
Chris Lattnerda9fb152008-10-20 06:10:06 +0000344 // If we got to the end of the file, exit the loop.
Chris Lattner038a3e32008-10-20 05:46:22 +0000345 if (Tok.is(tok::eof))
Fariborz Jahanian33d03742007-09-10 20:33:04 +0000346 break;
Mike Stump11289f42009-09-09 15:08:12 +0000347
Douglas Gregorf1934162010-01-13 21:24:21 +0000348 // Code completion within an Objective-C interface.
349 if (Tok.is(tok::code_completion)) {
Douglas Gregor0be31a22010-07-02 17:43:08 +0000350 Actions.CodeCompleteOrdinaryName(getCurScope(),
Douglas Gregor00c37ef2010-08-11 21:23:17 +0000351 ObjCImpDecl? Action::PCC_ObjCImplementation
352 : Action::PCC_ObjCInterface);
Douglas Gregor6da3db42010-05-25 05:58:43 +0000353 ConsumeCodeCompletionToken();
Douglas Gregorf1934162010-01-13 21:24:21 +0000354 }
355
Chris Lattner038a3e32008-10-20 05:46:22 +0000356 // If we don't have an @ directive, parse it as a function definition.
357 if (Tok.isNot(tok::at)) {
Chris Lattnerc7c9ab72009-01-09 04:34:13 +0000358 // The code below does not consume '}'s because it is afraid of eating the
359 // end of a namespace. Because of the way this code is structured, an
360 // erroneous r_brace would cause an infinite loop if not handled here.
361 if (Tok.is(tok::r_brace))
362 break;
Mike Stump11289f42009-09-09 15:08:12 +0000363
Steve Narofff1bc45b2007-08-22 18:35:33 +0000364 // FIXME: as the name implies, this rule allows function definitions.
365 // We could pass a flag or check for functions during semantic analysis.
Alexis Hunt96d5c762009-11-21 08:43:09 +0000366 allTUVariables.push_back(ParseDeclarationOrFunctionDefinition(0));
Chris Lattner038a3e32008-10-20 05:46:22 +0000367 continue;
368 }
Mike Stump11289f42009-09-09 15:08:12 +0000369
Chris Lattner038a3e32008-10-20 05:46:22 +0000370 // Otherwise, we have an @ directive, eat the @.
371 SourceLocation AtLoc = ConsumeToken(); // the "@"
Douglas Gregorf48706c2009-12-07 09:27:33 +0000372 if (Tok.is(tok::code_completion)) {
Douglas Gregor0be31a22010-07-02 17:43:08 +0000373 Actions.CodeCompleteObjCAtDirective(getCurScope(), ObjCImpDecl, true);
Douglas Gregor6da3db42010-05-25 05:58:43 +0000374 ConsumeCodeCompletionToken();
Douglas Gregorf48706c2009-12-07 09:27:33 +0000375 break;
376 }
377
Chris Lattnerbb8cc182008-10-20 05:57:40 +0000378 tok::ObjCKeywordKind DirectiveKind = Tok.getObjCKeywordID();
Mike Stump11289f42009-09-09 15:08:12 +0000379
Chris Lattnerbb8cc182008-10-20 05:57:40 +0000380 if (DirectiveKind == tok::objc_end) { // @end -> terminate list
Ted Kremenekc7c64312010-01-07 01:20:12 +0000381 AtEnd.setBegin(AtLoc);
382 AtEnd.setEnd(Tok.getLocation());
Chris Lattner038a3e32008-10-20 05:46:22 +0000383 break;
Douglas Gregor00a0cf72010-03-16 06:04:47 +0000384 } else if (DirectiveKind == tok::objc_not_keyword) {
385 Diag(Tok, diag::err_objc_unknown_at);
386 SkipUntil(tok::semi);
387 continue;
Chris Lattnerda9fb152008-10-20 06:10:06 +0000388 }
Mike Stump11289f42009-09-09 15:08:12 +0000389
Chris Lattnerda9fb152008-10-20 06:10:06 +0000390 // Eat the identifier.
391 ConsumeToken();
392
Chris Lattnerbb8cc182008-10-20 05:57:40 +0000393 switch (DirectiveKind) {
394 default:
Chris Lattnerda9fb152008-10-20 06:10:06 +0000395 // FIXME: If someone forgets an @end on a protocol, this loop will
396 // continue to eat up tons of stuff and spew lots of nonsense errors. It
397 // would probably be better to bail out if we saw an @class or @interface
398 // or something like that.
Chris Lattner76619232008-10-20 07:22:18 +0000399 Diag(AtLoc, diag::err_objc_illegal_interface_qual);
Chris Lattnerda9fb152008-10-20 06:10:06 +0000400 // Skip until we see an '@' or '}' or ';'.
Chris Lattnerbb8cc182008-10-20 05:57:40 +0000401 SkipUntil(tok::r_brace, tok::at);
402 break;
Mike Stump11289f42009-09-09 15:08:12 +0000403
Chris Lattnerbb8cc182008-10-20 05:57:40 +0000404 case tok::objc_required:
Chris Lattnerbb8cc182008-10-20 05:57:40 +0000405 case tok::objc_optional:
Chris Lattnerbb8cc182008-10-20 05:57:40 +0000406 // This is only valid on protocols.
Chris Lattnerda9fb152008-10-20 06:10:06 +0000407 // FIXME: Should this check for ObjC2 being enabled?
Chris Lattner038a3e32008-10-20 05:46:22 +0000408 if (contextKey != tok::objc_protocol)
Chris Lattnerda9fb152008-10-20 06:10:06 +0000409 Diag(AtLoc, diag::err_objc_directive_only_in_protocol);
Chris Lattnerbb8cc182008-10-20 05:57:40 +0000410 else
Chris Lattnerda9fb152008-10-20 06:10:06 +0000411 MethodImplKind = DirectiveKind;
Chris Lattnerbb8cc182008-10-20 05:57:40 +0000412 break;
Mike Stump11289f42009-09-09 15:08:12 +0000413
Chris Lattnerbb8cc182008-10-20 05:57:40 +0000414 case tok::objc_property:
Chris Lattner76619232008-10-20 07:22:18 +0000415 if (!getLang().ObjC2)
416 Diag(AtLoc, diag::err_objc_propertoes_require_objc2);
417
Chris Lattner038a3e32008-10-20 05:46:22 +0000418 ObjCDeclSpec OCDS;
Mike Stump11289f42009-09-09 15:08:12 +0000419 // Parse property attribute list, if any.
Chris Lattnerbeca7702008-10-20 07:24:39 +0000420 if (Tok.is(tok::l_paren))
Douglas Gregorc8537c52009-11-19 07:41:15 +0000421 ParseObjCPropertyAttribute(OCDS, interfaceDecl,
422 allMethods.data(), allMethods.size());
Mike Stump11289f42009-09-09 15:08:12 +0000423
John McCall064d77b2009-12-03 22:31:13 +0000424 ObjCPropertyCallback Callback(*this, interfaceDecl, allProperties,
425 OCDS, AtLoc, MethodImplKind);
John McCallcfefb6d2009-11-03 02:38:08 +0000426
Chris Lattner038a3e32008-10-20 05:46:22 +0000427 // Parse all the comma separated declarators.
428 DeclSpec DS;
John McCallcfefb6d2009-11-03 02:38:08 +0000429 ParseStructDeclaration(DS, Callback);
Mike Stump11289f42009-09-09 15:08:12 +0000430
Chris Lattnere0d3fe92008-10-20 06:15:13 +0000431 ExpectAndConsume(tok::semi, diag::err_expected_semi_decl_list, "",
432 tok::at);
Chris Lattnerbb8cc182008-10-20 05:57:40 +0000433 break;
Steve Naroffca85d1d2007-09-05 23:30:30 +0000434 }
Steve Naroff99264b42007-08-22 16:35:03 +0000435 }
Chris Lattnerda9fb152008-10-20 06:10:06 +0000436
437 // We break out of the big loop in two cases: when we see @end or when we see
438 // EOF. In the former case, eat the @end. In the later case, emit an error.
Douglas Gregorf48706c2009-12-07 09:27:33 +0000439 if (Tok.is(tok::code_completion)) {
Douglas Gregor0be31a22010-07-02 17:43:08 +0000440 Actions.CodeCompleteObjCAtDirective(getCurScope(), ObjCImpDecl, true);
Douglas Gregor6da3db42010-05-25 05:58:43 +0000441 ConsumeCodeCompletionToken();
Douglas Gregorf48706c2009-12-07 09:27:33 +0000442 } else if (Tok.isObjCAtKeyword(tok::objc_end))
Chris Lattnerda9fb152008-10-20 06:10:06 +0000443 ConsumeToken(); // the "end" identifier
444 else
445 Diag(Tok, diag::err_objc_missing_end);
Mike Stump11289f42009-09-09 15:08:12 +0000446
Chris Lattnerbb8cc182008-10-20 05:57:40 +0000447 // Insert collected methods declarations into the @interface object.
Chris Lattnerda9fb152008-10-20 06:10:06 +0000448 // This passes in an invalid SourceLocation for AtEndLoc when EOF is hit.
Douglas Gregor0be31a22010-07-02 17:43:08 +0000449 Actions.ActOnAtEnd(getCurScope(), AtEnd, interfaceDecl,
Mike Stump11289f42009-09-09 15:08:12 +0000450 allMethods.data(), allMethods.size(),
Jay Foad7d0479f2009-05-21 09:52:38 +0000451 allProperties.data(), allProperties.size(),
452 allTUVariables.data(), allTUVariables.size());
Steve Naroff99264b42007-08-22 16:35:03 +0000453}
454
Fariborz Jahanian9fca6df2007-08-31 16:11:31 +0000455/// Parse property attribute declarations.
456///
457/// property-attr-decl: '(' property-attrlist ')'
458/// property-attrlist:
459/// property-attribute
460/// property-attrlist ',' property-attribute
461/// property-attribute:
462/// getter '=' identifier
463/// setter '=' identifier ':'
464/// readonly
465/// readwrite
466/// assign
467/// retain
468/// copy
469/// nonatomic
470///
John McCall48871652010-08-21 09:40:31 +0000471void Parser::ParseObjCPropertyAttribute(ObjCDeclSpec &DS, Decl *ClassDecl,
472 Decl **Methods,
Douglas Gregorc8537c52009-11-19 07:41:15 +0000473 unsigned NumMethods) {
Chris Lattnerbeca7702008-10-20 07:24:39 +0000474 assert(Tok.getKind() == tok::l_paren);
Chris Lattner43c76c32008-10-20 07:00:43 +0000475 SourceLocation LHSLoc = ConsumeParen(); // consume '('
Mike Stump11289f42009-09-09 15:08:12 +0000476
Chris Lattner64b1f2f2008-10-20 07:15:22 +0000477 while (1) {
Steve Naroff936354c2009-10-08 21:55:05 +0000478 if (Tok.is(tok::code_completion)) {
Douglas Gregor0be31a22010-07-02 17:43:08 +0000479 Actions.CodeCompleteObjCPropertyFlags(getCurScope(), DS);
Douglas Gregor6da3db42010-05-25 05:58:43 +0000480 ConsumeCodeCompletionToken();
Steve Naroff936354c2009-10-08 21:55:05 +0000481 }
Fariborz Jahanian9fca6df2007-08-31 16:11:31 +0000482 const IdentifierInfo *II = Tok.getIdentifierInfo();
Mike Stump11289f42009-09-09 15:08:12 +0000483
Chris Lattner76619232008-10-20 07:22:18 +0000484 // If this is not an identifier at all, bail out early.
485 if (II == 0) {
486 MatchRHSPunctuation(tok::r_paren, LHSLoc);
487 return;
488 }
Mike Stump11289f42009-09-09 15:08:12 +0000489
Chris Lattner1db33542008-10-20 07:37:22 +0000490 SourceLocation AttrName = ConsumeToken(); // consume last attribute name
Mike Stump11289f42009-09-09 15:08:12 +0000491
Chris Lattner68e48682008-11-20 04:42:34 +0000492 if (II->isStr("readonly"))
Chris Lattner825bca12008-10-20 07:39:53 +0000493 DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_readonly);
Chris Lattner68e48682008-11-20 04:42:34 +0000494 else if (II->isStr("assign"))
Chris Lattner825bca12008-10-20 07:39:53 +0000495 DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_assign);
Chris Lattner68e48682008-11-20 04:42:34 +0000496 else if (II->isStr("readwrite"))
Chris Lattner825bca12008-10-20 07:39:53 +0000497 DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_readwrite);
Chris Lattner68e48682008-11-20 04:42:34 +0000498 else if (II->isStr("retain"))
Chris Lattner825bca12008-10-20 07:39:53 +0000499 DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_retain);
Chris Lattner68e48682008-11-20 04:42:34 +0000500 else if (II->isStr("copy"))
Chris Lattner825bca12008-10-20 07:39:53 +0000501 DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_copy);
Chris Lattner68e48682008-11-20 04:42:34 +0000502 else if (II->isStr("nonatomic"))
Chris Lattner825bca12008-10-20 07:39:53 +0000503 DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_nonatomic);
Chris Lattner68e48682008-11-20 04:42:34 +0000504 else if (II->isStr("getter") || II->isStr("setter")) {
Chris Lattner825bca12008-10-20 07:39:53 +0000505 // getter/setter require extra treatment.
Chris Lattner1db33542008-10-20 07:37:22 +0000506 if (ExpectAndConsume(tok::equal, diag::err_objc_expected_equal, "",
507 tok::r_paren))
Chris Lattner43c76c32008-10-20 07:00:43 +0000508 return;
Mike Stump11289f42009-09-09 15:08:12 +0000509
Douglas Gregorc8537c52009-11-19 07:41:15 +0000510 if (Tok.is(tok::code_completion)) {
511 if (II->getNameStart()[0] == 's')
Douglas Gregor0be31a22010-07-02 17:43:08 +0000512 Actions.CodeCompleteObjCPropertySetter(getCurScope(), ClassDecl,
Douglas Gregorc8537c52009-11-19 07:41:15 +0000513 Methods, NumMethods);
514 else
Douglas Gregor0be31a22010-07-02 17:43:08 +0000515 Actions.CodeCompleteObjCPropertyGetter(getCurScope(), ClassDecl,
Douglas Gregorc8537c52009-11-19 07:41:15 +0000516 Methods, NumMethods);
Douglas Gregor6da3db42010-05-25 05:58:43 +0000517 ConsumeCodeCompletionToken();
Douglas Gregorc8537c52009-11-19 07:41:15 +0000518 }
519
Chris Lattnerbeca7702008-10-20 07:24:39 +0000520 if (Tok.isNot(tok::identifier)) {
Chris Lattner6d29c102008-11-18 07:48:38 +0000521 Diag(Tok, diag::err_expected_ident);
Chris Lattnerbeca7702008-10-20 07:24:39 +0000522 SkipUntil(tok::r_paren);
523 return;
524 }
Mike Stump11289f42009-09-09 15:08:12 +0000525
Daniel Dunbar2c422dc92009-10-18 20:26:12 +0000526 if (II->getNameStart()[0] == 's') {
Chris Lattnerbeca7702008-10-20 07:24:39 +0000527 DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_setter);
528 DS.setSetterName(Tok.getIdentifierInfo());
Chris Lattner1db33542008-10-20 07:37:22 +0000529 ConsumeToken(); // consume method name
Mike Stump11289f42009-09-09 15:08:12 +0000530
Fariborz Jahanian8efe0ec2010-02-15 22:20:11 +0000531 if (ExpectAndConsume(tok::colon,
532 diag::err_expected_colon_after_setter_name, "",
Chris Lattner1db33542008-10-20 07:37:22 +0000533 tok::r_paren))
Chris Lattnerbeca7702008-10-20 07:24:39 +0000534 return;
Chris Lattnerbeca7702008-10-20 07:24:39 +0000535 } else {
536 DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_getter);
537 DS.setGetterName(Tok.getIdentifierInfo());
Chris Lattner1db33542008-10-20 07:37:22 +0000538 ConsumeToken(); // consume method name
Chris Lattnerbeca7702008-10-20 07:24:39 +0000539 }
Chris Lattner825bca12008-10-20 07:39:53 +0000540 } else {
Chris Lattner406c0962008-11-19 07:49:38 +0000541 Diag(AttrName, diag::err_objc_expected_property_attr) << II;
Chris Lattner64b1f2f2008-10-20 07:15:22 +0000542 SkipUntil(tok::r_paren);
543 return;
Chris Lattner64b1f2f2008-10-20 07:15:22 +0000544 }
Mike Stump11289f42009-09-09 15:08:12 +0000545
Chris Lattner1db33542008-10-20 07:37:22 +0000546 if (Tok.isNot(tok::comma))
547 break;
Mike Stump11289f42009-09-09 15:08:12 +0000548
Chris Lattner1db33542008-10-20 07:37:22 +0000549 ConsumeToken();
Fariborz Jahanian9fca6df2007-08-31 16:11:31 +0000550 }
Mike Stump11289f42009-09-09 15:08:12 +0000551
Chris Lattner1db33542008-10-20 07:37:22 +0000552 MatchRHSPunctuation(tok::r_paren, LHSLoc);
Fariborz Jahanian9fca6df2007-08-31 16:11:31 +0000553}
554
Steve Naroff09bf8152007-09-06 21:24:23 +0000555/// objc-method-proto:
Mike Stump11289f42009-09-09 15:08:12 +0000556/// objc-instance-method objc-method-decl objc-method-attributes[opt]
Steve Naroff09bf8152007-09-06 21:24:23 +0000557/// objc-class-method objc-method-decl objc-method-attributes[opt]
Steve Naroff99264b42007-08-22 16:35:03 +0000558///
559/// objc-instance-method: '-'
560/// objc-class-method: '+'
561///
Steve Narofff1bc45b2007-08-22 18:35:33 +0000562/// objc-method-attributes: [OBJC2]
563/// __attribute__((deprecated))
564///
John McCall48871652010-08-21 09:40:31 +0000565Decl *Parser::ParseObjCMethodPrototype(Decl *IDecl,
566 tok::ObjCKeywordKind MethodImplKind) {
Chris Lattner0ef13522007-10-09 17:51:17 +0000567 assert((Tok.is(tok::minus) || Tok.is(tok::plus)) && "expected +/-");
Steve Naroff99264b42007-08-22 16:35:03 +0000568
Mike Stump11289f42009-09-09 15:08:12 +0000569 tok::TokenKind methodType = Tok.getKind();
Steve Naroff161a92b2007-10-26 20:53:56 +0000570 SourceLocation mLoc = ConsumeToken();
Mike Stump11289f42009-09-09 15:08:12 +0000571
John McCall48871652010-08-21 09:40:31 +0000572 Decl *MDecl = ParseObjCMethodDecl(mLoc, methodType, IDecl,MethodImplKind);
Steve Naroff09bf8152007-09-06 21:24:23 +0000573 // Since this rule is used for both method declarations and definitions,
Steve Naroffacb1e742007-09-10 20:51:04 +0000574 // the caller is (optionally) responsible for consuming the ';'.
Steve Naroffca85d1d2007-09-05 23:30:30 +0000575 return MDecl;
Steve Naroff99264b42007-08-22 16:35:03 +0000576}
577
578/// objc-selector:
579/// identifier
580/// one of
581/// enum struct union if else while do for switch case default
582/// break continue return goto asm sizeof typeof __alignof
583/// unsigned long const short volatile signed restrict _Complex
584/// in out inout bycopy byref oneway int char float double void _Bool
585///
Chris Lattner4f472a32009-04-11 18:13:45 +0000586IdentifierInfo *Parser::ParseObjCSelectorPiece(SourceLocation &SelectorLoc) {
Chris Lattner5700fab2007-10-07 02:00:24 +0000587 switch (Tok.getKind()) {
588 default:
589 return 0;
590 case tok::identifier:
Anders Carlssonf93f56a2008-08-23 21:00:01 +0000591 case tok::kw_asm:
Chris Lattner5700fab2007-10-07 02:00:24 +0000592 case tok::kw_auto:
Chris Lattnerbb31a422007-11-15 05:25:19 +0000593 case tok::kw_bool:
Anders Carlssonf93f56a2008-08-23 21:00:01 +0000594 case tok::kw_break:
595 case tok::kw_case:
596 case tok::kw_catch:
597 case tok::kw_char:
598 case tok::kw_class:
599 case tok::kw_const:
600 case tok::kw_const_cast:
601 case tok::kw_continue:
602 case tok::kw_default:
603 case tok::kw_delete:
604 case tok::kw_do:
605 case tok::kw_double:
606 case tok::kw_dynamic_cast:
607 case tok::kw_else:
608 case tok::kw_enum:
609 case tok::kw_explicit:
610 case tok::kw_export:
611 case tok::kw_extern:
612 case tok::kw_false:
613 case tok::kw_float:
614 case tok::kw_for:
615 case tok::kw_friend:
616 case tok::kw_goto:
617 case tok::kw_if:
618 case tok::kw_inline:
619 case tok::kw_int:
620 case tok::kw_long:
621 case tok::kw_mutable:
622 case tok::kw_namespace:
623 case tok::kw_new:
624 case tok::kw_operator:
625 case tok::kw_private:
626 case tok::kw_protected:
627 case tok::kw_public:
628 case tok::kw_register:
629 case tok::kw_reinterpret_cast:
630 case tok::kw_restrict:
631 case tok::kw_return:
632 case tok::kw_short:
633 case tok::kw_signed:
634 case tok::kw_sizeof:
635 case tok::kw_static:
636 case tok::kw_static_cast:
637 case tok::kw_struct:
638 case tok::kw_switch:
639 case tok::kw_template:
640 case tok::kw_this:
641 case tok::kw_throw:
642 case tok::kw_true:
643 case tok::kw_try:
644 case tok::kw_typedef:
645 case tok::kw_typeid:
646 case tok::kw_typename:
647 case tok::kw_typeof:
648 case tok::kw_union:
649 case tok::kw_unsigned:
650 case tok::kw_using:
651 case tok::kw_virtual:
652 case tok::kw_void:
653 case tok::kw_volatile:
654 case tok::kw_wchar_t:
655 case tok::kw_while:
Chris Lattner5700fab2007-10-07 02:00:24 +0000656 case tok::kw__Bool:
657 case tok::kw__Complex:
Anders Carlssonf93f56a2008-08-23 21:00:01 +0000658 case tok::kw___alignof:
Chris Lattner5700fab2007-10-07 02:00:24 +0000659 IdentifierInfo *II = Tok.getIdentifierInfo();
Fariborz Jahanian70e8f102007-10-11 00:55:41 +0000660 SelectorLoc = ConsumeToken();
Chris Lattner5700fab2007-10-07 02:00:24 +0000661 return II;
Fariborz Jahanianfa80e802007-09-27 19:52:15 +0000662 }
Steve Naroff99264b42007-08-22 16:35:03 +0000663}
664
Fariborz Jahanian83615522008-01-02 22:54:34 +0000665/// objc-for-collection-in: 'in'
666///
Fariborz Jahanian3622e592008-01-04 23:04:08 +0000667bool Parser::isTokIdentifier_in() const {
Fariborz Jahanian732b8c22008-01-03 17:55:25 +0000668 // FIXME: May have to do additional look-ahead to only allow for
669 // valid tokens following an 'in'; such as an identifier, unary operators,
670 // '[' etc.
Mike Stump11289f42009-09-09 15:08:12 +0000671 return (getLang().ObjC2 && Tok.is(tok::identifier) &&
Chris Lattnerce90ef52008-08-23 02:02:23 +0000672 Tok.getIdentifierInfo() == ObjCTypeQuals[objc_in]);
Fariborz Jahanian83615522008-01-02 22:54:34 +0000673}
674
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000675/// ParseObjCTypeQualifierList - This routine parses the objective-c's type
Chris Lattner61511e12007-12-12 06:56:32 +0000676/// qualifier list and builds their bitmask representation in the input
677/// argument.
Steve Naroff99264b42007-08-22 16:35:03 +0000678///
679/// objc-type-qualifiers:
680/// objc-type-qualifier
681/// objc-type-qualifiers objc-type-qualifier
682///
Douglas Gregor99fa2642010-08-24 01:06:58 +0000683void Parser::ParseObjCTypeQualifierList(ObjCDeclSpec &DS, bool IsParameter) {
Chris Lattner61511e12007-12-12 06:56:32 +0000684 while (1) {
Douglas Gregor99fa2642010-08-24 01:06:58 +0000685 if (Tok.is(tok::code_completion)) {
686 Actions.CodeCompleteObjCPassingType(getCurScope(), DS);
687 ConsumeCodeCompletionToken();
688 }
689
Chris Lattner5e530bc2007-12-27 19:57:00 +0000690 if (Tok.isNot(tok::identifier))
Chris Lattner61511e12007-12-12 06:56:32 +0000691 return;
Mike Stump11289f42009-09-09 15:08:12 +0000692
Chris Lattner61511e12007-12-12 06:56:32 +0000693 const IdentifierInfo *II = Tok.getIdentifierInfo();
694 for (unsigned i = 0; i != objc_NumQuals; ++i) {
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000695 if (II != ObjCTypeQuals[i])
Chris Lattner61511e12007-12-12 06:56:32 +0000696 continue;
Mike Stump11289f42009-09-09 15:08:12 +0000697
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000698 ObjCDeclSpec::ObjCDeclQualifier Qual;
Chris Lattner61511e12007-12-12 06:56:32 +0000699 switch (i) {
700 default: assert(0 && "Unknown decl qualifier");
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000701 case objc_in: Qual = ObjCDeclSpec::DQ_In; break;
702 case objc_out: Qual = ObjCDeclSpec::DQ_Out; break;
703 case objc_inout: Qual = ObjCDeclSpec::DQ_Inout; break;
704 case objc_oneway: Qual = ObjCDeclSpec::DQ_Oneway; break;
705 case objc_bycopy: Qual = ObjCDeclSpec::DQ_Bycopy; break;
706 case objc_byref: Qual = ObjCDeclSpec::DQ_Byref; break;
Chris Lattner61511e12007-12-12 06:56:32 +0000707 }
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000708 DS.setObjCDeclQualifier(Qual);
Chris Lattner61511e12007-12-12 06:56:32 +0000709 ConsumeToken();
710 II = 0;
711 break;
712 }
Mike Stump11289f42009-09-09 15:08:12 +0000713
Chris Lattner61511e12007-12-12 06:56:32 +0000714 // If this wasn't a recognized qualifier, bail out.
715 if (II) return;
716 }
717}
718
719/// objc-type-name:
720/// '(' objc-type-qualifiers[opt] type-name ')'
721/// '(' objc-type-qualifiers[opt] ')'
722///
John McCallba7bf592010-08-24 05:47:05 +0000723ParsedType Parser::ParseObjCTypeName(ObjCDeclSpec &DS, bool IsParameter) {
Chris Lattner0ef13522007-10-09 17:51:17 +0000724 assert(Tok.is(tok::l_paren) && "expected (");
Mike Stump11289f42009-09-09 15:08:12 +0000725
Chris Lattnerb7954432008-10-22 03:52:06 +0000726 SourceLocation LParenLoc = ConsumeParen();
Chris Lattner2ebb1782008-08-23 01:48:03 +0000727 SourceLocation TypeStartLoc = Tok.getLocation();
Mike Stump11289f42009-09-09 15:08:12 +0000728
Fariborz Jahaniand822d682007-10-31 21:59:43 +0000729 // Parse type qualifiers, in, inout, etc.
Douglas Gregor99fa2642010-08-24 01:06:58 +0000730 ParseObjCTypeQualifierList(DS, IsParameter);
Steve Naroff7e901fd2007-08-22 23:18:22 +0000731
John McCallba7bf592010-08-24 05:47:05 +0000732 ParsedType Ty;
Douglas Gregor220cac52009-02-18 17:45:20 +0000733 if (isTypeSpecifierQualifier()) {
734 TypeResult TypeSpec = ParseTypeName();
735 if (!TypeSpec.isInvalid())
736 Ty = TypeSpec.get();
737 }
Mike Stump11289f42009-09-09 15:08:12 +0000738
Steve Naroff90255b42008-10-21 14:15:04 +0000739 if (Tok.is(tok::r_paren))
Chris Lattnerb7954432008-10-22 03:52:06 +0000740 ConsumeParen();
741 else if (Tok.getLocation() == TypeStartLoc) {
742 // If we didn't eat any tokens, then this isn't a type.
Chris Lattner6d29c102008-11-18 07:48:38 +0000743 Diag(Tok, diag::err_expected_type);
Chris Lattnerb7954432008-10-22 03:52:06 +0000744 SkipUntil(tok::r_paren);
745 } else {
746 // Otherwise, we found *something*, but didn't get a ')' in the right
747 // place. Emit an error then return what we have as the type.
748 MatchRHSPunctuation(tok::r_paren, LParenLoc);
749 }
Steve Naroffca85d1d2007-09-05 23:30:30 +0000750 return Ty;
Steve Naroff99264b42007-08-22 16:35:03 +0000751}
752
753/// objc-method-decl:
754/// objc-selector
Steve Narofff1bc45b2007-08-22 18:35:33 +0000755/// objc-keyword-selector objc-parmlist[opt]
Steve Naroff99264b42007-08-22 16:35:03 +0000756/// objc-type-name objc-selector
Steve Narofff1bc45b2007-08-22 18:35:33 +0000757/// objc-type-name objc-keyword-selector objc-parmlist[opt]
Steve Naroff99264b42007-08-22 16:35:03 +0000758///
759/// objc-keyword-selector:
Mike Stump11289f42009-09-09 15:08:12 +0000760/// objc-keyword-decl
Steve Naroff99264b42007-08-22 16:35:03 +0000761/// objc-keyword-selector objc-keyword-decl
762///
763/// objc-keyword-decl:
Steve Naroff0b6a01a2007-08-22 22:17:26 +0000764/// objc-selector ':' objc-type-name objc-keyword-attributes[opt] identifier
765/// objc-selector ':' objc-keyword-attributes[opt] identifier
766/// ':' objc-type-name objc-keyword-attributes[opt] identifier
767/// ':' objc-keyword-attributes[opt] identifier
Steve Naroff99264b42007-08-22 16:35:03 +0000768///
Steve Narofff1bc45b2007-08-22 18:35:33 +0000769/// objc-parmlist:
770/// objc-parms objc-ellipsis[opt]
Steve Naroff99264b42007-08-22 16:35:03 +0000771///
Steve Narofff1bc45b2007-08-22 18:35:33 +0000772/// objc-parms:
773/// objc-parms , parameter-declaration
Steve Naroff99264b42007-08-22 16:35:03 +0000774///
Steve Narofff1bc45b2007-08-22 18:35:33 +0000775/// objc-ellipsis:
Steve Naroff99264b42007-08-22 16:35:03 +0000776/// , ...
777///
Steve Naroff0b6a01a2007-08-22 22:17:26 +0000778/// objc-keyword-attributes: [OBJC2]
779/// __attribute__((unused))
780///
John McCall48871652010-08-21 09:40:31 +0000781Decl *Parser::ParseObjCMethodDecl(SourceLocation mLoc,
Douglas Gregorc49f5b22010-08-23 18:23:48 +0000782 tok::TokenKind mType,
783 Decl *IDecl,
784 tok::ObjCKeywordKind MethodImplKind) {
John McCall28a6aea2009-11-04 02:18:39 +0000785 ParsingDeclRAIIObject PD(*this);
786
Douglas Gregor636a61e2010-04-07 00:21:17 +0000787 if (Tok.is(tok::code_completion)) {
Douglas Gregor0be31a22010-07-02 17:43:08 +0000788 Actions.CodeCompleteObjCMethodDecl(getCurScope(), mType == tok::minus,
John McCallba7bf592010-08-24 05:47:05 +0000789 /*ReturnType=*/ ParsedType(), IDecl);
Douglas Gregor6da3db42010-05-25 05:58:43 +0000790 ConsumeCodeCompletionToken();
Douglas Gregor636a61e2010-04-07 00:21:17 +0000791 }
792
Chris Lattner2ebb1782008-08-23 01:48:03 +0000793 // Parse the return type if present.
John McCallba7bf592010-08-24 05:47:05 +0000794 ParsedType ReturnType;
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000795 ObjCDeclSpec DSRet;
Chris Lattner0ef13522007-10-09 17:51:17 +0000796 if (Tok.is(tok::l_paren))
Douglas Gregor99fa2642010-08-24 01:06:58 +0000797 ReturnType = ParseObjCTypeName(DSRet, false);
Mike Stump11289f42009-09-09 15:08:12 +0000798
Ted Kremenek66f2d6b2010-02-18 23:05:16 +0000799 // If attributes exist before the method, parse them.
800 llvm::OwningPtr<AttributeList> MethodAttrs;
801 if (getLang().ObjC2 && Tok.is(tok::kw___attribute))
802 MethodAttrs.reset(ParseGNUAttributes());
803
Douglas Gregor636a61e2010-04-07 00:21:17 +0000804 if (Tok.is(tok::code_completion)) {
Douglas Gregor0be31a22010-07-02 17:43:08 +0000805 Actions.CodeCompleteObjCMethodDecl(getCurScope(), mType == tok::minus,
Douglas Gregor636a61e2010-04-07 00:21:17 +0000806 ReturnType, IDecl);
Douglas Gregor6da3db42010-05-25 05:58:43 +0000807 ConsumeCodeCompletionToken();
Douglas Gregor636a61e2010-04-07 00:21:17 +0000808 }
809
Ted Kremenek66f2d6b2010-02-18 23:05:16 +0000810 // Now parse the selector.
Steve Naroff161a92b2007-10-26 20:53:56 +0000811 SourceLocation selLoc;
Chris Lattner4f472a32009-04-11 18:13:45 +0000812 IdentifierInfo *SelIdent = ParseObjCSelectorPiece(selLoc);
Chris Lattner2ebb1782008-08-23 01:48:03 +0000813
Steve Naroff7a54c0d2009-02-11 20:43:13 +0000814 // An unnamed colon is valid.
815 if (!SelIdent && Tok.isNot(tok::colon)) { // missing selector name.
Chris Lattner6d29c102008-11-18 07:48:38 +0000816 Diag(Tok, diag::err_expected_selector_for_method)
817 << SourceRange(mLoc, Tok.getLocation());
Chris Lattner2ebb1782008-08-23 01:48:03 +0000818 // Skip until we get a ; or {}.
819 SkipUntil(tok::r_brace);
John McCall48871652010-08-21 09:40:31 +0000820 return 0;
Chris Lattner2ebb1782008-08-23 01:48:03 +0000821 }
Mike Stump11289f42009-09-09 15:08:12 +0000822
Fariborz Jahanian60462092010-04-08 00:30:06 +0000823 llvm::SmallVector<DeclaratorChunk::ParamInfo, 8> CParamInfo;
Chris Lattner0ef13522007-10-09 17:51:17 +0000824 if (Tok.isNot(tok::colon)) {
Chris Lattner5700fab2007-10-07 02:00:24 +0000825 // If attributes exist after the method, parse them.
Mike Stump11289f42009-09-09 15:08:12 +0000826 if (getLang().ObjC2 && Tok.is(tok::kw___attribute))
Ted Kremenek66f2d6b2010-02-18 23:05:16 +0000827 MethodAttrs.reset(addAttributeLists(MethodAttrs.take(),
828 ParseGNUAttributes()));
Mike Stump11289f42009-09-09 15:08:12 +0000829
Chris Lattner5700fab2007-10-07 02:00:24 +0000830 Selector Sel = PP.getSelectorTable().getNullarySelector(SelIdent);
John McCall48871652010-08-21 09:40:31 +0000831 Decl *Result
John McCall28a6aea2009-11-04 02:18:39 +0000832 = Actions.ActOnMethodDeclaration(mLoc, Tok.getLocation(),
Fariborz Jahanianb5605172007-11-09 19:52:12 +0000833 mType, IDecl, DSRet, ReturnType, Sel,
Fariborz Jahanian60462092010-04-08 00:30:06 +0000834 0,
835 CParamInfo.data(), CParamInfo.size(),
836 MethodAttrs.get(),
Ted Kremenekbc76c722009-05-04 17:04:30 +0000837 MethodImplKind);
John McCall28a6aea2009-11-04 02:18:39 +0000838 PD.complete(Result);
839 return Result;
Chris Lattner5700fab2007-10-07 02:00:24 +0000840 }
Steve Naroffca85d1d2007-09-05 23:30:30 +0000841
Steve Narofff73590d2007-09-27 14:38:14 +0000842 llvm::SmallVector<IdentifierInfo *, 12> KeyIdents;
Chris Lattnerd8626fd2009-04-11 18:57:04 +0000843 llvm::SmallVector<Action::ObjCArgInfo, 12> ArgInfos;
Mike Stump11289f42009-09-09 15:08:12 +0000844
Chris Lattner5700fab2007-10-07 02:00:24 +0000845 while (1) {
Chris Lattnerd8626fd2009-04-11 18:57:04 +0000846 Action::ObjCArgInfo ArgInfo;
Mike Stump11289f42009-09-09 15:08:12 +0000847
Chris Lattner5700fab2007-10-07 02:00:24 +0000848 // Each iteration parses a single keyword argument.
Chris Lattner0ef13522007-10-09 17:51:17 +0000849 if (Tok.isNot(tok::colon)) {
Chris Lattner5700fab2007-10-07 02:00:24 +0000850 Diag(Tok, diag::err_expected_colon);
851 break;
852 }
853 ConsumeToken(); // Eat the ':'.
Mike Stump11289f42009-09-09 15:08:12 +0000854
John McCallba7bf592010-08-24 05:47:05 +0000855 ArgInfo.Type = ParsedType();
Chris Lattnerd8626fd2009-04-11 18:57:04 +0000856 if (Tok.is(tok::l_paren)) // Parse the argument type if present.
Douglas Gregor99fa2642010-08-24 01:06:58 +0000857 ArgInfo.Type = ParseObjCTypeName(ArgInfo.DeclSpec, true);
Chris Lattnerd8626fd2009-04-11 18:57:04 +0000858
Chris Lattner5700fab2007-10-07 02:00:24 +0000859 // If attributes exist before the argument name, parse them.
Chris Lattnerd8626fd2009-04-11 18:57:04 +0000860 ArgInfo.ArgAttrs = 0;
Chris Lattner0ef13522007-10-09 17:51:17 +0000861 if (getLang().ObjC2 && Tok.is(tok::kw___attribute))
Alexis Hunt96d5c762009-11-21 08:43:09 +0000862 ArgInfo.ArgAttrs = ParseGNUAttributes();
Steve Naroff0b6a01a2007-08-22 22:17:26 +0000863
Douglas Gregor45879692010-07-08 23:37:41 +0000864 // Code completion for the next piece of the selector.
865 if (Tok.is(tok::code_completion)) {
866 ConsumeCodeCompletionToken();
867 KeyIdents.push_back(SelIdent);
868 Actions.CodeCompleteObjCMethodDeclSelector(getCurScope(),
869 mType == tok::minus,
870 /*AtParameterName=*/true,
871 ReturnType,
872 KeyIdents.data(),
873 KeyIdents.size());
874 KeyIdents.pop_back();
875 break;
876 }
877
Chris Lattner0ef13522007-10-09 17:51:17 +0000878 if (Tok.isNot(tok::identifier)) {
Chris Lattner5700fab2007-10-07 02:00:24 +0000879 Diag(Tok, diag::err_expected_ident); // missing argument name.
880 break;
Steve Narofff1bc45b2007-08-22 18:35:33 +0000881 }
Mike Stump11289f42009-09-09 15:08:12 +0000882
Chris Lattnerd8626fd2009-04-11 18:57:04 +0000883 ArgInfo.Name = Tok.getIdentifierInfo();
884 ArgInfo.NameLoc = Tok.getLocation();
Chris Lattner5700fab2007-10-07 02:00:24 +0000885 ConsumeToken(); // Eat the identifier.
Mike Stump11289f42009-09-09 15:08:12 +0000886
Chris Lattnerd8626fd2009-04-11 18:57:04 +0000887 ArgInfos.push_back(ArgInfo);
888 KeyIdents.push_back(SelIdent);
889
Douglas Gregor95887f92010-07-08 23:20:03 +0000890 // Code completion for the next piece of the selector.
891 if (Tok.is(tok::code_completion)) {
892 ConsumeCodeCompletionToken();
893 Actions.CodeCompleteObjCMethodDeclSelector(getCurScope(),
894 mType == tok::minus,
Douglas Gregor45879692010-07-08 23:37:41 +0000895 /*AtParameterName=*/false,
Douglas Gregor95887f92010-07-08 23:20:03 +0000896 ReturnType,
897 KeyIdents.data(),
898 KeyIdents.size());
899 break;
900 }
901
Chris Lattner5700fab2007-10-07 02:00:24 +0000902 // Check for another keyword selector.
Fariborz Jahanian70e8f102007-10-11 00:55:41 +0000903 SourceLocation Loc;
Chris Lattner4f472a32009-04-11 18:13:45 +0000904 SelIdent = ParseObjCSelectorPiece(Loc);
Chris Lattner0ef13522007-10-09 17:51:17 +0000905 if (!SelIdent && Tok.isNot(tok::colon))
Chris Lattner5700fab2007-10-07 02:00:24 +0000906 break;
907 // We have a selector or a colon, continue parsing.
Steve Narofff1bc45b2007-08-22 18:35:33 +0000908 }
Mike Stump11289f42009-09-09 15:08:12 +0000909
Steve Naroffd8ea1ac2007-11-15 12:35:21 +0000910 bool isVariadic = false;
Mike Stump11289f42009-09-09 15:08:12 +0000911
Chris Lattner5700fab2007-10-07 02:00:24 +0000912 // Parse the (optional) parameter list.
Chris Lattner0ef13522007-10-09 17:51:17 +0000913 while (Tok.is(tok::comma)) {
Chris Lattner5700fab2007-10-07 02:00:24 +0000914 ConsumeToken();
Chris Lattner0ef13522007-10-09 17:51:17 +0000915 if (Tok.is(tok::ellipsis)) {
Steve Naroffd8ea1ac2007-11-15 12:35:21 +0000916 isVariadic = true;
Chris Lattner5700fab2007-10-07 02:00:24 +0000917 ConsumeToken();
918 break;
919 }
Chris Lattner5700fab2007-10-07 02:00:24 +0000920 DeclSpec DS;
921 ParseDeclarationSpecifiers(DS);
Mike Stump11289f42009-09-09 15:08:12 +0000922 // Parse the declarator.
Chris Lattner5700fab2007-10-07 02:00:24 +0000923 Declarator ParmDecl(DS, Declarator::PrototypeContext);
924 ParseDeclarator(ParmDecl);
Fariborz Jahanian60462092010-04-08 00:30:06 +0000925 IdentifierInfo *ParmII = ParmDecl.getIdentifier();
John McCall48871652010-08-21 09:40:31 +0000926 Decl *Param = Actions.ActOnParamDeclarator(getCurScope(), ParmDecl);
Fariborz Jahanian60462092010-04-08 00:30:06 +0000927 CParamInfo.push_back(DeclaratorChunk::ParamInfo(ParmII,
928 ParmDecl.getIdentifierLoc(),
929 Param,
930 0));
931
Chris Lattner5700fab2007-10-07 02:00:24 +0000932 }
Mike Stump11289f42009-09-09 15:08:12 +0000933
Chris Lattner5700fab2007-10-07 02:00:24 +0000934 // FIXME: Add support for optional parmameter list...
Fariborz Jahanian33d03742007-09-10 20:33:04 +0000935 // If attributes exist after the method, parse them.
Mike Stump11289f42009-09-09 15:08:12 +0000936 if (getLang().ObjC2 && Tok.is(tok::kw___attribute))
Ted Kremenek66f2d6b2010-02-18 23:05:16 +0000937 MethodAttrs.reset(addAttributeLists(MethodAttrs.take(),
938 ParseGNUAttributes()));
Mike Stump11289f42009-09-09 15:08:12 +0000939
Fariborz Jahanian6e9e4f32009-06-24 17:00:18 +0000940 if (KeyIdents.size() == 0)
John McCall48871652010-08-21 09:40:31 +0000941 return 0;
Chris Lattner5700fab2007-10-07 02:00:24 +0000942 Selector Sel = PP.getSelectorTable().getSelector(KeyIdents.size(),
943 &KeyIdents[0]);
John McCall48871652010-08-21 09:40:31 +0000944 Decl *Result
John McCall28a6aea2009-11-04 02:18:39 +0000945 = Actions.ActOnMethodDeclaration(mLoc, Tok.getLocation(),
Fariborz Jahanian6e9e4f32009-06-24 17:00:18 +0000946 mType, IDecl, DSRet, ReturnType, Sel,
Fariborz Jahanian60462092010-04-08 00:30:06 +0000947 &ArgInfos[0],
948 CParamInfo.data(), CParamInfo.size(),
Ted Kremenekc162e8e2010-02-11 02:19:13 +0000949 MethodAttrs.get(),
Steve Naroffd8ea1ac2007-11-15 12:35:21 +0000950 MethodImplKind, isVariadic);
John McCall28a6aea2009-11-04 02:18:39 +0000951 PD.complete(Result);
Ted Kremenekc162e8e2010-02-11 02:19:13 +0000952
953 // Delete referenced AttributeList objects.
954 for (llvm::SmallVectorImpl<Action::ObjCArgInfo>::iterator
955 I = ArgInfos.begin(), E = ArgInfos.end(); I != E; ++I)
956 delete I->ArgAttrs;
957
John McCall28a6aea2009-11-04 02:18:39 +0000958 return Result;
Steve Naroff99264b42007-08-22 16:35:03 +0000959}
960
Steve Naroff1eb1ad62007-08-20 21:31:48 +0000961/// objc-protocol-refs:
962/// '<' identifier-list '>'
963///
Chris Lattnerd7352d62008-07-21 22:17:28 +0000964bool Parser::
John McCall48871652010-08-21 09:40:31 +0000965ParseObjCProtocolReferences(llvm::SmallVectorImpl<Decl *> &Protocols,
Argyrios Kyrtzidisfc1f9e42009-09-29 19:41:44 +0000966 llvm::SmallVectorImpl<SourceLocation> &ProtocolLocs,
967 bool WarnOnDeclarations,
968 SourceLocation &LAngleLoc, SourceLocation &EndLoc) {
Chris Lattner3bbae002008-07-26 04:03:38 +0000969 assert(Tok.is(tok::less) && "expected <");
Mike Stump11289f42009-09-09 15:08:12 +0000970
Argyrios Kyrtzidisfc1f9e42009-09-29 19:41:44 +0000971 LAngleLoc = ConsumeToken(); // the "<"
Mike Stump11289f42009-09-09 15:08:12 +0000972
Chris Lattner3bbae002008-07-26 04:03:38 +0000973 llvm::SmallVector<IdentifierLocPair, 8> ProtocolIdents;
Mike Stump11289f42009-09-09 15:08:12 +0000974
Chris Lattner3bbae002008-07-26 04:03:38 +0000975 while (1) {
Douglas Gregorbaf69612009-11-18 04:19:12 +0000976 if (Tok.is(tok::code_completion)) {
977 Actions.CodeCompleteObjCProtocolReferences(ProtocolIdents.data(),
978 ProtocolIdents.size());
Douglas Gregor6da3db42010-05-25 05:58:43 +0000979 ConsumeCodeCompletionToken();
Douglas Gregorbaf69612009-11-18 04:19:12 +0000980 }
981
Chris Lattner3bbae002008-07-26 04:03:38 +0000982 if (Tok.isNot(tok::identifier)) {
983 Diag(Tok, diag::err_expected_ident);
984 SkipUntil(tok::greater);
985 return true;
986 }
987 ProtocolIdents.push_back(std::make_pair(Tok.getIdentifierInfo(),
988 Tok.getLocation()));
Argyrios Kyrtzidisfc1f9e42009-09-29 19:41:44 +0000989 ProtocolLocs.push_back(Tok.getLocation());
Chris Lattner3bbae002008-07-26 04:03:38 +0000990 ConsumeToken();
Mike Stump11289f42009-09-09 15:08:12 +0000991
Chris Lattner3bbae002008-07-26 04:03:38 +0000992 if (Tok.isNot(tok::comma))
993 break;
994 ConsumeToken();
995 }
Mike Stump11289f42009-09-09 15:08:12 +0000996
Chris Lattner3bbae002008-07-26 04:03:38 +0000997 // Consume the '>'.
998 if (Tok.isNot(tok::greater)) {
999 Diag(Tok, diag::err_expected_greater);
1000 return true;
1001 }
Mike Stump11289f42009-09-09 15:08:12 +00001002
Chris Lattner3bbae002008-07-26 04:03:38 +00001003 EndLoc = ConsumeAnyToken();
Mike Stump11289f42009-09-09 15:08:12 +00001004
Chris Lattner3bbae002008-07-26 04:03:38 +00001005 // Convert the list of protocols identifiers into a list of protocol decls.
1006 Actions.FindProtocolDeclaration(WarnOnDeclarations,
1007 &ProtocolIdents[0], ProtocolIdents.size(),
1008 Protocols);
1009 return false;
1010}
1011
Steve Naroff1eb1ad62007-08-20 21:31:48 +00001012/// objc-class-instance-variables:
1013/// '{' objc-instance-variable-decl-list[opt] '}'
1014///
1015/// objc-instance-variable-decl-list:
1016/// objc-visibility-spec
1017/// objc-instance-variable-decl ';'
1018/// ';'
1019/// objc-instance-variable-decl-list objc-visibility-spec
1020/// objc-instance-variable-decl-list objc-instance-variable-decl ';'
1021/// objc-instance-variable-decl-list ';'
1022///
1023/// objc-visibility-spec:
1024/// @private
1025/// @protected
1026/// @public
Steve Naroff00433d32007-08-21 21:17:12 +00001027/// @package [OBJC2]
Steve Naroff1eb1ad62007-08-20 21:31:48 +00001028///
1029/// objc-instance-variable-decl:
Mike Stump11289f42009-09-09 15:08:12 +00001030/// struct-declaration
Steve Naroff1eb1ad62007-08-20 21:31:48 +00001031///
John McCall48871652010-08-21 09:40:31 +00001032void Parser::ParseObjCClassInstanceVariables(Decl *interfaceDecl,
Fariborz Jahanian4c172c62010-02-22 23:04:20 +00001033 tok::ObjCKeywordKind visibility,
Steve Naroff33a1e802007-10-29 21:38:07 +00001034 SourceLocation atLoc) {
Chris Lattner0ef13522007-10-09 17:51:17 +00001035 assert(Tok.is(tok::l_brace) && "expected {");
John McCall48871652010-08-21 09:40:31 +00001036 llvm::SmallVector<Decl *, 32> AllIvarDecls;
Chris Lattnera12405b2008-04-10 06:46:29 +00001037
Douglas Gregor45a33ec2009-01-12 18:45:55 +00001038 ParseScope ClassScope(this, Scope::DeclScope|Scope::ClassScope);
Douglas Gregor82ac25e2009-01-08 20:45:30 +00001039
Steve Naroff00433d32007-08-21 21:17:12 +00001040 SourceLocation LBraceLoc = ConsumeBrace(); // the "{"
Mike Stump11289f42009-09-09 15:08:12 +00001041
Steve Naroff00433d32007-08-21 21:17:12 +00001042 // While we still have something to read, read the instance variables.
Chris Lattner0ef13522007-10-09 17:51:17 +00001043 while (Tok.isNot(tok::r_brace) && Tok.isNot(tok::eof)) {
Steve Naroff00433d32007-08-21 21:17:12 +00001044 // Each iteration of this loop reads one objc-instance-variable-decl.
Mike Stump11289f42009-09-09 15:08:12 +00001045
Steve Naroff00433d32007-08-21 21:17:12 +00001046 // Check for extraneous top-level semicolon.
Chris Lattner0ef13522007-10-09 17:51:17 +00001047 if (Tok.is(tok::semi)) {
Douglas Gregor13d05682010-06-16 23:08:59 +00001048 Diag(Tok, diag::ext_extra_ivar_semi)
Douglas Gregora771f462010-03-31 17:46:05 +00001049 << FixItHint::CreateRemoval(Tok.getLocation());
Steve Naroff00433d32007-08-21 21:17:12 +00001050 ConsumeToken();
1051 continue;
1052 }
Mike Stump11289f42009-09-09 15:08:12 +00001053
Steve Naroff00433d32007-08-21 21:17:12 +00001054 // Set the default visibility to private.
Chris Lattner0ef13522007-10-09 17:51:17 +00001055 if (Tok.is(tok::at)) { // parse objc-visibility-spec
Steve Naroff00433d32007-08-21 21:17:12 +00001056 ConsumeToken(); // eat the @ sign
Douglas Gregor48d46252010-01-13 21:54:15 +00001057
1058 if (Tok.is(tok::code_completion)) {
Douglas Gregor0be31a22010-07-02 17:43:08 +00001059 Actions.CodeCompleteObjCAtVisibility(getCurScope());
Douglas Gregor6da3db42010-05-25 05:58:43 +00001060 ConsumeCodeCompletionToken();
Douglas Gregor48d46252010-01-13 21:54:15 +00001061 }
1062
Steve Naroff7c348172007-08-23 18:16:40 +00001063 switch (Tok.getObjCKeywordID()) {
Steve Naroff00433d32007-08-21 21:17:12 +00001064 case tok::objc_private:
1065 case tok::objc_public:
1066 case tok::objc_protected:
1067 case tok::objc_package:
Steve Naroff7c348172007-08-23 18:16:40 +00001068 visibility = Tok.getObjCKeywordID();
Steve Naroff00433d32007-08-21 21:17:12 +00001069 ConsumeToken();
Mike Stump11289f42009-09-09 15:08:12 +00001070 continue;
Steve Naroff00433d32007-08-21 21:17:12 +00001071 default:
1072 Diag(Tok, diag::err_objc_illegal_visibility_spec);
Steve Naroff00433d32007-08-21 21:17:12 +00001073 continue;
1074 }
1075 }
Mike Stump11289f42009-09-09 15:08:12 +00001076
Douglas Gregor48d46252010-01-13 21:54:15 +00001077 if (Tok.is(tok::code_completion)) {
Douglas Gregor0be31a22010-07-02 17:43:08 +00001078 Actions.CodeCompleteOrdinaryName(getCurScope(),
Douglas Gregor00c37ef2010-08-11 21:23:17 +00001079 Action::PCC_ObjCInstanceVariableList);
Douglas Gregor6da3db42010-05-25 05:58:43 +00001080 ConsumeCodeCompletionToken();
Douglas Gregor48d46252010-01-13 21:54:15 +00001081 }
1082
John McCallcfefb6d2009-11-03 02:38:08 +00001083 struct ObjCIvarCallback : FieldCallback {
1084 Parser &P;
John McCall48871652010-08-21 09:40:31 +00001085 Decl *IDecl;
John McCallcfefb6d2009-11-03 02:38:08 +00001086 tok::ObjCKeywordKind visibility;
John McCall48871652010-08-21 09:40:31 +00001087 llvm::SmallVectorImpl<Decl *> &AllIvarDecls;
John McCallcfefb6d2009-11-03 02:38:08 +00001088
John McCall48871652010-08-21 09:40:31 +00001089 ObjCIvarCallback(Parser &P, Decl *IDecl, tok::ObjCKeywordKind V,
1090 llvm::SmallVectorImpl<Decl *> &AllIvarDecls) :
John McCallcfefb6d2009-11-03 02:38:08 +00001091 P(P), IDecl(IDecl), visibility(V), AllIvarDecls(AllIvarDecls) {
1092 }
1093
John McCall48871652010-08-21 09:40:31 +00001094 Decl *invoke(FieldDeclarator &FD) {
John McCallcfefb6d2009-11-03 02:38:08 +00001095 // Install the declarator into the interface decl.
John McCall48871652010-08-21 09:40:31 +00001096 Decl *Field
Douglas Gregor0be31a22010-07-02 17:43:08 +00001097 = P.Actions.ActOnIvar(P.getCurScope(),
John McCallcfefb6d2009-11-03 02:38:08 +00001098 FD.D.getDeclSpec().getSourceRange().getBegin(),
1099 IDecl, FD.D, FD.BitfieldSize, visibility);
Fariborz Jahanian6a0a2e02010-04-06 22:43:48 +00001100 if (Field)
1101 AllIvarDecls.push_back(Field);
John McCallcfefb6d2009-11-03 02:38:08 +00001102 return Field;
1103 }
1104 } Callback(*this, interfaceDecl, visibility, AllIvarDecls);
Fariborz Jahanian616d3e72010-08-23 22:46:52 +00001105
Chris Lattnera12405b2008-04-10 06:46:29 +00001106 // Parse all the comma separated declarators.
1107 DeclSpec DS;
John McCallcfefb6d2009-11-03 02:38:08 +00001108 ParseStructDeclaration(DS, Callback);
Mike Stump11289f42009-09-09 15:08:12 +00001109
Chris Lattner0ef13522007-10-09 17:51:17 +00001110 if (Tok.is(tok::semi)) {
Steve Naroff00433d32007-08-21 21:17:12 +00001111 ConsumeToken();
Steve Naroff00433d32007-08-21 21:17:12 +00001112 } else {
1113 Diag(Tok, diag::err_expected_semi_decl_list);
1114 // Skip to end of block or statement
1115 SkipUntil(tok::r_brace, true, true);
1116 }
1117 }
Steve Naroff33a1e802007-10-29 21:38:07 +00001118 SourceLocation RBraceLoc = MatchRHSPunctuation(tok::r_brace, LBraceLoc);
Fariborz Jahanian616d3e72010-08-23 22:46:52 +00001119 Actions.ActOnLastBitfield(RBraceLoc, interfaceDecl, AllIvarDecls);
Steve Naroff9c4fddd2007-10-31 22:11:35 +00001120 // Call ActOnFields() even if we don't have any decls. This is useful
1121 // for code rewriting tools that need to be aware of the empty list.
Douglas Gregor0be31a22010-07-02 17:43:08 +00001122 Actions.ActOnFields(getCurScope(), atLoc, interfaceDecl,
Jay Foad7d0479f2009-05-21 09:52:38 +00001123 AllIvarDecls.data(), AllIvarDecls.size(),
Daniel Dunbar15619c72008-10-03 02:03:53 +00001124 LBraceLoc, RBraceLoc, 0);
Steve Naroff00433d32007-08-21 21:17:12 +00001125 return;
Chris Lattnerda59c2f2006-11-05 02:08:13 +00001126}
Steve Naroff1eb1ad62007-08-20 21:31:48 +00001127
1128/// objc-protocol-declaration:
1129/// objc-protocol-definition
1130/// objc-protocol-forward-reference
1131///
1132/// objc-protocol-definition:
Mike Stump11289f42009-09-09 15:08:12 +00001133/// @protocol identifier
1134/// objc-protocol-refs[opt]
1135/// objc-interface-decl-list
Steve Naroff1eb1ad62007-08-20 21:31:48 +00001136/// @end
1137///
1138/// objc-protocol-forward-reference:
1139/// @protocol identifier-list ';'
1140///
1141/// "@protocol identifier ;" should be resolved as "@protocol
Steve Naroff09bf8152007-09-06 21:24:23 +00001142/// identifier-list ;": objc-interface-decl-list may not start with a
Steve Naroff1eb1ad62007-08-20 21:31:48 +00001143/// semicolon in the first alternative if objc-protocol-refs are omitted.
John McCall48871652010-08-21 09:40:31 +00001144Decl *Parser::ParseObjCAtProtocolDeclaration(SourceLocation AtLoc,
Chris Lattner83f095c2009-03-28 19:18:32 +00001145 AttributeList *attrList) {
Steve Naroff7c348172007-08-23 18:16:40 +00001146 assert(Tok.isObjCAtKeyword(tok::objc_protocol) &&
Steve Naroff0b6a01a2007-08-22 22:17:26 +00001147 "ParseObjCAtProtocolDeclaration(): Expected @protocol");
1148 ConsumeToken(); // the "protocol" identifier
Mike Stump11289f42009-09-09 15:08:12 +00001149
Douglas Gregor5b4671c2009-11-18 04:49:41 +00001150 if (Tok.is(tok::code_completion)) {
Douglas Gregor0be31a22010-07-02 17:43:08 +00001151 Actions.CodeCompleteObjCProtocolDecl(getCurScope());
Douglas Gregor6da3db42010-05-25 05:58:43 +00001152 ConsumeCodeCompletionToken();
Douglas Gregor5b4671c2009-11-18 04:49:41 +00001153 }
1154
Chris Lattner0ef13522007-10-09 17:51:17 +00001155 if (Tok.isNot(tok::identifier)) {
Steve Naroff0b6a01a2007-08-22 22:17:26 +00001156 Diag(Tok, diag::err_expected_ident); // missing protocol name.
John McCall48871652010-08-21 09:40:31 +00001157 return 0;
Steve Naroff0b6a01a2007-08-22 22:17:26 +00001158 }
1159 // Save the protocol name, then consume it.
1160 IdentifierInfo *protocolName = Tok.getIdentifierInfo();
1161 SourceLocation nameLoc = ConsumeToken();
Mike Stump11289f42009-09-09 15:08:12 +00001162
Chris Lattner0ef13522007-10-09 17:51:17 +00001163 if (Tok.is(tok::semi)) { // forward declaration of one protocol.
Chris Lattnerd7352d62008-07-21 22:17:28 +00001164 IdentifierLocPair ProtoInfo(protocolName, nameLoc);
Steve Naroff0b6a01a2007-08-22 22:17:26 +00001165 ConsumeToken();
Mike Stump11289f42009-09-09 15:08:12 +00001166 return Actions.ActOnForwardProtocolDeclaration(AtLoc, &ProtoInfo, 1,
Fariborz Jahanian1470e932008-12-17 01:07:27 +00001167 attrList);
Steve Naroff0b6a01a2007-08-22 22:17:26 +00001168 }
Mike Stump11289f42009-09-09 15:08:12 +00001169
Chris Lattner0ef13522007-10-09 17:51:17 +00001170 if (Tok.is(tok::comma)) { // list of forward declarations.
Chris Lattnerd7352d62008-07-21 22:17:28 +00001171 llvm::SmallVector<IdentifierLocPair, 8> ProtocolRefs;
1172 ProtocolRefs.push_back(std::make_pair(protocolName, nameLoc));
1173
Steve Naroff0b6a01a2007-08-22 22:17:26 +00001174 // Parse the list of forward declarations.
Steve Naroff0b6a01a2007-08-22 22:17:26 +00001175 while (1) {
1176 ConsumeToken(); // the ','
Chris Lattner0ef13522007-10-09 17:51:17 +00001177 if (Tok.isNot(tok::identifier)) {
Steve Naroff0b6a01a2007-08-22 22:17:26 +00001178 Diag(Tok, diag::err_expected_ident);
1179 SkipUntil(tok::semi);
John McCall48871652010-08-21 09:40:31 +00001180 return 0;
Steve Naroff0b6a01a2007-08-22 22:17:26 +00001181 }
Chris Lattnerd7352d62008-07-21 22:17:28 +00001182 ProtocolRefs.push_back(IdentifierLocPair(Tok.getIdentifierInfo(),
1183 Tok.getLocation()));
Steve Naroff0b6a01a2007-08-22 22:17:26 +00001184 ConsumeToken(); // the identifier
Mike Stump11289f42009-09-09 15:08:12 +00001185
Chris Lattner0ef13522007-10-09 17:51:17 +00001186 if (Tok.isNot(tok::comma))
Steve Naroff0b6a01a2007-08-22 22:17:26 +00001187 break;
1188 }
1189 // Consume the ';'.
1190 if (ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@protocol"))
John McCall48871652010-08-21 09:40:31 +00001191 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001192
Steve Naroff93eb5f12007-10-10 17:32:04 +00001193 return Actions.ActOnForwardProtocolDeclaration(AtLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001194 &ProtocolRefs[0],
Fariborz Jahanian1470e932008-12-17 01:07:27 +00001195 ProtocolRefs.size(),
1196 attrList);
Chris Lattnerd7352d62008-07-21 22:17:28 +00001197 }
Mike Stump11289f42009-09-09 15:08:12 +00001198
Steve Naroff0b6a01a2007-08-22 22:17:26 +00001199 // Last, and definitely not least, parse a protocol declaration.
Argyrios Kyrtzidisfc1f9e42009-09-29 19:41:44 +00001200 SourceLocation LAngleLoc, EndProtoLoc;
Chris Lattnerd7352d62008-07-21 22:17:28 +00001201
John McCall48871652010-08-21 09:40:31 +00001202 llvm::SmallVector<Decl *, 8> ProtocolRefs;
Argyrios Kyrtzidisfc1f9e42009-09-29 19:41:44 +00001203 llvm::SmallVector<SourceLocation, 8> ProtocolLocs;
Chris Lattnerd7352d62008-07-21 22:17:28 +00001204 if (Tok.is(tok::less) &&
Argyrios Kyrtzidisfc1f9e42009-09-29 19:41:44 +00001205 ParseObjCProtocolReferences(ProtocolRefs, ProtocolLocs, false,
1206 LAngleLoc, EndProtoLoc))
John McCall48871652010-08-21 09:40:31 +00001207 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001208
John McCall48871652010-08-21 09:40:31 +00001209 Decl *ProtoType =
Chris Lattner3bbae002008-07-26 04:03:38 +00001210 Actions.ActOnStartProtocolInterface(AtLoc, protocolName, nameLoc,
Jay Foad7d0479f2009-05-21 09:52:38 +00001211 ProtocolRefs.data(),
1212 ProtocolRefs.size(),
Douglas Gregor002b6712010-01-16 15:02:53 +00001213 ProtocolLocs.data(),
Daniel Dunbar26e2ab42008-09-26 04:48:09 +00001214 EndProtoLoc, attrList);
Fariborz Jahanian39d641f2007-09-17 21:07:36 +00001215 ParseObjCInterfaceDeclList(ProtoType, tok::objc_protocol);
Chris Lattnerda9fb152008-10-20 06:10:06 +00001216 return ProtoType;
Chris Lattnerda59c2f2006-11-05 02:08:13 +00001217}
Steve Naroff1eb1ad62007-08-20 21:31:48 +00001218
1219/// objc-implementation:
1220/// objc-class-implementation-prologue
1221/// objc-category-implementation-prologue
1222///
1223/// objc-class-implementation-prologue:
1224/// @implementation identifier objc-superclass[opt]
1225/// objc-class-instance-variables[opt]
1226///
1227/// objc-category-implementation-prologue:
1228/// @implementation identifier ( identifier )
John McCall48871652010-08-21 09:40:31 +00001229Decl *Parser::ParseObjCAtImplementationDeclaration(
Fariborz Jahanian53cacae2007-09-01 00:26:16 +00001230 SourceLocation atLoc) {
1231 assert(Tok.isObjCAtKeyword(tok::objc_implementation) &&
1232 "ParseObjCAtImplementationDeclaration(): Expected @implementation");
1233 ConsumeToken(); // the "implementation" identifier
Mike Stump11289f42009-09-09 15:08:12 +00001234
Douglas Gregor49c22a72009-11-18 16:26:39 +00001235 // Code completion after '@implementation'.
1236 if (Tok.is(tok::code_completion)) {
Douglas Gregor0be31a22010-07-02 17:43:08 +00001237 Actions.CodeCompleteObjCImplementationDecl(getCurScope());
Douglas Gregor6da3db42010-05-25 05:58:43 +00001238 ConsumeCodeCompletionToken();
Douglas Gregor49c22a72009-11-18 16:26:39 +00001239 }
1240
Chris Lattner0ef13522007-10-09 17:51:17 +00001241 if (Tok.isNot(tok::identifier)) {
Fariborz Jahanian53cacae2007-09-01 00:26:16 +00001242 Diag(Tok, diag::err_expected_ident); // missing class or category name.
John McCall48871652010-08-21 09:40:31 +00001243 return 0;
Fariborz Jahanian53cacae2007-09-01 00:26:16 +00001244 }
1245 // We have a class or category name - consume it.
Fariborz Jahanianbfe13c52007-09-25 18:38:09 +00001246 IdentifierInfo *nameId = Tok.getIdentifierInfo();
Fariborz Jahanian53cacae2007-09-01 00:26:16 +00001247 SourceLocation nameLoc = ConsumeToken(); // consume class or category name
Mike Stump11289f42009-09-09 15:08:12 +00001248
1249 if (Tok.is(tok::l_paren)) {
Fariborz Jahanian53cacae2007-09-01 00:26:16 +00001250 // we have a category implementation.
1251 SourceLocation lparenLoc = ConsumeParen();
1252 SourceLocation categoryLoc, rparenLoc;
1253 IdentifierInfo *categoryId = 0;
Mike Stump11289f42009-09-09 15:08:12 +00001254
Douglas Gregor5d34fd32009-11-18 19:08:43 +00001255 if (Tok.is(tok::code_completion)) {
Douglas Gregor0be31a22010-07-02 17:43:08 +00001256 Actions.CodeCompleteObjCImplementationCategory(getCurScope(), nameId, nameLoc);
Douglas Gregor6da3db42010-05-25 05:58:43 +00001257 ConsumeCodeCompletionToken();
Douglas Gregor5d34fd32009-11-18 19:08:43 +00001258 }
1259
Chris Lattner0ef13522007-10-09 17:51:17 +00001260 if (Tok.is(tok::identifier)) {
Fariborz Jahanian53cacae2007-09-01 00:26:16 +00001261 categoryId = Tok.getIdentifierInfo();
1262 categoryLoc = ConsumeToken();
1263 } else {
1264 Diag(Tok, diag::err_expected_ident); // missing category name.
John McCall48871652010-08-21 09:40:31 +00001265 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001266 }
Chris Lattner0ef13522007-10-09 17:51:17 +00001267 if (Tok.isNot(tok::r_paren)) {
Fariborz Jahanian53cacae2007-09-01 00:26:16 +00001268 Diag(Tok, diag::err_expected_rparen);
1269 SkipUntil(tok::r_paren, false); // don't stop at ';'
John McCall48871652010-08-21 09:40:31 +00001270 return 0;
Fariborz Jahanian53cacae2007-09-01 00:26:16 +00001271 }
1272 rparenLoc = ConsumeParen();
John McCall48871652010-08-21 09:40:31 +00001273 Decl *ImplCatType = Actions.ActOnStartCategoryImplementation(
Mike Stump11289f42009-09-09 15:08:12 +00001274 atLoc, nameId, nameLoc, categoryId,
Fariborz Jahanian89b8ef92007-10-02 16:38:50 +00001275 categoryLoc);
Ted Kremenek1b0ea822008-01-07 19:49:32 +00001276 ObjCImpDecl = ImplCatType;
Fariborz Jahanian9290ede2009-11-16 18:57:01 +00001277 PendingObjCImpDecl.push_back(ObjCImpDecl);
John McCall48871652010-08-21 09:40:31 +00001278 return 0;
Fariborz Jahanian53cacae2007-09-01 00:26:16 +00001279 }
1280 // We have a class implementation
Fariborz Jahanianbfe13c52007-09-25 18:38:09 +00001281 SourceLocation superClassLoc;
1282 IdentifierInfo *superClassId = 0;
Chris Lattner0ef13522007-10-09 17:51:17 +00001283 if (Tok.is(tok::colon)) {
Fariborz Jahanian53cacae2007-09-01 00:26:16 +00001284 // We have a super class
1285 ConsumeToken();
Chris Lattner0ef13522007-10-09 17:51:17 +00001286 if (Tok.isNot(tok::identifier)) {
Fariborz Jahanian53cacae2007-09-01 00:26:16 +00001287 Diag(Tok, diag::err_expected_ident); // missing super class name.
John McCall48871652010-08-21 09:40:31 +00001288 return 0;
Fariborz Jahanian53cacae2007-09-01 00:26:16 +00001289 }
Fariborz Jahanianbfe13c52007-09-25 18:38:09 +00001290 superClassId = Tok.getIdentifierInfo();
1291 superClassLoc = ConsumeToken(); // Consume super class name
Fariborz Jahanian53cacae2007-09-01 00:26:16 +00001292 }
John McCall48871652010-08-21 09:40:31 +00001293 Decl *ImplClsType = Actions.ActOnStartClassImplementation(
Chris Lattner5e530bc2007-12-27 19:57:00 +00001294 atLoc, nameId, nameLoc,
Fariborz Jahanianbfe13c52007-09-25 18:38:09 +00001295 superClassId, superClassLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001296
Steve Naroff33a1e802007-10-29 21:38:07 +00001297 if (Tok.is(tok::l_brace)) // we have ivars
Fariborz Jahanian4c172c62010-02-22 23:04:20 +00001298 ParseObjCClassInstanceVariables(ImplClsType/*FIXME*/,
Fariborz Jahaniana9effb52010-03-22 19:04:14 +00001299 tok::objc_private, atLoc);
Ted Kremenek1b0ea822008-01-07 19:49:32 +00001300 ObjCImpDecl = ImplClsType;
Fariborz Jahanian9290ede2009-11-16 18:57:01 +00001301 PendingObjCImpDecl.push_back(ObjCImpDecl);
1302
John McCall48871652010-08-21 09:40:31 +00001303 return 0;
Chris Lattnerda59c2f2006-11-05 02:08:13 +00001304}
Steve Naroff33a1e802007-10-29 21:38:07 +00001305
John McCall48871652010-08-21 09:40:31 +00001306Decl *Parser::ParseObjCAtEndDeclaration(SourceRange atEnd) {
Fariborz Jahanian53cacae2007-09-01 00:26:16 +00001307 assert(Tok.isObjCAtKeyword(tok::objc_end) &&
1308 "ParseObjCAtEndDeclaration(): Expected @end");
John McCall48871652010-08-21 09:40:31 +00001309 Decl *Result = ObjCImpDecl;
Fariborz Jahanian53cacae2007-09-01 00:26:16 +00001310 ConsumeToken(); // the "end" identifier
Fariborz Jahanianb8d091c2009-03-04 22:30:12 +00001311 if (ObjCImpDecl) {
Douglas Gregor0be31a22010-07-02 17:43:08 +00001312 Actions.ActOnAtEnd(getCurScope(), atEnd, ObjCImpDecl);
John McCall48871652010-08-21 09:40:31 +00001313 ObjCImpDecl = 0;
Fariborz Jahanian9290ede2009-11-16 18:57:01 +00001314 PendingObjCImpDecl.pop_back();
Fariborz Jahanianb8d091c2009-03-04 22:30:12 +00001315 }
Ted Kremenekc7c64312010-01-07 01:20:12 +00001316 else {
1317 // missing @implementation
1318 Diag(atEnd.getBegin(), diag::warn_expected_implementation);
1319 }
Fariborz Jahanianb8d091c2009-03-04 22:30:12 +00001320 return Result;
Steve Naroff1eb1ad62007-08-20 21:31:48 +00001321}
Fariborz Jahaniand8e12d32007-09-04 19:26:51 +00001322
Fariborz Jahanian6e7e8cc2010-07-22 18:24:20 +00001323Parser::DeclGroupPtrTy Parser::FinishPendingObjCActions() {
1324 Actions.DiagnoseUseOfUnimplementedSelectors();
Fariborz Jahanian9290ede2009-11-16 18:57:01 +00001325 if (PendingObjCImpDecl.empty())
John McCall48871652010-08-21 09:40:31 +00001326 return Actions.ConvertDeclToDeclGroup(0);
1327 Decl *ImpDecl = PendingObjCImpDecl.pop_back_val();
Douglas Gregor0be31a22010-07-02 17:43:08 +00001328 Actions.ActOnAtEnd(getCurScope(), SourceRange(), ImpDecl);
Fariborz Jahanian9290ede2009-11-16 18:57:01 +00001329 return Actions.ConvertDeclToDeclGroup(ImpDecl);
1330}
1331
Fariborz Jahaniand8e12d32007-09-04 19:26:51 +00001332/// compatibility-alias-decl:
1333/// @compatibility_alias alias-name class-name ';'
1334///
John McCall48871652010-08-21 09:40:31 +00001335Decl *Parser::ParseObjCAtAliasDeclaration(SourceLocation atLoc) {
Fariborz Jahaniand8e12d32007-09-04 19:26:51 +00001336 assert(Tok.isObjCAtKeyword(tok::objc_compatibility_alias) &&
1337 "ParseObjCAtAliasDeclaration(): Expected @compatibility_alias");
1338 ConsumeToken(); // consume compatibility_alias
Chris Lattner0ef13522007-10-09 17:51:17 +00001339 if (Tok.isNot(tok::identifier)) {
Fariborz Jahaniand8e12d32007-09-04 19:26:51 +00001340 Diag(Tok, diag::err_expected_ident);
John McCall48871652010-08-21 09:40:31 +00001341 return 0;
Fariborz Jahaniand8e12d32007-09-04 19:26:51 +00001342 }
Fariborz Jahanian49c64252007-10-11 23:42:27 +00001343 IdentifierInfo *aliasId = Tok.getIdentifierInfo();
1344 SourceLocation aliasLoc = ConsumeToken(); // consume alias-name
Chris Lattner0ef13522007-10-09 17:51:17 +00001345 if (Tok.isNot(tok::identifier)) {
Fariborz Jahaniand8e12d32007-09-04 19:26:51 +00001346 Diag(Tok, diag::err_expected_ident);
John McCall48871652010-08-21 09:40:31 +00001347 return 0;
Fariborz Jahaniand8e12d32007-09-04 19:26:51 +00001348 }
Fariborz Jahanian49c64252007-10-11 23:42:27 +00001349 IdentifierInfo *classId = Tok.getIdentifierInfo();
1350 SourceLocation classLoc = ConsumeToken(); // consume class-name;
1351 if (Tok.isNot(tok::semi)) {
Chris Lattner6d29c102008-11-18 07:48:38 +00001352 Diag(Tok, diag::err_expected_semi_after) << "@compatibility_alias";
John McCall48871652010-08-21 09:40:31 +00001353 return 0;
Fariborz Jahanian49c64252007-10-11 23:42:27 +00001354 }
Chris Lattner83f095c2009-03-28 19:18:32 +00001355 return Actions.ActOnCompatiblityAlias(atLoc, aliasId, aliasLoc,
1356 classId, classLoc);
Chris Lattnerda59c2f2006-11-05 02:08:13 +00001357}
1358
Fariborz Jahanian53cacae2007-09-01 00:26:16 +00001359/// property-synthesis:
1360/// @synthesize property-ivar-list ';'
1361///
1362/// property-ivar-list:
1363/// property-ivar
1364/// property-ivar-list ',' property-ivar
1365///
1366/// property-ivar:
1367/// identifier
1368/// identifier '=' identifier
1369///
John McCall48871652010-08-21 09:40:31 +00001370Decl *Parser::ParseObjCPropertySynthesize(SourceLocation atLoc) {
Fariborz Jahanian53cacae2007-09-01 00:26:16 +00001371 assert(Tok.isObjCAtKeyword(tok::objc_synthesize) &&
1372 "ParseObjCPropertyDynamic(): Expected '@synthesize'");
Fariborz Jahanianffe97a32008-04-18 00:19:30 +00001373 SourceLocation loc = ConsumeToken(); // consume synthesize
Mike Stump11289f42009-09-09 15:08:12 +00001374
Douglas Gregor88e72a02009-11-18 19:45:45 +00001375 while (true) {
Douglas Gregor5d649882009-11-18 22:32:06 +00001376 if (Tok.is(tok::code_completion)) {
Douglas Gregor0be31a22010-07-02 17:43:08 +00001377 Actions.CodeCompleteObjCPropertyDefinition(getCurScope(), ObjCImpDecl);
Douglas Gregor6da3db42010-05-25 05:58:43 +00001378 ConsumeCodeCompletionToken();
Douglas Gregor5d649882009-11-18 22:32:06 +00001379 }
1380
Douglas Gregor88e72a02009-11-18 19:45:45 +00001381 if (Tok.isNot(tok::identifier)) {
1382 Diag(Tok, diag::err_synthesized_property_name);
1383 SkipUntil(tok::semi);
John McCall48871652010-08-21 09:40:31 +00001384 return 0;
Douglas Gregor88e72a02009-11-18 19:45:45 +00001385 }
1386
Fariborz Jahanianffe97a32008-04-18 00:19:30 +00001387 IdentifierInfo *propertyIvar = 0;
1388 IdentifierInfo *propertyId = Tok.getIdentifierInfo();
1389 SourceLocation propertyLoc = ConsumeToken(); // consume property name
Chris Lattner0ef13522007-10-09 17:51:17 +00001390 if (Tok.is(tok::equal)) {
Fariborz Jahanian53cacae2007-09-01 00:26:16 +00001391 // property '=' ivar-name
1392 ConsumeToken(); // consume '='
Douglas Gregor5d649882009-11-18 22:32:06 +00001393
1394 if (Tok.is(tok::code_completion)) {
Douglas Gregor0be31a22010-07-02 17:43:08 +00001395 Actions.CodeCompleteObjCPropertySynthesizeIvar(getCurScope(), propertyId,
Douglas Gregor5d649882009-11-18 22:32:06 +00001396 ObjCImpDecl);
Douglas Gregor6da3db42010-05-25 05:58:43 +00001397 ConsumeCodeCompletionToken();
Douglas Gregor5d649882009-11-18 22:32:06 +00001398 }
1399
Chris Lattner0ef13522007-10-09 17:51:17 +00001400 if (Tok.isNot(tok::identifier)) {
Fariborz Jahanian53cacae2007-09-01 00:26:16 +00001401 Diag(Tok, diag::err_expected_ident);
1402 break;
1403 }
Fariborz Jahanianffe97a32008-04-18 00:19:30 +00001404 propertyIvar = Tok.getIdentifierInfo();
Fariborz Jahanian53cacae2007-09-01 00:26:16 +00001405 ConsumeToken(); // consume ivar-name
1406 }
Douglas Gregor0be31a22010-07-02 17:43:08 +00001407 Actions.ActOnPropertyImplDecl(getCurScope(), atLoc, propertyLoc, true, ObjCImpDecl,
Fariborz Jahanianffe97a32008-04-18 00:19:30 +00001408 propertyId, propertyIvar);
Chris Lattner0ef13522007-10-09 17:51:17 +00001409 if (Tok.isNot(tok::comma))
Fariborz Jahanian53cacae2007-09-01 00:26:16 +00001410 break;
1411 ConsumeToken(); // consume ','
1412 }
Douglas Gregor88e72a02009-11-18 19:45:45 +00001413 if (Tok.isNot(tok::semi)) {
Chris Lattner6d29c102008-11-18 07:48:38 +00001414 Diag(Tok, diag::err_expected_semi_after) << "@synthesize";
Douglas Gregor88e72a02009-11-18 19:45:45 +00001415 SkipUntil(tok::semi);
1416 }
Fariborz Jahanian95239112009-11-06 21:48:47 +00001417 else
1418 ConsumeToken(); // consume ';'
John McCall48871652010-08-21 09:40:31 +00001419 return 0;
Chris Lattnerda59c2f2006-11-05 02:08:13 +00001420}
1421
Fariborz Jahanian53cacae2007-09-01 00:26:16 +00001422/// property-dynamic:
1423/// @dynamic property-list
1424///
1425/// property-list:
1426/// identifier
1427/// property-list ',' identifier
1428///
John McCall48871652010-08-21 09:40:31 +00001429Decl *Parser::ParseObjCPropertyDynamic(SourceLocation atLoc) {
Fariborz Jahanian53cacae2007-09-01 00:26:16 +00001430 assert(Tok.isObjCAtKeyword(tok::objc_dynamic) &&
1431 "ParseObjCPropertyDynamic(): Expected '@dynamic'");
1432 SourceLocation loc = ConsumeToken(); // consume dynamic
Douglas Gregor52e78bd2009-11-18 22:56:13 +00001433 while (true) {
1434 if (Tok.is(tok::code_completion)) {
Douglas Gregor0be31a22010-07-02 17:43:08 +00001435 Actions.CodeCompleteObjCPropertyDefinition(getCurScope(), ObjCImpDecl);
Douglas Gregor6da3db42010-05-25 05:58:43 +00001436 ConsumeCodeCompletionToken();
Douglas Gregor52e78bd2009-11-18 22:56:13 +00001437 }
1438
1439 if (Tok.isNot(tok::identifier)) {
1440 Diag(Tok, diag::err_expected_ident);
1441 SkipUntil(tok::semi);
John McCall48871652010-08-21 09:40:31 +00001442 return 0;
Douglas Gregor52e78bd2009-11-18 22:56:13 +00001443 }
1444
Fariborz Jahanianf2a7d7c2008-04-21 21:05:54 +00001445 IdentifierInfo *propertyId = Tok.getIdentifierInfo();
1446 SourceLocation propertyLoc = ConsumeToken(); // consume property name
Douglas Gregor0be31a22010-07-02 17:43:08 +00001447 Actions.ActOnPropertyImplDecl(getCurScope(), atLoc, propertyLoc, false, ObjCImpDecl,
Fariborz Jahanianf2a7d7c2008-04-21 21:05:54 +00001448 propertyId, 0);
1449
Chris Lattner0ef13522007-10-09 17:51:17 +00001450 if (Tok.isNot(tok::comma))
Fariborz Jahanian53cacae2007-09-01 00:26:16 +00001451 break;
1452 ConsumeToken(); // consume ','
1453 }
Fariborz Jahanianb5795c02010-04-14 20:52:42 +00001454 if (Tok.isNot(tok::semi)) {
Chris Lattner6d29c102008-11-18 07:48:38 +00001455 Diag(Tok, diag::err_expected_semi_after) << "@dynamic";
Fariborz Jahanianb5795c02010-04-14 20:52:42 +00001456 SkipUntil(tok::semi);
1457 }
1458 else
1459 ConsumeToken(); // consume ';'
John McCall48871652010-08-21 09:40:31 +00001460 return 0;
Fariborz Jahanian53cacae2007-09-01 00:26:16 +00001461}
Mike Stump11289f42009-09-09 15:08:12 +00001462
Fariborz Jahanian62fd2b42007-09-19 19:14:32 +00001463/// objc-throw-statement:
1464/// throw expression[opt];
1465///
John McCalldadc5752010-08-24 06:29:42 +00001466StmtResult Parser::ParseObjCThrowStmt(SourceLocation atLoc) {
1467 ExprResult Res;
Fariborz Jahanian62fd2b42007-09-19 19:14:32 +00001468 ConsumeToken(); // consume throw
Chris Lattner0ef13522007-10-09 17:51:17 +00001469 if (Tok.isNot(tok::semi)) {
Fariborz Jahanianadfbbc32007-11-07 02:00:49 +00001470 Res = ParseExpression();
Sebastian Redl17f2c7d2008-12-09 13:15:23 +00001471 if (Res.isInvalid()) {
Fariborz Jahanian62fd2b42007-09-19 19:14:32 +00001472 SkipUntil(tok::semi);
Sebastian Redlbab9a4b2008-12-11 20:12:42 +00001473 return StmtError();
Fariborz Jahanian62fd2b42007-09-19 19:14:32 +00001474 }
1475 }
Ted Kremenek15a81e52010-04-20 21:21:51 +00001476 // consume ';'
1477 ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@throw");
John McCallb268a282010-08-23 23:25:46 +00001478 return Actions.ActOnObjCAtThrowStmt(atLoc, Res.take(), getCurScope());
Fariborz Jahanian62fd2b42007-09-19 19:14:32 +00001479}
1480
Fariborz Jahanianf89ca382008-01-29 18:21:32 +00001481/// objc-synchronized-statement:
Fariborz Jahanian049fa582008-01-30 17:38:29 +00001482/// @synchronized '(' expression ')' compound-statement
Fariborz Jahanianf89ca382008-01-29 18:21:32 +00001483///
John McCalldadc5752010-08-24 06:29:42 +00001484StmtResult
Sebastian Redlbab9a4b2008-12-11 20:12:42 +00001485Parser::ParseObjCSynchronizedStmt(SourceLocation atLoc) {
Fariborz Jahanian48085b82008-01-29 19:14:59 +00001486 ConsumeToken(); // consume synchronized
1487 if (Tok.isNot(tok::l_paren)) {
Chris Lattner6d29c102008-11-18 07:48:38 +00001488 Diag(Tok, diag::err_expected_lparen_after) << "@synchronized";
Sebastian Redlbab9a4b2008-12-11 20:12:42 +00001489 return StmtError();
Fariborz Jahanian48085b82008-01-29 19:14:59 +00001490 }
1491 ConsumeParen(); // '('
John McCalldadc5752010-08-24 06:29:42 +00001492 ExprResult Res(ParseExpression());
Sebastian Redl17f2c7d2008-12-09 13:15:23 +00001493 if (Res.isInvalid()) {
Fariborz Jahanian48085b82008-01-29 19:14:59 +00001494 SkipUntil(tok::semi);
Sebastian Redlbab9a4b2008-12-11 20:12:42 +00001495 return StmtError();
Fariborz Jahanian48085b82008-01-29 19:14:59 +00001496 }
1497 if (Tok.isNot(tok::r_paren)) {
Chris Lattner6d29c102008-11-18 07:48:38 +00001498 Diag(Tok, diag::err_expected_lbrace);
Sebastian Redlbab9a4b2008-12-11 20:12:42 +00001499 return StmtError();
Fariborz Jahanian48085b82008-01-29 19:14:59 +00001500 }
1501 ConsumeParen(); // ')'
Fariborz Jahanian049fa582008-01-30 17:38:29 +00001502 if (Tok.isNot(tok::l_brace)) {
Chris Lattner6d29c102008-11-18 07:48:38 +00001503 Diag(Tok, diag::err_expected_lbrace);
Sebastian Redlbab9a4b2008-12-11 20:12:42 +00001504 return StmtError();
Fariborz Jahanian049fa582008-01-30 17:38:29 +00001505 }
Steve Naroffd9c26072008-06-04 20:36:13 +00001506 // Enter a scope to hold everything within the compound stmt. Compound
1507 // statements can always hold declarations.
Douglas Gregor7307d6c2008-12-10 06:34:36 +00001508 ParseScope BodyScope(this, Scope::DeclScope);
Steve Naroffd9c26072008-06-04 20:36:13 +00001509
John McCalldadc5752010-08-24 06:29:42 +00001510 StmtResult SynchBody(ParseCompoundStatementBody());
Sebastian Redl17f2c7d2008-12-09 13:15:23 +00001511
Douglas Gregor7307d6c2008-12-10 06:34:36 +00001512 BodyScope.Exit();
Sebastian Redl17f2c7d2008-12-09 13:15:23 +00001513 if (SynchBody.isInvalid())
Fariborz Jahanian48085b82008-01-29 19:14:59 +00001514 SynchBody = Actions.ActOnNullStmt(Tok.getLocation());
John McCallb268a282010-08-23 23:25:46 +00001515 return Actions.ActOnObjCAtSynchronizedStmt(atLoc, Res.take(), SynchBody.take());
Fariborz Jahanianf89ca382008-01-29 18:21:32 +00001516}
1517
Fariborz Jahanian62fd2b42007-09-19 19:14:32 +00001518/// objc-try-catch-statement:
1519/// @try compound-statement objc-catch-list[opt]
1520/// @try compound-statement objc-catch-list[opt] @finally compound-statement
1521///
1522/// objc-catch-list:
1523/// @catch ( parameter-declaration ) compound-statement
1524/// objc-catch-list @catch ( catch-parameter-declaration ) compound-statement
1525/// catch-parameter-declaration:
1526/// parameter-declaration
1527/// '...' [OBJC2]
1528///
John McCalldadc5752010-08-24 06:29:42 +00001529StmtResult Parser::ParseObjCTryStmt(SourceLocation atLoc) {
Fariborz Jahanian62fd2b42007-09-19 19:14:32 +00001530 bool catch_or_finally_seen = false;
Sebastian Redlbab9a4b2008-12-11 20:12:42 +00001531
Fariborz Jahanian62fd2b42007-09-19 19:14:32 +00001532 ConsumeToken(); // consume try
Chris Lattner0ef13522007-10-09 17:51:17 +00001533 if (Tok.isNot(tok::l_brace)) {
Chris Lattner6d29c102008-11-18 07:48:38 +00001534 Diag(Tok, diag::err_expected_lbrace);
Sebastian Redlbab9a4b2008-12-11 20:12:42 +00001535 return StmtError();
Fariborz Jahanian62fd2b42007-09-19 19:14:32 +00001536 }
Douglas Gregor96c79492010-04-23 22:50:49 +00001537 StmtVector CatchStmts(Actions);
John McCalldadc5752010-08-24 06:29:42 +00001538 StmtResult FinallyStmt;
Douglas Gregor7307d6c2008-12-10 06:34:36 +00001539 ParseScope TryScope(this, Scope::DeclScope);
John McCalldadc5752010-08-24 06:29:42 +00001540 StmtResult TryBody(ParseCompoundStatementBody());
Douglas Gregor7307d6c2008-12-10 06:34:36 +00001541 TryScope.Exit();
Sebastian Redl17f2c7d2008-12-09 13:15:23 +00001542 if (TryBody.isInvalid())
Fariborz Jahanianf859ef22007-11-02 15:39:31 +00001543 TryBody = Actions.ActOnNullStmt(Tok.getLocation());
Sebastian Redl511ed552008-11-25 22:21:31 +00001544
Chris Lattner0ef13522007-10-09 17:51:17 +00001545 while (Tok.is(tok::at)) {
Chris Lattner3e468322008-03-10 06:06:04 +00001546 // At this point, we need to lookahead to determine if this @ is the start
1547 // of an @catch or @finally. We don't want to consume the @ token if this
1548 // is an @try or @encode or something else.
1549 Token AfterAt = GetLookAheadToken(1);
1550 if (!AfterAt.isObjCAtKeyword(tok::objc_catch) &&
1551 !AfterAt.isObjCAtKeyword(tok::objc_finally))
1552 break;
Sebastian Redl17f2c7d2008-12-09 13:15:23 +00001553
Fariborz Jahanian71234d82007-11-02 00:18:53 +00001554 SourceLocation AtCatchFinallyLoc = ConsumeToken();
Chris Lattner5e530bc2007-12-27 19:57:00 +00001555 if (Tok.isObjCAtKeyword(tok::objc_catch)) {
John McCall48871652010-08-21 09:40:31 +00001556 Decl *FirstPart = 0;
Fariborz Jahanian9e63b982007-11-01 23:59:59 +00001557 ConsumeToken(); // consume catch
Chris Lattner0ef13522007-10-09 17:51:17 +00001558 if (Tok.is(tok::l_paren)) {
Fariborz Jahanian62fd2b42007-09-19 19:14:32 +00001559 ConsumeParen();
Steve Naroff5ee2c022009-02-11 20:05:44 +00001560 ParseScope CatchScope(this, Scope::DeclScope|Scope::AtCatchScope);
Chris Lattner0ef13522007-10-09 17:51:17 +00001561 if (Tok.isNot(tok::ellipsis)) {
Fariborz Jahanian62fd2b42007-09-19 19:14:32 +00001562 DeclSpec DS;
1563 ParseDeclarationSpecifiers(DS);
Sebastian Redlbab9a4b2008-12-11 20:12:42 +00001564 // For some odd reason, the name of the exception variable is
Mike Stump11289f42009-09-09 15:08:12 +00001565 // optional. As a result, we need to use "PrototypeContext", because
Steve Naroff371b8fb2009-03-03 19:52:17 +00001566 // we must accept either 'declarator' or 'abstract-declarator' here.
1567 Declarator ParmDecl(DS, Declarator::PrototypeContext);
1568 ParseDeclarator(ParmDecl);
1569
Douglas Gregore11ee112010-04-23 23:01:43 +00001570 // Inform the actions module about the declarator, so it
Steve Naroff371b8fb2009-03-03 19:52:17 +00001571 // gets added to the current scope.
Douglas Gregor0be31a22010-07-02 17:43:08 +00001572 FirstPart = Actions.ActOnObjCExceptionDecl(getCurScope(), ParmDecl);
Steve Naroffe6016792008-02-05 21:27:35 +00001573 } else
Fariborz Jahanian62fd2b42007-09-19 19:14:32 +00001574 ConsumeToken(); // consume '...'
Mike Stump11289f42009-09-09 15:08:12 +00001575
Steve Naroff65a00892009-04-07 22:56:58 +00001576 SourceLocation RParenLoc;
Mike Stump11289f42009-09-09 15:08:12 +00001577
Steve Naroff65a00892009-04-07 22:56:58 +00001578 if (Tok.is(tok::r_paren))
1579 RParenLoc = ConsumeParen();
1580 else // Skip over garbage, until we get to ')'. Eat the ')'.
1581 SkipUntil(tok::r_paren, true, false);
1582
John McCalldadc5752010-08-24 06:29:42 +00001583 StmtResult CatchBody(true);
Chris Lattner99a59b62008-02-14 19:27:54 +00001584 if (Tok.is(tok::l_brace))
1585 CatchBody = ParseCompoundStatementBody();
1586 else
1587 Diag(Tok, diag::err_expected_lbrace);
Sebastian Redl17f2c7d2008-12-09 13:15:23 +00001588 if (CatchBody.isInvalid())
Fariborz Jahanian9e63b982007-11-01 23:59:59 +00001589 CatchBody = Actions.ActOnNullStmt(Tok.getLocation());
Douglas Gregor96c79492010-04-23 22:50:49 +00001590
John McCalldadc5752010-08-24 06:29:42 +00001591 StmtResult Catch = Actions.ActOnObjCAtCatchStmt(AtCatchFinallyLoc,
Douglas Gregor96c79492010-04-23 22:50:49 +00001592 RParenLoc,
1593 FirstPart,
John McCallb268a282010-08-23 23:25:46 +00001594 CatchBody.take());
Douglas Gregor96c79492010-04-23 22:50:49 +00001595 if (!Catch.isInvalid())
1596 CatchStmts.push_back(Catch.release());
1597
Steve Naroffe6016792008-02-05 21:27:35 +00001598 } else {
Chris Lattner6d29c102008-11-18 07:48:38 +00001599 Diag(AtCatchFinallyLoc, diag::err_expected_lparen_after)
1600 << "@catch clause";
Sebastian Redlbab9a4b2008-12-11 20:12:42 +00001601 return StmtError();
Fariborz Jahanian62fd2b42007-09-19 19:14:32 +00001602 }
1603 catch_or_finally_seen = true;
Chris Lattner3e468322008-03-10 06:06:04 +00001604 } else {
1605 assert(Tok.isObjCAtKeyword(tok::objc_finally) && "Lookahead confused?");
Steve Naroffe6016792008-02-05 21:27:35 +00001606 ConsumeToken(); // consume finally
Douglas Gregor7307d6c2008-12-10 06:34:36 +00001607 ParseScope FinallyScope(this, Scope::DeclScope);
Sebastian Redl17f2c7d2008-12-09 13:15:23 +00001608
John McCalldadc5752010-08-24 06:29:42 +00001609 StmtResult FinallyBody(true);
Chris Lattner99a59b62008-02-14 19:27:54 +00001610 if (Tok.is(tok::l_brace))
1611 FinallyBody = ParseCompoundStatementBody();
1612 else
1613 Diag(Tok, diag::err_expected_lbrace);
Sebastian Redl17f2c7d2008-12-09 13:15:23 +00001614 if (FinallyBody.isInvalid())
Fariborz Jahanian71234d82007-11-02 00:18:53 +00001615 FinallyBody = Actions.ActOnNullStmt(Tok.getLocation());
Sebastian Redl17f2c7d2008-12-09 13:15:23 +00001616 FinallyStmt = Actions.ActOnObjCAtFinallyStmt(AtCatchFinallyLoc,
John McCallb268a282010-08-23 23:25:46 +00001617 FinallyBody.take());
Fariborz Jahanian62fd2b42007-09-19 19:14:32 +00001618 catch_or_finally_seen = true;
1619 break;
1620 }
1621 }
Fariborz Jahanianf859ef22007-11-02 15:39:31 +00001622 if (!catch_or_finally_seen) {
Fariborz Jahanian62fd2b42007-09-19 19:14:32 +00001623 Diag(atLoc, diag::err_missing_catch_finally);
Sebastian Redlbab9a4b2008-12-11 20:12:42 +00001624 return StmtError();
Fariborz Jahanianf859ef22007-11-02 15:39:31 +00001625 }
Douglas Gregor96c79492010-04-23 22:50:49 +00001626
John McCallb268a282010-08-23 23:25:46 +00001627 return Actions.ActOnObjCAtTryStmt(atLoc, TryBody.take(),
Douglas Gregor96c79492010-04-23 22:50:49 +00001628 move_arg(CatchStmts),
John McCallb268a282010-08-23 23:25:46 +00001629 FinallyStmt.take());
Fariborz Jahanian62fd2b42007-09-19 19:14:32 +00001630}
Fariborz Jahanian53cacae2007-09-01 00:26:16 +00001631
Steve Naroff09bf8152007-09-06 21:24:23 +00001632/// objc-method-def: objc-method-proto ';'[opt] '{' body '}'
Fariborz Jahanian53cacae2007-09-01 00:26:16 +00001633///
John McCall48871652010-08-21 09:40:31 +00001634Decl *Parser::ParseObjCMethodDefinition() {
1635 Decl *MDecl = ParseObjCMethodPrototype(ObjCImpDecl);
Mike Stump11289f42009-09-09 15:08:12 +00001636
Chris Lattnereae6cb62009-03-05 08:00:35 +00001637 PrettyStackTraceActionsDecl CrashInfo(MDecl, Tok.getLocation(), Actions,
1638 PP.getSourceManager(),
1639 "parsing Objective-C method");
Mike Stump11289f42009-09-09 15:08:12 +00001640
Fariborz Jahanian53cacae2007-09-01 00:26:16 +00001641 // parse optional ';'
Fariborz Jahanian040d75d2009-10-20 16:39:13 +00001642 if (Tok.is(tok::semi)) {
Ted Kremenek0b61a802009-11-10 22:55:49 +00001643 if (ObjCImpDecl) {
1644 Diag(Tok, diag::warn_semicolon_before_method_body)
Douglas Gregora771f462010-03-31 17:46:05 +00001645 << FixItHint::CreateRemoval(Tok.getLocation());
Ted Kremenek0b61a802009-11-10 22:55:49 +00001646 }
Fariborz Jahanian53cacae2007-09-01 00:26:16 +00001647 ConsumeToken();
Fariborz Jahanian040d75d2009-10-20 16:39:13 +00001648 }
Fariborz Jahanian53cacae2007-09-01 00:26:16 +00001649
Steve Naroffbb875722007-11-11 19:54:21 +00001650 // We should have an opening brace now.
Chris Lattner0ef13522007-10-09 17:51:17 +00001651 if (Tok.isNot(tok::l_brace)) {
Steve Naroff83777fe2008-02-29 21:48:07 +00001652 Diag(Tok, diag::err_expected_method_body);
Mike Stump11289f42009-09-09 15:08:12 +00001653
Steve Naroffbb875722007-11-11 19:54:21 +00001654 // Skip over garbage, until we get to '{'. Don't eat the '{'.
1655 SkipUntil(tok::l_brace, true, true);
Mike Stump11289f42009-09-09 15:08:12 +00001656
Steve Naroffbb875722007-11-11 19:54:21 +00001657 // If we didn't find the '{', bail out.
1658 if (Tok.isNot(tok::l_brace))
John McCall48871652010-08-21 09:40:31 +00001659 return 0;
Fariborz Jahanian53cacae2007-09-01 00:26:16 +00001660 }
Steve Naroffbb875722007-11-11 19:54:21 +00001661 SourceLocation BraceLoc = Tok.getLocation();
Mike Stump11289f42009-09-09 15:08:12 +00001662
Steve Naroffbb875722007-11-11 19:54:21 +00001663 // Enter a scope for the method body.
Chris Lattnerc2ebb032010-04-12 05:38:43 +00001664 ParseScope BodyScope(this,
1665 Scope::ObjCMethodScope|Scope::FnScope|Scope::DeclScope);
Mike Stump11289f42009-09-09 15:08:12 +00001666
Steve Naroffbb875722007-11-11 19:54:21 +00001667 // Tell the actions module that we have entered a method definition with the
Steve Naroff542cd5d2008-07-25 17:57:26 +00001668 // specified Declarator for the method.
Douglas Gregor0be31a22010-07-02 17:43:08 +00001669 Actions.ActOnStartOfObjCMethodDef(getCurScope(), MDecl);
Sebastian Redl042ad952008-12-11 19:30:53 +00001670
John McCalldadc5752010-08-24 06:29:42 +00001671 StmtResult FnBody(ParseCompoundStatementBody());
Sebastian Redl042ad952008-12-11 19:30:53 +00001672
Steve Naroffbb875722007-11-11 19:54:21 +00001673 // If the function body could not be parsed, make a bogus compoundstmt.
Sebastian Redl17f2c7d2008-12-09 13:15:23 +00001674 if (FnBody.isInvalid())
Sebastian Redl52f03ba2008-12-21 12:04:03 +00001675 FnBody = Actions.ActOnCompoundStmt(BraceLoc, BraceLoc,
1676 MultiStmtArg(Actions), false);
Sebastian Redlc675bab2008-12-13 16:23:55 +00001677
Steve Naroffb94d7f62009-03-02 22:00:56 +00001678 // TODO: Pass argument information.
John McCallb268a282010-08-23 23:25:46 +00001679 Actions.ActOnFinishFunctionBody(MDecl, FnBody.take());
Mike Stump11289f42009-09-09 15:08:12 +00001680
Steve Naroffbb875722007-11-11 19:54:21 +00001681 // Leave the function body scope.
Douglas Gregor7307d6c2008-12-10 06:34:36 +00001682 BodyScope.Exit();
Sebastian Redlc675bab2008-12-13 16:23:55 +00001683
Steve Naroff7b8fa472007-11-13 23:01:27 +00001684 return MDecl;
Chris Lattnerda59c2f2006-11-05 02:08:13 +00001685}
Anders Carlsson76f4a902007-08-21 17:43:55 +00001686
John McCalldadc5752010-08-24 06:29:42 +00001687StmtResult Parser::ParseObjCAtStatement(SourceLocation AtLoc) {
Douglas Gregorbc7c5e42009-12-07 09:51:25 +00001688 if (Tok.is(tok::code_completion)) {
Douglas Gregor0be31a22010-07-02 17:43:08 +00001689 Actions.CodeCompleteObjCAtStatement(getCurScope());
Douglas Gregor6da3db42010-05-25 05:58:43 +00001690 ConsumeCodeCompletionToken();
Douglas Gregorbc7c5e42009-12-07 09:51:25 +00001691 return StmtError();
Chris Lattner3ababf52009-12-07 16:33:19 +00001692 }
1693
1694 if (Tok.isObjCAtKeyword(tok::objc_try))
Chris Lattner3e468322008-03-10 06:06:04 +00001695 return ParseObjCTryStmt(AtLoc);
Chris Lattner3ababf52009-12-07 16:33:19 +00001696
1697 if (Tok.isObjCAtKeyword(tok::objc_throw))
Steve Naroffe6016792008-02-05 21:27:35 +00001698 return ParseObjCThrowStmt(AtLoc);
Chris Lattner3ababf52009-12-07 16:33:19 +00001699
1700 if (Tok.isObjCAtKeyword(tok::objc_synchronized))
Steve Naroffe6016792008-02-05 21:27:35 +00001701 return ParseObjCSynchronizedStmt(AtLoc);
Chris Lattner3ababf52009-12-07 16:33:19 +00001702
John McCalldadc5752010-08-24 06:29:42 +00001703 ExprResult Res(ParseExpressionWithLeadingAt(AtLoc));
Sebastian Redl17f2c7d2008-12-09 13:15:23 +00001704 if (Res.isInvalid()) {
Steve Naroffe6016792008-02-05 21:27:35 +00001705 // If the expression is invalid, skip ahead to the next semicolon. Not
1706 // doing this opens us up to the possibility of infinite loops if
1707 // ParseExpression does not consume any tokens.
1708 SkipUntil(tok::semi);
Sebastian Redlbab9a4b2008-12-11 20:12:42 +00001709 return StmtError();
Steve Naroffe6016792008-02-05 21:27:35 +00001710 }
Chris Lattner3ababf52009-12-07 16:33:19 +00001711
Steve Naroffe6016792008-02-05 21:27:35 +00001712 // Otherwise, eat the semicolon.
1713 ExpectAndConsume(tok::semi, diag::err_expected_semi_after_expr);
John McCallb268a282010-08-23 23:25:46 +00001714 return Actions.ActOnExprStmt(Actions.MakeFullExpr(Res.take()));
Steve Naroffe6016792008-02-05 21:27:35 +00001715}
1716
John McCalldadc5752010-08-24 06:29:42 +00001717ExprResult Parser::ParseObjCAtExpression(SourceLocation AtLoc) {
Anders Carlsson76f4a902007-08-21 17:43:55 +00001718 switch (Tok.getKind()) {
Douglas Gregorbc7c5e42009-12-07 09:51:25 +00001719 case tok::code_completion:
Douglas Gregor0be31a22010-07-02 17:43:08 +00001720 Actions.CodeCompleteObjCAtExpression(getCurScope());
Douglas Gregor6da3db42010-05-25 05:58:43 +00001721 ConsumeCodeCompletionToken();
Douglas Gregorbc7c5e42009-12-07 09:51:25 +00001722 return ExprError();
1723
Chris Lattnere002fbe2007-12-12 01:04:12 +00001724 case tok::string_literal: // primary-expression: string-literal
1725 case tok::wide_string_literal:
Sebastian Redlcb6e2c62008-12-13 15:32:12 +00001726 return ParsePostfixExpressionSuffix(ParseObjCStringLiteral(AtLoc));
Chris Lattnere002fbe2007-12-12 01:04:12 +00001727 default:
Chris Lattner197a3012008-08-05 06:19:09 +00001728 if (Tok.getIdentifierInfo() == 0)
Sebastian Redlcb6e2c62008-12-13 15:32:12 +00001729 return ExprError(Diag(AtLoc, diag::err_unexpected_at));
Sebastian Redl59b5e512008-12-11 21:36:32 +00001730
Chris Lattner197a3012008-08-05 06:19:09 +00001731 switch (Tok.getIdentifierInfo()->getObjCKeywordID()) {
1732 case tok::objc_encode:
Sebastian Redlcb6e2c62008-12-13 15:32:12 +00001733 return ParsePostfixExpressionSuffix(ParseObjCEncodeExpression(AtLoc));
Chris Lattner197a3012008-08-05 06:19:09 +00001734 case tok::objc_protocol:
Sebastian Redlcb6e2c62008-12-13 15:32:12 +00001735 return ParsePostfixExpressionSuffix(ParseObjCProtocolExpression(AtLoc));
Chris Lattner197a3012008-08-05 06:19:09 +00001736 case tok::objc_selector:
Sebastian Redlcb6e2c62008-12-13 15:32:12 +00001737 return ParsePostfixExpressionSuffix(ParseObjCSelectorExpression(AtLoc));
Chris Lattner197a3012008-08-05 06:19:09 +00001738 default:
Sebastian Redlcb6e2c62008-12-13 15:32:12 +00001739 return ExprError(Diag(AtLoc, diag::err_unexpected_at));
Chris Lattner197a3012008-08-05 06:19:09 +00001740 }
Anders Carlsson76f4a902007-08-21 17:43:55 +00001741 }
Anders Carlsson76f4a902007-08-21 17:43:55 +00001742}
1743
Douglas Gregor8d4de672010-04-21 22:36:40 +00001744/// \brirg Parse the receiver of an Objective-C++ message send.
1745///
1746/// This routine parses the receiver of a message send in
1747/// Objective-C++ either as a type or as an expression. Note that this
1748/// routine must not be called to parse a send to 'super', since it
1749/// has no way to return such a result.
1750///
1751/// \param IsExpr Whether the receiver was parsed as an expression.
1752///
1753/// \param TypeOrExpr If the receiver was parsed as an expression (\c
1754/// IsExpr is true), the parsed expression. If the receiver was parsed
1755/// as a type (\c IsExpr is false), the parsed type.
1756///
1757/// \returns True if an error occurred during parsing or semantic
1758/// analysis, in which case the arguments do not have valid
1759/// values. Otherwise, returns false for a successful parse.
1760///
1761/// objc-receiver: [C++]
1762/// 'super' [not parsed here]
1763/// expression
1764/// simple-type-specifier
1765/// typename-specifier
Douglas Gregor8d4de672010-04-21 22:36:40 +00001766bool Parser::ParseObjCXXMessageReceiver(bool &IsExpr, void *&TypeOrExpr) {
1767 if (Tok.is(tok::identifier) || Tok.is(tok::coloncolon) ||
1768 Tok.is(tok::kw_typename) || Tok.is(tok::annot_cxxscope))
1769 TryAnnotateTypeOrScopeToken();
1770
1771 if (!isCXXSimpleTypeSpecifier()) {
1772 // objc-receiver:
1773 // expression
John McCalldadc5752010-08-24 06:29:42 +00001774 ExprResult Receiver = ParseExpression();
Douglas Gregor8d4de672010-04-21 22:36:40 +00001775 if (Receiver.isInvalid())
1776 return true;
1777
1778 IsExpr = true;
1779 TypeOrExpr = Receiver.take();
1780 return false;
1781 }
1782
1783 // objc-receiver:
1784 // typename-specifier
1785 // simple-type-specifier
1786 // expression (that starts with one of the above)
1787 DeclSpec DS;
1788 ParseCXXSimpleTypeSpecifier(DS);
1789
1790 if (Tok.is(tok::l_paren)) {
1791 // If we see an opening parentheses at this point, we are
1792 // actually parsing an expression that starts with a
1793 // function-style cast, e.g.,
1794 //
1795 // postfix-expression:
1796 // simple-type-specifier ( expression-list [opt] )
1797 // typename-specifier ( expression-list [opt] )
1798 //
1799 // Parse the remainder of this case, then the (optional)
1800 // postfix-expression suffix, followed by the (optional)
1801 // right-hand side of the binary expression. We have an
1802 // instance method.
John McCalldadc5752010-08-24 06:29:42 +00001803 ExprResult Receiver = ParseCXXTypeConstructExpression(DS);
Douglas Gregor8d4de672010-04-21 22:36:40 +00001804 if (!Receiver.isInvalid())
John McCallb268a282010-08-23 23:25:46 +00001805 Receiver = ParsePostfixExpressionSuffix(Receiver.take());
Douglas Gregor8d4de672010-04-21 22:36:40 +00001806 if (!Receiver.isInvalid())
John McCallb268a282010-08-23 23:25:46 +00001807 Receiver = ParseRHSOfBinaryExpression(Receiver.take(), prec::Comma);
Douglas Gregor8d4de672010-04-21 22:36:40 +00001808 if (Receiver.isInvalid())
1809 return true;
1810
1811 IsExpr = true;
1812 TypeOrExpr = Receiver.take();
1813 return false;
1814 }
1815
1816 // We have a class message. Turn the simple-type-specifier or
1817 // typename-specifier we parsed into a type and parse the
1818 // remainder of the class message.
1819 Declarator DeclaratorInfo(DS, Declarator::TypeNameContext);
Douglas Gregor0be31a22010-07-02 17:43:08 +00001820 TypeResult Type = Actions.ActOnTypeName(getCurScope(), DeclaratorInfo);
Douglas Gregor8d4de672010-04-21 22:36:40 +00001821 if (Type.isInvalid())
1822 return true;
1823
1824 IsExpr = false;
John McCallba7bf592010-08-24 05:47:05 +00001825 TypeOrExpr = Type.get().getAsOpaquePtr();
Douglas Gregor8d4de672010-04-21 22:36:40 +00001826 return false;
1827}
1828
Douglas Gregor990ccac2010-05-31 14:40:22 +00001829/// \brief Determine whether the parser is currently referring to a an
1830/// Objective-C message send, using a simplified heuristic to avoid overhead.
1831///
1832/// This routine will only return true for a subset of valid message-send
1833/// expressions.
1834bool Parser::isSimpleObjCMessageExpression() {
Chris Lattner47054fb2010-05-31 18:18:22 +00001835 assert(Tok.is(tok::l_square) && getLang().ObjC1 &&
Douglas Gregor990ccac2010-05-31 14:40:22 +00001836 "Incorrect start for isSimpleObjCMessageExpression");
Douglas Gregor990ccac2010-05-31 14:40:22 +00001837 return GetLookAheadToken(1).is(tok::identifier) &&
1838 GetLookAheadToken(2).is(tok::identifier);
1839}
1840
Mike Stump11289f42009-09-09 15:08:12 +00001841/// objc-message-expr:
Fariborz Jahanian7db004d2007-09-05 19:52:07 +00001842/// '[' objc-receiver objc-message-args ']'
1843///
Douglas Gregor0c78ad92010-04-21 19:57:20 +00001844/// objc-receiver: [C]
Chris Lattnera36ec422010-04-11 08:28:14 +00001845/// 'super'
Fariborz Jahanian7db004d2007-09-05 19:52:07 +00001846/// expression
1847/// class-name
1848/// type-name
Douglas Gregor8d4de672010-04-21 22:36:40 +00001849///
John McCalldadc5752010-08-24 06:29:42 +00001850ExprResult Parser::ParseObjCMessageExpression() {
Chris Lattner8f697062008-01-25 18:59:06 +00001851 assert(Tok.is(tok::l_square) && "'[' expected");
1852 SourceLocation LBracLoc = ConsumeBracket(); // consume '['
1853
Douglas Gregora817a192010-05-27 23:06:34 +00001854 if (Tok.is(tok::code_completion)) {
Douglas Gregor0be31a22010-07-02 17:43:08 +00001855 Actions.CodeCompleteObjCMessageReceiver(getCurScope());
Douglas Gregora817a192010-05-27 23:06:34 +00001856 ConsumeCodeCompletionToken();
1857 SkipUntil(tok::r_square);
1858 return ExprError();
1859 }
1860
Douglas Gregor8d4de672010-04-21 22:36:40 +00001861 if (getLang().CPlusPlus) {
1862 // We completely separate the C and C++ cases because C++ requires
1863 // more complicated (read: slower) parsing.
1864
1865 // Handle send to super.
1866 // FIXME: This doesn't benefit from the same typo-correction we
1867 // get in Objective-C.
1868 if (Tok.is(tok::identifier) && Tok.getIdentifierInfo() == Ident_super &&
Douglas Gregor0be31a22010-07-02 17:43:08 +00001869 NextToken().isNot(tok::period) && getCurScope()->isInObjcMethodScope())
John McCallba7bf592010-08-24 05:47:05 +00001870 return ParseObjCMessageExpressionBody(LBracLoc, ConsumeToken(),
1871 ParsedType(), 0);
Douglas Gregor8d4de672010-04-21 22:36:40 +00001872
1873 // Parse the receiver, which is either a type or an expression.
1874 bool IsExpr;
1875 void *TypeOrExpr;
1876 if (ParseObjCXXMessageReceiver(IsExpr, TypeOrExpr)) {
1877 SkipUntil(tok::r_square);
1878 return ExprError();
1879 }
1880
1881 if (IsExpr)
John McCallba7bf592010-08-24 05:47:05 +00001882 return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(),
1883 ParsedType(),
John McCallb268a282010-08-23 23:25:46 +00001884 static_cast<Expr*>(TypeOrExpr));
Douglas Gregor8d4de672010-04-21 22:36:40 +00001885
1886 return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(),
John McCallba7bf592010-08-24 05:47:05 +00001887 ParsedType::getFromOpaquePtr(TypeOrExpr),
1888 0);
Chris Lattner47054fb2010-05-31 18:18:22 +00001889 }
1890
1891 if (Tok.is(tok::identifier)) {
Douglas Gregora148a1d2010-04-14 02:22:16 +00001892 IdentifierInfo *Name = Tok.getIdentifierInfo();
1893 SourceLocation NameLoc = Tok.getLocation();
John McCallba7bf592010-08-24 05:47:05 +00001894 ParsedType ReceiverType;
Douglas Gregor0be31a22010-07-02 17:43:08 +00001895 switch (Actions.getObjCMessageKind(getCurScope(), Name, NameLoc,
Douglas Gregora148a1d2010-04-14 02:22:16 +00001896 Name == Ident_super,
Douglas Gregore5798dc2010-04-21 20:38:13 +00001897 NextToken().is(tok::period),
1898 ReceiverType)) {
Douglas Gregora148a1d2010-04-14 02:22:16 +00001899 case Action::ObjCSuperMessage:
John McCallba7bf592010-08-24 05:47:05 +00001900 return ParseObjCMessageExpressionBody(LBracLoc, ConsumeToken(),
1901 ParsedType(), 0);
Douglas Gregor0c78ad92010-04-21 19:57:20 +00001902
Douglas Gregore5798dc2010-04-21 20:38:13 +00001903 case Action::ObjCClassMessage:
1904 if (!ReceiverType) {
Douglas Gregor0c78ad92010-04-21 19:57:20 +00001905 SkipUntil(tok::r_square);
1906 return ExprError();
1907 }
1908
Douglas Gregore5798dc2010-04-21 20:38:13 +00001909 ConsumeToken(); // the type name
1910
1911 return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(),
John McCallb268a282010-08-23 23:25:46 +00001912 ReceiverType, 0);
Douglas Gregora148a1d2010-04-14 02:22:16 +00001913
1914 case Action::ObjCInstanceMessage:
Douglas Gregor0c78ad92010-04-21 19:57:20 +00001915 // Fall through to parse an expression.
Douglas Gregora148a1d2010-04-14 02:22:16 +00001916 break;
Fariborz Jahanianfc58ca42009-04-08 19:50:10 +00001917 }
Chris Lattner8f697062008-01-25 18:59:06 +00001918 }
Chris Lattnera36ec422010-04-11 08:28:14 +00001919
1920 // Otherwise, an arbitrary expression can be the receiver of a send.
John McCalldadc5752010-08-24 06:29:42 +00001921 ExprResult Res(ParseExpression());
Sebastian Redl17f2c7d2008-12-09 13:15:23 +00001922 if (Res.isInvalid()) {
Chris Lattner77927cc2008-01-25 19:43:26 +00001923 SkipUntil(tok::r_square);
Sebastian Redlcb6e2c62008-12-13 15:32:12 +00001924 return move(Res);
Chris Lattner8f697062008-01-25 18:59:06 +00001925 }
Sebastian Redlcb6e2c62008-12-13 15:32:12 +00001926
John McCallba7bf592010-08-24 05:47:05 +00001927 return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(),
1928 ParsedType(), Res.take());
Chris Lattner8f697062008-01-25 18:59:06 +00001929}
Sebastian Redlcb6e2c62008-12-13 15:32:12 +00001930
Douglas Gregor0c78ad92010-04-21 19:57:20 +00001931/// \brief Parse the remainder of an Objective-C message following the
1932/// '[' objc-receiver.
1933///
1934/// This routine handles sends to super, class messages (sent to a
1935/// class name), and instance messages (sent to an object), and the
1936/// target is represented by \p SuperLoc, \p ReceiverType, or \p
1937/// ReceiverExpr, respectively. Only one of these parameters may have
1938/// a valid value.
1939///
1940/// \param LBracLoc The location of the opening '['.
1941///
1942/// \param SuperLoc If this is a send to 'super', the location of the
1943/// 'super' keyword that indicates a send to the superclass.
1944///
1945/// \param ReceiverType If this is a class message, the type of the
1946/// class we are sending a message to.
1947///
1948/// \param ReceiverExpr If this is an instance message, the expression
1949/// used to compute the receiver object.
Mike Stump11289f42009-09-09 15:08:12 +00001950///
Fariborz Jahanian7db004d2007-09-05 19:52:07 +00001951/// objc-message-args:
1952/// objc-selector
1953/// objc-keywordarg-list
1954///
1955/// objc-keywordarg-list:
1956/// objc-keywordarg
1957/// objc-keywordarg-list objc-keywordarg
1958///
Mike Stump11289f42009-09-09 15:08:12 +00001959/// objc-keywordarg:
Fariborz Jahanian7db004d2007-09-05 19:52:07 +00001960/// selector-name[opt] ':' objc-keywordexpr
1961///
1962/// objc-keywordexpr:
1963/// nonempty-expr-list
1964///
1965/// nonempty-expr-list:
1966/// assignment-expression
1967/// nonempty-expr-list , assignment-expression
Sebastian Redlcb6e2c62008-12-13 15:32:12 +00001968///
John McCalldadc5752010-08-24 06:29:42 +00001969ExprResult
Chris Lattner8f697062008-01-25 18:59:06 +00001970Parser::ParseObjCMessageExpressionBody(SourceLocation LBracLoc,
Douglas Gregor0c78ad92010-04-21 19:57:20 +00001971 SourceLocation SuperLoc,
John McCallba7bf592010-08-24 05:47:05 +00001972 ParsedType ReceiverType,
Sebastian Redlcb6e2c62008-12-13 15:32:12 +00001973 ExprArg ReceiverExpr) {
Steve Naroffeae65032009-11-07 02:08:14 +00001974 if (Tok.is(tok::code_completion)) {
Douglas Gregor0c78ad92010-04-21 19:57:20 +00001975 if (SuperLoc.isValid())
Douglas Gregor0be31a22010-07-02 17:43:08 +00001976 Actions.CodeCompleteObjCSuperMessage(getCurScope(), SuperLoc, 0, 0);
Douglas Gregor0c78ad92010-04-21 19:57:20 +00001977 else if (ReceiverType)
Douglas Gregor0be31a22010-07-02 17:43:08 +00001978 Actions.CodeCompleteObjCClassMessage(getCurScope(), ReceiverType, 0, 0);
Steve Naroffeae65032009-11-07 02:08:14 +00001979 else
John McCallb268a282010-08-23 23:25:46 +00001980 Actions.CodeCompleteObjCInstanceMessage(getCurScope(), ReceiverExpr,
Douglas Gregor1b605f72009-11-19 01:08:35 +00001981 0, 0);
Douglas Gregor6da3db42010-05-25 05:58:43 +00001982 ConsumeCodeCompletionToken();
Steve Naroffeae65032009-11-07 02:08:14 +00001983 }
Douglas Gregor1b605f72009-11-19 01:08:35 +00001984
Fariborz Jahanianbd25f7d2007-09-05 23:08:20 +00001985 // Parse objc-selector
Fariborz Jahanian70e8f102007-10-11 00:55:41 +00001986 SourceLocation Loc;
Chris Lattner4f472a32009-04-11 18:13:45 +00001987 IdentifierInfo *selIdent = ParseObjCSelectorPiece(Loc);
Steve Narofff73590d2007-09-27 14:38:14 +00001988
Anders Carlsson978f08d2009-02-14 18:21:46 +00001989 SourceLocation SelectorLoc = Loc;
Mike Stump11289f42009-09-09 15:08:12 +00001990
Steve Narofff73590d2007-09-27 14:38:14 +00001991 llvm::SmallVector<IdentifierInfo *, 12> KeyIdents;
Sebastian Redl511ed552008-11-25 22:21:31 +00001992 ExprVector KeyExprs(Actions);
Steve Narofff73590d2007-09-27 14:38:14 +00001993
Chris Lattner0ef13522007-10-09 17:51:17 +00001994 if (Tok.is(tok::colon)) {
Fariborz Jahanianbd25f7d2007-09-05 23:08:20 +00001995 while (1) {
1996 // Each iteration parses a single keyword argument.
Steve Narofff73590d2007-09-27 14:38:14 +00001997 KeyIdents.push_back(selIdent);
Steve Naroff486760a2007-09-17 20:25:27 +00001998
Chris Lattner0ef13522007-10-09 17:51:17 +00001999 if (Tok.isNot(tok::colon)) {
Fariborz Jahanianbd25f7d2007-09-05 23:08:20 +00002000 Diag(Tok, diag::err_expected_colon);
Chris Lattner197a3012008-08-05 06:19:09 +00002001 // We must manually skip to a ']', otherwise the expression skipper will
2002 // stop at the ']' when it skips to the ';'. We want it to skip beyond
2003 // the enclosing expression.
2004 SkipUntil(tok::r_square);
Sebastian Redlcb6e2c62008-12-13 15:32:12 +00002005 return ExprError();
Fariborz Jahanianbd25f7d2007-09-05 23:08:20 +00002006 }
Sebastian Redlcb6e2c62008-12-13 15:32:12 +00002007
Steve Narofff73590d2007-09-27 14:38:14 +00002008 ConsumeToken(); // Eat the ':'.
Mike Stump11289f42009-09-09 15:08:12 +00002009 /// Parse the expression after ':'
John McCalldadc5752010-08-24 06:29:42 +00002010 ExprResult Res(ParseAssignmentExpression());
Sebastian Redl17f2c7d2008-12-09 13:15:23 +00002011 if (Res.isInvalid()) {
Chris Lattner197a3012008-08-05 06:19:09 +00002012 // We must manually skip to a ']', otherwise the expression skipper will
2013 // stop at the ']' when it skips to the ';'. We want it to skip beyond
2014 // the enclosing expression.
2015 SkipUntil(tok::r_square);
Sebastian Redlcb6e2c62008-12-13 15:32:12 +00002016 return move(Res);
Steve Naroff486760a2007-09-17 20:25:27 +00002017 }
Sebastian Redlcb6e2c62008-12-13 15:32:12 +00002018
Steve Naroff486760a2007-09-17 20:25:27 +00002019 // We have a valid expression.
Sebastian Redld9f7b1c2008-12-10 00:02:53 +00002020 KeyExprs.push_back(Res.release());
Sebastian Redlcb6e2c62008-12-13 15:32:12 +00002021
Douglas Gregor1b605f72009-11-19 01:08:35 +00002022 // Code completion after each argument.
2023 if (Tok.is(tok::code_completion)) {
Douglas Gregor0c78ad92010-04-21 19:57:20 +00002024 if (SuperLoc.isValid())
Douglas Gregor0be31a22010-07-02 17:43:08 +00002025 Actions.CodeCompleteObjCSuperMessage(getCurScope(), SuperLoc,
Douglas Gregor0c78ad92010-04-21 19:57:20 +00002026 KeyIdents.data(),
2027 KeyIdents.size());
2028 else if (ReceiverType)
Douglas Gregor0be31a22010-07-02 17:43:08 +00002029 Actions.CodeCompleteObjCClassMessage(getCurScope(), ReceiverType,
Douglas Gregor1b605f72009-11-19 01:08:35 +00002030 KeyIdents.data(),
2031 KeyIdents.size());
2032 else
John McCallb268a282010-08-23 23:25:46 +00002033 Actions.CodeCompleteObjCInstanceMessage(getCurScope(), ReceiverExpr,
Douglas Gregor1b605f72009-11-19 01:08:35 +00002034 KeyIdents.data(),
2035 KeyIdents.size());
Douglas Gregor6da3db42010-05-25 05:58:43 +00002036 ConsumeCodeCompletionToken();
Douglas Gregor1b605f72009-11-19 01:08:35 +00002037 }
2038
Steve Naroff486760a2007-09-17 20:25:27 +00002039 // Check for another keyword selector.
Chris Lattner4f472a32009-04-11 18:13:45 +00002040 selIdent = ParseObjCSelectorPiece(Loc);
Chris Lattner0ef13522007-10-09 17:51:17 +00002041 if (!selIdent && Tok.isNot(tok::colon))
Fariborz Jahanianbd25f7d2007-09-05 23:08:20 +00002042 break;
2043 // We have a selector or a colon, continue parsing.
2044 }
2045 // Parse the, optional, argument list, comma separated.
Chris Lattner0ef13522007-10-09 17:51:17 +00002046 while (Tok.is(tok::comma)) {
Steve Naroffe3ffc2f2007-11-15 13:05:42 +00002047 ConsumeToken(); // Eat the ','.
Mike Stump11289f42009-09-09 15:08:12 +00002048 /// Parse the expression after ','
John McCalldadc5752010-08-24 06:29:42 +00002049 ExprResult Res(ParseAssignmentExpression());
Sebastian Redl17f2c7d2008-12-09 13:15:23 +00002050 if (Res.isInvalid()) {
Chris Lattner197a3012008-08-05 06:19:09 +00002051 // We must manually skip to a ']', otherwise the expression skipper will
2052 // stop at the ']' when it skips to the ';'. We want it to skip beyond
2053 // the enclosing expression.
2054 SkipUntil(tok::r_square);
Sebastian Redlcb6e2c62008-12-13 15:32:12 +00002055 return move(Res);
Steve Naroffe3ffc2f2007-11-15 13:05:42 +00002056 }
Sebastian Redl17f2c7d2008-12-09 13:15:23 +00002057
Steve Naroffe3ffc2f2007-11-15 13:05:42 +00002058 // We have a valid expression.
Sebastian Redld9f7b1c2008-12-10 00:02:53 +00002059 KeyExprs.push_back(Res.release());
Fariborz Jahanianbd25f7d2007-09-05 23:08:20 +00002060 }
2061 } else if (!selIdent) {
2062 Diag(Tok, diag::err_expected_ident); // missing selector name.
Sebastian Redlcb6e2c62008-12-13 15:32:12 +00002063
Chris Lattner197a3012008-08-05 06:19:09 +00002064 // We must manually skip to a ']', otherwise the expression skipper will
2065 // stop at the ']' when it skips to the ';'. We want it to skip beyond
2066 // the enclosing expression.
2067 SkipUntil(tok::r_square);
Sebastian Redlcb6e2c62008-12-13 15:32:12 +00002068 return ExprError();
Fariborz Jahanianbd25f7d2007-09-05 23:08:20 +00002069 }
Fariborz Jahanian083712f2010-03-31 20:22:35 +00002070
Chris Lattner0ef13522007-10-09 17:51:17 +00002071 if (Tok.isNot(tok::r_square)) {
Fariborz Jahanian083712f2010-03-31 20:22:35 +00002072 if (Tok.is(tok::identifier))
2073 Diag(Tok, diag::err_expected_colon);
2074 else
2075 Diag(Tok, diag::err_expected_rsquare);
Chris Lattner197a3012008-08-05 06:19:09 +00002076 // We must manually skip to a ']', otherwise the expression skipper will
2077 // stop at the ']' when it skips to the ';'. We want it to skip beyond
2078 // the enclosing expression.
2079 SkipUntil(tok::r_square);
Sebastian Redlcb6e2c62008-12-13 15:32:12 +00002080 return ExprError();
Fariborz Jahanianbd25f7d2007-09-05 23:08:20 +00002081 }
Sebastian Redlcb6e2c62008-12-13 15:32:12 +00002082
Chris Lattner8f697062008-01-25 18:59:06 +00002083 SourceLocation RBracLoc = ConsumeBracket(); // consume ']'
Sebastian Redlcb6e2c62008-12-13 15:32:12 +00002084
Steve Naroffe61bfa82007-10-05 18:42:47 +00002085 unsigned nKeys = KeyIdents.size();
Chris Lattner5700fab2007-10-07 02:00:24 +00002086 if (nKeys == 0)
2087 KeyIdents.push_back(selIdent);
2088 Selector Sel = PP.getSelectorTable().getSelector(nKeys, &KeyIdents[0]);
Sebastian Redlcb6e2c62008-12-13 15:32:12 +00002089
Douglas Gregor0c78ad92010-04-21 19:57:20 +00002090 if (SuperLoc.isValid())
Douglas Gregor0be31a22010-07-02 17:43:08 +00002091 return Actions.ActOnSuperMessage(getCurScope(), SuperLoc, Sel,
Douglas Gregor0c78ad92010-04-21 19:57:20 +00002092 LBracLoc, SelectorLoc, RBracLoc,
2093 Action::MultiExprArg(Actions,
2094 KeyExprs.take(),
2095 KeyExprs.size()));
2096 else if (ReceiverType)
Douglas Gregor0be31a22010-07-02 17:43:08 +00002097 return Actions.ActOnClassMessage(getCurScope(), ReceiverType, Sel,
Douglas Gregor0c78ad92010-04-21 19:57:20 +00002098 LBracLoc, SelectorLoc, RBracLoc,
2099 Action::MultiExprArg(Actions,
2100 KeyExprs.take(),
2101 KeyExprs.size()));
John McCallb268a282010-08-23 23:25:46 +00002102 return Actions.ActOnInstanceMessage(getCurScope(), ReceiverExpr, Sel,
Douglas Gregor0c78ad92010-04-21 19:57:20 +00002103 LBracLoc, SelectorLoc, RBracLoc,
2104 Action::MultiExprArg(Actions,
2105 KeyExprs.take(),
2106 KeyExprs.size()));
Fariborz Jahanian7db004d2007-09-05 19:52:07 +00002107}
2108
John McCalldadc5752010-08-24 06:29:42 +00002109ExprResult Parser::ParseObjCStringLiteral(SourceLocation AtLoc) {
2110 ExprResult Res(ParseStringLiteralExpression());
Sebastian Redlcb6e2c62008-12-13 15:32:12 +00002111 if (Res.isInvalid()) return move(Res);
2112
Chris Lattnere002fbe2007-12-12 01:04:12 +00002113 // @"foo" @"bar" is a valid concatenated string. Eat any subsequent string
2114 // expressions. At this point, we know that the only valid thing that starts
2115 // with '@' is an @"".
2116 llvm::SmallVector<SourceLocation, 4> AtLocs;
Sebastian Redl511ed552008-11-25 22:21:31 +00002117 ExprVector AtStrings(Actions);
Chris Lattnere002fbe2007-12-12 01:04:12 +00002118 AtLocs.push_back(AtLoc);
Sebastian Redld9f7b1c2008-12-10 00:02:53 +00002119 AtStrings.push_back(Res.release());
Sebastian Redl17f2c7d2008-12-09 13:15:23 +00002120
Chris Lattnere002fbe2007-12-12 01:04:12 +00002121 while (Tok.is(tok::at)) {
2122 AtLocs.push_back(ConsumeToken()); // eat the @.
Anders Carlsson76f4a902007-08-21 17:43:55 +00002123
Sebastian Redlc13f2682008-12-09 20:22:58 +00002124 // Invalid unless there is a string literal.
Chris Lattnerd3b5d5d2009-02-18 05:56:09 +00002125 if (!isTokenStringLiteral())
2126 return ExprError(Diag(Tok, diag::err_objc_concat_string));
Chris Lattnere002fbe2007-12-12 01:04:12 +00002127
John McCalldadc5752010-08-24 06:29:42 +00002128 ExprResult Lit(ParseStringLiteralExpression());
Sebastian Redl17f2c7d2008-12-09 13:15:23 +00002129 if (Lit.isInvalid())
Sebastian Redlcb6e2c62008-12-13 15:32:12 +00002130 return move(Lit);
Sebastian Redl17f2c7d2008-12-09 13:15:23 +00002131
Sebastian Redld9f7b1c2008-12-10 00:02:53 +00002132 AtStrings.push_back(Lit.release());
Chris Lattnere002fbe2007-12-12 01:04:12 +00002133 }
Sebastian Redlcb6e2c62008-12-13 15:32:12 +00002134
2135 return Owned(Actions.ParseObjCStringLiteral(&AtLocs[0], AtStrings.take(),
2136 AtStrings.size()));
Anders Carlsson76f4a902007-08-21 17:43:55 +00002137}
Anders Carlssonc5a81eb2007-08-22 15:14:15 +00002138
2139/// objc-encode-expression:
2140/// @encode ( type-name )
John McCalldadc5752010-08-24 06:29:42 +00002141ExprResult
Sebastian Redlcb6e2c62008-12-13 15:32:12 +00002142Parser::ParseObjCEncodeExpression(SourceLocation AtLoc) {
Steve Naroff7c348172007-08-23 18:16:40 +00002143 assert(Tok.isObjCAtKeyword(tok::objc_encode) && "Not an @encode expression!");
Sebastian Redlcb6e2c62008-12-13 15:32:12 +00002144
Anders Carlssonc5a81eb2007-08-22 15:14:15 +00002145 SourceLocation EncLoc = ConsumeToken();
Sebastian Redlcb6e2c62008-12-13 15:32:12 +00002146
Chris Lattner197a3012008-08-05 06:19:09 +00002147 if (Tok.isNot(tok::l_paren))
Sebastian Redlcb6e2c62008-12-13 15:32:12 +00002148 return ExprError(Diag(Tok, diag::err_expected_lparen_after) << "@encode");
2149
Anders Carlssonc5a81eb2007-08-22 15:14:15 +00002150 SourceLocation LParenLoc = ConsumeParen();
Sebastian Redlcb6e2c62008-12-13 15:32:12 +00002151
Douglas Gregor220cac52009-02-18 17:45:20 +00002152 TypeResult Ty = ParseTypeName();
Sebastian Redlcb6e2c62008-12-13 15:32:12 +00002153
Anders Carlssoncb8f8322007-08-23 15:31:37 +00002154 SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc);
Sebastian Redlcb6e2c62008-12-13 15:32:12 +00002155
Douglas Gregor220cac52009-02-18 17:45:20 +00002156 if (Ty.isInvalid())
2157 return ExprError();
2158
Mike Stump11289f42009-09-09 15:08:12 +00002159 return Owned(Actions.ParseObjCEncodeExpression(AtLoc, EncLoc, LParenLoc,
Douglas Gregor220cac52009-02-18 17:45:20 +00002160 Ty.get(), RParenLoc));
Anders Carlssonc5a81eb2007-08-22 15:14:15 +00002161}
Anders Carlssone01493d2007-08-23 15:25:28 +00002162
2163/// objc-protocol-expression
2164/// @protocol ( protocol-name )
John McCalldadc5752010-08-24 06:29:42 +00002165ExprResult
Sebastian Redlcb6e2c62008-12-13 15:32:12 +00002166Parser::ParseObjCProtocolExpression(SourceLocation AtLoc) {
Anders Carlssone01493d2007-08-23 15:25:28 +00002167 SourceLocation ProtoLoc = ConsumeToken();
Sebastian Redlcb6e2c62008-12-13 15:32:12 +00002168
Chris Lattner197a3012008-08-05 06:19:09 +00002169 if (Tok.isNot(tok::l_paren))
Sebastian Redlcb6e2c62008-12-13 15:32:12 +00002170 return ExprError(Diag(Tok, diag::err_expected_lparen_after) << "@protocol");
2171
Anders Carlssone01493d2007-08-23 15:25:28 +00002172 SourceLocation LParenLoc = ConsumeParen();
Sebastian Redlcb6e2c62008-12-13 15:32:12 +00002173
Chris Lattner197a3012008-08-05 06:19:09 +00002174 if (Tok.isNot(tok::identifier))
Sebastian Redlcb6e2c62008-12-13 15:32:12 +00002175 return ExprError(Diag(Tok, diag::err_expected_ident));
2176
Fariborz Jahaniana32aaef2007-10-17 16:58:11 +00002177 IdentifierInfo *protocolId = Tok.getIdentifierInfo();
Anders Carlssone01493d2007-08-23 15:25:28 +00002178 ConsumeToken();
Sebastian Redlcb6e2c62008-12-13 15:32:12 +00002179
Anders Carlssoncb8f8322007-08-23 15:31:37 +00002180 SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc);
Anders Carlssone01493d2007-08-23 15:25:28 +00002181
Sebastian Redlcb6e2c62008-12-13 15:32:12 +00002182 return Owned(Actions.ParseObjCProtocolExpression(protocolId, AtLoc, ProtoLoc,
2183 LParenLoc, RParenLoc));
Anders Carlssone01493d2007-08-23 15:25:28 +00002184}
Fariborz Jahanian76a94272007-10-15 23:39:13 +00002185
2186/// objc-selector-expression
2187/// @selector '(' objc-keyword-selector ')'
John McCalldadc5752010-08-24 06:29:42 +00002188ExprResult Parser::ParseObjCSelectorExpression(SourceLocation AtLoc) {
Fariborz Jahanian76a94272007-10-15 23:39:13 +00002189 SourceLocation SelectorLoc = ConsumeToken();
Sebastian Redlcb6e2c62008-12-13 15:32:12 +00002190
Chris Lattner197a3012008-08-05 06:19:09 +00002191 if (Tok.isNot(tok::l_paren))
Sebastian Redlcb6e2c62008-12-13 15:32:12 +00002192 return ExprError(Diag(Tok, diag::err_expected_lparen_after) << "@selector");
2193
Fariborz Jahanian4bef4622007-10-16 20:40:23 +00002194 llvm::SmallVector<IdentifierInfo *, 12> KeyIdents;
Fariborz Jahanian76a94272007-10-15 23:39:13 +00002195 SourceLocation LParenLoc = ConsumeParen();
2196 SourceLocation sLoc;
Chris Lattner4f472a32009-04-11 18:13:45 +00002197 IdentifierInfo *SelIdent = ParseObjCSelectorPiece(sLoc);
Sebastian Redlcb6e2c62008-12-13 15:32:12 +00002198 if (!SelIdent && Tok.isNot(tok::colon)) // missing selector name.
2199 return ExprError(Diag(Tok, diag::err_expected_ident));
2200
Fariborz Jahanian4bef4622007-10-16 20:40:23 +00002201 KeyIdents.push_back(SelIdent);
Steve Naroff152dd812007-12-05 22:21:29 +00002202 unsigned nColons = 0;
2203 if (Tok.isNot(tok::r_paren)) {
Fariborz Jahanian76a94272007-10-15 23:39:13 +00002204 while (1) {
Chris Lattner197a3012008-08-05 06:19:09 +00002205 if (Tok.isNot(tok::colon))
Sebastian Redlcb6e2c62008-12-13 15:32:12 +00002206 return ExprError(Diag(Tok, diag::err_expected_colon));
2207
Chris Lattner5e530bc2007-12-27 19:57:00 +00002208 nColons++;
Fariborz Jahanian76a94272007-10-15 23:39:13 +00002209 ConsumeToken(); // Eat the ':'.
2210 if (Tok.is(tok::r_paren))
2211 break;
2212 // Check for another keyword selector.
2213 SourceLocation Loc;
Chris Lattner4f472a32009-04-11 18:13:45 +00002214 SelIdent = ParseObjCSelectorPiece(Loc);
Fariborz Jahanian4bef4622007-10-16 20:40:23 +00002215 KeyIdents.push_back(SelIdent);
Fariborz Jahanian76a94272007-10-15 23:39:13 +00002216 if (!SelIdent && Tok.isNot(tok::colon))
2217 break;
2218 }
Steve Naroff152dd812007-12-05 22:21:29 +00002219 }
Fariborz Jahanian76a94272007-10-15 23:39:13 +00002220 SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc);
Steve Naroff152dd812007-12-05 22:21:29 +00002221 Selector Sel = PP.getSelectorTable().getSelector(nColons, &KeyIdents[0]);
Sebastian Redlcb6e2c62008-12-13 15:32:12 +00002222 return Owned(Actions.ParseObjCSelectorExpression(Sel, AtLoc, SelectorLoc,
2223 LParenLoc, RParenLoc));
Gabor Greif24032f12007-10-19 15:38:32 +00002224 }