blob: 4fbbc1854f94f23eae3f783dad6628267bb76c2d [file] [log] [blame]
Chris Lattner4b009652007-07-25 00:24:17 +00001//===--- ParseObjc.cpp - Objective C Parsing ------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by Steve Naroff and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the Objective-C portions of the Parser interface.
11//
12//===----------------------------------------------------------------------===//
13
14#include "clang/Parse/Parser.h"
Steve Naroff09a0c4c2007-08-22 18:35:33 +000015#include "clang/Parse/DeclSpec.h"
Fariborz Jahanian06798362007-11-01 23:59:59 +000016#include "clang/Parse/Scope.h"
Chris Lattner4b009652007-07-25 00:24:17 +000017#include "clang/Basic/Diagnostic.h"
18#include "llvm/ADT/SmallVector.h"
19using namespace clang;
20
21
22/// ParseExternalDeclaration:
23/// external-declaration: [C99 6.9]
24/// [OBJC] objc-class-definition
Steve Naroff5b96e2e2007-10-29 21:39:29 +000025/// [OBJC] objc-class-declaration
26/// [OBJC] objc-alias-declaration
27/// [OBJC] objc-protocol-definition
28/// [OBJC] objc-method-definition
29/// [OBJC] '@' 'end'
Steve Narofffb367882007-08-20 21:31:48 +000030Parser::DeclTy *Parser::ParseObjCAtDirectives() {
Chris Lattner4b009652007-07-25 00:24:17 +000031 SourceLocation AtLoc = ConsumeToken(); // the "@"
32
Steve Naroff87c329f2007-08-23 18:16:40 +000033 switch (Tok.getObjCKeywordID()) {
Chris Lattner4b009652007-07-25 00:24:17 +000034 case tok::objc_class:
35 return ParseObjCAtClassDeclaration(AtLoc);
36 case tok::objc_interface:
Steve Narofffb367882007-08-20 21:31:48 +000037 return ParseObjCAtInterfaceDeclaration(AtLoc);
Chris Lattner4b009652007-07-25 00:24:17 +000038 case tok::objc_protocol:
Steve Naroff72f17fb2007-08-22 22:17:26 +000039 return ParseObjCAtProtocolDeclaration(AtLoc);
Chris Lattner4b009652007-07-25 00:24:17 +000040 case tok::objc_implementation:
Fariborz Jahanian83ddf822007-11-10 20:59:13 +000041 return ParseObjCAtImplementationDeclaration(AtLoc);
Chris Lattner4b009652007-07-25 00:24:17 +000042 case tok::objc_end:
Fariborz Jahanian027c23b2007-09-01 00:26:16 +000043 return ParseObjCAtEndDeclaration(AtLoc);
Chris Lattner4b009652007-07-25 00:24:17 +000044 case tok::objc_compatibility_alias:
Fariborz Jahanianb62aff32007-09-04 19:26:51 +000045 return ParseObjCAtAliasDeclaration(AtLoc);
Fariborz Jahanian027c23b2007-09-01 00:26:16 +000046 case tok::objc_synthesize:
47 return ParseObjCPropertySynthesize(AtLoc);
48 case tok::objc_dynamic:
49 return ParseObjCPropertyDynamic(AtLoc);
Chris Lattner4b009652007-07-25 00:24:17 +000050 default:
51 Diag(AtLoc, diag::err_unexpected_at);
52 SkipUntil(tok::semi);
Steve Narofffb367882007-08-20 21:31:48 +000053 return 0;
Chris Lattner4b009652007-07-25 00:24:17 +000054 }
55}
56
57///
58/// objc-class-declaration:
59/// '@' 'class' identifier-list ';'
60///
Steve Narofffb367882007-08-20 21:31:48 +000061Parser::DeclTy *Parser::ParseObjCAtClassDeclaration(SourceLocation atLoc) {
Chris Lattner4b009652007-07-25 00:24:17 +000062 ConsumeToken(); // the identifier "class"
63 llvm::SmallVector<IdentifierInfo *, 8> ClassNames;
64
65 while (1) {
Chris Lattnera1d2bb72007-10-09 17:51:17 +000066 if (Tok.isNot(tok::identifier)) {
Chris Lattner4b009652007-07-25 00:24:17 +000067 Diag(Tok, diag::err_expected_ident);
68 SkipUntil(tok::semi);
Steve Narofffb367882007-08-20 21:31:48 +000069 return 0;
Chris Lattner4b009652007-07-25 00:24:17 +000070 }
Chris Lattner4b009652007-07-25 00:24:17 +000071 ClassNames.push_back(Tok.getIdentifierInfo());
72 ConsumeToken();
73
Chris Lattnera1d2bb72007-10-09 17:51:17 +000074 if (Tok.isNot(tok::comma))
Chris Lattner4b009652007-07-25 00:24:17 +000075 break;
76
77 ConsumeToken();
78 }
79
80 // Consume the ';'.
81 if (ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@class"))
Steve Narofffb367882007-08-20 21:31:48 +000082 return 0;
Chris Lattner4b009652007-07-25 00:24:17 +000083
Steve Naroff415c1832007-10-10 17:32:04 +000084 return Actions.ActOnForwardClassDeclaration(atLoc,
Steve Naroff81f1bba2007-09-06 21:24:23 +000085 &ClassNames[0], ClassNames.size());
Chris Lattner4b009652007-07-25 00:24:17 +000086}
87
Steve Narofffb367882007-08-20 21:31:48 +000088///
89/// objc-interface:
90/// objc-class-interface-attributes[opt] objc-class-interface
91/// objc-category-interface
92///
93/// objc-class-interface:
94/// '@' 'interface' identifier objc-superclass[opt]
95/// objc-protocol-refs[opt]
96/// objc-class-instance-variables[opt]
97/// objc-interface-decl-list
98/// @end
99///
100/// objc-category-interface:
101/// '@' 'interface' identifier '(' identifier[opt] ')'
102/// objc-protocol-refs[opt]
103/// objc-interface-decl-list
104/// @end
105///
106/// objc-superclass:
107/// ':' identifier
108///
109/// objc-class-interface-attributes:
110/// __attribute__((visibility("default")))
111/// __attribute__((visibility("hidden")))
112/// __attribute__((deprecated))
113/// __attribute__((unavailable))
114/// __attribute__((objc_exception)) - used by NSException on 64-bit
115///
116Parser::DeclTy *Parser::ParseObjCAtInterfaceDeclaration(
117 SourceLocation atLoc, AttributeList *attrList) {
Steve Naroff87c329f2007-08-23 18:16:40 +0000118 assert(Tok.isObjCAtKeyword(tok::objc_interface) &&
Steve Narofffb367882007-08-20 21:31:48 +0000119 "ParseObjCAtInterfaceDeclaration(): Expected @interface");
120 ConsumeToken(); // the "interface" identifier
121
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000122 if (Tok.isNot(tok::identifier)) {
Steve Narofffb367882007-08-20 21:31:48 +0000123 Diag(Tok, diag::err_expected_ident); // missing class or category name.
124 return 0;
125 }
126 // We have a class or category name - consume it.
Steve Naroff72f17fb2007-08-22 22:17:26 +0000127 IdentifierInfo *nameId = Tok.getIdentifierInfo();
Steve Narofffb367882007-08-20 21:31:48 +0000128 SourceLocation nameLoc = ConsumeToken();
129
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000130 if (Tok.is(tok::l_paren)) { // we have a category.
Steve Narofffb367882007-08-20 21:31:48 +0000131 SourceLocation lparenLoc = ConsumeParen();
132 SourceLocation categoryLoc, rparenLoc;
133 IdentifierInfo *categoryId = 0;
Fariborz Jahanianf25220e2007-09-18 20:26:58 +0000134 llvm::SmallVector<IdentifierInfo *, 8> ProtocolRefs;
Steve Narofffb367882007-08-20 21:31:48 +0000135
Steve Naroffa7f62782007-08-23 19:56:30 +0000136 // For ObjC2, the category name is optional (not an error).
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000137 if (Tok.is(tok::identifier)) {
Steve Narofffb367882007-08-20 21:31:48 +0000138 categoryId = Tok.getIdentifierInfo();
139 categoryLoc = ConsumeToken();
Steve Naroffa7f62782007-08-23 19:56:30 +0000140 } else if (!getLang().ObjC2) {
141 Diag(Tok, diag::err_expected_ident); // missing category name.
142 return 0;
Steve Narofffb367882007-08-20 21:31:48 +0000143 }
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000144 if (Tok.isNot(tok::r_paren)) {
Steve Narofffb367882007-08-20 21:31:48 +0000145 Diag(Tok, diag::err_expected_rparen);
146 SkipUntil(tok::r_paren, false); // don't stop at ';'
147 return 0;
148 }
149 rparenLoc = ConsumeParen();
Steve Naroffef20ed32007-10-30 02:23:23 +0000150 SourceLocation endProtoLoc;
Steve Narofffb367882007-08-20 21:31:48 +0000151 // Next, we need to check for any protocol references.
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000152 if (Tok.is(tok::less)) {
Steve Naroffef20ed32007-10-30 02:23:23 +0000153 if (ParseObjCProtocolReferences(ProtocolRefs, endProtoLoc))
Steve Narofffb367882007-08-20 21:31:48 +0000154 return 0;
155 }
156 if (attrList) // categories don't support attributes.
157 Diag(Tok, diag::err_objc_no_attributes_on_category);
158
Steve Naroff415c1832007-10-10 17:32:04 +0000159 DeclTy *CategoryType = Actions.ActOnStartCategoryInterface(atLoc,
Steve Naroff25aace82007-10-03 21:00:46 +0000160 nameId, nameLoc, categoryId, categoryLoc,
Steve Naroff667f1682007-10-30 13:30:57 +0000161 &ProtocolRefs[0], ProtocolRefs.size(),
162 endProtoLoc);
Fariborz Jahanianf25220e2007-09-18 20:26:58 +0000163
164 ParseObjCInterfaceDeclList(CategoryType, tok::objc_not_keyword);
Steve Narofffb367882007-08-20 21:31:48 +0000165
Steve Naroff0bbffd82007-08-22 16:35:03 +0000166 // The @ sign was already consumed by ParseObjCInterfaceDeclList().
Steve Naroff87c329f2007-08-23 18:16:40 +0000167 if (Tok.isObjCAtKeyword(tok::objc_end)) {
Steve Naroff0bbffd82007-08-22 16:35:03 +0000168 ConsumeToken(); // the "end" identifier
Fariborz Jahanianac20be22007-10-08 18:53:38 +0000169 return CategoryType;
Steve Narofffb367882007-08-20 21:31:48 +0000170 }
Steve Naroff0bbffd82007-08-22 16:35:03 +0000171 Diag(Tok, diag::err_objc_missing_end);
Steve Narofffb367882007-08-20 21:31:48 +0000172 return 0;
173 }
174 // Parse a class interface.
175 IdentifierInfo *superClassId = 0;
176 SourceLocation superClassLoc;
Steve Naroff72f17fb2007-08-22 22:17:26 +0000177
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000178 if (Tok.is(tok::colon)) { // a super class is specified.
Steve Narofffb367882007-08-20 21:31:48 +0000179 ConsumeToken();
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000180 if (Tok.isNot(tok::identifier)) {
Steve Narofffb367882007-08-20 21:31:48 +0000181 Diag(Tok, diag::err_expected_ident); // missing super class name.
182 return 0;
183 }
184 superClassId = Tok.getIdentifierInfo();
185 superClassLoc = ConsumeToken();
186 }
187 // Next, we need to check for any protocol references.
Steve Naroff304ed392007-09-05 23:30:30 +0000188 llvm::SmallVector<IdentifierInfo *, 8> ProtocolRefs;
Steve Naroffef20ed32007-10-30 02:23:23 +0000189 SourceLocation endProtoLoc;
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000190 if (Tok.is(tok::less)) {
Steve Naroffef20ed32007-10-30 02:23:23 +0000191 if (ParseObjCProtocolReferences(ProtocolRefs, endProtoLoc))
Steve Narofffb367882007-08-20 21:31:48 +0000192 return 0;
193 }
Steve Naroff415c1832007-10-10 17:32:04 +0000194 DeclTy *ClsType = Actions.ActOnStartClassInterface(
Fariborz Jahanianc091b5d2007-09-25 18:38:09 +0000195 atLoc, nameId, nameLoc,
Steve Naroff304ed392007-09-05 23:30:30 +0000196 superClassId, superClassLoc, &ProtocolRefs[0],
Steve Naroffef20ed32007-10-30 02:23:23 +0000197 ProtocolRefs.size(), endProtoLoc, attrList);
Steve Naroff304ed392007-09-05 23:30:30 +0000198
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000199 if (Tok.is(tok::l_brace))
Steve Naroff1a7fa7b2007-10-29 21:38:07 +0000200 ParseObjCClassInstanceVariables(ClsType, atLoc);
Steve Narofffb367882007-08-20 21:31:48 +0000201
Fariborz Jahanian63ca8ae2007-09-17 21:07:36 +0000202 ParseObjCInterfaceDeclList(ClsType, tok::objc_interface);
Steve Naroff0bbffd82007-08-22 16:35:03 +0000203
204 // The @ sign was already consumed by ParseObjCInterfaceDeclList().
Steve Naroff87c329f2007-08-23 18:16:40 +0000205 if (Tok.isObjCAtKeyword(tok::objc_end)) {
Steve Naroff0bbffd82007-08-22 16:35:03 +0000206 ConsumeToken(); // the "end" identifier
Steve Narofffaed3bf2007-09-10 20:51:04 +0000207 return ClsType;
Steve Narofffb367882007-08-20 21:31:48 +0000208 }
Steve Naroff0bbffd82007-08-22 16:35:03 +0000209 Diag(Tok, diag::err_objc_missing_end);
Steve Narofffb367882007-08-20 21:31:48 +0000210 return 0;
211}
212
213/// objc-interface-decl-list:
214/// empty
Steve Narofffb367882007-08-20 21:31:48 +0000215/// objc-interface-decl-list objc-property-decl [OBJC2]
Steve Naroff0bbffd82007-08-22 16:35:03 +0000216/// objc-interface-decl-list objc-method-requirement [OBJC2]
Steve Naroff81f1bba2007-09-06 21:24:23 +0000217/// objc-interface-decl-list objc-method-proto ';'
Steve Narofffb367882007-08-20 21:31:48 +0000218/// objc-interface-decl-list declaration
219/// objc-interface-decl-list ';'
220///
Steve Naroff0bbffd82007-08-22 16:35:03 +0000221/// objc-method-requirement: [OBJC2]
222/// @required
223/// @optional
224///
Fariborz Jahanian63ca8ae2007-09-17 21:07:36 +0000225void Parser::ParseObjCInterfaceDeclList(DeclTy *interfaceDecl,
226 tok::ObjCKeywordKind contextKey) {
Fariborz Jahanian3dc7cbc2007-09-10 20:33:04 +0000227 llvm::SmallVector<DeclTy*, 32> allMethods;
Fariborz Jahaniand8df6d82007-11-06 22:01:00 +0000228 llvm::SmallVector<DeclTy*, 16> allProperties;
Fariborz Jahanian8b5ab6f2007-09-18 00:25:23 +0000229 tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword;
Steve Naroff1a7fa7b2007-10-29 21:38:07 +0000230 SourceLocation AtEndLoc;
231
Steve Naroff0bbffd82007-08-22 16:35:03 +0000232 while (1) {
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000233 if (Tok.is(tok::at)) {
Steve Naroff0bbffd82007-08-22 16:35:03 +0000234 SourceLocation AtLoc = ConsumeToken(); // the "@"
Steve Naroff87c329f2007-08-23 18:16:40 +0000235 tok::ObjCKeywordKind ocKind = Tok.getObjCKeywordID();
Steve Naroff0bbffd82007-08-22 16:35:03 +0000236
237 if (ocKind == tok::objc_end) { // terminate list
Steve Naroff1a7fa7b2007-10-29 21:38:07 +0000238 AtEndLoc = AtLoc;
Fariborz Jahanian3dc7cbc2007-09-10 20:33:04 +0000239 break;
Steve Naroff0bbffd82007-08-22 16:35:03 +0000240 } else if (ocKind == tok::objc_required) { // protocols only
241 ConsumeToken();
Fariborz Jahanian8b5ab6f2007-09-18 00:25:23 +0000242 MethodImplKind = ocKind;
Fariborz Jahanian63ca8ae2007-09-17 21:07:36 +0000243 if (contextKey != tok::objc_protocol)
244 Diag(AtLoc, diag::err_objc_protocol_required);
Steve Naroff0bbffd82007-08-22 16:35:03 +0000245 } else if (ocKind == tok::objc_optional) { // protocols only
246 ConsumeToken();
Fariborz Jahanian8b5ab6f2007-09-18 00:25:23 +0000247 MethodImplKind = ocKind;
Fariborz Jahanian63ca8ae2007-09-17 21:07:36 +0000248 if (contextKey != tok::objc_protocol)
249 Diag(AtLoc, diag::err_objc_protocol_optional);
Steve Naroff0bbffd82007-08-22 16:35:03 +0000250 } else if (ocKind == tok::objc_property) {
Fariborz Jahaniand8df6d82007-11-06 22:01:00 +0000251 allProperties.push_back(ParseObjCPropertyDecl(interfaceDecl, AtLoc));
Steve Naroff0bbffd82007-08-22 16:35:03 +0000252 continue;
253 } else {
254 Diag(Tok, diag::err_objc_illegal_interface_qual);
255 ConsumeToken();
256 }
257 }
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000258 if (Tok.is(tok::minus) || Tok.is(tok::plus)) {
259 DeclTy *methodPrototype =
260 ParseObjCMethodPrototype(interfaceDecl, MethodImplKind);
Fariborz Jahanian63ca8ae2007-09-17 21:07:36 +0000261 allMethods.push_back(methodPrototype);
Steve Naroff81f1bba2007-09-06 21:24:23 +0000262 // Consume the ';' here, since ParseObjCMethodPrototype() is re-used for
263 // method definitions.
Steve Naroffaa1b6d42007-09-17 15:07:43 +0000264 ExpectAndConsume(tok::semi, diag::err_expected_semi_after,"method proto");
Steve Naroff0bbffd82007-08-22 16:35:03 +0000265 continue;
266 }
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000267 if (Tok.is(tok::semi))
Steve Naroff0bbffd82007-08-22 16:35:03 +0000268 ConsumeToken();
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000269 else if (Tok.is(tok::eof))
Fariborz Jahanian3dc7cbc2007-09-10 20:33:04 +0000270 break;
Steve Naroff304ed392007-09-05 23:30:30 +0000271 else {
Steve Naroff09a0c4c2007-08-22 18:35:33 +0000272 // FIXME: as the name implies, this rule allows function definitions.
273 // We could pass a flag or check for functions during semantic analysis.
Steve Naroff81f1bba2007-09-06 21:24:23 +0000274 ParseDeclarationOrFunctionDefinition();
Steve Naroff304ed392007-09-05 23:30:30 +0000275 }
Steve Naroff0bbffd82007-08-22 16:35:03 +0000276 }
Steve Naroff1ccf4632007-10-30 03:43:13 +0000277 /// Insert collected methods declarations into the @interface object.
278 /// This action is executed even if we don't have any methods (so the @end
279 /// can be recorded properly).
280 Actions.ActOnAddMethodsToObjcDecl(CurScope, interfaceDecl, &allMethods[0],
Fariborz Jahaniand8df6d82007-11-06 22:01:00 +0000281 allMethods.size(),
282 &allProperties[0], allProperties.size(),
283 AtEndLoc);
Steve Naroff0bbffd82007-08-22 16:35:03 +0000284}
285
Fariborz Jahanian6668b8c2007-08-31 16:11:31 +0000286/// Parse property attribute declarations.
287///
288/// property-attr-decl: '(' property-attrlist ')'
289/// property-attrlist:
290/// property-attribute
291/// property-attrlist ',' property-attribute
292/// property-attribute:
293/// getter '=' identifier
294/// setter '=' identifier ':'
295/// readonly
296/// readwrite
297/// assign
298/// retain
299/// copy
300/// nonatomic
301///
Fariborz Jahaniand8df6d82007-11-06 22:01:00 +0000302void Parser::ParseObjCPropertyAttribute (ObjcDeclSpec &DS) {
Fariborz Jahanian6668b8c2007-08-31 16:11:31 +0000303 SourceLocation loc = ConsumeParen(); // consume '('
304 while (isObjCPropertyAttribute()) {
305 const IdentifierInfo *II = Tok.getIdentifierInfo();
306 // getter/setter require extra treatment.
307 if (II == ObjcPropertyAttrs[objc_getter] ||
308 II == ObjcPropertyAttrs[objc_setter]) {
309 // skip getter/setter part.
310 SourceLocation loc = ConsumeToken();
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000311 if (Tok.is(tok::equal)) {
Fariborz Jahanian6668b8c2007-08-31 16:11:31 +0000312 loc = ConsumeToken();
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000313 if (Tok.is(tok::identifier)) {
Fariborz Jahanian6668b8c2007-08-31 16:11:31 +0000314 if (II == ObjcPropertyAttrs[objc_setter]) {
Fariborz Jahaniand8df6d82007-11-06 22:01:00 +0000315 DS.setPropertyAttributes(ObjcDeclSpec::DQ_PR_setter);
316 DS.setSetterName(Tok.getIdentifierInfo());
Fariborz Jahanian6668b8c2007-08-31 16:11:31 +0000317 loc = ConsumeToken(); // consume method name
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000318 if (Tok.isNot(tok::colon)) {
Fariborz Jahanian6668b8c2007-08-31 16:11:31 +0000319 Diag(loc, diag::err_expected_colon);
320 SkipUntil(tok::r_paren,true,true);
321 break;
322 }
323 }
Fariborz Jahaniand8df6d82007-11-06 22:01:00 +0000324 else {
325 DS.setPropertyAttributes(ObjcDeclSpec::DQ_PR_getter);
326 DS.setGetterName(Tok.getIdentifierInfo());
327 }
Fariborz Jahanian6668b8c2007-08-31 16:11:31 +0000328 }
329 else {
330 Diag(loc, diag::err_expected_ident);
331 SkipUntil(tok::r_paren,true,true);
332 break;
333 }
334 }
335 else {
336 Diag(loc, diag::err_objc_expected_equal);
337 SkipUntil(tok::r_paren,true,true);
338 break;
339 }
340 }
Fariborz Jahaniand8df6d82007-11-06 22:01:00 +0000341
342 else if (II == ObjcPropertyAttrs[objc_readonly])
343 DS.setPropertyAttributes(ObjcDeclSpec::DQ_PR_readonly);
344 else if (II == ObjcPropertyAttrs[objc_assign])
345 DS.setPropertyAttributes(ObjcDeclSpec::DQ_PR_assign);
346 else if (II == ObjcPropertyAttrs[objc_readwrite])
347 DS.setPropertyAttributes(ObjcDeclSpec::DQ_PR_readwrite);
348 else if (II == ObjcPropertyAttrs[objc_retain])
349 DS.setPropertyAttributes(ObjcDeclSpec::DQ_PR_retain);
350 else if (II == ObjcPropertyAttrs[objc_copy])
351 DS.setPropertyAttributes(ObjcDeclSpec::DQ_PR_copy);
352 else if (II == ObjcPropertyAttrs[objc_nonatomic])
353 DS.setPropertyAttributes(ObjcDeclSpec::DQ_PR_nonatomic);
354
Fariborz Jahanian6668b8c2007-08-31 16:11:31 +0000355 ConsumeToken(); // consume last attribute token
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000356 if (Tok.is(tok::comma)) {
Fariborz Jahanian6668b8c2007-08-31 16:11:31 +0000357 loc = ConsumeToken();
358 continue;
359 }
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000360 if (Tok.is(tok::r_paren))
Fariborz Jahanian6668b8c2007-08-31 16:11:31 +0000361 break;
362 Diag(loc, diag::err_expected_rparen);
363 SkipUntil(tok::semi);
364 return;
365 }
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000366 if (Tok.is(tok::r_paren))
Fariborz Jahanian6668b8c2007-08-31 16:11:31 +0000367 ConsumeParen();
368 else {
369 Diag(loc, diag::err_objc_expected_property_attr);
370 SkipUntil(tok::r_paren); // recover from error inside attribute list
371 }
372}
373
374/// Main routine to parse property declaration.
375///
376/// @property property-attr-decl[opt] property-component-decl ';'
377///
Fariborz Jahaniand8df6d82007-11-06 22:01:00 +0000378Parser::DeclTy *Parser::ParseObjCPropertyDecl(DeclTy *interfaceDecl,
379 SourceLocation AtLoc) {
Fariborz Jahanian6668b8c2007-08-31 16:11:31 +0000380 assert(Tok.isObjCAtKeyword(tok::objc_property) &&
381 "ParseObjCPropertyDecl(): Expected @property");
Fariborz Jahaniand8df6d82007-11-06 22:01:00 +0000382 ObjcDeclSpec DS;
Fariborz Jahanian6668b8c2007-08-31 16:11:31 +0000383 ConsumeToken(); // the "property" identifier
384 // Parse property attribute list, if any.
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000385 if (Tok.is(tok::l_paren)) {
Fariborz Jahanian6668b8c2007-08-31 16:11:31 +0000386 // property has attribute list.
Fariborz Jahaniand8df6d82007-11-06 22:01:00 +0000387 ParseObjCPropertyAttribute(DS);
Fariborz Jahanian6668b8c2007-08-31 16:11:31 +0000388 }
389 // Parse declaration portion of @property.
Fariborz Jahaniand8df6d82007-11-06 22:01:00 +0000390 llvm::SmallVector<DeclTy*, 8> PropertyDecls;
Fariborz Jahanian6668b8c2007-08-31 16:11:31 +0000391 ParseStructDeclaration(interfaceDecl, PropertyDecls);
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000392 if (Tok.is(tok::semi))
Fariborz Jahanian6668b8c2007-08-31 16:11:31 +0000393 ConsumeToken();
394 else {
395 Diag(Tok, diag::err_expected_semi_decl_list);
396 SkipUntil(tok::r_brace, true, true);
397 }
Fariborz Jahaniand8df6d82007-11-06 22:01:00 +0000398 return Actions.ActOnAddObjcProperties(AtLoc,
399 &PropertyDecls[0], PropertyDecls.size(), DS);
Chris Lattner4b009652007-07-25 00:24:17 +0000400}
Steve Narofffb367882007-08-20 21:31:48 +0000401
Steve Naroff81f1bba2007-09-06 21:24:23 +0000402/// objc-method-proto:
Fariborz Jahanian027c23b2007-09-01 00:26:16 +0000403/// objc-instance-method objc-method-decl objc-method-attributes[opt]
Steve Naroff81f1bba2007-09-06 21:24:23 +0000404/// objc-class-method objc-method-decl objc-method-attributes[opt]
Steve Naroff0bbffd82007-08-22 16:35:03 +0000405///
406/// objc-instance-method: '-'
407/// objc-class-method: '+'
408///
Steve Naroff09a0c4c2007-08-22 18:35:33 +0000409/// objc-method-attributes: [OBJC2]
410/// __attribute__((deprecated))
411///
Fariborz Jahanian8b5ab6f2007-09-18 00:25:23 +0000412Parser::DeclTy *Parser::ParseObjCMethodPrototype(DeclTy *IDecl,
413 tok::ObjCKeywordKind MethodImplKind) {
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000414 assert((Tok.is(tok::minus) || Tok.is(tok::plus)) && "expected +/-");
Steve Naroff0bbffd82007-08-22 16:35:03 +0000415
416 tok::TokenKind methodType = Tok.getKind();
Steve Naroff3774dd92007-10-26 20:53:56 +0000417 SourceLocation mLoc = ConsumeToken();
Steve Naroff0bbffd82007-08-22 16:35:03 +0000418
Fariborz Jahanian8473b222007-11-09 19:52:12 +0000419 DeclTy *MDecl = ParseObjCMethodDecl(mLoc, methodType, IDecl, MethodImplKind);
Steve Naroff81f1bba2007-09-06 21:24:23 +0000420 // Since this rule is used for both method declarations and definitions,
Steve Narofffaed3bf2007-09-10 20:51:04 +0000421 // the caller is (optionally) responsible for consuming the ';'.
Steve Naroff304ed392007-09-05 23:30:30 +0000422 return MDecl;
Steve Naroff0bbffd82007-08-22 16:35:03 +0000423}
424
425/// objc-selector:
426/// identifier
427/// one of
428/// enum struct union if else while do for switch case default
429/// break continue return goto asm sizeof typeof __alignof
430/// unsigned long const short volatile signed restrict _Complex
431/// in out inout bycopy byref oneway int char float double void _Bool
432///
Fariborz Jahanian91193f62007-10-11 00:55:41 +0000433IdentifierInfo *Parser::ParseObjCSelector(SourceLocation &SelectorLoc) {
Chris Lattnerd031a452007-10-07 02:00:24 +0000434 switch (Tok.getKind()) {
435 default:
436 return 0;
437 case tok::identifier:
438 case tok::kw_typeof:
439 case tok::kw___alignof:
440 case tok::kw_auto:
441 case tok::kw_break:
442 case tok::kw_case:
443 case tok::kw_char:
444 case tok::kw_const:
445 case tok::kw_continue:
446 case tok::kw_default:
447 case tok::kw_do:
448 case tok::kw_double:
449 case tok::kw_else:
450 case tok::kw_enum:
451 case tok::kw_extern:
452 case tok::kw_float:
453 case tok::kw_for:
454 case tok::kw_goto:
455 case tok::kw_if:
456 case tok::kw_inline:
457 case tok::kw_int:
458 case tok::kw_long:
459 case tok::kw_register:
460 case tok::kw_restrict:
461 case tok::kw_return:
462 case tok::kw_short:
463 case tok::kw_signed:
464 case tok::kw_sizeof:
465 case tok::kw_static:
466 case tok::kw_struct:
467 case tok::kw_switch:
468 case tok::kw_typedef:
469 case tok::kw_union:
470 case tok::kw_unsigned:
471 case tok::kw_void:
472 case tok::kw_volatile:
473 case tok::kw_while:
474 case tok::kw__Bool:
475 case tok::kw__Complex:
476 IdentifierInfo *II = Tok.getIdentifierInfo();
Fariborz Jahanian91193f62007-10-11 00:55:41 +0000477 SelectorLoc = ConsumeToken();
Chris Lattnerd031a452007-10-07 02:00:24 +0000478 return II;
Fariborz Jahanian171ceb52007-09-27 19:52:15 +0000479 }
Steve Naroff0bbffd82007-08-22 16:35:03 +0000480}
481
Fariborz Jahanian6668b8c2007-08-31 16:11:31 +0000482/// property-attrlist: one of
483/// readonly getter setter assign retain copy nonatomic
484///
485bool Parser::isObjCPropertyAttribute() {
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000486 if (Tok.is(tok::identifier)) {
Fariborz Jahanian6668b8c2007-08-31 16:11:31 +0000487 const IdentifierInfo *II = Tok.getIdentifierInfo();
488 for (unsigned i = 0; i < objc_NumAttrs; ++i)
489 if (II == ObjcPropertyAttrs[i]) return true;
490 }
491 return false;
492}
493
Steve Naroff0bbffd82007-08-22 16:35:03 +0000494/// objc-type-name:
495/// '(' objc-type-qualifiers[opt] type-name ')'
496/// '(' objc-type-qualifiers[opt] ')'
497///
498/// objc-type-qualifiers:
499/// objc-type-qualifier
500/// objc-type-qualifiers objc-type-qualifier
501///
Fariborz Jahanian2fd0daa2007-10-31 23:53:01 +0000502Parser::TypeTy *Parser::ParseObjCTypeName(ObjcDeclSpec &DS) {
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000503 assert(Tok.is(tok::l_paren) && "expected (");
Steve Naroff0bbffd82007-08-22 16:35:03 +0000504
505 SourceLocation LParenLoc = ConsumeParen(), RParenLoc;
Chris Lattner265c8172007-09-27 15:15:46 +0000506 TypeTy *Ty = 0;
Steve Naroff0bbffd82007-08-22 16:35:03 +0000507
Fariborz Jahanian6dab49b2007-10-31 21:59:43 +0000508 // Parse type qualifiers, in, inout, etc.
Fariborz Jahanian6dab49b2007-10-31 21:59:43 +0000509 ParseObjcTypeQualifierList(DS);
Steve Naroffa8ee2262007-08-22 23:18:22 +0000510
Steve Naroff0bbffd82007-08-22 16:35:03 +0000511 if (isTypeSpecifierQualifier()) {
Steve Naroff304ed392007-09-05 23:30:30 +0000512 Ty = ParseTypeName();
513 // FIXME: back when Sema support is in place...
514 // assert(Ty && "Parser::ParseObjCTypeName(): missing type");
Steve Naroff0bbffd82007-08-22 16:35:03 +0000515 }
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000516 if (Tok.isNot(tok::r_paren)) {
Steve Naroff0bbffd82007-08-22 16:35:03 +0000517 MatchRHSPunctuation(tok::r_paren, LParenLoc);
Steve Naroff304ed392007-09-05 23:30:30 +0000518 return 0; // FIXME: decide how we want to handle this error...
Steve Naroff0bbffd82007-08-22 16:35:03 +0000519 }
520 RParenLoc = ConsumeParen();
Steve Naroff304ed392007-09-05 23:30:30 +0000521 return Ty;
Steve Naroff0bbffd82007-08-22 16:35:03 +0000522}
523
524/// objc-method-decl:
525/// objc-selector
Steve Naroff09a0c4c2007-08-22 18:35:33 +0000526/// objc-keyword-selector objc-parmlist[opt]
Steve Naroff0bbffd82007-08-22 16:35:03 +0000527/// objc-type-name objc-selector
Steve Naroff09a0c4c2007-08-22 18:35:33 +0000528/// objc-type-name objc-keyword-selector objc-parmlist[opt]
Steve Naroff0bbffd82007-08-22 16:35:03 +0000529///
530/// objc-keyword-selector:
Steve Naroff72f17fb2007-08-22 22:17:26 +0000531/// objc-keyword-decl
Steve Naroff0bbffd82007-08-22 16:35:03 +0000532/// objc-keyword-selector objc-keyword-decl
533///
534/// objc-keyword-decl:
Steve Naroff72f17fb2007-08-22 22:17:26 +0000535/// objc-selector ':' objc-type-name objc-keyword-attributes[opt] identifier
536/// objc-selector ':' objc-keyword-attributes[opt] identifier
537/// ':' objc-type-name objc-keyword-attributes[opt] identifier
538/// ':' objc-keyword-attributes[opt] identifier
Steve Naroff0bbffd82007-08-22 16:35:03 +0000539///
Steve Naroff09a0c4c2007-08-22 18:35:33 +0000540/// objc-parmlist:
541/// objc-parms objc-ellipsis[opt]
Steve Naroff0bbffd82007-08-22 16:35:03 +0000542///
Steve Naroff09a0c4c2007-08-22 18:35:33 +0000543/// objc-parms:
544/// objc-parms , parameter-declaration
Steve Naroff0bbffd82007-08-22 16:35:03 +0000545///
Steve Naroff09a0c4c2007-08-22 18:35:33 +0000546/// objc-ellipsis:
Steve Naroff0bbffd82007-08-22 16:35:03 +0000547/// , ...
548///
Steve Naroff72f17fb2007-08-22 22:17:26 +0000549/// objc-keyword-attributes: [OBJC2]
550/// __attribute__((unused))
551///
Steve Naroff3774dd92007-10-26 20:53:56 +0000552Parser::DeclTy *Parser::ParseObjCMethodDecl(SourceLocation mLoc,
Fariborz Jahanian8473b222007-11-09 19:52:12 +0000553 tok::TokenKind mType,
554 DeclTy *IDecl,
Steve Naroff4ed9d662007-09-27 14:38:14 +0000555 tok::ObjCKeywordKind MethodImplKind)
556{
Steve Naroff09a0c4c2007-08-22 18:35:33 +0000557 // Parse the return type.
Chris Lattnerd031a452007-10-07 02:00:24 +0000558 TypeTy *ReturnType = 0;
Fariborz Jahanian2fd0daa2007-10-31 23:53:01 +0000559 ObjcDeclSpec DSRet;
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000560 if (Tok.is(tok::l_paren))
Fariborz Jahanian2fd0daa2007-10-31 23:53:01 +0000561 ReturnType = ParseObjCTypeName(DSRet);
Steve Naroff3774dd92007-10-26 20:53:56 +0000562 SourceLocation selLoc;
563 IdentifierInfo *SelIdent = ParseObjCSelector(selLoc);
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000564 if (Tok.isNot(tok::colon)) {
Chris Lattnerd031a452007-10-07 02:00:24 +0000565 if (!SelIdent) {
566 Diag(Tok, diag::err_expected_ident); // missing selector name.
567 // FIXME: this creates a unary selector with a null identifier, is this
568 // ok?? Maybe we should skip to the next semicolon or something.
569 }
570
571 // If attributes exist after the method, parse them.
572 AttributeList *MethodAttrs = 0;
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000573 if (getLang().ObjC2 && Tok.is(tok::kw___attribute))
Chris Lattnerd031a452007-10-07 02:00:24 +0000574 MethodAttrs = ParseAttributes();
575
576 Selector Sel = PP.getSelectorTable().getNullarySelector(SelIdent);
Steve Naroff3774dd92007-10-26 20:53:56 +0000577 return Actions.ActOnMethodDeclaration(mLoc, Tok.getLocation(),
Fariborz Jahanian8473b222007-11-09 19:52:12 +0000578 mType, IDecl, DSRet, ReturnType, Sel,
Fariborz Jahanian2fd0daa2007-10-31 23:53:01 +0000579 0, 0, 0, MethodAttrs, MethodImplKind);
Chris Lattnerd031a452007-10-07 02:00:24 +0000580 }
Steve Naroff304ed392007-09-05 23:30:30 +0000581
Steve Naroff4ed9d662007-09-27 14:38:14 +0000582 llvm::SmallVector<IdentifierInfo *, 12> KeyIdents;
583 llvm::SmallVector<Action::TypeTy *, 12> KeyTypes;
Fariborz Jahanian2fd0daa2007-10-31 23:53:01 +0000584 llvm::SmallVector<ObjcDeclSpec, 12> ArgTypeQuals;
Steve Naroff4ed9d662007-09-27 14:38:14 +0000585 llvm::SmallVector<IdentifierInfo *, 12> ArgNames;
Chris Lattnerd031a452007-10-07 02:00:24 +0000586
587 Action::TypeTy *TypeInfo;
588 while (1) {
589 KeyIdents.push_back(SelIdent);
Steve Naroff4ed9d662007-09-27 14:38:14 +0000590
Chris Lattnerd031a452007-10-07 02:00:24 +0000591 // Each iteration parses a single keyword argument.
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000592 if (Tok.isNot(tok::colon)) {
Chris Lattnerd031a452007-10-07 02:00:24 +0000593 Diag(Tok, diag::err_expected_colon);
594 break;
595 }
596 ConsumeToken(); // Eat the ':'.
Fariborz Jahanian2fd0daa2007-10-31 23:53:01 +0000597 ObjcDeclSpec DSType;
598 if (Tok.is(tok::l_paren)) { // Parse the argument type.
599 TypeInfo = ParseObjCTypeName(DSType);
600 }
Chris Lattnerd031a452007-10-07 02:00:24 +0000601 else
602 TypeInfo = 0;
603 KeyTypes.push_back(TypeInfo);
Fariborz Jahanian2fd0daa2007-10-31 23:53:01 +0000604 ArgTypeQuals.push_back(DSType);
Steve Naroff304ed392007-09-05 23:30:30 +0000605
Chris Lattnerd031a452007-10-07 02:00:24 +0000606 // If attributes exist before the argument name, parse them.
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000607 if (getLang().ObjC2 && Tok.is(tok::kw___attribute))
Chris Lattnerd031a452007-10-07 02:00:24 +0000608 ParseAttributes(); // FIXME: pass attributes through.
Steve Naroff72f17fb2007-08-22 22:17:26 +0000609
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000610 if (Tok.isNot(tok::identifier)) {
Chris Lattnerd031a452007-10-07 02:00:24 +0000611 Diag(Tok, diag::err_expected_ident); // missing argument name.
612 break;
Steve Naroff09a0c4c2007-08-22 18:35:33 +0000613 }
Chris Lattnerd031a452007-10-07 02:00:24 +0000614 ArgNames.push_back(Tok.getIdentifierInfo());
615 ConsumeToken(); // Eat the identifier.
Steve Narofff9e80db2007-10-05 18:42:47 +0000616
Chris Lattnerd031a452007-10-07 02:00:24 +0000617 // Check for another keyword selector.
Fariborz Jahanian91193f62007-10-11 00:55:41 +0000618 SourceLocation Loc;
619 SelIdent = ParseObjCSelector(Loc);
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000620 if (!SelIdent && Tok.isNot(tok::colon))
Chris Lattnerd031a452007-10-07 02:00:24 +0000621 break;
622 // We have a selector or a colon, continue parsing.
Steve Naroff09a0c4c2007-08-22 18:35:33 +0000623 }
Chris Lattnerd031a452007-10-07 02:00:24 +0000624
625 // Parse the (optional) parameter list.
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000626 while (Tok.is(tok::comma)) {
Chris Lattnerd031a452007-10-07 02:00:24 +0000627 ConsumeToken();
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000628 if (Tok.is(tok::ellipsis)) {
Chris Lattnerd031a452007-10-07 02:00:24 +0000629 ConsumeToken();
630 break;
631 }
632 // Parse the c-style argument declaration-specifier.
633 DeclSpec DS;
634 ParseDeclarationSpecifiers(DS);
635 // Parse the declarator.
636 Declarator ParmDecl(DS, Declarator::PrototypeContext);
637 ParseDeclarator(ParmDecl);
638 }
639
640 // FIXME: Add support for optional parmameter list...
Fariborz Jahanian3dc7cbc2007-09-10 20:33:04 +0000641 // If attributes exist after the method, parse them.
Chris Lattnerd031a452007-10-07 02:00:24 +0000642 AttributeList *MethodAttrs = 0;
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000643 if (getLang().ObjC2 && Tok.is(tok::kw___attribute))
Chris Lattnerd031a452007-10-07 02:00:24 +0000644 MethodAttrs = ParseAttributes();
645
646 Selector Sel = PP.getSelectorTable().getSelector(KeyIdents.size(),
647 &KeyIdents[0]);
Steve Naroff3774dd92007-10-26 20:53:56 +0000648 return Actions.ActOnMethodDeclaration(mLoc, Tok.getLocation(),
Fariborz Jahanian8473b222007-11-09 19:52:12 +0000649 mType, IDecl, DSRet, ReturnType, Sel,
Fariborz Jahanian2fd0daa2007-10-31 23:53:01 +0000650 &ArgTypeQuals[0], &KeyTypes[0],
651 &ArgNames[0],
Chris Lattnerd031a452007-10-07 02:00:24 +0000652 MethodAttrs, MethodImplKind);
Steve Naroff0bbffd82007-08-22 16:35:03 +0000653}
654
Fariborz Jahanianc04aff12007-10-08 23:06:41 +0000655/// CmpProtocolVals - Comparison predicate for sorting protocols.
656static bool CmpProtocolVals(const IdentifierInfo* const& lhs,
657 const IdentifierInfo* const& rhs) {
658 return strcmp(lhs->getName(), rhs->getName()) < 0;
659}
660
Steve Narofffb367882007-08-20 21:31:48 +0000661/// objc-protocol-refs:
662/// '<' identifier-list '>'
663///
Steve Naroff304ed392007-09-05 23:30:30 +0000664bool Parser::ParseObjCProtocolReferences(
Steve Naroffef20ed32007-10-30 02:23:23 +0000665 llvm::SmallVectorImpl<IdentifierInfo*> &ProtocolRefs, SourceLocation &endLoc)
666{
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000667 assert(Tok.is(tok::less) && "expected <");
Steve Narofffb367882007-08-20 21:31:48 +0000668
669 ConsumeToken(); // the "<"
Steve Narofffb367882007-08-20 21:31:48 +0000670
671 while (1) {
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000672 if (Tok.isNot(tok::identifier)) {
Steve Narofffb367882007-08-20 21:31:48 +0000673 Diag(Tok, diag::err_expected_ident);
674 SkipUntil(tok::greater);
675 return true;
676 }
677 ProtocolRefs.push_back(Tok.getIdentifierInfo());
678 ConsumeToken();
679
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000680 if (Tok.isNot(tok::comma))
Steve Narofffb367882007-08-20 21:31:48 +0000681 break;
682 ConsumeToken();
683 }
Fariborz Jahanianc04aff12007-10-08 23:06:41 +0000684
685 // Sort protocols, keyed by name.
686 // Later on, we remove duplicates.
687 std::stable_sort(ProtocolRefs.begin(), ProtocolRefs.end(), CmpProtocolVals);
688
689 // Make protocol names unique.
690 ProtocolRefs.erase(std::unique(ProtocolRefs.begin(), ProtocolRefs.end()),
691 ProtocolRefs.end());
Steve Narofffb367882007-08-20 21:31:48 +0000692 // Consume the '>'.
Steve Naroffef20ed32007-10-30 02:23:23 +0000693 if (Tok.is(tok::greater)) {
694 endLoc = ConsumeAnyToken();
695 return false;
696 }
697 Diag(Tok, diag::err_expected_greater);
698 return true;
Steve Narofffb367882007-08-20 21:31:48 +0000699}
700
701/// objc-class-instance-variables:
702/// '{' objc-instance-variable-decl-list[opt] '}'
703///
704/// objc-instance-variable-decl-list:
705/// objc-visibility-spec
706/// objc-instance-variable-decl ';'
707/// ';'
708/// objc-instance-variable-decl-list objc-visibility-spec
709/// objc-instance-variable-decl-list objc-instance-variable-decl ';'
710/// objc-instance-variable-decl-list ';'
711///
712/// objc-visibility-spec:
713/// @private
714/// @protected
715/// @public
Steve Naroffc4474992007-08-21 21:17:12 +0000716/// @package [OBJC2]
Steve Narofffb367882007-08-20 21:31:48 +0000717///
718/// objc-instance-variable-decl:
719/// struct-declaration
720///
Steve Naroff1a7fa7b2007-10-29 21:38:07 +0000721void Parser::ParseObjCClassInstanceVariables(DeclTy *interfaceDecl,
722 SourceLocation atLoc) {
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000723 assert(Tok.is(tok::l_brace) && "expected {");
Steve Naroff81f1bba2007-09-06 21:24:23 +0000724 llvm::SmallVector<DeclTy*, 16> IvarDecls;
Fariborz Jahanian3957dae2007-09-13 20:56:13 +0000725 llvm::SmallVector<DeclTy*, 32> AllIvarDecls;
726 llvm::SmallVector<tok::ObjCKeywordKind, 32> AllVisibilities;
Steve Naroffc4474992007-08-21 21:17:12 +0000727
728 SourceLocation LBraceLoc = ConsumeBrace(); // the "{"
Steve Naroffc4474992007-08-21 21:17:12 +0000729
Fariborz Jahanian3957dae2007-09-13 20:56:13 +0000730 tok::ObjCKeywordKind visibility = tok::objc_private;
Steve Naroffc4474992007-08-21 21:17:12 +0000731 // While we still have something to read, read the instance variables.
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000732 while (Tok.isNot(tok::r_brace) && Tok.isNot(tok::eof)) {
Steve Naroffc4474992007-08-21 21:17:12 +0000733 // Each iteration of this loop reads one objc-instance-variable-decl.
734
735 // Check for extraneous top-level semicolon.
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000736 if (Tok.is(tok::semi)) {
Steve Naroffc4474992007-08-21 21:17:12 +0000737 Diag(Tok, diag::ext_extra_struct_semi);
738 ConsumeToken();
739 continue;
740 }
741 // Set the default visibility to private.
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000742 if (Tok.is(tok::at)) { // parse objc-visibility-spec
Steve Naroffc4474992007-08-21 21:17:12 +0000743 ConsumeToken(); // eat the @ sign
Steve Naroff87c329f2007-08-23 18:16:40 +0000744 switch (Tok.getObjCKeywordID()) {
Steve Naroffc4474992007-08-21 21:17:12 +0000745 case tok::objc_private:
746 case tok::objc_public:
747 case tok::objc_protected:
748 case tok::objc_package:
Steve Naroff87c329f2007-08-23 18:16:40 +0000749 visibility = Tok.getObjCKeywordID();
Steve Naroffc4474992007-08-21 21:17:12 +0000750 ConsumeToken();
751 continue;
752 default:
753 Diag(Tok, diag::err_objc_illegal_visibility_spec);
754 ConsumeToken();
755 continue;
756 }
757 }
758 ParseStructDeclaration(interfaceDecl, IvarDecls);
Fariborz Jahanian3957dae2007-09-13 20:56:13 +0000759 for (unsigned i = 0; i < IvarDecls.size(); i++) {
760 AllIvarDecls.push_back(IvarDecls[i]);
761 AllVisibilities.push_back(visibility);
762 }
Steve Naroff81f1bba2007-09-06 21:24:23 +0000763 IvarDecls.clear();
764
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000765 if (Tok.is(tok::semi)) {
Steve Naroffc4474992007-08-21 21:17:12 +0000766 ConsumeToken();
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000767 } else if (Tok.is(tok::r_brace)) {
Steve Naroffc4474992007-08-21 21:17:12 +0000768 Diag(Tok.getLocation(), diag::ext_expected_semi_decl_list);
769 break;
770 } else {
771 Diag(Tok, diag::err_expected_semi_decl_list);
772 // Skip to end of block or statement
773 SkipUntil(tok::r_brace, true, true);
774 }
775 }
Steve Naroff1a7fa7b2007-10-29 21:38:07 +0000776 SourceLocation RBraceLoc = MatchRHSPunctuation(tok::r_brace, LBraceLoc);
Steve Naroff809b4f02007-10-31 22:11:35 +0000777 // Call ActOnFields() even if we don't have any decls. This is useful
778 // for code rewriting tools that need to be aware of the empty list.
779 Actions.ActOnFields(CurScope, atLoc, interfaceDecl,
780 &AllIvarDecls[0], AllIvarDecls.size(),
781 LBraceLoc, RBraceLoc, &AllVisibilities[0]);
Steve Naroffc4474992007-08-21 21:17:12 +0000782 return;
Chris Lattner4b009652007-07-25 00:24:17 +0000783}
Steve Narofffb367882007-08-20 21:31:48 +0000784
785/// objc-protocol-declaration:
786/// objc-protocol-definition
787/// objc-protocol-forward-reference
788///
789/// objc-protocol-definition:
790/// @protocol identifier
791/// objc-protocol-refs[opt]
Steve Naroff81f1bba2007-09-06 21:24:23 +0000792/// objc-interface-decl-list
Steve Narofffb367882007-08-20 21:31:48 +0000793/// @end
794///
795/// objc-protocol-forward-reference:
796/// @protocol identifier-list ';'
797///
798/// "@protocol identifier ;" should be resolved as "@protocol
Steve Naroff81f1bba2007-09-06 21:24:23 +0000799/// identifier-list ;": objc-interface-decl-list may not start with a
Steve Narofffb367882007-08-20 21:31:48 +0000800/// semicolon in the first alternative if objc-protocol-refs are omitted.
801
Steve Naroff72f17fb2007-08-22 22:17:26 +0000802Parser::DeclTy *Parser::ParseObjCAtProtocolDeclaration(SourceLocation AtLoc) {
Steve Naroff87c329f2007-08-23 18:16:40 +0000803 assert(Tok.isObjCAtKeyword(tok::objc_protocol) &&
Steve Naroff72f17fb2007-08-22 22:17:26 +0000804 "ParseObjCAtProtocolDeclaration(): Expected @protocol");
805 ConsumeToken(); // the "protocol" identifier
806
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000807 if (Tok.isNot(tok::identifier)) {
Steve Naroff72f17fb2007-08-22 22:17:26 +0000808 Diag(Tok, diag::err_expected_ident); // missing protocol name.
809 return 0;
810 }
811 // Save the protocol name, then consume it.
812 IdentifierInfo *protocolName = Tok.getIdentifierInfo();
813 SourceLocation nameLoc = ConsumeToken();
814
Fariborz Jahanianc716c942007-09-21 15:40:54 +0000815 llvm::SmallVector<IdentifierInfo *, 8> ProtocolRefs;
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000816 if (Tok.is(tok::semi)) { // forward declaration of one protocol.
Steve Naroff72f17fb2007-08-22 22:17:26 +0000817 ConsumeToken();
Fariborz Jahanianc716c942007-09-21 15:40:54 +0000818 ProtocolRefs.push_back(protocolName);
Steve Naroff72f17fb2007-08-22 22:17:26 +0000819 }
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000820 if (Tok.is(tok::comma)) { // list of forward declarations.
Steve Naroff72f17fb2007-08-22 22:17:26 +0000821 // Parse the list of forward declarations.
Steve Naroff72f17fb2007-08-22 22:17:26 +0000822 ProtocolRefs.push_back(protocolName);
823
824 while (1) {
825 ConsumeToken(); // the ','
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000826 if (Tok.isNot(tok::identifier)) {
Steve Naroff72f17fb2007-08-22 22:17:26 +0000827 Diag(Tok, diag::err_expected_ident);
828 SkipUntil(tok::semi);
829 return 0;
830 }
831 ProtocolRefs.push_back(Tok.getIdentifierInfo());
832 ConsumeToken(); // the identifier
833
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000834 if (Tok.isNot(tok::comma))
Steve Naroff72f17fb2007-08-22 22:17:26 +0000835 break;
836 }
837 // Consume the ';'.
838 if (ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@protocol"))
839 return 0;
Steve Naroff72f17fb2007-08-22 22:17:26 +0000840 }
Fariborz Jahanianc716c942007-09-21 15:40:54 +0000841 if (ProtocolRefs.size() > 0)
Steve Naroff415c1832007-10-10 17:32:04 +0000842 return Actions.ActOnForwardProtocolDeclaration(AtLoc,
Steve Naroffb4dfe362007-10-02 22:39:18 +0000843 &ProtocolRefs[0],
844 ProtocolRefs.size());
Steve Naroff72f17fb2007-08-22 22:17:26 +0000845 // Last, and definitely not least, parse a protocol declaration.
Steve Naroffef20ed32007-10-30 02:23:23 +0000846 SourceLocation endProtoLoc;
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000847 if (Tok.is(tok::less)) {
Steve Naroffef20ed32007-10-30 02:23:23 +0000848 if (ParseObjCProtocolReferences(ProtocolRefs, endProtoLoc))
Steve Naroff72f17fb2007-08-22 22:17:26 +0000849 return 0;
850 }
Fariborz Jahanian63ca8ae2007-09-17 21:07:36 +0000851
Steve Naroff415c1832007-10-10 17:32:04 +0000852 DeclTy *ProtoType = Actions.ActOnStartProtocolInterface(AtLoc,
Fariborz Jahanian63ca8ae2007-09-17 21:07:36 +0000853 protocolName, nameLoc,
854 &ProtocolRefs[0],
Steve Naroffef20ed32007-10-30 02:23:23 +0000855 ProtocolRefs.size(), endProtoLoc);
Fariborz Jahanian63ca8ae2007-09-17 21:07:36 +0000856 ParseObjCInterfaceDeclList(ProtoType, tok::objc_protocol);
Steve Naroff72f17fb2007-08-22 22:17:26 +0000857
858 // The @ sign was already consumed by ParseObjCInterfaceDeclList().
Steve Naroff87c329f2007-08-23 18:16:40 +0000859 if (Tok.isObjCAtKeyword(tok::objc_end)) {
Steve Naroff72f17fb2007-08-22 22:17:26 +0000860 ConsumeToken(); // the "end" identifier
Fariborz Jahanianac20be22007-10-08 18:53:38 +0000861 return ProtoType;
Steve Naroff72f17fb2007-08-22 22:17:26 +0000862 }
863 Diag(Tok, diag::err_objc_missing_end);
Steve Narofffb367882007-08-20 21:31:48 +0000864 return 0;
Chris Lattner4b009652007-07-25 00:24:17 +0000865}
Steve Narofffb367882007-08-20 21:31:48 +0000866
867/// objc-implementation:
868/// objc-class-implementation-prologue
869/// objc-category-implementation-prologue
870///
871/// objc-class-implementation-prologue:
872/// @implementation identifier objc-superclass[opt]
873/// objc-class-instance-variables[opt]
874///
875/// objc-category-implementation-prologue:
876/// @implementation identifier ( identifier )
877
Fariborz Jahanian027c23b2007-09-01 00:26:16 +0000878Parser::DeclTy *Parser::ParseObjCAtImplementationDeclaration(
879 SourceLocation atLoc) {
880 assert(Tok.isObjCAtKeyword(tok::objc_implementation) &&
881 "ParseObjCAtImplementationDeclaration(): Expected @implementation");
882 ConsumeToken(); // the "implementation" identifier
883
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000884 if (Tok.isNot(tok::identifier)) {
Fariborz Jahanian027c23b2007-09-01 00:26:16 +0000885 Diag(Tok, diag::err_expected_ident); // missing class or category name.
886 return 0;
887 }
888 // We have a class or category name - consume it.
Fariborz Jahanianc091b5d2007-09-25 18:38:09 +0000889 IdentifierInfo *nameId = Tok.getIdentifierInfo();
Fariborz Jahanian027c23b2007-09-01 00:26:16 +0000890 SourceLocation nameLoc = ConsumeToken(); // consume class or category name
891
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000892 if (Tok.is(tok::l_paren)) {
Fariborz Jahanian027c23b2007-09-01 00:26:16 +0000893 // we have a category implementation.
894 SourceLocation lparenLoc = ConsumeParen();
895 SourceLocation categoryLoc, rparenLoc;
896 IdentifierInfo *categoryId = 0;
897
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000898 if (Tok.is(tok::identifier)) {
Fariborz Jahanian027c23b2007-09-01 00:26:16 +0000899 categoryId = Tok.getIdentifierInfo();
900 categoryLoc = ConsumeToken();
901 } else {
902 Diag(Tok, diag::err_expected_ident); // missing category name.
903 return 0;
904 }
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000905 if (Tok.isNot(tok::r_paren)) {
Fariborz Jahanian027c23b2007-09-01 00:26:16 +0000906 Diag(Tok, diag::err_expected_rparen);
907 SkipUntil(tok::r_paren, false); // don't stop at ';'
908 return 0;
909 }
910 rparenLoc = ConsumeParen();
Steve Naroff415c1832007-10-10 17:32:04 +0000911 DeclTy *ImplCatType = Actions.ActOnStartCategoryImplementation(
Fariborz Jahaniana91aa322007-10-02 16:38:50 +0000912 atLoc, nameId, nameLoc, categoryId,
913 categoryLoc);
Fariborz Jahanian83ddf822007-11-10 20:59:13 +0000914 ObjcImpDecl = ImplCatType;
915 return 0;
Fariborz Jahanian027c23b2007-09-01 00:26:16 +0000916 }
917 // We have a class implementation
Fariborz Jahanianc091b5d2007-09-25 18:38:09 +0000918 SourceLocation superClassLoc;
919 IdentifierInfo *superClassId = 0;
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000920 if (Tok.is(tok::colon)) {
Fariborz Jahanian027c23b2007-09-01 00:26:16 +0000921 // We have a super class
922 ConsumeToken();
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000923 if (Tok.isNot(tok::identifier)) {
Fariborz Jahanian027c23b2007-09-01 00:26:16 +0000924 Diag(Tok, diag::err_expected_ident); // missing super class name.
925 return 0;
926 }
Fariborz Jahanianc091b5d2007-09-25 18:38:09 +0000927 superClassId = Tok.getIdentifierInfo();
928 superClassLoc = ConsumeToken(); // Consume super class name
Fariborz Jahanian027c23b2007-09-01 00:26:16 +0000929 }
Steve Naroff415c1832007-10-10 17:32:04 +0000930 DeclTy *ImplClsType = Actions.ActOnStartClassImplementation(
Steve Naroff25aace82007-10-03 21:00:46 +0000931 atLoc, nameId, nameLoc,
Fariborz Jahanianc091b5d2007-09-25 18:38:09 +0000932 superClassId, superClassLoc);
933
Steve Naroff1a7fa7b2007-10-29 21:38:07 +0000934 if (Tok.is(tok::l_brace)) // we have ivars
935 ParseObjCClassInstanceVariables(ImplClsType/*FIXME*/, atLoc);
Fariborz Jahanian83ddf822007-11-10 20:59:13 +0000936 ObjcImpDecl = ImplClsType;
Fariborz Jahanian027c23b2007-09-01 00:26:16 +0000937
Fariborz Jahanian83ddf822007-11-10 20:59:13 +0000938 return 0;
Chris Lattner4b009652007-07-25 00:24:17 +0000939}
Steve Naroff1a7fa7b2007-10-29 21:38:07 +0000940
Fariborz Jahanian027c23b2007-09-01 00:26:16 +0000941Parser::DeclTy *Parser::ParseObjCAtEndDeclaration(SourceLocation atLoc) {
942 assert(Tok.isObjCAtKeyword(tok::objc_end) &&
943 "ParseObjCAtEndDeclaration(): Expected @end");
944 ConsumeToken(); // the "end" identifier
Fariborz Jahanian1e4e82f2007-09-27 18:57:03 +0000945 if (ObjcImpDecl) {
946 // Checking is not necessary except that a parse error might have caused
947 // @implementation not to have been parsed to completion and ObjcImpDecl
948 // could be 0.
949 /// Insert collected methods declarations into the @interface object.
Steve Naroff25aace82007-10-03 21:00:46 +0000950 Actions.ActOnAddMethodsToObjcDecl(CurScope, ObjcImpDecl,
Steve Naroff1a7fa7b2007-10-29 21:38:07 +0000951 &AllImplMethods[0], AllImplMethods.size(),
Fariborz Jahaniand8df6d82007-11-06 22:01:00 +0000952 (DeclTy **)0, 0,
Steve Naroff1a7fa7b2007-10-29 21:38:07 +0000953 atLoc);
Fariborz Jahanian1e4e82f2007-09-27 18:57:03 +0000954 AllImplMethods.clear();
955 }
Fariborz Jahanian027c23b2007-09-01 00:26:16 +0000956
Fariborz Jahanian83ddf822007-11-10 20:59:13 +0000957 return ObjcImpDecl;
Steve Narofffb367882007-08-20 21:31:48 +0000958}
Fariborz Jahanianb62aff32007-09-04 19:26:51 +0000959
960/// compatibility-alias-decl:
961/// @compatibility_alias alias-name class-name ';'
962///
963Parser::DeclTy *Parser::ParseObjCAtAliasDeclaration(SourceLocation atLoc) {
964 assert(Tok.isObjCAtKeyword(tok::objc_compatibility_alias) &&
965 "ParseObjCAtAliasDeclaration(): Expected @compatibility_alias");
966 ConsumeToken(); // consume compatibility_alias
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000967 if (Tok.isNot(tok::identifier)) {
Fariborz Jahanianb62aff32007-09-04 19:26:51 +0000968 Diag(Tok, diag::err_expected_ident);
969 return 0;
970 }
Fariborz Jahanian05d212a2007-10-11 23:42:27 +0000971 IdentifierInfo *aliasId = Tok.getIdentifierInfo();
972 SourceLocation aliasLoc = ConsumeToken(); // consume alias-name
Chris Lattnera1d2bb72007-10-09 17:51:17 +0000973 if (Tok.isNot(tok::identifier)) {
Fariborz Jahanianb62aff32007-09-04 19:26:51 +0000974 Diag(Tok, diag::err_expected_ident);
975 return 0;
976 }
Fariborz Jahanian05d212a2007-10-11 23:42:27 +0000977 IdentifierInfo *classId = Tok.getIdentifierInfo();
978 SourceLocation classLoc = ConsumeToken(); // consume class-name;
979 if (Tok.isNot(tok::semi)) {
Fariborz Jahanian6c30fa62007-09-04 21:42:12 +0000980 Diag(Tok, diag::err_expected_semi_after, "@compatibility_alias");
Fariborz Jahanian05d212a2007-10-11 23:42:27 +0000981 return 0;
982 }
983 DeclTy *ClsType = Actions.ActOnCompatiblityAlias(atLoc,
984 aliasId, aliasLoc,
985 classId, classLoc);
986 return ClsType;
Chris Lattner4b009652007-07-25 00:24:17 +0000987}
988
Fariborz Jahanian027c23b2007-09-01 00:26:16 +0000989/// property-synthesis:
990/// @synthesize property-ivar-list ';'
991///
992/// property-ivar-list:
993/// property-ivar
994/// property-ivar-list ',' property-ivar
995///
996/// property-ivar:
997/// identifier
998/// identifier '=' identifier
999///
1000Parser::DeclTy *Parser::ParseObjCPropertySynthesize(SourceLocation atLoc) {
1001 assert(Tok.isObjCAtKeyword(tok::objc_synthesize) &&
1002 "ParseObjCPropertyDynamic(): Expected '@synthesize'");
1003 SourceLocation loc = ConsumeToken(); // consume dynamic
Chris Lattnera1d2bb72007-10-09 17:51:17 +00001004 if (Tok.isNot(tok::identifier)) {
Fariborz Jahanian027c23b2007-09-01 00:26:16 +00001005 Diag(Tok, diag::err_expected_ident);
1006 return 0;
1007 }
Chris Lattnera1d2bb72007-10-09 17:51:17 +00001008 while (Tok.is(tok::identifier)) {
Fariborz Jahanian027c23b2007-09-01 00:26:16 +00001009 ConsumeToken(); // consume property name
Chris Lattnera1d2bb72007-10-09 17:51:17 +00001010 if (Tok.is(tok::equal)) {
Fariborz Jahanian027c23b2007-09-01 00:26:16 +00001011 // property '=' ivar-name
1012 ConsumeToken(); // consume '='
Chris Lattnera1d2bb72007-10-09 17:51:17 +00001013 if (Tok.isNot(tok::identifier)) {
Fariborz Jahanian027c23b2007-09-01 00:26:16 +00001014 Diag(Tok, diag::err_expected_ident);
1015 break;
1016 }
1017 ConsumeToken(); // consume ivar-name
1018 }
Chris Lattnera1d2bb72007-10-09 17:51:17 +00001019 if (Tok.isNot(tok::comma))
Fariborz Jahanian027c23b2007-09-01 00:26:16 +00001020 break;
1021 ConsumeToken(); // consume ','
1022 }
Chris Lattnera1d2bb72007-10-09 17:51:17 +00001023 if (Tok.isNot(tok::semi))
Fariborz Jahanian027c23b2007-09-01 00:26:16 +00001024 Diag(Tok, diag::err_expected_semi_after, "@synthesize");
1025 return 0;
Chris Lattner4b009652007-07-25 00:24:17 +00001026}
1027
Fariborz Jahanian027c23b2007-09-01 00:26:16 +00001028/// property-dynamic:
1029/// @dynamic property-list
1030///
1031/// property-list:
1032/// identifier
1033/// property-list ',' identifier
1034///
1035Parser::DeclTy *Parser::ParseObjCPropertyDynamic(SourceLocation atLoc) {
1036 assert(Tok.isObjCAtKeyword(tok::objc_dynamic) &&
1037 "ParseObjCPropertyDynamic(): Expected '@dynamic'");
1038 SourceLocation loc = ConsumeToken(); // consume dynamic
Chris Lattnera1d2bb72007-10-09 17:51:17 +00001039 if (Tok.isNot(tok::identifier)) {
Fariborz Jahanian027c23b2007-09-01 00:26:16 +00001040 Diag(Tok, diag::err_expected_ident);
1041 return 0;
1042 }
Chris Lattnera1d2bb72007-10-09 17:51:17 +00001043 while (Tok.is(tok::identifier)) {
Fariborz Jahanian027c23b2007-09-01 00:26:16 +00001044 ConsumeToken(); // consume property name
Chris Lattnera1d2bb72007-10-09 17:51:17 +00001045 if (Tok.isNot(tok::comma))
Fariborz Jahanian027c23b2007-09-01 00:26:16 +00001046 break;
1047 ConsumeToken(); // consume ','
1048 }
Chris Lattnera1d2bb72007-10-09 17:51:17 +00001049 if (Tok.isNot(tok::semi))
Fariborz Jahanian027c23b2007-09-01 00:26:16 +00001050 Diag(Tok, diag::err_expected_semi_after, "@dynamic");
1051 return 0;
1052}
Fariborz Jahanian64b864e2007-09-19 19:14:32 +00001053
1054/// objc-throw-statement:
1055/// throw expression[opt];
1056///
Fariborz Jahanian08df2c62007-11-07 02:00:49 +00001057Parser::StmtResult Parser::ParseObjCThrowStmt(SourceLocation atLoc) {
1058 ExprResult Res;
Fariborz Jahanian64b864e2007-09-19 19:14:32 +00001059 ConsumeToken(); // consume throw
Chris Lattnera1d2bb72007-10-09 17:51:17 +00001060 if (Tok.isNot(tok::semi)) {
Fariborz Jahanian08df2c62007-11-07 02:00:49 +00001061 Res = ParseExpression();
Fariborz Jahanian64b864e2007-09-19 19:14:32 +00001062 if (Res.isInvalid) {
1063 SkipUntil(tok::semi);
Fariborz Jahanian08df2c62007-11-07 02:00:49 +00001064 return true;
Fariborz Jahanian64b864e2007-09-19 19:14:32 +00001065 }
1066 }
Fariborz Jahanian08df2c62007-11-07 02:00:49 +00001067 ConsumeToken(); // consume ';'
1068 return Actions.ActOnObjcAtThrowStmt(atLoc, Res.Val);
Fariborz Jahanian64b864e2007-09-19 19:14:32 +00001069}
1070
1071/// objc-try-catch-statement:
1072/// @try compound-statement objc-catch-list[opt]
1073/// @try compound-statement objc-catch-list[opt] @finally compound-statement
1074///
1075/// objc-catch-list:
1076/// @catch ( parameter-declaration ) compound-statement
1077/// objc-catch-list @catch ( catch-parameter-declaration ) compound-statement
1078/// catch-parameter-declaration:
1079/// parameter-declaration
1080/// '...' [OBJC2]
1081///
Fariborz Jahanian70952482007-11-01 21:12:44 +00001082Parser::StmtResult Parser::ParseObjCTryStmt(SourceLocation atLoc) {
Fariborz Jahanian64b864e2007-09-19 19:14:32 +00001083 bool catch_or_finally_seen = false;
1084 ConsumeToken(); // consume try
Chris Lattnera1d2bb72007-10-09 17:51:17 +00001085 if (Tok.isNot(tok::l_brace)) {
Fariborz Jahanian64b864e2007-09-19 19:14:32 +00001086 Diag (Tok, diag::err_expected_lbrace);
Fariborz Jahanian70952482007-11-01 21:12:44 +00001087 return true;
Fariborz Jahanian64b864e2007-09-19 19:14:32 +00001088 }
Fariborz Jahanian06798362007-11-01 23:59:59 +00001089 StmtResult CatchStmts;
Fariborz Jahaniande3abf82007-11-02 00:18:53 +00001090 StmtResult FinallyStmt;
Fariborz Jahanian64b864e2007-09-19 19:14:32 +00001091 StmtResult TryBody = ParseCompoundStatementBody();
Fariborz Jahanianb8bf6072007-11-02 15:39:31 +00001092 if (TryBody.isInvalid)
1093 TryBody = Actions.ActOnNullStmt(Tok.getLocation());
Chris Lattnera1d2bb72007-10-09 17:51:17 +00001094 while (Tok.is(tok::at)) {
Fariborz Jahaniande3abf82007-11-02 00:18:53 +00001095 SourceLocation AtCatchFinallyLoc = ConsumeToken();
Fariborz Jahanian64b864e2007-09-19 19:14:32 +00001096 if (Tok.getIdentifierInfo()->getObjCKeywordID() == tok::objc_catch) {
Fariborz Jahanian06798362007-11-01 23:59:59 +00001097 StmtTy *FirstPart = 0;
1098 ConsumeToken(); // consume catch
Chris Lattnera1d2bb72007-10-09 17:51:17 +00001099 if (Tok.is(tok::l_paren)) {
Fariborz Jahanian64b864e2007-09-19 19:14:32 +00001100 ConsumeParen();
Fariborz Jahanian06798362007-11-01 23:59:59 +00001101 EnterScope(Scope::DeclScope);
Chris Lattnera1d2bb72007-10-09 17:51:17 +00001102 if (Tok.isNot(tok::ellipsis)) {
Fariborz Jahanian64b864e2007-09-19 19:14:32 +00001103 DeclSpec DS;
1104 ParseDeclarationSpecifiers(DS);
Fariborz Jahanian06798362007-11-01 23:59:59 +00001105 // FIXME: Is BlockContext right?
1106 Declarator DeclaratorInfo(DS, Declarator::BlockContext);
1107 ParseDeclarator(DeclaratorInfo);
Fariborz Jahanian59e9e042007-11-02 18:16:07 +00001108 DeclTy * aBlockVarDecl = Actions.ActOnDeclarator(CurScope,
1109 DeclaratorInfo, 0);
1110 StmtResult stmtResult = Actions.ActOnDeclStmt(aBlockVarDecl);
Fariborz Jahanian06798362007-11-01 23:59:59 +00001111 FirstPart = stmtResult.isInvalid ? 0 : stmtResult.Val;
Fariborz Jahanian64b864e2007-09-19 19:14:32 +00001112 }
1113 else
1114 ConsumeToken(); // consume '...'
Fariborz Jahanian06798362007-11-01 23:59:59 +00001115 SourceLocation RParenLoc = ConsumeParen();
Fariborz Jahanian70952482007-11-01 21:12:44 +00001116 StmtResult CatchBody = ParseCompoundStatementBody();
Fariborz Jahanian06798362007-11-01 23:59:59 +00001117 if (CatchBody.isInvalid)
1118 CatchBody = Actions.ActOnNullStmt(Tok.getLocation());
Fariborz Jahaniande3abf82007-11-02 00:18:53 +00001119 CatchStmts = Actions.ActOnObjcAtCatchStmt(AtCatchFinallyLoc, RParenLoc,
Fariborz Jahanian06798362007-11-01 23:59:59 +00001120 FirstPart, CatchBody.Val, CatchStmts.Val);
1121 ExitScope();
Fariborz Jahanian64b864e2007-09-19 19:14:32 +00001122 }
1123 else {
Fariborz Jahaniande3abf82007-11-02 00:18:53 +00001124 Diag(AtCatchFinallyLoc, diag::err_expected_lparen_after,
1125 "@catch clause");
Fariborz Jahanian70952482007-11-01 21:12:44 +00001126 return true;
Fariborz Jahanian64b864e2007-09-19 19:14:32 +00001127 }
1128 catch_or_finally_seen = true;
1129 }
1130 else if (Tok.getIdentifierInfo()->getObjCKeywordID() == tok::objc_finally) {
1131 ConsumeToken(); // consume finally
1132 StmtResult FinallyBody = ParseCompoundStatementBody();
Fariborz Jahaniande3abf82007-11-02 00:18:53 +00001133 if (FinallyBody.isInvalid)
1134 FinallyBody = Actions.ActOnNullStmt(Tok.getLocation());
1135 FinallyStmt = Actions.ActOnObjcAtFinallyStmt(AtCatchFinallyLoc,
1136 FinallyBody.Val);
Fariborz Jahanian64b864e2007-09-19 19:14:32 +00001137 catch_or_finally_seen = true;
1138 break;
1139 }
1140 }
Fariborz Jahanianb8bf6072007-11-02 15:39:31 +00001141 if (!catch_or_finally_seen) {
Fariborz Jahanian64b864e2007-09-19 19:14:32 +00001142 Diag(atLoc, diag::err_missing_catch_finally);
Fariborz Jahanianb8bf6072007-11-02 15:39:31 +00001143 return true;
1144 }
1145 return Actions.ActOnObjcAtTryStmt(atLoc, TryBody.Val, CatchStmts.Val,
1146 FinallyStmt.Val);
Fariborz Jahanian64b864e2007-09-19 19:14:32 +00001147}
Fariborz Jahanian027c23b2007-09-01 00:26:16 +00001148
Steve Naroff81f1bba2007-09-06 21:24:23 +00001149/// objc-method-def: objc-method-proto ';'[opt] '{' body '}'
Fariborz Jahanian027c23b2007-09-01 00:26:16 +00001150///
Fariborz Jahaniane6f59f12007-11-10 16:31:34 +00001151void Parser::ParseObjCInstanceMethodDefinition() {
Chris Lattnera1d2bb72007-10-09 17:51:17 +00001152 assert(Tok.is(tok::minus) && "Method definitions should start with '-'");
Fariborz Jahaniandfb1c372007-11-08 23:49:49 +00001153 DeclTy *MDecl = ParseObjCMethodPrototype(ObjcImpDecl);
Fariborz Jahanian63ca8ae2007-09-17 21:07:36 +00001154 // FIXME: @optional/@protocol??
Fariborz Jahaniandfb1c372007-11-08 23:49:49 +00001155 AllImplMethods.push_back(MDecl);
Fariborz Jahanian027c23b2007-09-01 00:26:16 +00001156 // parse optional ';'
Chris Lattnera1d2bb72007-10-09 17:51:17 +00001157 if (Tok.is(tok::semi))
Fariborz Jahanian027c23b2007-09-01 00:26:16 +00001158 ConsumeToken();
1159
Chris Lattnera1d2bb72007-10-09 17:51:17 +00001160 if (Tok.isNot(tok::l_brace)) {
Fariborz Jahanian027c23b2007-09-01 00:26:16 +00001161 Diag (Tok, diag::err_expected_lbrace);
Fariborz Jahaniane6f59f12007-11-10 16:31:34 +00001162 return;
Fariborz Jahanian027c23b2007-09-01 00:26:16 +00001163 }
Fariborz Jahaniane6f59f12007-11-10 16:31:34 +00001164 ObjcParseMethodDefinition(MDecl);
Fariborz Jahanian027c23b2007-09-01 00:26:16 +00001165}
1166
Steve Naroff81f1bba2007-09-06 21:24:23 +00001167/// objc-method-def: objc-method-proto ';'[opt] '{' body '}'
Fariborz Jahanian027c23b2007-09-01 00:26:16 +00001168///
Fariborz Jahaniane6f59f12007-11-10 16:31:34 +00001169void Parser::ParseObjCClassMethodDefinition() {
Chris Lattnera1d2bb72007-10-09 17:51:17 +00001170 assert(Tok.is(tok::plus) && "Class method definitions should start with '+'");
Fariborz Jahaniandfb1c372007-11-08 23:49:49 +00001171 DeclTy *MDecl = ParseObjCMethodPrototype(ObjcImpDecl);
Fariborz Jahanian63ca8ae2007-09-17 21:07:36 +00001172 // FIXME: @optional/@protocol??
Fariborz Jahaniandfb1c372007-11-08 23:49:49 +00001173 AllImplMethods.push_back(MDecl);
Fariborz Jahanian027c23b2007-09-01 00:26:16 +00001174 // parse optional ';'
Chris Lattnera1d2bb72007-10-09 17:51:17 +00001175 if (Tok.is(tok::semi))
Fariborz Jahanian027c23b2007-09-01 00:26:16 +00001176 ConsumeToken();
Chris Lattnera1d2bb72007-10-09 17:51:17 +00001177 if (Tok.isNot(tok::l_brace)) {
Fariborz Jahanian027c23b2007-09-01 00:26:16 +00001178 Diag (Tok, diag::err_expected_lbrace);
Fariborz Jahaniane6f59f12007-11-10 16:31:34 +00001179 return;
Fariborz Jahanian027c23b2007-09-01 00:26:16 +00001180 }
Fariborz Jahaniane6f59f12007-11-10 16:31:34 +00001181 ObjcParseMethodDefinition(MDecl);
Chris Lattner4b009652007-07-25 00:24:17 +00001182}
Anders Carlssona66cad42007-08-21 17:43:55 +00001183
Steve Narofffb9dd752007-10-15 20:55:58 +00001184Parser::ExprResult Parser::ParseObjCAtExpression(SourceLocation AtLoc) {
Anders Carlssona66cad42007-08-21 17:43:55 +00001185
1186 switch (Tok.getKind()) {
1187 case tok::string_literal: // primary-expression: string-literal
1188 case tok::wide_string_literal:
Steve Naroff0add5d22007-11-03 11:27:19 +00001189 return ParsePostfixExpressionSuffix(ParseObjCStringLiteral(AtLoc));
Anders Carlsson2996b4e2007-08-23 15:25:28 +00001190 default:
1191 break;
1192 }
1193
1194 switch (Tok.getIdentifierInfo()->getObjCKeywordID()) {
Chris Lattnercfd61c82007-10-16 22:51:17 +00001195 case tok::objc_encode:
1196 return ParsePostfixExpressionSuffix(ParseObjCEncodeExpression(AtLoc));
1197 case tok::objc_protocol:
Fariborz Jahanian957448a2007-10-16 23:21:02 +00001198 return ParsePostfixExpressionSuffix(ParseObjCProtocolExpression(AtLoc));
Chris Lattnercfd61c82007-10-16 22:51:17 +00001199 case tok::objc_selector:
Fariborz Jahanian957448a2007-10-16 23:21:02 +00001200 return ParsePostfixExpressionSuffix(ParseObjCSelectorExpression(AtLoc));
Chris Lattnercfd61c82007-10-16 22:51:17 +00001201 default:
1202 Diag(AtLoc, diag::err_unexpected_at);
1203 SkipUntil(tok::semi);
1204 break;
Anders Carlssona66cad42007-08-21 17:43:55 +00001205 }
1206
1207 return 0;
1208}
1209
Fariborz Jahanian1e534dc2007-09-05 19:52:07 +00001210/// objc-message-expr:
1211/// '[' objc-receiver objc-message-args ']'
1212///
1213/// objc-receiver:
1214/// expression
1215/// class-name
1216/// type-name
1217///
1218/// objc-message-args:
1219/// objc-selector
1220/// objc-keywordarg-list
1221///
1222/// objc-keywordarg-list:
1223/// objc-keywordarg
1224/// objc-keywordarg-list objc-keywordarg
1225///
1226/// objc-keywordarg:
1227/// selector-name[opt] ':' objc-keywordexpr
1228///
1229/// objc-keywordexpr:
1230/// nonempty-expr-list
1231///
1232/// nonempty-expr-list:
1233/// assignment-expression
1234/// nonempty-expr-list , assignment-expression
1235///
1236Parser::ExprResult Parser::ParseObjCMessageExpression() {
Chris Lattnera1d2bb72007-10-09 17:51:17 +00001237 assert(Tok.is(tok::l_square) && "'[' expected");
Steve Naroffc39ca262007-09-18 23:55:05 +00001238 SourceLocation LBracloc = ConsumeBracket(); // consume '['
Steve Naroff253118b2007-09-17 20:25:27 +00001239 IdentifierInfo *ReceiverName = 0;
1240 ExprTy *ReceiverExpr = 0;
Fariborz Jahaniand4462f92007-09-05 23:08:20 +00001241 // Parse receiver
Chris Lattnera1d2bb72007-10-09 17:51:17 +00001242 if (Tok.is(tok::identifier) &&
Steve Naroff253118b2007-09-17 20:25:27 +00001243 Actions.isTypeName(*Tok.getIdentifierInfo(), CurScope)) {
1244 ReceiverName = Tok.getIdentifierInfo();
Steve Narofff0c31dd2007-09-16 16:16:00 +00001245 ConsumeToken();
Steve Naroff253118b2007-09-17 20:25:27 +00001246 } else {
1247 ExprResult Res = ParseAssignmentExpression();
1248 if (Res.isInvalid) {
1249 SkipUntil(tok::identifier);
1250 return Res;
1251 }
1252 ReceiverExpr = Res.Val;
1253 }
Fariborz Jahaniand4462f92007-09-05 23:08:20 +00001254 // Parse objc-selector
Fariborz Jahanian91193f62007-10-11 00:55:41 +00001255 SourceLocation Loc;
1256 IdentifierInfo *selIdent = ParseObjCSelector(Loc);
Steve Naroff4ed9d662007-09-27 14:38:14 +00001257
1258 llvm::SmallVector<IdentifierInfo *, 12> KeyIdents;
1259 llvm::SmallVector<Action::ExprTy *, 12> KeyExprs;
1260
Chris Lattnera1d2bb72007-10-09 17:51:17 +00001261 if (Tok.is(tok::colon)) {
Fariborz Jahaniand4462f92007-09-05 23:08:20 +00001262 while (1) {
1263 // Each iteration parses a single keyword argument.
Steve Naroff4ed9d662007-09-27 14:38:14 +00001264 KeyIdents.push_back(selIdent);
Steve Naroff253118b2007-09-17 20:25:27 +00001265
Chris Lattnera1d2bb72007-10-09 17:51:17 +00001266 if (Tok.isNot(tok::colon)) {
Fariborz Jahaniand4462f92007-09-05 23:08:20 +00001267 Diag(Tok, diag::err_expected_colon);
1268 SkipUntil(tok::semi);
Steve Naroff253118b2007-09-17 20:25:27 +00001269 return true;
Fariborz Jahaniand4462f92007-09-05 23:08:20 +00001270 }
Steve Naroff4ed9d662007-09-27 14:38:14 +00001271 ConsumeToken(); // Eat the ':'.
Fariborz Jahaniand4462f92007-09-05 23:08:20 +00001272 /// Parse the expression after ':'
Steve Naroff253118b2007-09-17 20:25:27 +00001273 ExprResult Res = ParseAssignmentExpression();
1274 if (Res.isInvalid) {
1275 SkipUntil(tok::identifier);
1276 return Res;
1277 }
1278 // We have a valid expression.
Steve Naroff4ed9d662007-09-27 14:38:14 +00001279 KeyExprs.push_back(Res.Val);
Steve Naroff253118b2007-09-17 20:25:27 +00001280
1281 // Check for another keyword selector.
Fariborz Jahanian91193f62007-10-11 00:55:41 +00001282 selIdent = ParseObjCSelector(Loc);
Chris Lattnera1d2bb72007-10-09 17:51:17 +00001283 if (!selIdent && Tok.isNot(tok::colon))
Fariborz Jahaniand4462f92007-09-05 23:08:20 +00001284 break;
1285 // We have a selector or a colon, continue parsing.
1286 }
1287 // Parse the, optional, argument list, comma separated.
Chris Lattnera1d2bb72007-10-09 17:51:17 +00001288 while (Tok.is(tok::comma)) {
Fariborz Jahaniand4462f92007-09-05 23:08:20 +00001289 ConsumeToken();
1290 /// Parse the expression after ','
1291 ParseAssignmentExpression();
1292 }
1293 } else if (!selIdent) {
1294 Diag(Tok, diag::err_expected_ident); // missing selector name.
1295 SkipUntil(tok::semi);
1296 return 0;
1297 }
Chris Lattnerd031a452007-10-07 02:00:24 +00001298
Chris Lattnera1d2bb72007-10-09 17:51:17 +00001299 if (Tok.isNot(tok::r_square)) {
Fariborz Jahaniand4462f92007-09-05 23:08:20 +00001300 Diag(Tok, diag::err_expected_rsquare);
1301 SkipUntil(tok::semi);
1302 return 0;
1303 }
Steve Naroffc39ca262007-09-18 23:55:05 +00001304 SourceLocation RBracloc = ConsumeBracket(); // consume ']'
Steve Naroff253118b2007-09-17 20:25:27 +00001305
Steve Narofff9e80db2007-10-05 18:42:47 +00001306 unsigned nKeys = KeyIdents.size();
Chris Lattnerd031a452007-10-07 02:00:24 +00001307 if (nKeys == 0)
1308 KeyIdents.push_back(selIdent);
1309 Selector Sel = PP.getSelectorTable().getSelector(nKeys, &KeyIdents[0]);
1310
1311 // We've just parsed a keyword message.
Steve Naroff253118b2007-09-17 20:25:27 +00001312 if (ReceiverName)
Chris Lattnerd031a452007-10-07 02:00:24 +00001313 return Actions.ActOnClassMessage(ReceiverName, Sel, LBracloc, RBracloc,
1314 &KeyExprs[0]);
1315 return Actions.ActOnInstanceMessage(ReceiverExpr, Sel, LBracloc, RBracloc,
1316 &KeyExprs[0]);
Fariborz Jahanian1e534dc2007-09-05 19:52:07 +00001317}
1318
Steve Naroff0add5d22007-11-03 11:27:19 +00001319Parser::ExprResult Parser::ParseObjCStringLiteral(SourceLocation AtLoc) {
Anders Carlssona66cad42007-08-21 17:43:55 +00001320 ExprResult Res = ParseStringLiteralExpression();
1321
1322 if (Res.isInvalid) return Res;
1323
Steve Naroff0add5d22007-11-03 11:27:19 +00001324 return Actions.ParseObjCStringLiteral(AtLoc, Res.Val);
Anders Carlssona66cad42007-08-21 17:43:55 +00001325}
Anders Carlsson8be1d402007-08-22 15:14:15 +00001326
1327/// objc-encode-expression:
1328/// @encode ( type-name )
Chris Lattnercfd61c82007-10-16 22:51:17 +00001329Parser::ExprResult Parser::ParseObjCEncodeExpression(SourceLocation AtLoc) {
Steve Naroff87c329f2007-08-23 18:16:40 +00001330 assert(Tok.isObjCAtKeyword(tok::objc_encode) && "Not an @encode expression!");
Anders Carlsson8be1d402007-08-22 15:14:15 +00001331
1332 SourceLocation EncLoc = ConsumeToken();
1333
Chris Lattnera1d2bb72007-10-09 17:51:17 +00001334 if (Tok.isNot(tok::l_paren)) {
Anders Carlsson8be1d402007-08-22 15:14:15 +00001335 Diag(Tok, diag::err_expected_lparen_after, "@encode");
1336 return true;
1337 }
1338
1339 SourceLocation LParenLoc = ConsumeParen();
1340
1341 TypeTy *Ty = ParseTypeName();
1342
Anders Carlsson92faeb82007-08-23 15:31:37 +00001343 SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc);
Anders Carlsson8be1d402007-08-22 15:14:15 +00001344
Chris Lattnercfd61c82007-10-16 22:51:17 +00001345 return Actions.ParseObjCEncodeExpression(AtLoc, EncLoc, LParenLoc, Ty,
Anders Carlsson92faeb82007-08-23 15:31:37 +00001346 RParenLoc);
Anders Carlsson8be1d402007-08-22 15:14:15 +00001347}
Anders Carlsson2996b4e2007-08-23 15:25:28 +00001348
1349/// objc-protocol-expression
1350/// @protocol ( protocol-name )
1351
Fariborz Jahanian957448a2007-10-16 23:21:02 +00001352Parser::ExprResult Parser::ParseObjCProtocolExpression(SourceLocation AtLoc)
Anders Carlsson2996b4e2007-08-23 15:25:28 +00001353{
1354 SourceLocation ProtoLoc = ConsumeToken();
1355
Chris Lattnera1d2bb72007-10-09 17:51:17 +00001356 if (Tok.isNot(tok::l_paren)) {
Anders Carlsson2996b4e2007-08-23 15:25:28 +00001357 Diag(Tok, diag::err_expected_lparen_after, "@protocol");
1358 return true;
1359 }
1360
1361 SourceLocation LParenLoc = ConsumeParen();
1362
Chris Lattnera1d2bb72007-10-09 17:51:17 +00001363 if (Tok.isNot(tok::identifier)) {
Anders Carlsson2996b4e2007-08-23 15:25:28 +00001364 Diag(Tok, diag::err_expected_ident);
1365 return true;
1366 }
Fariborz Jahanianb391e6e2007-10-17 16:58:11 +00001367 IdentifierInfo *protocolId = Tok.getIdentifierInfo();
Anders Carlsson2996b4e2007-08-23 15:25:28 +00001368 ConsumeToken();
1369
Anders Carlsson92faeb82007-08-23 15:31:37 +00001370 SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc);
Anders Carlsson2996b4e2007-08-23 15:25:28 +00001371
Fariborz Jahanianb391e6e2007-10-17 16:58:11 +00001372 return Actions.ParseObjCProtocolExpression(protocolId, AtLoc, ProtoLoc,
1373 LParenLoc, RParenLoc);
Anders Carlsson2996b4e2007-08-23 15:25:28 +00001374}
Fariborz Jahanian056c6b02007-10-15 23:39:13 +00001375
1376/// objc-selector-expression
1377/// @selector '(' objc-keyword-selector ')'
Fariborz Jahanian957448a2007-10-16 23:21:02 +00001378Parser::ExprResult Parser::ParseObjCSelectorExpression(SourceLocation AtLoc)
Fariborz Jahanian056c6b02007-10-15 23:39:13 +00001379{
1380 SourceLocation SelectorLoc = ConsumeToken();
1381
1382 if (Tok.isNot(tok::l_paren)) {
1383 Diag(Tok, diag::err_expected_lparen_after, "@selector");
1384 return 0;
1385 }
1386
Fariborz Jahanianf807c202007-10-16 20:40:23 +00001387 llvm::SmallVector<IdentifierInfo *, 12> KeyIdents;
Fariborz Jahanian056c6b02007-10-15 23:39:13 +00001388 SourceLocation LParenLoc = ConsumeParen();
1389 SourceLocation sLoc;
1390 IdentifierInfo *SelIdent = ParseObjCSelector(sLoc);
1391 if (!SelIdent && Tok.isNot(tok::colon)) {
1392
1393 Diag(Tok, diag::err_expected_ident); // missing selector name.
1394 return 0;
1395 }
Fariborz Jahanianf807c202007-10-16 20:40:23 +00001396 KeyIdents.push_back(SelIdent);
Fariborz Jahanian056c6b02007-10-15 23:39:13 +00001397 if (Tok.isNot(tok::r_paren))
1398 while (1) {
1399 if (Tok.isNot(tok::colon)) {
1400 Diag(Tok, diag::err_expected_colon);
1401 break;
1402 }
1403 ConsumeToken(); // Eat the ':'.
1404 if (Tok.is(tok::r_paren))
1405 break;
1406 // Check for another keyword selector.
1407 SourceLocation Loc;
1408 SelIdent = ParseObjCSelector(Loc);
Fariborz Jahanianf807c202007-10-16 20:40:23 +00001409 KeyIdents.push_back(SelIdent);
Fariborz Jahanian056c6b02007-10-15 23:39:13 +00001410 if (!SelIdent && Tok.isNot(tok::colon))
1411 break;
1412 }
1413 SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc);
Fariborz Jahanianf807c202007-10-16 20:40:23 +00001414 Selector Sel = PP.getSelectorTable().getSelector(KeyIdents.size(),
1415 &KeyIdents[0]);
Fariborz Jahanian957448a2007-10-16 23:21:02 +00001416 return Actions.ParseObjCSelectorExpression(Sel, AtLoc, SelectorLoc, LParenLoc,
Fariborz Jahanianf807c202007-10-16 20:40:23 +00001417 RParenLoc);
Gabor Greifa823dd12007-10-19 15:38:32 +00001418 }