ParseObjc.cpp revision ef708fd4abccf4d21b1f82ab2ab62f6ae7cc1265
1a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek//===--- ParseObjC.cpp - Objective C Parsing ------------------------------===// 25f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 35f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// The LLVM Compiler Infrastructure 45f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// This file is distributed under the University of Illinois Open Source 60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// License. See LICENSE.TXT for details. 75f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 85f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 95f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// This file implements the Objective-C portions of the Parser interface. 115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/Parse/Parser.h" 154985aceceb9b9261b876b515d32726175c13a775Steve Naroff#include "clang/Parse/DeclSpec.h" 163b1191d7eaf2f4984564e01ab84b6713a9d80e70Fariborz Jahanian#include "clang/Parse/Scope.h" 175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/Basic/Diagnostic.h" 185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "llvm/ADT/SmallVector.h" 195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing namespace clang; 205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ParseExternalDeclaration: 235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// external-declaration: [C99 6.9] 245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// [OBJC] objc-class-definition 2591fa0b7759b575045142abd6ee48c076297ad77bSteve Naroff/// [OBJC] objc-class-declaration 2691fa0b7759b575045142abd6ee48c076297ad77bSteve Naroff/// [OBJC] objc-alias-declaration 2791fa0b7759b575045142abd6ee48c076297ad77bSteve Naroff/// [OBJC] objc-protocol-definition 2891fa0b7759b575045142abd6ee48c076297ad77bSteve Naroff/// [OBJC] objc-method-definition 2991fa0b7759b575045142abd6ee48c076297ad77bSteve Naroff/// [OBJC] '@' 'end' 30dac269b65eed82182fc3e96566dedd6562dfe11eSteve NaroffParser::DeclTy *Parser::ParseObjCAtDirectives() { 315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation AtLoc = ConsumeToken(); // the "@" 325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 33861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff switch (Tok.getObjCKeywordID()) { 345ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner case tok::objc_class: 355ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner return ParseObjCAtClassDeclaration(AtLoc); 365ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner case tok::objc_interface: 375ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner return ParseObjCAtInterfaceDeclaration(AtLoc); 385ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner case tok::objc_protocol: 395ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner return ParseObjCAtProtocolDeclaration(AtLoc); 405ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner case tok::objc_implementation: 415ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner return ParseObjCAtImplementationDeclaration(AtLoc); 425ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner case tok::objc_end: 435ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner return ParseObjCAtEndDeclaration(AtLoc); 445ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner case tok::objc_compatibility_alias: 455ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner return ParseObjCAtAliasDeclaration(AtLoc); 465ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner case tok::objc_synthesize: 475ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner return ParseObjCPropertySynthesize(AtLoc); 485ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner case tok::objc_dynamic: 495ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner return ParseObjCPropertyDynamic(AtLoc); 505ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner default: 515ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner Diag(AtLoc, diag::err_unexpected_at); 525ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner SkipUntil(tok::semi); 535ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner return 0; 545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// objc-class-declaration: 595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// '@' 'class' identifier-list ';' 605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 61dac269b65eed82182fc3e96566dedd6562dfe11eSteve NaroffParser::DeclTy *Parser::ParseObjCAtClassDeclaration(SourceLocation atLoc) { 625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ConsumeToken(); // the identifier "class" 635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::SmallVector<IdentifierInfo *, 8> ClassNames; 645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer while (1) { 66df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Diag(Tok, diag::err_expected_ident); 685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SkipUntil(tok::semi); 69dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff return 0; 705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ClassNames.push_back(Tok.getIdentifierInfo()); 725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ConsumeToken(); 735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 74df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::comma)) 755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer break; 765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ConsumeToken(); 785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Consume the ';'. 815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@class")) 82dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff return 0; 835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 84e440eb8158e71deb1e4ab11618ae3d680aac6da1Steve Naroff return Actions.ActOnForwardClassDeclaration(atLoc, 853536b443bc50d58a79f14fca9b6842541a434854Steve Naroff &ClassNames[0], ClassNames.size()); 865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 88dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 89dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-interface: 90dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-interface-attributes[opt] objc-class-interface 91dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-category-interface 92dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 93dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-interface: 94dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// '@' 'interface' identifier objc-superclass[opt] 95dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-refs[opt] 96dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-instance-variables[opt] 97dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-interface-decl-list 98dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @end 99dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 100dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-category-interface: 101dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// '@' 'interface' identifier '(' identifier[opt] ')' 102dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-refs[opt] 103dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-interface-decl-list 104dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @end 105dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 106dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-superclass: 107dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// ':' identifier 108dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 109dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-interface-attributes: 110dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// __attribute__((visibility("default"))) 111dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// __attribute__((visibility("hidden"))) 112dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// __attribute__((deprecated)) 113dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// __attribute__((unavailable)) 114dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// __attribute__((objc_exception)) - used by NSException on 64-bit 115dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 116dac269b65eed82182fc3e96566dedd6562dfe11eSteve NaroffParser::DeclTy *Parser::ParseObjCAtInterfaceDeclaration( 117dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff SourceLocation atLoc, AttributeList *attrList) { 118861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff assert(Tok.isObjCAtKeyword(tok::objc_interface) && 119dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff "ParseObjCAtInterfaceDeclaration(): Expected @interface"); 120dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff ConsumeToken(); // the "interface" identifier 121dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff 122df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 123dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff Diag(Tok, diag::err_expected_ident); // missing class or category name. 124dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff return 0; 125dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff } 126dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff // We have a class or category name - consume it. 1277ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff IdentifierInfo *nameId = Tok.getIdentifierInfo(); 128dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff SourceLocation nameLoc = ConsumeToken(); 129dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff 130df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::l_paren)) { // we have a category. 131dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff SourceLocation lparenLoc = ConsumeParen(); 132dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff SourceLocation categoryLoc, rparenLoc; 133dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff IdentifierInfo *categoryId = 0; 134dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff 135527fe23f8cbc6a4da1737a547a2517bc92fa88c8Steve Naroff // For ObjC2, the category name is optional (not an error). 136df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::identifier)) { 137dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff categoryId = Tok.getIdentifierInfo(); 138dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff categoryLoc = ConsumeToken(); 139527fe23f8cbc6a4da1737a547a2517bc92fa88c8Steve Naroff } else if (!getLang().ObjC2) { 140527fe23f8cbc6a4da1737a547a2517bc92fa88c8Steve Naroff Diag(Tok, diag::err_expected_ident); // missing category name. 141527fe23f8cbc6a4da1737a547a2517bc92fa88c8Steve Naroff return 0; 142dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff } 143df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::r_paren)) { 144dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff Diag(Tok, diag::err_expected_rparen); 145dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff SkipUntil(tok::r_paren, false); // don't stop at ';' 146dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff return 0; 147dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff } 148dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff rparenLoc = ConsumeParen(); 1496bd6d0b9d8944c5e192097bef24f2becb83af172Chris Lattner 150dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff // Next, we need to check for any protocol references. 1516bd6d0b9d8944c5e192097bef24f2becb83af172Chris Lattner SourceLocation EndProtoLoc; 1526bd6d0b9d8944c5e192097bef24f2becb83af172Chris Lattner llvm::SmallVector<DeclTy *, 8> ProtocolRefs; 1536bd6d0b9d8944c5e192097bef24f2becb83af172Chris Lattner if (Tok.is(tok::less) && 1546bd6d0b9d8944c5e192097bef24f2becb83af172Chris Lattner ParseObjCProtocolReferences(ProtocolRefs, true, EndProtoLoc)) 1556bd6d0b9d8944c5e192097bef24f2becb83af172Chris Lattner return 0; 1566bd6d0b9d8944c5e192097bef24f2becb83af172Chris Lattner 157dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff if (attrList) // categories don't support attributes. 158dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff Diag(Tok, diag::err_objc_no_attributes_on_category); 159dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff 160e440eb8158e71deb1e4ab11618ae3d680aac6da1Steve Naroff DeclTy *CategoryType = Actions.ActOnStartCategoryInterface(atLoc, 1613a165b066e665870c163af64844073a664c042d0Steve Naroff nameId, nameLoc, categoryId, categoryLoc, 162423cb565abc681b770fb4b9b4bc24d398c98157bSteve Naroff &ProtocolRefs[0], ProtocolRefs.size(), 1636bd6d0b9d8944c5e192097bef24f2becb83af172Chris Lattner EndProtoLoc); 164fd225cc227143553898f2d3902242d25db9a4902Fariborz Jahanian 165fd225cc227143553898f2d3902242d25db9a4902Fariborz Jahanian ParseObjCInterfaceDeclList(CategoryType, tok::objc_not_keyword); 166bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner return CategoryType; 167dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff } 168dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff // Parse a class interface. 169dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff IdentifierInfo *superClassId = 0; 170dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff SourceLocation superClassLoc; 1717ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff 172df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::colon)) { // a super class is specified. 173dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff ConsumeToken(); 174df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 175dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff Diag(Tok, diag::err_expected_ident); // missing super class name. 176dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff return 0; 177dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff } 178dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff superClassId = Tok.getIdentifierInfo(); 179dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff superClassLoc = ConsumeToken(); 180dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff } 181dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff // Next, we need to check for any protocol references. 18206036d3709955a53297b4cbe14e20db88f321470Chris Lattner llvm::SmallVector<Action::DeclTy*, 8> ProtocolRefs; 18306036d3709955a53297b4cbe14e20db88f321470Chris Lattner SourceLocation EndProtoLoc; 18406036d3709955a53297b4cbe14e20db88f321470Chris Lattner if (Tok.is(tok::less) && 18506036d3709955a53297b4cbe14e20db88f321470Chris Lattner ParseObjCProtocolReferences(ProtocolRefs, true, EndProtoLoc)) 18606036d3709955a53297b4cbe14e20db88f321470Chris Lattner return 0; 18706036d3709955a53297b4cbe14e20db88f321470Chris Lattner 18806036d3709955a53297b4cbe14e20db88f321470Chris Lattner DeclTy *ClsType = 18906036d3709955a53297b4cbe14e20db88f321470Chris Lattner Actions.ActOnStartClassInterface(atLoc, nameId, nameLoc, 19006036d3709955a53297b4cbe14e20db88f321470Chris Lattner superClassId, superClassLoc, 19106036d3709955a53297b4cbe14e20db88f321470Chris Lattner &ProtocolRefs[0], ProtocolRefs.size(), 19206036d3709955a53297b4cbe14e20db88f321470Chris Lattner EndProtoLoc, attrList); 193f28b264437053fb0deacc9ba02b18a0966f7290aSteve Naroff 194df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::l_brace)) 19560fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff ParseObjCClassInstanceVariables(ClsType, atLoc); 196dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff 19725e077d59a8e8e43b65882b69610a3d5e2aaf53cFariborz Jahanian ParseObjCInterfaceDeclList(ClsType, tok::objc_interface); 198bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner return ClsType; 199dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff} 200dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff 2014d7da2f4a39adcc2ea211fb30600fabde4f3a0b1Daniel Dunbar/// constructSetterName - Return the setter name for the given 2024d7da2f4a39adcc2ea211fb30600fabde4f3a0b1Daniel Dunbar/// identifier, i.e. "set" + Name where the initial character of Name 2034d7da2f4a39adcc2ea211fb30600fabde4f3a0b1Daniel Dunbar/// has been capitalized. 2044d7da2f4a39adcc2ea211fb30600fabde4f3a0b1Daniel Dunbarstatic IdentifierInfo *constructSetterName(IdentifierTable &Idents, 2054d7da2f4a39adcc2ea211fb30600fabde4f3a0b1Daniel Dunbar const IdentifierInfo *Name) { 2064d7da2f4a39adcc2ea211fb30600fabde4f3a0b1Daniel Dunbar unsigned N = Name->getLength(); 2074d7da2f4a39adcc2ea211fb30600fabde4f3a0b1Daniel Dunbar char *SelectorName = new char[3 + N]; 2084d7da2f4a39adcc2ea211fb30600fabde4f3a0b1Daniel Dunbar memcpy(SelectorName, "set", 3); 2094d7da2f4a39adcc2ea211fb30600fabde4f3a0b1Daniel Dunbar memcpy(&SelectorName[3], Name->getName(), N); 2104d7da2f4a39adcc2ea211fb30600fabde4f3a0b1Daniel Dunbar SelectorName[3] = toupper(SelectorName[3]); 2114d7da2f4a39adcc2ea211fb30600fabde4f3a0b1Daniel Dunbar 2124d7da2f4a39adcc2ea211fb30600fabde4f3a0b1Daniel Dunbar IdentifierInfo *Setter = 2134d7da2f4a39adcc2ea211fb30600fabde4f3a0b1Daniel Dunbar &Idents.get(SelectorName, &SelectorName[3 + N]); 2144d7da2f4a39adcc2ea211fb30600fabde4f3a0b1Daniel Dunbar delete[] SelectorName; 2154d7da2f4a39adcc2ea211fb30600fabde4f3a0b1Daniel Dunbar return Setter; 2164d7da2f4a39adcc2ea211fb30600fabde4f3a0b1Daniel Dunbar} 2174d7da2f4a39adcc2ea211fb30600fabde4f3a0b1Daniel Dunbar 218dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-interface-decl-list: 219dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// empty 220dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-interface-decl-list objc-property-decl [OBJC2] 221294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-interface-decl-list objc-method-requirement [OBJC2] 2223536b443bc50d58a79f14fca9b6842541a434854Steve Naroff/// objc-interface-decl-list objc-method-proto ';' 223dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-interface-decl-list declaration 224dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-interface-decl-list ';' 225dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 226294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-method-requirement: [OBJC2] 227294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// @required 228294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// @optional 229294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 23025e077d59a8e8e43b65882b69610a3d5e2aaf53cFariborz Jahanianvoid Parser::ParseObjCInterfaceDeclList(DeclTy *interfaceDecl, 231cb53b361bce341c8591333c6997f62e480acc0b4Chris Lattner tok::ObjCKeywordKind contextKey) { 2328a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek llvm::SmallVector<DeclTy*, 32> allMethods; 23382a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian llvm::SmallVector<DeclTy*, 16> allProperties; 23400933591a2795d09dd1acff12a2d21bce7cb12c5Fariborz Jahanian tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword; 23560fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff 236bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner SourceLocation AtEndLoc; 237bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner 238294494e1cce92043562b4680c613df7fd028c02eSteve Naroff while (1) { 239e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner // If this is a method prototype, parse it. 240df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::minus) || Tok.is(tok::plus)) { 241df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner DeclTy *methodPrototype = 242df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner ParseObjCMethodPrototype(interfaceDecl, MethodImplKind); 24325e077d59a8e8e43b65882b69610a3d5e2aaf53cFariborz Jahanian allMethods.push_back(methodPrototype); 2443536b443bc50d58a79f14fca9b6842541a434854Steve Naroff // Consume the ';' here, since ParseObjCMethodPrototype() is re-used for 2453536b443bc50d58a79f14fca9b6842541a434854Steve Naroff // method definitions. 246d16245b6d48c6b4e7bbd40713aed6565b882746dSteve Naroff ExpectAndConsume(tok::semi, diag::err_expected_semi_after,"method proto"); 247294494e1cce92043562b4680c613df7fd028c02eSteve Naroff continue; 248294494e1cce92043562b4680c613df7fd028c02eSteve Naroff } 249f366b4c84485b646c30d6891a249ad6f65abef7cFariborz Jahanian 250e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner // Ignore excess semicolons. 251e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner if (Tok.is(tok::semi)) { 252294494e1cce92043562b4680c613df7fd028c02eSteve Naroff ConsumeToken(); 253e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner continue; 254e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner } 255e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner 256bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // If we got to the end of the file, exit the loop. 257e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner if (Tok.is(tok::eof)) 258e3a2ca7e30601cdd31c77a830f4cc487851e8096Fariborz Jahanian break; 259e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner 260e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner // If we don't have an @ directive, parse it as a function definition. 261e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner if (Tok.isNot(tok::at)) { 2624985aceceb9b9261b876b515d32726175c13a775Steve Naroff // FIXME: as the name implies, this rule allows function definitions. 2634985aceceb9b9261b876b515d32726175c13a775Steve Naroff // We could pass a flag or check for functions during semantic analysis. 2643536b443bc50d58a79f14fca9b6842541a434854Steve Naroff ParseDeclarationOrFunctionDefinition(); 265e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner continue; 266e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner } 267e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner 268e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner // Otherwise, we have an @ directive, eat the @. 269e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner SourceLocation AtLoc = ConsumeToken(); // the "@" 270a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner tok::ObjCKeywordKind DirectiveKind = Tok.getObjCKeywordID(); 271e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner 272a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner if (DirectiveKind == tok::objc_end) { // @end -> terminate list 273e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner AtEndLoc = AtLoc; 274e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner break; 275bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner } 276e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner 277bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // Eat the identifier. 278bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner ConsumeToken(); 279bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner 280a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner switch (DirectiveKind) { 281a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner default: 282bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // FIXME: If someone forgets an @end on a protocol, this loop will 283bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // continue to eat up tons of stuff and spew lots of nonsense errors. It 284bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // would probably be better to bail out if we saw an @class or @interface 285bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // or something like that. 286f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner Diag(AtLoc, diag::err_objc_illegal_interface_qual); 287bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // Skip until we see an '@' or '}' or ';'. 288a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner SkipUntil(tok::r_brace, tok::at); 289a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner break; 290a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner 291a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner case tok::objc_required: 292a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner case tok::objc_optional: 293a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner // This is only valid on protocols. 294bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // FIXME: Should this check for ObjC2 being enabled? 295e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner if (contextKey != tok::objc_protocol) 296bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner Diag(AtLoc, diag::err_objc_directive_only_in_protocol); 297a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner else 298bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner MethodImplKind = DirectiveKind; 299a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner break; 300a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner 301a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner case tok::objc_property: 302f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner if (!getLang().ObjC2) 303f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner Diag(AtLoc, diag::err_objc_propertoes_require_objc2); 304f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner 305e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner ObjCDeclSpec OCDS; 306e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner // Parse property attribute list, if any. 3078ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner if (Tok.is(tok::l_paren)) 308e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner ParseObjCPropertyAttribute(OCDS); 309dd5b5f2bb73d037745940431b71eb98393d12d4fChris Lattner 310e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner // Parse all the comma separated declarators. 311e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner DeclSpec DS; 312e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner llvm::SmallVector<FieldDeclarator, 8> FieldDeclarators; 313e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner ParseStructDeclaration(DS, FieldDeclarators); 314e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner 315a1fed7e3beebf9bb1bc85123f283be3eb631c120Chris Lattner ExpectAndConsume(tok::semi, diag::err_expected_semi_decl_list, "", 316a1fed7e3beebf9bb1bc85123f283be3eb631c120Chris Lattner tok::at); 317a1fed7e3beebf9bb1bc85123f283be3eb631c120Chris Lattner 318e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner // Convert them all to property declarations. 319e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner for (unsigned i = 0, e = FieldDeclarators.size(); i != e; ++i) { 320e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner FieldDeclarator &FD = FieldDeclarators[i]; 321da3253d8a97981257185c89ced71ce137278b121Chris Lattner if (FD.D.getIdentifier() == 0) { 322ef708fd4abccf4d21b1f82ab2ab62f6ae7cc1265Chris Lattner Diag(AtLoc, diag::err_objc_property_requires_field_name) 323ef708fd4abccf4d21b1f82ab2ab62f6ae7cc1265Chris Lattner << FD.D.getSourceRange(); 324da3253d8a97981257185c89ced71ce137278b121Chris Lattner continue; 325da3253d8a97981257185c89ced71ce137278b121Chris Lattner } 326da3253d8a97981257185c89ced71ce137278b121Chris Lattner 327e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner // Install the property declarator into interfaceDecl. 328da3253d8a97981257185c89ced71ce137278b121Chris Lattner IdentifierInfo *SelName = 329da3253d8a97981257185c89ced71ce137278b121Chris Lattner OCDS.getGetterName() ? OCDS.getGetterName() : FD.D.getIdentifier(); 330da3253d8a97981257185c89ced71ce137278b121Chris Lattner 331e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner Selector GetterSel = 332da3253d8a97981257185c89ced71ce137278b121Chris Lattner PP.getSelectorTable().getNullarySelector(SelName); 333e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner IdentifierInfo *SetterName = OCDS.getSetterName(); 334e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner if (!SetterName) 335e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner SetterName = constructSetterName(PP.getIdentifierTable(), 336e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner FD.D.getIdentifier()); 337e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner Selector SetterSel = 338e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner PP.getSelectorTable().getUnarySelector(SetterName); 339da3253d8a97981257185c89ced71ce137278b121Chris Lattner DeclTy *Property = Actions.ActOnProperty(CurScope, AtLoc, FD, OCDS, 340da3253d8a97981257185c89ced71ce137278b121Chris Lattner GetterSel, SetterSel, 341da3253d8a97981257185c89ced71ce137278b121Chris Lattner MethodImplKind); 342e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner allProperties.push_back(Property); 343e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner } 344a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner break; 345f28b264437053fb0deacc9ba02b18a0966f7290aSteve Naroff } 346294494e1cce92043562b4680c613df7fd028c02eSteve Naroff } 347bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner 348bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // We break out of the big loop in two cases: when we see @end or when we see 349bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // EOF. In the former case, eat the @end. In the later case, emit an error. 350bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner if (Tok.isObjCAtKeyword(tok::objc_end)) 351bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner ConsumeToken(); // the "end" identifier 352bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner else 353bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner Diag(Tok, diag::err_objc_missing_end); 354bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner 355a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner // Insert collected methods declarations into the @interface object. 356bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // This passes in an invalid SourceLocation for AtEndLoc when EOF is hit. 3578a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek Actions.ActOnAtEnd(AtEndLoc, interfaceDecl, 3588a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek allMethods.empty() ? 0 : &allMethods[0], 3598a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek allMethods.size(), 3608a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek allProperties.empty() ? 0 : &allProperties[0], 3618a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek allProperties.size()); 362294494e1cce92043562b4680c613df7fd028c02eSteve Naroff} 363294494e1cce92043562b4680c613df7fd028c02eSteve Naroff 364d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// Parse property attribute declarations. 365d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// 366d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// property-attr-decl: '(' property-attrlist ')' 367d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// property-attrlist: 368d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// property-attribute 369d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// property-attrlist ',' property-attribute 370d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// property-attribute: 371d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// getter '=' identifier 372d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// setter '=' identifier ':' 373d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// readonly 374d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// readwrite 375d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// assign 376d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// retain 377d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// copy 378d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// nonatomic 379d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// 3807caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattnervoid Parser::ParseObjCPropertyAttribute(ObjCDeclSpec &DS) { 3818ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner assert(Tok.getKind() == tok::l_paren); 382dd5b5f2bb73d037745940431b71eb98393d12d4fChris Lattner SourceLocation LHSLoc = ConsumeParen(); // consume '(' 383dd5b5f2bb73d037745940431b71eb98393d12d4fChris Lattner 384cd9f4b31c4fe5b77b5519cc17b4583fab912bad1Chris Lattner while (1) { 385d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian const IdentifierInfo *II = Tok.getIdentifierInfo(); 386f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner 387f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner // If this is not an identifier at all, bail out early. 388f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner if (II == 0) { 389f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner MatchRHSPunctuation(tok::r_paren, LHSLoc); 390f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner return; 391f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner } 392f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner 393156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner SourceLocation AttrName = ConsumeToken(); // consume last attribute name 394156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner 3955fd80fada1eeecd279af8333a7f58b86d8df8016Chris Lattner if (!strcmp(II->getName(), "readonly")) 396e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_readonly); 3975fd80fada1eeecd279af8333a7f58b86d8df8016Chris Lattner else if (!strcmp(II->getName(), "assign")) 398e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_assign); 3995fd80fada1eeecd279af8333a7f58b86d8df8016Chris Lattner else if (!strcmp(II->getName(), "readwrite")) 400e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_readwrite); 4015fd80fada1eeecd279af8333a7f58b86d8df8016Chris Lattner else if (!strcmp(II->getName(), "retain")) 402e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_retain); 4035fd80fada1eeecd279af8333a7f58b86d8df8016Chris Lattner else if (!strcmp(II->getName(), "copy")) 404e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_copy); 4055fd80fada1eeecd279af8333a7f58b86d8df8016Chris Lattner else if (!strcmp(II->getName(), "nonatomic")) 406e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_nonatomic); 4075fd80fada1eeecd279af8333a7f58b86d8df8016Chris Lattner else if (!strcmp(II->getName(), "getter") || 4085fd80fada1eeecd279af8333a7f58b86d8df8016Chris Lattner !strcmp(II->getName(), "setter")) { 409e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner // getter/setter require extra treatment. 410156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner if (ExpectAndConsume(tok::equal, diag::err_objc_expected_equal, "", 411156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner tok::r_paren)) 412dd5b5f2bb73d037745940431b71eb98393d12d4fChris Lattner return; 413156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner 4148ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner if (Tok.isNot(tok::identifier)) { 4151ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_ident); 4168ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner SkipUntil(tok::r_paren); 4178ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner return; 4188ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner } 4198ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner 4205fd80fada1eeecd279af8333a7f58b86d8df8016Chris Lattner if (II->getName()[0] == 's') { 4218ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_setter); 4228ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner DS.setSetterName(Tok.getIdentifierInfo()); 423156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner ConsumeToken(); // consume method name 424156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner 425156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner if (ExpectAndConsume(tok::colon, diag::err_expected_colon, "", 426156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner tok::r_paren)) 4278ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner return; 4288ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner } else { 4298ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_getter); 4308ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner DS.setGetterName(Tok.getIdentifierInfo()); 431156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner ConsumeToken(); // consume method name 4328ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner } 433e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner } else { 4341ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(AttrName, diag::err_objc_expected_property_attr) << II->getName(); 435cd9f4b31c4fe5b77b5519cc17b4583fab912bad1Chris Lattner SkipUntil(tok::r_paren); 436cd9f4b31c4fe5b77b5519cc17b4583fab912bad1Chris Lattner return; 437cd9f4b31c4fe5b77b5519cc17b4583fab912bad1Chris Lattner } 43882a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian 439156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner if (Tok.isNot(tok::comma)) 440156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner break; 441dd5b5f2bb73d037745940431b71eb98393d12d4fChris Lattner 442156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner ConsumeToken(); 443d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian } 444156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner 445156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner MatchRHSPunctuation(tok::r_paren, LHSLoc); 446d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian} 447d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian 4483536b443bc50d58a79f14fca9b6842541a434854Steve Naroff/// objc-method-proto: 449ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// objc-instance-method objc-method-decl objc-method-attributes[opt] 4503536b443bc50d58a79f14fca9b6842541a434854Steve Naroff/// objc-class-method objc-method-decl objc-method-attributes[opt] 451294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 452294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-instance-method: '-' 453294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-class-method: '+' 454294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 4554985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-method-attributes: [OBJC2] 4564985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// __attribute__((deprecated)) 4574985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// 45800933591a2795d09dd1acff12a2d21bce7cb12c5Fariborz JahanianParser::DeclTy *Parser::ParseObjCMethodPrototype(DeclTy *IDecl, 459cb53b361bce341c8591333c6997f62e480acc0b4Chris Lattner tok::ObjCKeywordKind MethodImplKind) { 460df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner assert((Tok.is(tok::minus) || Tok.is(tok::plus)) && "expected +/-"); 461294494e1cce92043562b4680c613df7fd028c02eSteve Naroff 462294494e1cce92043562b4680c613df7fd028c02eSteve Naroff tok::TokenKind methodType = Tok.getKind(); 463bef1185418705e16012b3dd50cd7c260c8d6b79cSteve Naroff SourceLocation mLoc = ConsumeToken(); 464294494e1cce92043562b4680c613df7fd028c02eSteve Naroff 4651f7b6f88f18d7f6b10265acec5d41c4ed1897487Fariborz Jahanian DeclTy *MDecl = ParseObjCMethodDecl(mLoc, methodType, IDecl, MethodImplKind); 4663536b443bc50d58a79f14fca9b6842541a434854Steve Naroff // Since this rule is used for both method declarations and definitions, 4672bd42fadafddc8acf744b57a970bdc96a077c617Steve Naroff // the caller is (optionally) responsible for consuming the ';'. 468f28b264437053fb0deacc9ba02b18a0966f7290aSteve Naroff return MDecl; 469294494e1cce92043562b4680c613df7fd028c02eSteve Naroff} 470294494e1cce92043562b4680c613df7fd028c02eSteve Naroff 471294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-selector: 472294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// identifier 473294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// one of 474294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// enum struct union if else while do for switch case default 475294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// break continue return goto asm sizeof typeof __alignof 476294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// unsigned long const short volatile signed restrict _Complex 477294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// in out inout bycopy byref oneway int char float double void _Bool 478294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 4794b6c9051c6522894978c9ba6a819a659d102db36Fariborz JahanianIdentifierInfo *Parser::ParseObjCSelector(SourceLocation &SelectorLoc) { 480ff38491c18b060526d754765b952f4a497a89416Chris Lattner switch (Tok.getKind()) { 481ff38491c18b060526d754765b952f4a497a89416Chris Lattner default: 482ff38491c18b060526d754765b952f4a497a89416Chris Lattner return 0; 483ff38491c18b060526d754765b952f4a497a89416Chris Lattner case tok::identifier: 484ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_asm: 485ff38491c18b060526d754765b952f4a497a89416Chris Lattner case tok::kw_auto: 4869298d9655aed28b2d9f6cc65c81401b209f03fdcChris Lattner case tok::kw_bool: 487ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_break: 488ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_case: 489ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_catch: 490ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_char: 491ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_class: 492ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_const: 493ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_const_cast: 494ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_continue: 495ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_default: 496ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_delete: 497ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_do: 498ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_double: 499ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_dynamic_cast: 500ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_else: 501ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_enum: 502ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_explicit: 503ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_export: 504ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_extern: 505ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_false: 506ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_float: 507ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_for: 508ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_friend: 509ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_goto: 510ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_if: 511ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_inline: 512ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_int: 513ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_long: 514ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_mutable: 515ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_namespace: 516ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_new: 517ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_operator: 518ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_private: 519ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_protected: 520ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_public: 521ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_register: 522ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_reinterpret_cast: 523ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_restrict: 524ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_return: 525ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_short: 526ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_signed: 527ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_sizeof: 528ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_static: 529ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_static_cast: 530ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_struct: 531ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_switch: 532ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_template: 533ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_this: 534ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_throw: 535ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_true: 536ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_try: 537ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_typedef: 538ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_typeid: 539ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_typename: 540ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_typeof: 541ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_union: 542ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_unsigned: 543ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_using: 544ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_virtual: 545ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_void: 546ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_volatile: 547ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_wchar_t: 548ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_while: 549ff38491c18b060526d754765b952f4a497a89416Chris Lattner case tok::kw__Bool: 550ff38491c18b060526d754765b952f4a497a89416Chris Lattner case tok::kw__Complex: 551ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw___alignof: 552ff38491c18b060526d754765b952f4a497a89416Chris Lattner IdentifierInfo *II = Tok.getIdentifierInfo(); 5534b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian SelectorLoc = ConsumeToken(); 554ff38491c18b060526d754765b952f4a497a89416Chris Lattner return II; 555d064951b0dcc95f8604d0d69ae82d9ecbd38c796Fariborz Jahanian } 556294494e1cce92043562b4680c613df7fd028c02eSteve Naroff} 557294494e1cce92043562b4680c613df7fd028c02eSteve Naroff 5580196cab54007ff072ec2642da8911c6b7e8d3fb5Fariborz Jahanian/// objc-for-collection-in: 'in' 5590196cab54007ff072ec2642da8911c6b7e8d3fb5Fariborz Jahanian/// 560335a2d4122e41343fe11a775889b8bec5b14be60Fariborz Jahanianbool Parser::isTokIdentifier_in() const { 5613ba5a0f90a03d5e13d02cbee9abd2a1ba01b18bcFariborz Jahanian // FIXME: May have to do additional look-ahead to only allow for 5623ba5a0f90a03d5e13d02cbee9abd2a1ba01b18bcFariborz Jahanian // valid tokens following an 'in'; such as an identifier, unary operators, 5633ba5a0f90a03d5e13d02cbee9abd2a1ba01b18bcFariborz Jahanian // '[' etc. 564335a2d4122e41343fe11a775889b8bec5b14be60Fariborz Jahanian return (getLang().ObjC2 && Tok.is(tok::identifier) && 5655ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner Tok.getIdentifierInfo() == ObjCTypeQuals[objc_in]); 5660196cab54007ff072ec2642da8911c6b7e8d3fb5Fariborz Jahanian} 5670196cab54007ff072ec2642da8911c6b7e8d3fb5Fariborz Jahanian 568a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ParseObjCTypeQualifierList - This routine parses the objective-c's type 569e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner/// qualifier list and builds their bitmask representation in the input 570e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner/// argument. 571294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 572294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-type-qualifiers: 573294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-type-qualifier 574294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-type-qualifiers objc-type-qualifier 575294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 576a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekvoid Parser::ParseObjCTypeQualifierList(ObjCDeclSpec &DS) { 577e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner while (1) { 578cb53b361bce341c8591333c6997f62e480acc0b4Chris Lattner if (Tok.isNot(tok::identifier)) 579e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner return; 580e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner 581e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner const IdentifierInfo *II = Tok.getIdentifierInfo(); 582e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner for (unsigned i = 0; i != objc_NumQuals; ++i) { 583a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek if (II != ObjCTypeQuals[i]) 584e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner continue; 585e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner 586a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCDeclSpec::ObjCDeclQualifier Qual; 587e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner switch (i) { 588e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner default: assert(0 && "Unknown decl qualifier"); 589a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek case objc_in: Qual = ObjCDeclSpec::DQ_In; break; 590a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek case objc_out: Qual = ObjCDeclSpec::DQ_Out; break; 591a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek case objc_inout: Qual = ObjCDeclSpec::DQ_Inout; break; 592a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek case objc_oneway: Qual = ObjCDeclSpec::DQ_Oneway; break; 593a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek case objc_bycopy: Qual = ObjCDeclSpec::DQ_Bycopy; break; 594a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek case objc_byref: Qual = ObjCDeclSpec::DQ_Byref; break; 595e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner } 596a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek DS.setObjCDeclQualifier(Qual); 597e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner ConsumeToken(); 598e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner II = 0; 599e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner break; 600e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner } 601e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner 602e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner // If this wasn't a recognized qualifier, bail out. 603e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner if (II) return; 604e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner } 605e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner} 606e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner 607e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner/// objc-type-name: 608e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner/// '(' objc-type-qualifiers[opt] type-name ')' 609e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner/// '(' objc-type-qualifiers[opt] ')' 610e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner/// 611a526c5c67e5a0473c340903ee542ce570119665fTed KremenekParser::TypeTy *Parser::ParseObjCTypeName(ObjCDeclSpec &DS) { 612df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner assert(Tok.is(tok::l_paren) && "expected ("); 613294494e1cce92043562b4680c613df7fd028c02eSteve Naroff 6144a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner SourceLocation LParenLoc = ConsumeParen(); 615e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner SourceLocation TypeStartLoc = Tok.getLocation(); 616294494e1cce92043562b4680c613df7fd028c02eSteve Naroff 61719d74e1494fe399f0e2a94e9419c095f8214851bFariborz Jahanian // Parse type qualifiers, in, inout, etc. 618a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ParseObjCTypeQualifierList(DS); 6194fa7afd07421e7276d1717e4fdf43a5fdd65a622Steve Naroff 6204a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner TypeTy *Ty = 0; 6214a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner if (isTypeSpecifierQualifier()) 622f28b264437053fb0deacc9ba02b18a0966f7290aSteve Naroff Ty = ParseTypeName(); 623e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner 6244a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner if (Tok.is(tok::r_paren)) 6254a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner ConsumeParen(); 6264a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner else if (Tok.getLocation() == TypeStartLoc) { 627e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner // If we didn't eat any tokens, then this isn't a type. 6281ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_type); 6294a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner SkipUntil(tok::r_paren); 6304a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner } else { 6314a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner // Otherwise, we found *something*, but didn't get a ')' in the right 6324a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner // place. Emit an error then return what we have as the type. 6334a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner MatchRHSPunctuation(tok::r_paren, LParenLoc); 634294494e1cce92043562b4680c613df7fd028c02eSteve Naroff } 635f28b264437053fb0deacc9ba02b18a0966f7290aSteve Naroff return Ty; 636294494e1cce92043562b4680c613df7fd028c02eSteve Naroff} 637294494e1cce92043562b4680c613df7fd028c02eSteve Naroff 638294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-method-decl: 639294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-selector 6404985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-keyword-selector objc-parmlist[opt] 641294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-type-name objc-selector 6424985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-type-name objc-keyword-selector objc-parmlist[opt] 643294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 644294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-keyword-selector: 6457ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// objc-keyword-decl 646294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-keyword-selector objc-keyword-decl 647294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 648294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-keyword-decl: 6497ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// objc-selector ':' objc-type-name objc-keyword-attributes[opt] identifier 6507ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// objc-selector ':' objc-keyword-attributes[opt] identifier 6517ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// ':' objc-type-name objc-keyword-attributes[opt] identifier 6527ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// ':' objc-keyword-attributes[opt] identifier 653294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 6544985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-parmlist: 6554985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-parms objc-ellipsis[opt] 656294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 6574985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-parms: 6584985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-parms , parameter-declaration 659294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 6604985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-ellipsis: 661294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// , ... 662294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 6637ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// objc-keyword-attributes: [OBJC2] 6647ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// __attribute__((unused)) 6657ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// 666bef1185418705e16012b3dd50cd7c260c8d6b79cSteve NaroffParser::DeclTy *Parser::ParseObjCMethodDecl(SourceLocation mLoc, 6671f7b6f88f18d7f6b10265acec5d41c4ed1897487Fariborz Jahanian tok::TokenKind mType, 6681f7b6f88f18d7f6b10265acec5d41c4ed1897487Fariborz Jahanian DeclTy *IDecl, 669cb53b361bce341c8591333c6997f62e480acc0b4Chris Lattner tok::ObjCKeywordKind MethodImplKind) 67068d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff{ 671e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner // Parse the return type if present. 672ff38491c18b060526d754765b952f4a497a89416Chris Lattner TypeTy *ReturnType = 0; 673a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCDeclSpec DSRet; 674df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::l_paren)) 675f1de0ca05e2df6f23bd559028693a12d1ebdaaf6Fariborz Jahanian ReturnType = ParseObjCTypeName(DSRet); 676e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner 677bef1185418705e16012b3dd50cd7c260c8d6b79cSteve Naroff SourceLocation selLoc; 678bef1185418705e16012b3dd50cd7c260c8d6b79cSteve Naroff IdentifierInfo *SelIdent = ParseObjCSelector(selLoc); 679e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner 680e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner if (!SelIdent) { // missing selector name. 6811ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_selector_for_method) 6821ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner << SourceRange(mLoc, Tok.getLocation()); 683e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner // Skip until we get a ; or {}. 684e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner SkipUntil(tok::r_brace); 685e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner return 0; 686e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner } 687e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner 688df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::colon)) { 689ff38491c18b060526d754765b952f4a497a89416Chris Lattner // If attributes exist after the method, parse them. 690ff38491c18b060526d754765b952f4a497a89416Chris Lattner AttributeList *MethodAttrs = 0; 691df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (getLang().ObjC2 && Tok.is(tok::kw___attribute)) 692ff38491c18b060526d754765b952f4a497a89416Chris Lattner MethodAttrs = ParseAttributes(); 693ff38491c18b060526d754765b952f4a497a89416Chris Lattner 694ff38491c18b060526d754765b952f4a497a89416Chris Lattner Selector Sel = PP.getSelectorTable().getNullarySelector(SelIdent); 695bef1185418705e16012b3dd50cd7c260c8d6b79cSteve Naroff return Actions.ActOnMethodDeclaration(mLoc, Tok.getLocation(), 6961f7b6f88f18d7f6b10265acec5d41c4ed1897487Fariborz Jahanian mType, IDecl, DSRet, ReturnType, Sel, 697f1de0ca05e2df6f23bd559028693a12d1ebdaaf6Fariborz Jahanian 0, 0, 0, MethodAttrs, MethodImplKind); 698ff38491c18b060526d754765b952f4a497a89416Chris Lattner } 699f28b264437053fb0deacc9ba02b18a0966f7290aSteve Naroff 70068d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff llvm::SmallVector<IdentifierInfo *, 12> KeyIdents; 70168d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff llvm::SmallVector<Action::TypeTy *, 12> KeyTypes; 702a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek llvm::SmallVector<ObjCDeclSpec, 12> ArgTypeQuals; 70368d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff llvm::SmallVector<IdentifierInfo *, 12> ArgNames; 704ff38491c18b060526d754765b952f4a497a89416Chris Lattner 705ff38491c18b060526d754765b952f4a497a89416Chris Lattner Action::TypeTy *TypeInfo; 706ff38491c18b060526d754765b952f4a497a89416Chris Lattner while (1) { 707ff38491c18b060526d754765b952f4a497a89416Chris Lattner KeyIdents.push_back(SelIdent); 70868d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff 709ff38491c18b060526d754765b952f4a497a89416Chris Lattner // Each iteration parses a single keyword argument. 710df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::colon)) { 711ff38491c18b060526d754765b952f4a497a89416Chris Lattner Diag(Tok, diag::err_expected_colon); 712ff38491c18b060526d754765b952f4a497a89416Chris Lattner break; 713ff38491c18b060526d754765b952f4a497a89416Chris Lattner } 714ff38491c18b060526d754765b952f4a497a89416Chris Lattner ConsumeToken(); // Eat the ':'. 715a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCDeclSpec DSType; 716e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner if (Tok.is(tok::l_paren)) // Parse the argument type. 717f1de0ca05e2df6f23bd559028693a12d1ebdaaf6Fariborz Jahanian TypeInfo = ParseObjCTypeName(DSType); 718ff38491c18b060526d754765b952f4a497a89416Chris Lattner else 719ff38491c18b060526d754765b952f4a497a89416Chris Lattner TypeInfo = 0; 720ff38491c18b060526d754765b952f4a497a89416Chris Lattner KeyTypes.push_back(TypeInfo); 721f1de0ca05e2df6f23bd559028693a12d1ebdaaf6Fariborz Jahanian ArgTypeQuals.push_back(DSType); 722f28b264437053fb0deacc9ba02b18a0966f7290aSteve Naroff 723ff38491c18b060526d754765b952f4a497a89416Chris Lattner // If attributes exist before the argument name, parse them. 724df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (getLang().ObjC2 && Tok.is(tok::kw___attribute)) 725ff38491c18b060526d754765b952f4a497a89416Chris Lattner ParseAttributes(); // FIXME: pass attributes through. 7267ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff 727df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 728ff38491c18b060526d754765b952f4a497a89416Chris Lattner Diag(Tok, diag::err_expected_ident); // missing argument name. 729ff38491c18b060526d754765b952f4a497a89416Chris Lattner break; 7304985aceceb9b9261b876b515d32726175c13a775Steve Naroff } 731ff38491c18b060526d754765b952f4a497a89416Chris Lattner ArgNames.push_back(Tok.getIdentifierInfo()); 732ff38491c18b060526d754765b952f4a497a89416Chris Lattner ConsumeToken(); // Eat the identifier. 733ff38491c18b060526d754765b952f4a497a89416Chris Lattner 734ff38491c18b060526d754765b952f4a497a89416Chris Lattner // Check for another keyword selector. 7354b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian SourceLocation Loc; 7364b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian SelIdent = ParseObjCSelector(Loc); 737df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (!SelIdent && Tok.isNot(tok::colon)) 738ff38491c18b060526d754765b952f4a497a89416Chris Lattner break; 739ff38491c18b060526d754765b952f4a497a89416Chris Lattner // We have a selector or a colon, continue parsing. 740ff38491c18b060526d754765b952f4a497a89416Chris Lattner } 741ff38491c18b060526d754765b952f4a497a89416Chris Lattner 742335eafa5be51f6440672a74c73d588af72e96732Steve Naroff bool isVariadic = false; 743335eafa5be51f6440672a74c73d588af72e96732Steve Naroff 744ff38491c18b060526d754765b952f4a497a89416Chris Lattner // Parse the (optional) parameter list. 745df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner while (Tok.is(tok::comma)) { 746ff38491c18b060526d754765b952f4a497a89416Chris Lattner ConsumeToken(); 747df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::ellipsis)) { 748335eafa5be51f6440672a74c73d588af72e96732Steve Naroff isVariadic = true; 7494985aceceb9b9261b876b515d32726175c13a775Steve Naroff ConsumeToken(); 750ff38491c18b060526d754765b952f4a497a89416Chris Lattner break; 7514985aceceb9b9261b876b515d32726175c13a775Steve Naroff } 752335eafa5be51f6440672a74c73d588af72e96732Steve Naroff // FIXME: implement this... 753ff38491c18b060526d754765b952f4a497a89416Chris Lattner // Parse the c-style argument declaration-specifier. 754ff38491c18b060526d754765b952f4a497a89416Chris Lattner DeclSpec DS; 755ff38491c18b060526d754765b952f4a497a89416Chris Lattner ParseDeclarationSpecifiers(DS); 756ff38491c18b060526d754765b952f4a497a89416Chris Lattner // Parse the declarator. 757ff38491c18b060526d754765b952f4a497a89416Chris Lattner Declarator ParmDecl(DS, Declarator::PrototypeContext); 758ff38491c18b060526d754765b952f4a497a89416Chris Lattner ParseDeclarator(ParmDecl); 7594985aceceb9b9261b876b515d32726175c13a775Steve Naroff } 760ff38491c18b060526d754765b952f4a497a89416Chris Lattner 761ff38491c18b060526d754765b952f4a497a89416Chris Lattner // FIXME: Add support for optional parmameter list... 762e3a2ca7e30601cdd31c77a830f4cc487851e8096Fariborz Jahanian // If attributes exist after the method, parse them. 763ff38491c18b060526d754765b952f4a497a89416Chris Lattner AttributeList *MethodAttrs = 0; 764df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (getLang().ObjC2 && Tok.is(tok::kw___attribute)) 765ff38491c18b060526d754765b952f4a497a89416Chris Lattner MethodAttrs = ParseAttributes(); 766ff38491c18b060526d754765b952f4a497a89416Chris Lattner 767ff38491c18b060526d754765b952f4a497a89416Chris Lattner Selector Sel = PP.getSelectorTable().getSelector(KeyIdents.size(), 768ff38491c18b060526d754765b952f4a497a89416Chris Lattner &KeyIdents[0]); 769bef1185418705e16012b3dd50cd7c260c8d6b79cSteve Naroff return Actions.ActOnMethodDeclaration(mLoc, Tok.getLocation(), 7701f7b6f88f18d7f6b10265acec5d41c4ed1897487Fariborz Jahanian mType, IDecl, DSRet, ReturnType, Sel, 771f1de0ca05e2df6f23bd559028693a12d1ebdaaf6Fariborz Jahanian &ArgTypeQuals[0], &KeyTypes[0], 772335eafa5be51f6440672a74c73d588af72e96732Steve Naroff &ArgNames[0], MethodAttrs, 773335eafa5be51f6440672a74c73d588af72e96732Steve Naroff MethodImplKind, isVariadic); 774294494e1cce92043562b4680c613df7fd028c02eSteve Naroff} 775294494e1cce92043562b4680c613df7fd028c02eSteve Naroff 776dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-refs: 777dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// '<' identifier-list '>' 778dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 7797caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattnerbool Parser:: 780e13b9595dc1e2f4288bec34f3412359f648e84a5Chris LattnerParseObjCProtocolReferences(llvm::SmallVectorImpl<Action::DeclTy*> &Protocols, 781e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner bool WarnOnDeclarations, SourceLocation &EndLoc) { 782e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner assert(Tok.is(tok::less) && "expected <"); 783e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner 784e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner ConsumeToken(); // the "<" 785e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner 786e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner llvm::SmallVector<IdentifierLocPair, 8> ProtocolIdents; 787e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner 788e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner while (1) { 789e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner if (Tok.isNot(tok::identifier)) { 790e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner Diag(Tok, diag::err_expected_ident); 791e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner SkipUntil(tok::greater); 792e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner return true; 793e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner } 794e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner ProtocolIdents.push_back(std::make_pair(Tok.getIdentifierInfo(), 795e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner Tok.getLocation())); 796e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner ConsumeToken(); 797e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner 798e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner if (Tok.isNot(tok::comma)) 799e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner break; 800e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner ConsumeToken(); 801e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner } 802e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner 803e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner // Consume the '>'. 804e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner if (Tok.isNot(tok::greater)) { 805e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner Diag(Tok, diag::err_expected_greater); 806e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner return true; 807e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner } 808e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner 809e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner EndLoc = ConsumeAnyToken(); 810e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner 811e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner // Convert the list of protocols identifiers into a list of protocol decls. 812e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner Actions.FindProtocolDeclaration(WarnOnDeclarations, 813e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner &ProtocolIdents[0], ProtocolIdents.size(), 814e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner Protocols); 815e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner return false; 816e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner} 817e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner 818dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-instance-variables: 819dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// '{' objc-instance-variable-decl-list[opt] '}' 820dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 821dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-instance-variable-decl-list: 822dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-visibility-spec 823dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-instance-variable-decl ';' 824dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// ';' 825dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-instance-variable-decl-list objc-visibility-spec 826dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-instance-variable-decl-list objc-instance-variable-decl ';' 827dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-instance-variable-decl-list ';' 828dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 829dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-visibility-spec: 830dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @private 831dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @protected 832dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @public 833ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff/// @package [OBJC2] 834dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 835dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-instance-variable-decl: 836dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// struct-declaration 837dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 83860fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroffvoid Parser::ParseObjCClassInstanceVariables(DeclTy *interfaceDecl, 83960fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff SourceLocation atLoc) { 840df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner assert(Tok.is(tok::l_brace) && "expected {"); 8417d6402f753916a82d93ef0bf0f703ae4243a52beFariborz Jahanian llvm::SmallVector<DeclTy*, 32> AllIvarDecls; 842e13594279a952537ac903325efff57e3edca79d9Chris Lattner llvm::SmallVector<FieldDeclarator, 8> FieldDeclarators; 843e13594279a952537ac903325efff57e3edca79d9Chris Lattner 844ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff SourceLocation LBraceLoc = ConsumeBrace(); // the "{" 845ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff 846aa847fe3c88ee5e8d180e48537c58b805d48d95dFariborz Jahanian tok::ObjCKeywordKind visibility = tok::objc_protected; 847ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff // While we still have something to read, read the instance variables. 848df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner while (Tok.isNot(tok::r_brace) && Tok.isNot(tok::eof)) { 849ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff // Each iteration of this loop reads one objc-instance-variable-decl. 850ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff 851ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff // Check for extraneous top-level semicolon. 852df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::semi)) { 853ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff Diag(Tok, diag::ext_extra_struct_semi); 854ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff ConsumeToken(); 855ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff continue; 856ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff } 857e13594279a952537ac903325efff57e3edca79d9Chris Lattner 858ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff // Set the default visibility to private. 859df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::at)) { // parse objc-visibility-spec 860ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff ConsumeToken(); // eat the @ sign 861861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff switch (Tok.getObjCKeywordID()) { 862ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff case tok::objc_private: 863ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff case tok::objc_public: 864ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff case tok::objc_protected: 865ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff case tok::objc_package: 866861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff visibility = Tok.getObjCKeywordID(); 867ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff ConsumeToken(); 868ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff continue; 869ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff default: 870ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff Diag(Tok, diag::err_objc_illegal_visibility_spec); 871ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff continue; 872ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff } 873ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff } 874e13594279a952537ac903325efff57e3edca79d9Chris Lattner 875e13594279a952537ac903325efff57e3edca79d9Chris Lattner // Parse all the comma separated declarators. 876e13594279a952537ac903325efff57e3edca79d9Chris Lattner DeclSpec DS; 877e13594279a952537ac903325efff57e3edca79d9Chris Lattner FieldDeclarators.clear(); 878e13594279a952537ac903325efff57e3edca79d9Chris Lattner ParseStructDeclaration(DS, FieldDeclarators); 879e13594279a952537ac903325efff57e3edca79d9Chris Lattner 880e13594279a952537ac903325efff57e3edca79d9Chris Lattner // Convert them all to fields. 881e13594279a952537ac903325efff57e3edca79d9Chris Lattner for (unsigned i = 0, e = FieldDeclarators.size(); i != e; ++i) { 882e13594279a952537ac903325efff57e3edca79d9Chris Lattner FieldDeclarator &FD = FieldDeclarators[i]; 883e13594279a952537ac903325efff57e3edca79d9Chris Lattner // Install the declarator into interfaceDecl. 8841d78cc443084134428c4c333fab25148900c3ca4Fariborz Jahanian DeclTy *Field = Actions.ActOnIvar(CurScope, 885e13594279a952537ac903325efff57e3edca79d9Chris Lattner DS.getSourceRange().getBegin(), 8861d78cc443084134428c4c333fab25148900c3ca4Fariborz Jahanian FD.D, FD.BitfieldSize, visibility); 887e13594279a952537ac903325efff57e3edca79d9Chris Lattner AllIvarDecls.push_back(Field); 8887d6402f753916a82d93ef0bf0f703ae4243a52beFariborz Jahanian } 8893536b443bc50d58a79f14fca9b6842541a434854Steve Naroff 890df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::semi)) { 891ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff ConsumeToken(); 892ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff } else { 893ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff Diag(Tok, diag::err_expected_semi_decl_list); 894ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff // Skip to end of block or statement 895ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff SkipUntil(tok::r_brace, true, true); 896ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff } 897ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff } 89860fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff SourceLocation RBraceLoc = MatchRHSPunctuation(tok::r_brace, LBraceLoc); 8998749be53f53384e7846502791ceda6c657228d07Steve Naroff // Call ActOnFields() even if we don't have any decls. This is useful 9008749be53f53384e7846502791ceda6c657228d07Steve Naroff // for code rewriting tools that need to be aware of the empty list. 9018749be53f53384e7846502791ceda6c657228d07Steve Naroff Actions.ActOnFields(CurScope, atLoc, interfaceDecl, 9028749be53f53384e7846502791ceda6c657228d07Steve Naroff &AllIvarDecls[0], AllIvarDecls.size(), 9031bfe1c2129771c06fb58ae5e8c079ae30e138309Daniel Dunbar LBraceLoc, RBraceLoc, 0); 904ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff return; 9055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 906dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff 907dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-declaration: 908dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-definition 909dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-forward-reference 910dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 911dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-definition: 912dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @protocol identifier 913dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-refs[opt] 9143536b443bc50d58a79f14fca9b6842541a434854Steve Naroff/// objc-interface-decl-list 915dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @end 916dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 917dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-forward-reference: 918dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @protocol identifier-list ';' 919dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 920dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// "@protocol identifier ;" should be resolved as "@protocol 9213536b443bc50d58a79f14fca9b6842541a434854Steve Naroff/// identifier-list ;": objc-interface-decl-list may not start with a 922dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// semicolon in the first alternative if objc-protocol-refs are omitted. 923246e70f69cb8aeb67225c54690f1c6b25abd5a86Daniel DunbarParser::DeclTy *Parser::ParseObjCAtProtocolDeclaration(SourceLocation AtLoc, 924246e70f69cb8aeb67225c54690f1c6b25abd5a86Daniel Dunbar AttributeList *attrList) { 925861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff assert(Tok.isObjCAtKeyword(tok::objc_protocol) && 9267ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff "ParseObjCAtProtocolDeclaration(): Expected @protocol"); 9277ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff ConsumeToken(); // the "protocol" identifier 9287ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff 929df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 9307ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff Diag(Tok, diag::err_expected_ident); // missing protocol name. 9317ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff return 0; 9327ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff } 9337ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff // Save the protocol name, then consume it. 9347ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff IdentifierInfo *protocolName = Tok.getIdentifierInfo(); 9357ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff SourceLocation nameLoc = ConsumeToken(); 9367ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff 937df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::semi)) { // forward declaration of one protocol. 9387caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner IdentifierLocPair ProtoInfo(protocolName, nameLoc); 9397ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff ConsumeToken(); 9407caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner return Actions.ActOnForwardProtocolDeclaration(AtLoc, &ProtoInfo, 1); 9417ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff } 9427caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner 943df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::comma)) { // list of forward declarations. 9447caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner llvm::SmallVector<IdentifierLocPair, 8> ProtocolRefs; 9457caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner ProtocolRefs.push_back(std::make_pair(protocolName, nameLoc)); 9467caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner 9477ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff // Parse the list of forward declarations. 9487ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff while (1) { 9497ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff ConsumeToken(); // the ',' 950df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 9517ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff Diag(Tok, diag::err_expected_ident); 9527ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff SkipUntil(tok::semi); 9537ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff return 0; 9547ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff } 9557caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner ProtocolRefs.push_back(IdentifierLocPair(Tok.getIdentifierInfo(), 9567caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner Tok.getLocation())); 9577ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff ConsumeToken(); // the identifier 9587ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff 959df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::comma)) 9607ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff break; 9617ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff } 9627ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff // Consume the ';'. 9637ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff if (ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@protocol")) 9647ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff return 0; 9657caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner 966e440eb8158e71deb1e4ab11618ae3d680aac6da1Steve Naroff return Actions.ActOnForwardProtocolDeclaration(AtLoc, 96737e58d104d7756f7c18f525b74e46b8eeec8ef81Steve Naroff &ProtocolRefs[0], 96837e58d104d7756f7c18f525b74e46b8eeec8ef81Steve Naroff ProtocolRefs.size()); 9697caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner } 9707caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner 9717ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff // Last, and definitely not least, parse a protocol declaration. 972e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner SourceLocation EndProtoLoc; 9737caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner 974e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner llvm::SmallVector<DeclTy *, 8> ProtocolRefs; 9757caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner if (Tok.is(tok::less) && 976e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner ParseObjCProtocolReferences(ProtocolRefs, true, EndProtoLoc)) 9777caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner return 0; 97825e077d59a8e8e43b65882b69610a3d5e2aaf53cFariborz Jahanian 979e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner DeclTy *ProtoType = 980e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner Actions.ActOnStartProtocolInterface(AtLoc, protocolName, nameLoc, 981e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner &ProtocolRefs[0], ProtocolRefs.size(), 982246e70f69cb8aeb67225c54690f1c6b25abd5a86Daniel Dunbar EndProtoLoc, attrList); 98325e077d59a8e8e43b65882b69610a3d5e2aaf53cFariborz Jahanian ParseObjCInterfaceDeclList(ProtoType, tok::objc_protocol); 984bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner return ProtoType; 985dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff} 986dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff 987dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-implementation: 988dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-implementation-prologue 989dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-category-implementation-prologue 990dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 991dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-implementation-prologue: 992dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @implementation identifier objc-superclass[opt] 993dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-instance-variables[opt] 994dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 995dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-category-implementation-prologue: 996dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @implementation identifier ( identifier ) 997dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff 998ac00b7f4a933e60e2f0afd83092339160adc140cFariborz JahanianParser::DeclTy *Parser::ParseObjCAtImplementationDeclaration( 999ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian SourceLocation atLoc) { 1000ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian assert(Tok.isObjCAtKeyword(tok::objc_implementation) && 1001ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian "ParseObjCAtImplementationDeclaration(): Expected @implementation"); 1002ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); // the "implementation" identifier 1003ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian 1004df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 1005ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian Diag(Tok, diag::err_expected_ident); // missing class or category name. 1006ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian return 0; 1007ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1008ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian // We have a class or category name - consume it. 1009ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian IdentifierInfo *nameId = Tok.getIdentifierInfo(); 1010ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian SourceLocation nameLoc = ConsumeToken(); // consume class or category name 1011ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian 1012df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::l_paren)) { 1013ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian // we have a category implementation. 1014ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian SourceLocation lparenLoc = ConsumeParen(); 1015ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian SourceLocation categoryLoc, rparenLoc; 1016ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian IdentifierInfo *categoryId = 0; 1017ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian 1018df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::identifier)) { 1019ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian categoryId = Tok.getIdentifierInfo(); 1020ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian categoryLoc = ConsumeToken(); 1021ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } else { 1022ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian Diag(Tok, diag::err_expected_ident); // missing category name. 1023ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian return 0; 1024ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1025df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::r_paren)) { 1026ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian Diag(Tok, diag::err_expected_rparen); 1027ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian SkipUntil(tok::r_paren, false); // don't stop at ';' 1028ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian return 0; 1029ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1030ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian rparenLoc = ConsumeParen(); 1031e440eb8158e71deb1e4ab11618ae3d680aac6da1Steve Naroff DeclTy *ImplCatType = Actions.ActOnStartCategoryImplementation( 10328f3fde00ad4d4f943321e338b914ae4740711c84Fariborz Jahanian atLoc, nameId, nameLoc, categoryId, 10338f3fde00ad4d4f943321e338b914ae4740711c84Fariborz Jahanian categoryLoc); 1034a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCImpDecl = ImplCatType; 1035db8f3d3bb96c75440f513c43ac73adace2aae5ffFariborz Jahanian return 0; 1036ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1037ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian // We have a class implementation 1038ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian SourceLocation superClassLoc; 1039ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian IdentifierInfo *superClassId = 0; 1040df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::colon)) { 1041ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian // We have a super class 1042ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); 1043df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 1044ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian Diag(Tok, diag::err_expected_ident); // missing super class name. 1045ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian return 0; 1046ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1047ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian superClassId = Tok.getIdentifierInfo(); 1048ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian superClassLoc = ConsumeToken(); // Consume super class name 1049ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1050e440eb8158e71deb1e4ab11618ae3d680aac6da1Steve Naroff DeclTy *ImplClsType = Actions.ActOnStartClassImplementation( 1051cb53b361bce341c8591333c6997f62e480acc0b4Chris Lattner atLoc, nameId, nameLoc, 1052ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian superClassId, superClassLoc); 1053ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian 105460fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff if (Tok.is(tok::l_brace)) // we have ivars 105560fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff ParseObjCClassInstanceVariables(ImplClsType/*FIXME*/, atLoc); 1056a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCImpDecl = ImplClsType; 1057ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian 1058db8f3d3bb96c75440f513c43ac73adace2aae5ffFariborz Jahanian return 0; 10595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 106060fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff 1061ac00b7f4a933e60e2f0afd83092339160adc140cFariborz JahanianParser::DeclTy *Parser::ParseObjCAtEndDeclaration(SourceLocation atLoc) { 1062ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian assert(Tok.isObjCAtKeyword(tok::objc_end) && 1063ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian "ParseObjCAtEndDeclaration(): Expected @end"); 1064ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); // the "end" identifier 106594cdb25a49bd3716ab56ef6de0ea57d29e686bf2Fariborz Jahanian if (ObjCImpDecl) 1066a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek Actions.ActOnAtEnd(atLoc, ObjCImpDecl); 106794cdb25a49bd3716ab56ef6de0ea57d29e686bf2Fariborz Jahanian else 106894cdb25a49bd3716ab56ef6de0ea57d29e686bf2Fariborz Jahanian Diag(atLoc, diag::warn_expected_implementation); // missing @implementation 1069a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek return ObjCImpDecl; 10705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 1071e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian 1072e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian/// compatibility-alias-decl: 1073e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian/// @compatibility_alias alias-name class-name ';' 1074e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian/// 1075e992af01d14e2e31037562c123af0a71ae1ed374Fariborz JahanianParser::DeclTy *Parser::ParseObjCAtAliasDeclaration(SourceLocation atLoc) { 1076e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian assert(Tok.isObjCAtKeyword(tok::objc_compatibility_alias) && 1077e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian "ParseObjCAtAliasDeclaration(): Expected @compatibility_alias"); 1078e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian ConsumeToken(); // consume compatibility_alias 1079df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 1080e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian Diag(Tok, diag::err_expected_ident); 1081e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian return 0; 1082e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian } 1083243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian IdentifierInfo *aliasId = Tok.getIdentifierInfo(); 1084243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian SourceLocation aliasLoc = ConsumeToken(); // consume alias-name 1085df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 1086e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian Diag(Tok, diag::err_expected_ident); 1087e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian return 0; 1088e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian } 1089243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian IdentifierInfo *classId = Tok.getIdentifierInfo(); 1090243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian SourceLocation classLoc = ConsumeToken(); // consume class-name; 1091243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian if (Tok.isNot(tok::semi)) { 10921ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_semi_after) << "@compatibility_alias"; 1093243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian return 0; 1094243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian } 1095243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian DeclTy *ClsType = Actions.ActOnCompatiblityAlias(atLoc, 1096243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian aliasId, aliasLoc, 1097243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian classId, classLoc); 1098243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian return ClsType; 10995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 11005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1101ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-synthesis: 1102ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// @synthesize property-ivar-list ';' 1103ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// 1104ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-ivar-list: 1105ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-ivar 1106ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-ivar-list ',' property-ivar 1107ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// 1108ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-ivar: 1109ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// identifier 1110ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// identifier '=' identifier 1111ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// 1112ac00b7f4a933e60e2f0afd83092339160adc140cFariborz JahanianParser::DeclTy *Parser::ParseObjCPropertySynthesize(SourceLocation atLoc) { 1113ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian assert(Tok.isObjCAtKeyword(tok::objc_synthesize) && 1114ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian "ParseObjCPropertyDynamic(): Expected '@synthesize'"); 1115f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian SourceLocation loc = ConsumeToken(); // consume synthesize 1116df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 1117ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian Diag(Tok, diag::err_expected_ident); 1118ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian return 0; 1119ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1120df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner while (Tok.is(tok::identifier)) { 1121f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian IdentifierInfo *propertyIvar = 0; 1122f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian IdentifierInfo *propertyId = Tok.getIdentifierInfo(); 1123f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian SourceLocation propertyLoc = ConsumeToken(); // consume property name 1124df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::equal)) { 1125ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian // property '=' ivar-name 1126ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); // consume '=' 1127df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 1128ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian Diag(Tok, diag::err_expected_ident); 1129ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian break; 1130ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1131f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian propertyIvar = Tok.getIdentifierInfo(); 1132ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); // consume ivar-name 1133ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1134f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian Actions.ActOnPropertyImplDecl(atLoc, propertyLoc, true, ObjCImpDecl, 1135f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian propertyId, propertyIvar); 1136df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::comma)) 1137ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian break; 1138ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); // consume ',' 1139ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1140df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::semi)) 11411ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_semi_after) << "@synthesize"; 1142ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian return 0; 1143ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian} 1144ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian 1145ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-dynamic: 1146ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// @dynamic property-list 1147ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// 1148ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-list: 1149ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// identifier 1150ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-list ',' identifier 1151ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// 1152ac00b7f4a933e60e2f0afd83092339160adc140cFariborz JahanianParser::DeclTy *Parser::ParseObjCPropertyDynamic(SourceLocation atLoc) { 1153ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian assert(Tok.isObjCAtKeyword(tok::objc_dynamic) && 1154ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian "ParseObjCPropertyDynamic(): Expected '@dynamic'"); 1155ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian SourceLocation loc = ConsumeToken(); // consume dynamic 1156df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 1157ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian Diag(Tok, diag::err_expected_ident); 1158ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian return 0; 1159ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1160df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner while (Tok.is(tok::identifier)) { 1161c35b9e4e2efad727538c848cf30d4b0eb1031dc9Fariborz Jahanian IdentifierInfo *propertyId = Tok.getIdentifierInfo(); 1162c35b9e4e2efad727538c848cf30d4b0eb1031dc9Fariborz Jahanian SourceLocation propertyLoc = ConsumeToken(); // consume property name 1163c35b9e4e2efad727538c848cf30d4b0eb1031dc9Fariborz Jahanian Actions.ActOnPropertyImplDecl(atLoc, propertyLoc, false, ObjCImpDecl, 1164c35b9e4e2efad727538c848cf30d4b0eb1031dc9Fariborz Jahanian propertyId, 0); 1165c35b9e4e2efad727538c848cf30d4b0eb1031dc9Fariborz Jahanian 1166df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::comma)) 1167ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian break; 1168ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); // consume ',' 1169ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1170df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::semi)) 11711ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_semi_after) << "@dynamic"; 1172ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian return 0; 1173ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian} 1174397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian 1175397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// objc-throw-statement: 1176397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// throw expression[opt]; 1177397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// 117839f8f159c488a900e5958d5aab3e467af9ec8a2bFariborz JahanianParser::StmtResult Parser::ParseObjCThrowStmt(SourceLocation atLoc) { 117939f8f159c488a900e5958d5aab3e467af9ec8a2bFariborz Jahanian ExprResult Res; 1180397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian ConsumeToken(); // consume throw 1181df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::semi)) { 118239f8f159c488a900e5958d5aab3e467af9ec8a2bFariborz Jahanian Res = ParseExpression(); 1183397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian if (Res.isInvalid) { 1184397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian SkipUntil(tok::semi); 118539f8f159c488a900e5958d5aab3e467af9ec8a2bFariborz Jahanian return true; 1186397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian } 1187397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian } 118839f8f159c488a900e5958d5aab3e467af9ec8a2bFariborz Jahanian ConsumeToken(); // consume ';' 1189a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek return Actions.ActOnObjCAtThrowStmt(atLoc, Res.Val); 1190397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian} 1191397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian 1192c385c90c68dfa376650e2facfbb444b2ec9bd110Fariborz Jahanian/// objc-synchronized-statement: 119378a677bbb5fa115fa0995b5783adeeefad67167eFariborz Jahanian/// @synchronized '(' expression ')' compound-statement 1194c385c90c68dfa376650e2facfbb444b2ec9bd110Fariborz Jahanian/// 1195c385c90c68dfa376650e2facfbb444b2ec9bd110Fariborz JahanianParser::StmtResult Parser::ParseObjCSynchronizedStmt(SourceLocation atLoc) { 1196fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian ConsumeToken(); // consume synchronized 1197fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian if (Tok.isNot(tok::l_paren)) { 11981ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_lparen_after) << "@synchronized"; 1199fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian return true; 1200fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian } 1201fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian ConsumeParen(); // '(' 120278a677bbb5fa115fa0995b5783adeeefad67167eFariborz Jahanian ExprResult Res = ParseExpression(); 1203fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian if (Res.isInvalid) { 1204fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian SkipUntil(tok::semi); 1205fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian return true; 1206fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian } 1207fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian if (Tok.isNot(tok::r_paren)) { 12081ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_lbrace); 1209fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian return true; 1210fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian } 1211fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian ConsumeParen(); // ')' 121278a677bbb5fa115fa0995b5783adeeefad67167eFariborz Jahanian if (Tok.isNot(tok::l_brace)) { 12131ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_lbrace); 121478a677bbb5fa115fa0995b5783adeeefad67167eFariborz Jahanian return true; 121578a677bbb5fa115fa0995b5783adeeefad67167eFariborz Jahanian } 12163ac438c383a4a9a73c76a05c76ec5d02f10a3c52Steve Naroff // Enter a scope to hold everything within the compound stmt. Compound 12173ac438c383a4a9a73c76a05c76ec5d02f10a3c52Steve Naroff // statements can always hold declarations. 12183ac438c383a4a9a73c76a05c76ec5d02f10a3c52Steve Naroff EnterScope(Scope::DeclScope); 12193ac438c383a4a9a73c76a05c76ec5d02f10a3c52Steve Naroff 1220fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian StmtResult SynchBody = ParseCompoundStatementBody(); 12213ac438c383a4a9a73c76a05c76ec5d02f10a3c52Steve Naroff 12223ac438c383a4a9a73c76a05c76ec5d02f10a3c52Steve Naroff ExitScope(); 1223fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian if (SynchBody.isInvalid) 1224fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian SynchBody = Actions.ActOnNullStmt(Tok.getLocation()); 1225fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian return Actions.ActOnObjCAtSynchronizedStmt(atLoc, Res.Val, SynchBody.Val); 1226c385c90c68dfa376650e2facfbb444b2ec9bd110Fariborz Jahanian} 1227c385c90c68dfa376650e2facfbb444b2ec9bd110Fariborz Jahanian 1228397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// objc-try-catch-statement: 1229397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// @try compound-statement objc-catch-list[opt] 1230397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// @try compound-statement objc-catch-list[opt] @finally compound-statement 1231397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// 1232397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// objc-catch-list: 1233397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// @catch ( parameter-declaration ) compound-statement 1234397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// objc-catch-list @catch ( catch-parameter-declaration ) compound-statement 1235397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// catch-parameter-declaration: 1236397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// parameter-declaration 1237397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// '...' [OBJC2] 1238397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// 12396b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris LattnerParser::StmtResult Parser::ParseObjCTryStmt(SourceLocation atLoc) { 1240397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian bool catch_or_finally_seen = false; 124164515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff 1242397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian ConsumeToken(); // consume try 1243df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::l_brace)) { 12441ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_lbrace); 1245b210bd0404f84b99259c9987d347a44d3c202238Fariborz Jahanian return true; 1246397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian } 12473b1191d7eaf2f4984564e01ab84b6713a9d80e70Fariborz Jahanian StmtResult CatchStmts; 1248161a9c5afaafb4d527b7efba9675a8b2cbbe32e0Fariborz Jahanian StmtResult FinallyStmt; 12493527b59f246cde170e6877e3e62f78a95dbcdfceTed Kremenek EnterScope(Scope::DeclScope); 1250397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian StmtResult TryBody = ParseCompoundStatementBody(); 12513527b59f246cde170e6877e3e62f78a95dbcdfceTed Kremenek ExitScope(); 1252bd49a647afd9cc534fef13cadf652d4e9c396e2bFariborz Jahanian if (TryBody.isInvalid) 1253bd49a647afd9cc534fef13cadf652d4e9c396e2bFariborz Jahanian TryBody = Actions.ActOnNullStmt(Tok.getLocation()); 12546b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner 1255df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner while (Tok.is(tok::at)) { 12566b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner // At this point, we need to lookahead to determine if this @ is the start 12576b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner // of an @catch or @finally. We don't want to consume the @ token if this 12586b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner // is an @try or @encode or something else. 12596b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner Token AfterAt = GetLookAheadToken(1); 12606b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner if (!AfterAt.isObjCAtKeyword(tok::objc_catch) && 12616b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner !AfterAt.isObjCAtKeyword(tok::objc_finally)) 12626b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner break; 12636b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner 1264161a9c5afaafb4d527b7efba9675a8b2cbbe32e0Fariborz Jahanian SourceLocation AtCatchFinallyLoc = ConsumeToken(); 1265cb53b361bce341c8591333c6997f62e480acc0b4Chris Lattner if (Tok.isObjCAtKeyword(tok::objc_catch)) { 12663b1191d7eaf2f4984564e01ab84b6713a9d80e70Fariborz Jahanian StmtTy *FirstPart = 0; 12673b1191d7eaf2f4984564e01ab84b6713a9d80e70Fariborz Jahanian ConsumeToken(); // consume catch 1268df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::l_paren)) { 1269397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian ConsumeParen(); 12703b1191d7eaf2f4984564e01ab84b6713a9d80e70Fariborz Jahanian EnterScope(Scope::DeclScope); 1271df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::ellipsis)) { 1272397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian DeclSpec DS; 1273397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian ParseDeclarationSpecifiers(DS); 1274459a1e2212115f4ff89db7f444df5af41792b18aSteve Naroff // For some odd reason, the name of the exception variable is 1275459a1e2212115f4ff89db7f444df5af41792b18aSteve Naroff // optional. As a result, we need to use PrototypeContext. 1276459a1e2212115f4ff89db7f444df5af41792b18aSteve Naroff Declarator DeclaratorInfo(DS, Declarator::PrototypeContext); 12773b1191d7eaf2f4984564e01ab84b6713a9d80e70Fariborz Jahanian ParseDeclarator(DeclaratorInfo); 1278459a1e2212115f4ff89db7f444df5af41792b18aSteve Naroff if (DeclaratorInfo.getIdentifier()) { 1279459a1e2212115f4ff89db7f444df5af41792b18aSteve Naroff DeclTy *aBlockVarDecl = Actions.ActOnDeclarator(CurScope, 1280914701ed49f31323176a784b49df05a0d177d1adDaniel Dunbar DeclaratorInfo, 0); 1281459a1e2212115f4ff89db7f444df5af41792b18aSteve Naroff StmtResult stmtResult = 1282459a1e2212115f4ff89db7f444df5af41792b18aSteve Naroff Actions.ActOnDeclStmt(aBlockVarDecl, 1283459a1e2212115f4ff89db7f444df5af41792b18aSteve Naroff DS.getSourceRange().getBegin(), 1284459a1e2212115f4ff89db7f444df5af41792b18aSteve Naroff DeclaratorInfo.getSourceRange().getEnd()); 1285459a1e2212115f4ff89db7f444df5af41792b18aSteve Naroff FirstPart = stmtResult.isInvalid ? 0 : stmtResult.Val; 1286459a1e2212115f4ff89db7f444df5af41792b18aSteve Naroff } 128764515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff } else 1288397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian ConsumeToken(); // consume '...' 12893b1191d7eaf2f4984564e01ab84b6713a9d80e70Fariborz Jahanian SourceLocation RParenLoc = ConsumeParen(); 1290c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner 1291c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner StmtResult CatchBody(true); 1292c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner if (Tok.is(tok::l_brace)) 1293c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner CatchBody = ParseCompoundStatementBody(); 1294c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner else 1295c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner Diag(Tok, diag::err_expected_lbrace); 12963b1191d7eaf2f4984564e01ab84b6713a9d80e70Fariborz Jahanian if (CatchBody.isInvalid) 12973b1191d7eaf2f4984564e01ab84b6713a9d80e70Fariborz Jahanian CatchBody = Actions.ActOnNullStmt(Tok.getLocation()); 1298a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek CatchStmts = Actions.ActOnObjCAtCatchStmt(AtCatchFinallyLoc, RParenLoc, 12993b1191d7eaf2f4984564e01ab84b6713a9d80e70Fariborz Jahanian FirstPart, CatchBody.Val, CatchStmts.Val); 13003b1191d7eaf2f4984564e01ab84b6713a9d80e70Fariborz Jahanian ExitScope(); 130164515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff } else { 13021ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(AtCatchFinallyLoc, diag::err_expected_lparen_after) 13031ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner << "@catch clause"; 1304b210bd0404f84b99259c9987d347a44d3c202238Fariborz Jahanian return true; 1305397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian } 1306397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian catch_or_finally_seen = true; 13076b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner } else { 13086b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner assert(Tok.isObjCAtKeyword(tok::objc_finally) && "Lookahead confused?"); 130964515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff ConsumeToken(); // consume finally 1310aefc36656d3113ef32a50cea9ae0621e07c8b26cTed Kremenek EnterScope(Scope::DeclScope); 1311aefc36656d3113ef32a50cea9ae0621e07c8b26cTed Kremenek 1312c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner 1313c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner StmtResult FinallyBody(true); 1314c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner if (Tok.is(tok::l_brace)) 1315c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner FinallyBody = ParseCompoundStatementBody(); 1316c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner else 1317c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner Diag(Tok, diag::err_expected_lbrace); 1318161a9c5afaafb4d527b7efba9675a8b2cbbe32e0Fariborz Jahanian if (FinallyBody.isInvalid) 1319161a9c5afaafb4d527b7efba9675a8b2cbbe32e0Fariborz Jahanian FinallyBody = Actions.ActOnNullStmt(Tok.getLocation()); 1320a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek FinallyStmt = Actions.ActOnObjCAtFinallyStmt(AtCatchFinallyLoc, 1321161a9c5afaafb4d527b7efba9675a8b2cbbe32e0Fariborz Jahanian FinallyBody.Val); 1322397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian catch_or_finally_seen = true; 1323aefc36656d3113ef32a50cea9ae0621e07c8b26cTed Kremenek ExitScope(); 1324397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian break; 1325397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian } 1326397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian } 1327bd49a647afd9cc534fef13cadf652d4e9c396e2bFariborz Jahanian if (!catch_or_finally_seen) { 1328397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian Diag(atLoc, diag::err_missing_catch_finally); 1329bd49a647afd9cc534fef13cadf652d4e9c396e2bFariborz Jahanian return true; 1330bd49a647afd9cc534fef13cadf652d4e9c396e2bFariborz Jahanian } 1331a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek return Actions.ActOnObjCAtTryStmt(atLoc, TryBody.Val, CatchStmts.Val, 1332bd49a647afd9cc534fef13cadf652d4e9c396e2bFariborz Jahanian FinallyStmt.Val); 1333397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian} 1334ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian 13353536b443bc50d58a79f14fca9b6842541a434854Steve Naroff/// objc-method-def: objc-method-proto ';'[opt] '{' body '}' 1336ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// 133771c0a951d08dc7a2a057df8c15f22b36f6aa47c7Steve NaroffParser::DeclTy *Parser::ParseObjCMethodDefinition() { 1338a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek DeclTy *MDecl = ParseObjCMethodPrototype(ObjCImpDecl); 1339ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian // parse optional ';' 1340df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::semi)) 1341ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); 1342ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian 1343409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // We should have an opening brace now. 1344df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::l_brace)) { 1345da323adbb99cee19a203ead852d5d9bfebb23fb7Steve Naroff Diag(Tok, diag::err_expected_method_body); 1346409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff 1347409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // Skip over garbage, until we get to '{'. Don't eat the '{'. 1348409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff SkipUntil(tok::l_brace, true, true); 1349409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff 1350409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // If we didn't find the '{', bail out. 1351409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff if (Tok.isNot(tok::l_brace)) 135271c0a951d08dc7a2a057df8c15f22b36f6aa47c7Steve Naroff return 0; 1353ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1354409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff SourceLocation BraceLoc = Tok.getLocation(); 1355409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff 1356409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // Enter a scope for the method body. 1357409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff EnterScope(Scope::FnScope|Scope::DeclScope); 1358409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff 1359409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // Tell the actions module that we have entered a method definition with the 1360394f3f483fa4e7b472630cfcd03f7840520958c5Steve Naroff // specified Declarator for the method. 1361394f3f483fa4e7b472630cfcd03f7840520958c5Steve Naroff Actions.ObjCActOnStartOfMethodDef(CurScope, MDecl); 1362409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff 1363409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff StmtResult FnBody = ParseCompoundStatementBody(); 1364409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff 1365409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // If the function body could not be parsed, make a bogus compoundstmt. 1366409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff if (FnBody.isInvalid) 1367409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff FnBody = Actions.ActOnCompoundStmt(BraceLoc, BraceLoc, 0, 0, false); 1368409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff 1369409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // Leave the function body scope. 1370409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff ExitScope(); 1371409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff 1372409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // TODO: Pass argument information. 1373394f3f483fa4e7b472630cfcd03f7840520958c5Steve Naroff Actions.ActOnFinishFunctionBody(MDecl, FnBody.Val); 137471c0a951d08dc7a2a057df8c15f22b36f6aa47c7Steve Naroff return MDecl; 13755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 13765508518a2702b00be3b15a26d772bde968972f54Anders Carlsson 137764515f31850024a263e8f55f81e9ea4b39925cfaSteve NaroffParser::StmtResult Parser::ParseObjCAtStatement(SourceLocation AtLoc) { 137864515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff if (Tok.isObjCAtKeyword(tok::objc_try)) { 13796b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner return ParseObjCTryStmt(AtLoc); 138064515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff } else if (Tok.isObjCAtKeyword(tok::objc_throw)) 138164515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff return ParseObjCThrowStmt(AtLoc); 138264515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff else if (Tok.isObjCAtKeyword(tok::objc_synchronized)) 138364515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff return ParseObjCSynchronizedStmt(AtLoc); 138464515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff ExprResult Res = ParseExpressionWithLeadingAt(AtLoc); 138564515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff if (Res.isInvalid) { 138664515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff // If the expression is invalid, skip ahead to the next semicolon. Not 138764515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff // doing this opens us up to the possibility of infinite loops if 138864515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff // ParseExpression does not consume any tokens. 138964515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff SkipUntil(tok::semi); 139064515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff return true; 139164515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff } 139264515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff // Otherwise, eat the semicolon. 139364515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff ExpectAndConsume(tok::semi, diag::err_expected_semi_after_expr); 139464515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff return Actions.ActOnExprStmt(Res.Val); 139564515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff} 139664515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff 1397a642beb9f143130588dcf622f5f7020832b22707Steve NaroffParser::ExprResult Parser::ParseObjCAtExpression(SourceLocation AtLoc) { 13985508518a2702b00be3b15a26d772bde968972f54Anders Carlsson switch (Tok.getKind()) { 1399b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner case tok::string_literal: // primary-expression: string-literal 1400b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner case tok::wide_string_literal: 1401b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner return ParsePostfixExpressionSuffix(ParseObjCStringLiteral(AtLoc)); 1402b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner default: 14034fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner if (Tok.getIdentifierInfo() == 0) 14044fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner return Diag(AtLoc, diag::err_unexpected_at); 14054fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner 14064fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner switch (Tok.getIdentifierInfo()->getObjCKeywordID()) { 14074fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner case tok::objc_encode: 14084fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner return ParsePostfixExpressionSuffix(ParseObjCEncodeExpression(AtLoc)); 14094fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner case tok::objc_protocol: 14104fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner return ParsePostfixExpressionSuffix(ParseObjCProtocolExpression(AtLoc)); 14114fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner case tok::objc_selector: 14124fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner return ParsePostfixExpressionSuffix(ParseObjCSelectorExpression(AtLoc)); 14134fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner default: 14141ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner return Diag(AtLoc, diag::err_unexpected_at); 14154fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner } 14165508518a2702b00be3b15a26d772bde968972f54Anders Carlsson } 14175508518a2702b00be3b15a26d772bde968972f54Anders Carlsson} 14185508518a2702b00be3b15a26d772bde968972f54Anders Carlsson 14190ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-message-expr: 14200ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// '[' objc-receiver objc-message-args ']' 14210ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// 14220ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-receiver: 14230ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// expression 14240ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// class-name 14250ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// type-name 1426699b66138ac307a32e238463e0eff513ff17d337Chris LattnerParser::ExprResult Parser::ParseObjCMessageExpression() { 1427699b66138ac307a32e238463e0eff513ff17d337Chris Lattner assert(Tok.is(tok::l_square) && "'[' expected"); 1428699b66138ac307a32e238463e0eff513ff17d337Chris Lattner SourceLocation LBracLoc = ConsumeBracket(); // consume '[' 1429699b66138ac307a32e238463e0eff513ff17d337Chris Lattner 1430699b66138ac307a32e238463e0eff513ff17d337Chris Lattner // Parse receiver 143114dd98a7952c9559e0d17fff8272bf3be67135afChris Lattner if (isTokObjCMessageIdentifierReceiver()) { 1432699b66138ac307a32e238463e0eff513ff17d337Chris Lattner IdentifierInfo *ReceiverName = Tok.getIdentifierInfo(); 1433699b66138ac307a32e238463e0eff513ff17d337Chris Lattner ConsumeToken(); 1434699b66138ac307a32e238463e0eff513ff17d337Chris Lattner return ParseObjCMessageExpressionBody(LBracLoc, ReceiverName, 0); 1435699b66138ac307a32e238463e0eff513ff17d337Chris Lattner } 1436699b66138ac307a32e238463e0eff513ff17d337Chris Lattner 143769d349a8743f156b965141cda80520bddda84601Chris Lattner ExprResult Res = ParseExpression(); 1438699b66138ac307a32e238463e0eff513ff17d337Chris Lattner if (Res.isInvalid) { 14395c749428a9938d5e2e9564b1c9b7a9252c30ee27Chris Lattner SkipUntil(tok::r_square); 1440699b66138ac307a32e238463e0eff513ff17d337Chris Lattner return Res; 1441699b66138ac307a32e238463e0eff513ff17d337Chris Lattner } 14424fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner 1443699b66138ac307a32e238463e0eff513ff17d337Chris Lattner return ParseObjCMessageExpressionBody(LBracLoc, 0, Res.Val); 1444699b66138ac307a32e238463e0eff513ff17d337Chris Lattner} 1445699b66138ac307a32e238463e0eff513ff17d337Chris Lattner 1446699b66138ac307a32e238463e0eff513ff17d337Chris Lattner/// ParseObjCMessageExpressionBody - Having parsed "'[' objc-receiver", parse 1447699b66138ac307a32e238463e0eff513ff17d337Chris Lattner/// the rest of a message expression. 14480ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// 14490ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-message-args: 14500ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-selector 14510ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-keywordarg-list 14520ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// 14530ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-keywordarg-list: 14540ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-keywordarg 14550ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-keywordarg-list objc-keywordarg 14560ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// 14570ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-keywordarg: 14580ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// selector-name[opt] ':' objc-keywordexpr 14590ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// 14600ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-keywordexpr: 14610ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// nonempty-expr-list 14620ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// 14630ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// nonempty-expr-list: 14640ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// assignment-expression 14650ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// nonempty-expr-list , assignment-expression 14660ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// 1467699b66138ac307a32e238463e0eff513ff17d337Chris LattnerParser::ExprResult 1468699b66138ac307a32e238463e0eff513ff17d337Chris LattnerParser::ParseObjCMessageExpressionBody(SourceLocation LBracLoc, 1469699b66138ac307a32e238463e0eff513ff17d337Chris Lattner IdentifierInfo *ReceiverName, 1470699b66138ac307a32e238463e0eff513ff17d337Chris Lattner ExprTy *ReceiverExpr) { 1471a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian // Parse objc-selector 14724b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian SourceLocation Loc; 14734b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian IdentifierInfo *selIdent = ParseObjCSelector(Loc); 147468d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff 147568d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff llvm::SmallVector<IdentifierInfo *, 12> KeyIdents; 147668d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff llvm::SmallVector<Action::ExprTy *, 12> KeyExprs; 147768d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff 1478df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::colon)) { 1479a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian while (1) { 1480a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian // Each iteration parses a single keyword argument. 148168d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff KeyIdents.push_back(selIdent); 148237387c932855c6d58d70bdd705cd3a9fdcd2a931Steve Naroff 1483df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::colon)) { 1484a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian Diag(Tok, diag::err_expected_colon); 14854fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // We must manually skip to a ']', otherwise the expression skipper will 14864fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // stop at the ']' when it skips to the ';'. We want it to skip beyond 14874fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // the enclosing expression. 14884fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner SkipUntil(tok::r_square); 148937387c932855c6d58d70bdd705cd3a9fdcd2a931Steve Naroff return true; 1490a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian } 14914fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner 149268d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff ConsumeToken(); // Eat the ':'. 1493a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian /// Parse the expression after ':' 149437387c932855c6d58d70bdd705cd3a9fdcd2a931Steve Naroff ExprResult Res = ParseAssignmentExpression(); 149537387c932855c6d58d70bdd705cd3a9fdcd2a931Steve Naroff if (Res.isInvalid) { 14964fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // We must manually skip to a ']', otherwise the expression skipper will 14974fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // stop at the ']' when it skips to the ';'. We want it to skip beyond 14984fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // the enclosing expression. 14994fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner SkipUntil(tok::r_square); 150037387c932855c6d58d70bdd705cd3a9fdcd2a931Steve Naroff return Res; 150137387c932855c6d58d70bdd705cd3a9fdcd2a931Steve Naroff } 15024fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner 150337387c932855c6d58d70bdd705cd3a9fdcd2a931Steve Naroff // We have a valid expression. 150468d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff KeyExprs.push_back(Res.Val); 1505a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian 150637387c932855c6d58d70bdd705cd3a9fdcd2a931Steve Naroff // Check for another keyword selector. 15074b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian selIdent = ParseObjCSelector(Loc); 1508df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (!selIdent && Tok.isNot(tok::colon)) 1509a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian break; 1510a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian // We have a selector or a colon, continue parsing. 1511a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian } 1512a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian // Parse the, optional, argument list, comma separated. 1513df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner while (Tok.is(tok::comma)) { 151449f109c786f99eb7468dac3976db083a65493444Steve Naroff ConsumeToken(); // Eat the ','. 151549f109c786f99eb7468dac3976db083a65493444Steve Naroff /// Parse the expression after ',' 151649f109c786f99eb7468dac3976db083a65493444Steve Naroff ExprResult Res = ParseAssignmentExpression(); 151749f109c786f99eb7468dac3976db083a65493444Steve Naroff if (Res.isInvalid) { 15184fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // We must manually skip to a ']', otherwise the expression skipper will 15194fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // stop at the ']' when it skips to the ';'. We want it to skip beyond 15204fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // the enclosing expression. 15214fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner SkipUntil(tok::r_square); 152249f109c786f99eb7468dac3976db083a65493444Steve Naroff return Res; 152349f109c786f99eb7468dac3976db083a65493444Steve Naroff } 15244fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner 152549f109c786f99eb7468dac3976db083a65493444Steve Naroff // We have a valid expression. 152649f109c786f99eb7468dac3976db083a65493444Steve Naroff KeyExprs.push_back(Res.Val); 1527a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian } 1528a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian } else if (!selIdent) { 1529a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian Diag(Tok, diag::err_expected_ident); // missing selector name. 15304fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner 15314fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // We must manually skip to a ']', otherwise the expression skipper will 15324fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // stop at the ']' when it skips to the ';'. We want it to skip beyond 15334fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // the enclosing expression. 15344fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner SkipUntil(tok::r_square); 15350ba0aa1460ae234423609c09da1b6ad11fae24f3Fariborz Jahanian return true; 1536a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian } 1537ff38491c18b060526d754765b952f4a497a89416Chris Lattner 1538df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::r_square)) { 1539a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian Diag(Tok, diag::err_expected_rsquare); 15404fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // We must manually skip to a ']', otherwise the expression skipper will 15414fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // stop at the ']' when it skips to the ';'. We want it to skip beyond 15424fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // the enclosing expression. 15434fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner SkipUntil(tok::r_square); 15440ba0aa1460ae234423609c09da1b6ad11fae24f3Fariborz Jahanian return true; 1545a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian } 15464fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner 1547699b66138ac307a32e238463e0eff513ff17d337Chris Lattner SourceLocation RBracLoc = ConsumeBracket(); // consume ']' 154837387c932855c6d58d70bdd705cd3a9fdcd2a931Steve Naroff 154929238a0bf7cbf5b396efb451a0adb5fe4aa037caSteve Naroff unsigned nKeys = KeyIdents.size(); 1550ff38491c18b060526d754765b952f4a497a89416Chris Lattner if (nKeys == 0) 1551ff38491c18b060526d754765b952f4a497a89416Chris Lattner KeyIdents.push_back(selIdent); 1552ff38491c18b060526d754765b952f4a497a89416Chris Lattner Selector Sel = PP.getSelectorTable().getSelector(nKeys, &KeyIdents[0]); 1553ff38491c18b060526d754765b952f4a497a89416Chris Lattner 1554ff38491c18b060526d754765b952f4a497a89416Chris Lattner // We've just parsed a keyword message. 155537387c932855c6d58d70bdd705cd3a9fdcd2a931Steve Naroff if (ReceiverName) 15560523aaf9759cd9524956f0930558737458849743Fariborz Jahanian return Actions.ActOnClassMessage(CurScope, 1557699b66138ac307a32e238463e0eff513ff17d337Chris Lattner ReceiverName, Sel, LBracLoc, RBracLoc, 155849f109c786f99eb7468dac3976db083a65493444Steve Naroff &KeyExprs[0], KeyExprs.size()); 1559699b66138ac307a32e238463e0eff513ff17d337Chris Lattner return Actions.ActOnInstanceMessage(ReceiverExpr, Sel, LBracLoc, RBracLoc, 156049f109c786f99eb7468dac3976db083a65493444Steve Naroff &KeyExprs[0], KeyExprs.size()); 15610ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian} 15620ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian 1563beaf299a2701c5559a4e5d76b0c40f805afb8e6aSteve NaroffParser::ExprResult Parser::ParseObjCStringLiteral(SourceLocation AtLoc) { 15645508518a2702b00be3b15a26d772bde968972f54Anders Carlsson ExprResult Res = ParseStringLiteralExpression(); 15655508518a2702b00be3b15a26d772bde968972f54Anders Carlsson if (Res.isInvalid) return Res; 1566b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner 1567b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner // @"foo" @"bar" is a valid concatenated string. Eat any subsequent string 1568b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner // expressions. At this point, we know that the only valid thing that starts 1569b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner // with '@' is an @"". 1570b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner llvm::SmallVector<SourceLocation, 4> AtLocs; 1571b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner llvm::SmallVector<ExprTy*, 4> AtStrings; 1572b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner AtLocs.push_back(AtLoc); 1573b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner AtStrings.push_back(Res.Val); 1574b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner 1575b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner while (Tok.is(tok::at)) { 1576b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner AtLocs.push_back(ConsumeToken()); // eat the @. 1577b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner 1578b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner ExprResult Res(true); // Invalid unless there is a string literal. 1579b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner if (isTokenStringLiteral()) 1580b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner Res = ParseStringLiteralExpression(); 1581b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner else 1582b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner Diag(Tok, diag::err_objc_concat_string); 1583b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner 1584b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner if (Res.isInvalid) { 1585b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner while (!AtStrings.empty()) { 1586b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner Actions.DeleteExpr(AtStrings.back()); 1587b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner AtStrings.pop_back(); 1588b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner } 1589b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner return Res; 1590b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner } 1591b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner 1592b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner AtStrings.push_back(Res.Val); 1593b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner } 159479a99f2c063ce7cd9b18852a39bf4c937fc1faf8Fariborz Jahanian 1595b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner return Actions.ParseObjCStringLiteral(&AtLocs[0], &AtStrings[0], 1596b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner AtStrings.size()); 15975508518a2702b00be3b15a26d772bde968972f54Anders Carlsson} 1598f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson 1599f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson/// objc-encode-expression: 1600f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson/// @encode ( type-name ) 1601674af9541256dc3ef803e3723027a8b028f1f7a2Chris LattnerParser::ExprResult Parser::ParseObjCEncodeExpression(SourceLocation AtLoc) { 1602861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff assert(Tok.isObjCAtKeyword(tok::objc_encode) && "Not an @encode expression!"); 1603f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson 1604f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson SourceLocation EncLoc = ConsumeToken(); 1605f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson 16064fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner if (Tok.isNot(tok::l_paren)) 16071ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner return Diag(Tok, diag::err_expected_lparen_after) << "@encode"; 1608f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson 1609f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson SourceLocation LParenLoc = ConsumeParen(); 1610f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson 1611f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson TypeTy *Ty = ParseTypeName(); 1612f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson 16134988ae3fda10743c8ed8a98cdcb5a783362587b4Anders Carlsson SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); 1614f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson 1615674af9541256dc3ef803e3723027a8b028f1f7a2Chris Lattner return Actions.ParseObjCEncodeExpression(AtLoc, EncLoc, LParenLoc, Ty, 16164988ae3fda10743c8ed8a98cdcb5a783362587b4Anders Carlsson RParenLoc); 1617f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson} 161829b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson 161929b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson/// objc-protocol-expression 162029b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson/// @protocol ( protocol-name ) 162129b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson 16221ab3b96de160e4fbffec2a776e284a48a3bb543dChris LattnerParser::ExprResult Parser::ParseObjCProtocolExpression(SourceLocation AtLoc) { 162329b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson SourceLocation ProtoLoc = ConsumeToken(); 162429b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson 16254fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner if (Tok.isNot(tok::l_paren)) 16261ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner return Diag(Tok, diag::err_expected_lparen_after) << "@protocol"; 162729b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson 162829b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson SourceLocation LParenLoc = ConsumeParen(); 162929b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson 16304fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner if (Tok.isNot(tok::identifier)) 16314fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner return Diag(Tok, diag::err_expected_ident); 16324fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner 1633390d50a725497e99247dc104a7d2c2a255d3af14Fariborz Jahanian IdentifierInfo *protocolId = Tok.getIdentifierInfo(); 163429b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson ConsumeToken(); 163529b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson 16364988ae3fda10743c8ed8a98cdcb5a783362587b4Anders Carlsson SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); 163729b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson 1638390d50a725497e99247dc104a7d2c2a255d3af14Fariborz Jahanian return Actions.ParseObjCProtocolExpression(protocolId, AtLoc, ProtoLoc, 1639390d50a725497e99247dc104a7d2c2a255d3af14Fariborz Jahanian LParenLoc, RParenLoc); 164029b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson} 1641a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian 1642a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian/// objc-selector-expression 1643a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian/// @selector '(' objc-keyword-selector ')' 16441ab3b96de160e4fbffec2a776e284a48a3bb543dChris LattnerParser::ExprResult Parser::ParseObjCSelectorExpression(SourceLocation AtLoc) { 1645a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian SourceLocation SelectorLoc = ConsumeToken(); 1646a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian 16474fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner if (Tok.isNot(tok::l_paren)) 16481ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner return Diag(Tok, diag::err_expected_lparen_after) << "@selector"; 1649a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian 1650b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian llvm::SmallVector<IdentifierInfo *, 12> KeyIdents; 1651a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian SourceLocation LParenLoc = ConsumeParen(); 1652a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian SourceLocation sLoc; 1653a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian IdentifierInfo *SelIdent = ParseObjCSelector(sLoc); 16544fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner if (!SelIdent && Tok.isNot(tok::colon)) 16554fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner return Diag(Tok, diag::err_expected_ident); // missing selector name. 16564fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner 1657b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian KeyIdents.push_back(SelIdent); 1658887407e71fd58de452361b77d72970e32b20ebe0Steve Naroff unsigned nColons = 0; 1659887407e71fd58de452361b77d72970e32b20ebe0Steve Naroff if (Tok.isNot(tok::r_paren)) { 1660a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian while (1) { 16614fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner if (Tok.isNot(tok::colon)) 16624fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner return Diag(Tok, diag::err_expected_colon); 16634fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner 1664cb53b361bce341c8591333c6997f62e480acc0b4Chris Lattner nColons++; 1665a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian ConsumeToken(); // Eat the ':'. 1666a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian if (Tok.is(tok::r_paren)) 1667a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian break; 1668a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian // Check for another keyword selector. 1669a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian SourceLocation Loc; 1670a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian SelIdent = ParseObjCSelector(Loc); 1671b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian KeyIdents.push_back(SelIdent); 1672a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian if (!SelIdent && Tok.isNot(tok::colon)) 1673a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian break; 1674a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian } 1675887407e71fd58de452361b77d72970e32b20ebe0Steve Naroff } 1676a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); 1677887407e71fd58de452361b77d72970e32b20ebe0Steve Naroff Selector Sel = PP.getSelectorTable().getSelector(nColons, &KeyIdents[0]); 16782a35fa9b5e0f9d9429c04adb2e1249b6fd425e7aFariborz Jahanian return Actions.ParseObjCSelectorExpression(Sel, AtLoc, SelectorLoc, LParenLoc, 1679b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian RParenLoc); 168058065b2d8038a4e9a91ea4813bd1774c0f6efacbGabor Greif } 1681