ParseObjc.cpp revision 97cf6eb380016db868866faf27a086cd55a316d4
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" 17a55e52c0802cae3b7c366a05c461d3d15074c1a3Sebastian Redl#include "AstGuard.h" 18500d3297d2a21edeac4d46cbcbe21bc2352c2a28Chris Lattner#include "clang/Parse/ParseDiagnostic.h" 195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "llvm/ADT/SmallVector.h" 205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing namespace clang; 215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 23891dca671a80c865c6def7259f170ba785e4faaaChris Lattner/// ParseObjCAtDirectives - Handle parts of the external-declaration production: 245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// external-declaration: [C99 6.9] 255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// [OBJC] objc-class-definition 2691fa0b7759b575045142abd6ee48c076297ad77bSteve Naroff/// [OBJC] objc-class-declaration 2791fa0b7759b575045142abd6ee48c076297ad77bSteve Naroff/// [OBJC] objc-alias-declaration 2891fa0b7759b575045142abd6ee48c076297ad77bSteve Naroff/// [OBJC] objc-protocol-definition 2991fa0b7759b575045142abd6ee48c076297ad77bSteve Naroff/// [OBJC] objc-method-definition 3091fa0b7759b575045142abd6ee48c076297ad77bSteve Naroff/// [OBJC] '@' 'end' 31dac269b65eed82182fc3e96566dedd6562dfe11eSteve NaroffParser::DeclTy *Parser::ParseObjCAtDirectives() { 325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation AtLoc = ConsumeToken(); // the "@" 335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 34861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff switch (Tok.getObjCKeywordID()) { 355ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner case tok::objc_class: 365ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner return ParseObjCAtClassDeclaration(AtLoc); 375ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner case tok::objc_interface: 385ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner return ParseObjCAtInterfaceDeclaration(AtLoc); 395ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner case tok::objc_protocol: 405ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner return ParseObjCAtProtocolDeclaration(AtLoc); 415ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner case tok::objc_implementation: 425ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner return ParseObjCAtImplementationDeclaration(AtLoc); 435ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner case tok::objc_end: 445ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner return ParseObjCAtEndDeclaration(AtLoc); 455ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner case tok::objc_compatibility_alias: 465ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner return ParseObjCAtAliasDeclaration(AtLoc); 475ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner case tok::objc_synthesize: 485ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner return ParseObjCPropertySynthesize(AtLoc); 495ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner case tok::objc_dynamic: 505ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner return ParseObjCPropertyDynamic(AtLoc); 515ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner default: 525ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner Diag(AtLoc, diag::err_unexpected_at); 535ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner SkipUntil(tok::semi); 545ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner return 0; 555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// objc-class-declaration: 605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// '@' 'class' identifier-list ';' 615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 62dac269b65eed82182fc3e96566dedd6562dfe11eSteve NaroffParser::DeclTy *Parser::ParseObjCAtClassDeclaration(SourceLocation atLoc) { 635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ConsumeToken(); // the identifier "class" 645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::SmallVector<IdentifierInfo *, 8> ClassNames; 655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer while (1) { 67df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Diag(Tok, diag::err_expected_ident); 695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SkipUntil(tok::semi); 70dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff return 0; 715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ClassNames.push_back(Tok.getIdentifierInfo()); 735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ConsumeToken(); 745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 75df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::comma)) 765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer break; 775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ConsumeToken(); 795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Consume the ';'. 825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@class")) 83dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff return 0; 845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 85e440eb8158e71deb1e4ab11618ae3d680aac6da1Steve Naroff return Actions.ActOnForwardClassDeclaration(atLoc, 863536b443bc50d58a79f14fca9b6842541a434854Steve Naroff &ClassNames[0], ClassNames.size()); 875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 89dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 90dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-interface: 91dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-interface-attributes[opt] objc-class-interface 92dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-category-interface 93dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 94dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-interface: 95dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// '@' 'interface' identifier objc-superclass[opt] 96dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-refs[opt] 97dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-instance-variables[opt] 98dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-interface-decl-list 99dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @end 100dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 101dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-category-interface: 102dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// '@' 'interface' identifier '(' identifier[opt] ')' 103dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-refs[opt] 104dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-interface-decl-list 105dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @end 106dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 107dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-superclass: 108dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// ':' identifier 109dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 110dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-interface-attributes: 111dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// __attribute__((visibility("default"))) 112dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// __attribute__((visibility("hidden"))) 113dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// __attribute__((deprecated)) 114dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// __attribute__((unavailable)) 115dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// __attribute__((objc_exception)) - used by NSException on 64-bit 116dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 117dac269b65eed82182fc3e96566dedd6562dfe11eSteve NaroffParser::DeclTy *Parser::ParseObjCAtInterfaceDeclaration( 118dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff SourceLocation atLoc, AttributeList *attrList) { 119861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff assert(Tok.isObjCAtKeyword(tok::objc_interface) && 120dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff "ParseObjCAtInterfaceDeclaration(): Expected @interface"); 121dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff ConsumeToken(); // the "interface" identifier 122dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff 123df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 124dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff Diag(Tok, diag::err_expected_ident); // missing class or category name. 125dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff return 0; 126dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff } 127dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff // We have a class or category name - consume it. 1287ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff IdentifierInfo *nameId = Tok.getIdentifierInfo(); 129dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff SourceLocation nameLoc = ConsumeToken(); 130dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff 131df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::l_paren)) { // we have a category. 132dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff SourceLocation lparenLoc = ConsumeParen(); 133dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff SourceLocation categoryLoc, rparenLoc; 134dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff IdentifierInfo *categoryId = 0; 135dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff 136527fe23f8cbc6a4da1737a547a2517bc92fa88c8Steve Naroff // For ObjC2, the category name is optional (not an error). 137df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::identifier)) { 138dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff categoryId = Tok.getIdentifierInfo(); 139dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff categoryLoc = ConsumeToken(); 140527fe23f8cbc6a4da1737a547a2517bc92fa88c8Steve Naroff } else if (!getLang().ObjC2) { 141527fe23f8cbc6a4da1737a547a2517bc92fa88c8Steve Naroff Diag(Tok, diag::err_expected_ident); // missing category name. 142527fe23f8cbc6a4da1737a547a2517bc92fa88c8Steve Naroff return 0; 143dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff } 144df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::r_paren)) { 145dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff Diag(Tok, diag::err_expected_rparen); 146dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff SkipUntil(tok::r_paren, false); // don't stop at ';' 147dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff return 0; 148dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff } 149dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff rparenLoc = ConsumeParen(); 1506bd6d0b9d8944c5e192097bef24f2becb83af172Chris Lattner 151dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff // Next, we need to check for any protocol references. 1526bd6d0b9d8944c5e192097bef24f2becb83af172Chris Lattner SourceLocation EndProtoLoc; 1536bd6d0b9d8944c5e192097bef24f2becb83af172Chris Lattner llvm::SmallVector<DeclTy *, 8> ProtocolRefs; 1546bd6d0b9d8944c5e192097bef24f2becb83af172Chris Lattner if (Tok.is(tok::less) && 1556bd6d0b9d8944c5e192097bef24f2becb83af172Chris Lattner ParseObjCProtocolReferences(ProtocolRefs, true, EndProtoLoc)) 1566bd6d0b9d8944c5e192097bef24f2becb83af172Chris Lattner return 0; 1576bd6d0b9d8944c5e192097bef24f2becb83af172Chris Lattner 158dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff if (attrList) // categories don't support attributes. 159dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff Diag(Tok, diag::err_objc_no_attributes_on_category); 160dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff 161e440eb8158e71deb1e4ab11618ae3d680aac6da1Steve Naroff DeclTy *CategoryType = Actions.ActOnStartCategoryInterface(atLoc, 1623a165b066e665870c163af64844073a664c042d0Steve Naroff nameId, nameLoc, categoryId, categoryLoc, 163423cb565abc681b770fb4b9b4bc24d398c98157bSteve Naroff &ProtocolRefs[0], ProtocolRefs.size(), 1646bd6d0b9d8944c5e192097bef24f2becb83af172Chris Lattner EndProtoLoc); 165fd225cc227143553898f2d3902242d25db9a4902Fariborz Jahanian 166fd225cc227143553898f2d3902242d25db9a4902Fariborz Jahanian ParseObjCInterfaceDeclList(CategoryType, tok::objc_not_keyword); 167bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner return CategoryType; 168dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff } 169dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff // Parse a class interface. 170dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff IdentifierInfo *superClassId = 0; 171dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff SourceLocation superClassLoc; 1727ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff 173df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::colon)) { // a super class is specified. 174dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff ConsumeToken(); 175df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 176dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff Diag(Tok, diag::err_expected_ident); // missing super class name. 177dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff return 0; 178dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff } 179dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff superClassId = Tok.getIdentifierInfo(); 180dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff superClassLoc = ConsumeToken(); 181dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff } 182dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff // Next, we need to check for any protocol references. 18306036d3709955a53297b4cbe14e20db88f321470Chris Lattner llvm::SmallVector<Action::DeclTy*, 8> ProtocolRefs; 18406036d3709955a53297b4cbe14e20db88f321470Chris Lattner SourceLocation EndProtoLoc; 18506036d3709955a53297b4cbe14e20db88f321470Chris Lattner if (Tok.is(tok::less) && 18606036d3709955a53297b4cbe14e20db88f321470Chris Lattner ParseObjCProtocolReferences(ProtocolRefs, true, EndProtoLoc)) 18706036d3709955a53297b4cbe14e20db88f321470Chris Lattner return 0; 18806036d3709955a53297b4cbe14e20db88f321470Chris Lattner 18906036d3709955a53297b4cbe14e20db88f321470Chris Lattner DeclTy *ClsType = 19006036d3709955a53297b4cbe14e20db88f321470Chris Lattner Actions.ActOnStartClassInterface(atLoc, nameId, nameLoc, 19106036d3709955a53297b4cbe14e20db88f321470Chris Lattner superClassId, superClassLoc, 19206036d3709955a53297b4cbe14e20db88f321470Chris Lattner &ProtocolRefs[0], ProtocolRefs.size(), 19306036d3709955a53297b4cbe14e20db88f321470Chris Lattner EndProtoLoc, attrList); 194f28b264437053fb0deacc9ba02b18a0966f7290aSteve Naroff 195df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::l_brace)) 19660fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff ParseObjCClassInstanceVariables(ClsType, atLoc); 197dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff 19825e077d59a8e8e43b65882b69610a3d5e2aaf53cFariborz Jahanian ParseObjCInterfaceDeclList(ClsType, tok::objc_interface); 199bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner return ClsType; 200dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff} 201dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff 2024d7da2f4a39adcc2ea211fb30600fabde4f3a0b1Daniel Dunbar/// constructSetterName - Return the setter name for the given 2034d7da2f4a39adcc2ea211fb30600fabde4f3a0b1Daniel Dunbar/// identifier, i.e. "set" + Name where the initial character of Name 2044d7da2f4a39adcc2ea211fb30600fabde4f3a0b1Daniel Dunbar/// has been capitalized. 2054d7da2f4a39adcc2ea211fb30600fabde4f3a0b1Daniel Dunbarstatic IdentifierInfo *constructSetterName(IdentifierTable &Idents, 2064d7da2f4a39adcc2ea211fb30600fabde4f3a0b1Daniel Dunbar const IdentifierInfo *Name) { 207edc66f3ab000f54e0e03c5840d7b54e9bf8615cbChris Lattner llvm::SmallString<100> SelectorName; 20869d27b9f2e1c678b6b8a199fa3f705f2b3ff5e0dChris Lattner SelectorName = "set"; 209edc66f3ab000f54e0e03c5840d7b54e9bf8615cbChris Lattner SelectorName.append(Name->getName(), Name->getName()+Name->getLength()); 2104d7da2f4a39adcc2ea211fb30600fabde4f3a0b1Daniel Dunbar SelectorName[3] = toupper(SelectorName[3]); 211edc66f3ab000f54e0e03c5840d7b54e9bf8615cbChris Lattner return &Idents.get(&SelectorName[0], &SelectorName[SelectorName.size()]); 2124d7da2f4a39adcc2ea211fb30600fabde4f3a0b1Daniel Dunbar} 2134d7da2f4a39adcc2ea211fb30600fabde4f3a0b1Daniel Dunbar 214dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-interface-decl-list: 215dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// empty 216dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-interface-decl-list objc-property-decl [OBJC2] 217294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-interface-decl-list objc-method-requirement [OBJC2] 2183536b443bc50d58a79f14fca9b6842541a434854Steve Naroff/// objc-interface-decl-list objc-method-proto ';' 219dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-interface-decl-list declaration 220dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-interface-decl-list ';' 221dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 222294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-method-requirement: [OBJC2] 223294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// @required 224294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// @optional 225294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 22625e077d59a8e8e43b65882b69610a3d5e2aaf53cFariborz Jahanianvoid Parser::ParseObjCInterfaceDeclList(DeclTy *interfaceDecl, 227cb53b361bce341c8591333c6997f62e480acc0b4Chris Lattner tok::ObjCKeywordKind contextKey) { 2288a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek llvm::SmallVector<DeclTy*, 32> allMethods; 22982a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian llvm::SmallVector<DeclTy*, 16> allProperties; 23000933591a2795d09dd1acff12a2d21bce7cb12c5Fariborz Jahanian tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword; 23160fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff 232bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner SourceLocation AtEndLoc; 233bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner 234294494e1cce92043562b4680c613df7fd028c02eSteve Naroff while (1) { 235e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner // If this is a method prototype, parse it. 236df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::minus) || Tok.is(tok::plus)) { 237df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner DeclTy *methodPrototype = 238df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner ParseObjCMethodPrototype(interfaceDecl, MethodImplKind); 23925e077d59a8e8e43b65882b69610a3d5e2aaf53cFariborz Jahanian allMethods.push_back(methodPrototype); 2403536b443bc50d58a79f14fca9b6842541a434854Steve Naroff // Consume the ';' here, since ParseObjCMethodPrototype() is re-used for 2413536b443bc50d58a79f14fca9b6842541a434854Steve Naroff // method definitions. 242b6d74a158a9c002e3c0fcbda8ad8d0ccbb2e5088Chris Lattner ExpectAndConsume(tok::semi, diag::err_expected_semi_after_method_proto, 243b6d74a158a9c002e3c0fcbda8ad8d0ccbb2e5088Chris Lattner "", tok::semi); 244294494e1cce92043562b4680c613df7fd028c02eSteve Naroff continue; 245294494e1cce92043562b4680c613df7fd028c02eSteve Naroff } 246f366b4c84485b646c30d6891a249ad6f65abef7cFariborz Jahanian 247e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner // Ignore excess semicolons. 248e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner if (Tok.is(tok::semi)) { 249294494e1cce92043562b4680c613df7fd028c02eSteve Naroff ConsumeToken(); 250e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner continue; 251e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner } 252e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner 253bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // If we got to the end of the file, exit the loop. 254e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner if (Tok.is(tok::eof)) 255e3a2ca7e30601cdd31c77a830f4cc487851e8096Fariborz Jahanian break; 256e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner 257e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner // If we don't have an @ directive, parse it as a function definition. 258e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner if (Tok.isNot(tok::at)) { 2591fd80116b49782c367ff5d5f50a8b76dd8a5d7f7Chris Lattner // The code below does not consume '}'s because it is afraid of eating the 2601fd80116b49782c367ff5d5f50a8b76dd8a5d7f7Chris Lattner // end of a namespace. Because of the way this code is structured, an 2611fd80116b49782c367ff5d5f50a8b76dd8a5d7f7Chris Lattner // erroneous r_brace would cause an infinite loop if not handled here. 2621fd80116b49782c367ff5d5f50a8b76dd8a5d7f7Chris Lattner if (Tok.is(tok::r_brace)) 2631fd80116b49782c367ff5d5f50a8b76dd8a5d7f7Chris Lattner break; 2641fd80116b49782c367ff5d5f50a8b76dd8a5d7f7Chris Lattner 2654985aceceb9b9261b876b515d32726175c13a775Steve Naroff // FIXME: as the name implies, this rule allows function definitions. 2664985aceceb9b9261b876b515d32726175c13a775Steve Naroff // We could pass a flag or check for functions during semantic analysis. 2673536b443bc50d58a79f14fca9b6842541a434854Steve Naroff ParseDeclarationOrFunctionDefinition(); 268e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner continue; 269e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner } 270e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner 271e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner // Otherwise, we have an @ directive, eat the @. 272e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner SourceLocation AtLoc = ConsumeToken(); // the "@" 273a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner tok::ObjCKeywordKind DirectiveKind = Tok.getObjCKeywordID(); 274e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner 275a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner if (DirectiveKind == tok::objc_end) { // @end -> terminate list 276e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner AtEndLoc = AtLoc; 277e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner break; 278bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner } 279e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner 280bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // Eat the identifier. 281bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner ConsumeToken(); 282bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner 283a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner switch (DirectiveKind) { 284a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner default: 285bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // FIXME: If someone forgets an @end on a protocol, this loop will 286bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // continue to eat up tons of stuff and spew lots of nonsense errors. It 287bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // would probably be better to bail out if we saw an @class or @interface 288bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // or something like that. 289f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner Diag(AtLoc, diag::err_objc_illegal_interface_qual); 290bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // Skip until we see an '@' or '}' or ';'. 291a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner SkipUntil(tok::r_brace, tok::at); 292a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner break; 293a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner 294a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner case tok::objc_required: 295a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner case tok::objc_optional: 296a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner // This is only valid on protocols. 297bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // FIXME: Should this check for ObjC2 being enabled? 298e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner if (contextKey != tok::objc_protocol) 299bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner Diag(AtLoc, diag::err_objc_directive_only_in_protocol); 300a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner else 301bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner MethodImplKind = DirectiveKind; 302a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner break; 303a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner 304a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner case tok::objc_property: 305f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner if (!getLang().ObjC2) 306f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner Diag(AtLoc, diag::err_objc_propertoes_require_objc2); 307f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner 308e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner ObjCDeclSpec OCDS; 309e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner // Parse property attribute list, if any. 3108ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner if (Tok.is(tok::l_paren)) 311e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner ParseObjCPropertyAttribute(OCDS); 312dd5b5f2bb73d037745940431b71eb98393d12d4fChris Lattner 313e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner // Parse all the comma separated declarators. 314e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner DeclSpec DS; 315e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner llvm::SmallVector<FieldDeclarator, 8> FieldDeclarators; 316e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner ParseStructDeclaration(DS, FieldDeclarators); 317e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner 318a1fed7e3beebf9bb1bc85123f283be3eb631c120Chris Lattner ExpectAndConsume(tok::semi, diag::err_expected_semi_decl_list, "", 319a1fed7e3beebf9bb1bc85123f283be3eb631c120Chris Lattner tok::at); 320a1fed7e3beebf9bb1bc85123f283be3eb631c120Chris Lattner 321e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner // Convert them all to property declarations. 322e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner for (unsigned i = 0, e = FieldDeclarators.size(); i != e; ++i) { 323e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner FieldDeclarator &FD = FieldDeclarators[i]; 324da3253d8a97981257185c89ced71ce137278b121Chris Lattner if (FD.D.getIdentifier() == 0) { 325ef708fd4abccf4d21b1f82ab2ab62f6ae7cc1265Chris Lattner Diag(AtLoc, diag::err_objc_property_requires_field_name) 326ef708fd4abccf4d21b1f82ab2ab62f6ae7cc1265Chris Lattner << FD.D.getSourceRange(); 327da3253d8a97981257185c89ced71ce137278b121Chris Lattner continue; 328da3253d8a97981257185c89ced71ce137278b121Chris Lattner } 329573acde1db5cb3e216e3d63fee173230834093d8Fariborz Jahanian if (FD.BitfieldSize) { 330573acde1db5cb3e216e3d63fee173230834093d8Fariborz Jahanian Diag(AtLoc, diag::err_objc_property_bitfield) 331573acde1db5cb3e216e3d63fee173230834093d8Fariborz Jahanian << FD.D.getSourceRange(); 332573acde1db5cb3e216e3d63fee173230834093d8Fariborz Jahanian continue; 333573acde1db5cb3e216e3d63fee173230834093d8Fariborz Jahanian } 334da3253d8a97981257185c89ced71ce137278b121Chris Lattner 335e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner // Install the property declarator into interfaceDecl. 336da3253d8a97981257185c89ced71ce137278b121Chris Lattner IdentifierInfo *SelName = 337da3253d8a97981257185c89ced71ce137278b121Chris Lattner OCDS.getGetterName() ? OCDS.getGetterName() : FD.D.getIdentifier(); 338da3253d8a97981257185c89ced71ce137278b121Chris Lattner 339e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner Selector GetterSel = 340da3253d8a97981257185c89ced71ce137278b121Chris Lattner PP.getSelectorTable().getNullarySelector(SelName); 341e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner IdentifierInfo *SetterName = OCDS.getSetterName(); 342e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner if (!SetterName) 343e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner SetterName = constructSetterName(PP.getIdentifierTable(), 344e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner FD.D.getIdentifier()); 345e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner Selector SetterSel = 346e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner PP.getSelectorTable().getUnarySelector(SetterName); 3478cf0bb3c2a798ce3acacaac2d3178648cd4c65c6Fariborz Jahanian bool isOverridingProperty = false; 348da3253d8a97981257185c89ced71ce137278b121Chris Lattner DeclTy *Property = Actions.ActOnProperty(CurScope, AtLoc, FD, OCDS, 349da3253d8a97981257185c89ced71ce137278b121Chris Lattner GetterSel, SetterSel, 3508cf0bb3c2a798ce3acacaac2d3178648cd4c65c6Fariborz Jahanian interfaceDecl, 3518cf0bb3c2a798ce3acacaac2d3178648cd4c65c6Fariborz Jahanian &isOverridingProperty, 352da3253d8a97981257185c89ced71ce137278b121Chris Lattner MethodImplKind); 3538cf0bb3c2a798ce3acacaac2d3178648cd4c65c6Fariborz Jahanian if (!isOverridingProperty) 3548cf0bb3c2a798ce3acacaac2d3178648cd4c65c6Fariborz Jahanian allProperties.push_back(Property); 355e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner } 356a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner break; 357f28b264437053fb0deacc9ba02b18a0966f7290aSteve Naroff } 358294494e1cce92043562b4680c613df7fd028c02eSteve Naroff } 359bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner 360bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // We break out of the big loop in two cases: when we see @end or when we see 361bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // EOF. In the former case, eat the @end. In the later case, emit an error. 362bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner if (Tok.isObjCAtKeyword(tok::objc_end)) 363bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner ConsumeToken(); // the "end" identifier 364bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner else 365bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner Diag(Tok, diag::err_objc_missing_end); 366bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner 367a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner // Insert collected methods declarations into the @interface object. 368bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // This passes in an invalid SourceLocation for AtEndLoc when EOF is hit. 3698a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek Actions.ActOnAtEnd(AtEndLoc, interfaceDecl, 3708a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek allMethods.empty() ? 0 : &allMethods[0], 3718a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek allMethods.size(), 3728a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek allProperties.empty() ? 0 : &allProperties[0], 3738a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek allProperties.size()); 374294494e1cce92043562b4680c613df7fd028c02eSteve Naroff} 375294494e1cce92043562b4680c613df7fd028c02eSteve Naroff 376d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// Parse property attribute declarations. 377d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// 378d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// property-attr-decl: '(' property-attrlist ')' 379d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// property-attrlist: 380d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// property-attribute 381d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// property-attrlist ',' property-attribute 382d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// property-attribute: 383d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// getter '=' identifier 384d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// setter '=' identifier ':' 385d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// readonly 386d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// readwrite 387d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// assign 388d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// retain 389d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// copy 390d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// nonatomic 391d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// 3927caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattnervoid Parser::ParseObjCPropertyAttribute(ObjCDeclSpec &DS) { 3938ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner assert(Tok.getKind() == tok::l_paren); 394dd5b5f2bb73d037745940431b71eb98393d12d4fChris Lattner SourceLocation LHSLoc = ConsumeParen(); // consume '(' 395dd5b5f2bb73d037745940431b71eb98393d12d4fChris Lattner 396cd9f4b31c4fe5b77b5519cc17b4583fab912bad1Chris Lattner while (1) { 397d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian const IdentifierInfo *II = Tok.getIdentifierInfo(); 398f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner 399f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner // If this is not an identifier at all, bail out early. 400f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner if (II == 0) { 401f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner MatchRHSPunctuation(tok::r_paren, LHSLoc); 402f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner return; 403f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner } 404f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner 405156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner SourceLocation AttrName = ConsumeToken(); // consume last attribute name 406156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner 40792e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner if (II->isStr("readonly")) 408e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_readonly); 40992e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner else if (II->isStr("assign")) 410e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_assign); 41192e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner else if (II->isStr("readwrite")) 412e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_readwrite); 41392e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner else if (II->isStr("retain")) 414e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_retain); 41592e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner else if (II->isStr("copy")) 416e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_copy); 41792e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner else if (II->isStr("nonatomic")) 418e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_nonatomic); 41992e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner else if (II->isStr("getter") || II->isStr("setter")) { 420e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner // getter/setter require extra treatment. 421156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner if (ExpectAndConsume(tok::equal, diag::err_objc_expected_equal, "", 422156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner tok::r_paren)) 423dd5b5f2bb73d037745940431b71eb98393d12d4fChris Lattner return; 424156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner 4258ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner if (Tok.isNot(tok::identifier)) { 4261ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_ident); 4278ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner SkipUntil(tok::r_paren); 4288ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner return; 4298ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner } 4308ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner 4315fd80fada1eeecd279af8333a7f58b86d8df8016Chris Lattner if (II->getName()[0] == 's') { 4328ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_setter); 4338ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner DS.setSetterName(Tok.getIdentifierInfo()); 434156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner ConsumeToken(); // consume method name 435156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner 436156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner if (ExpectAndConsume(tok::colon, diag::err_expected_colon, "", 437156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner tok::r_paren)) 4388ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner return; 4398ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner } else { 4408ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_getter); 4418ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner DS.setGetterName(Tok.getIdentifierInfo()); 442156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner ConsumeToken(); // consume method name 4438ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner } 444e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner } else { 445a9500f05ba6c09bbd84d342236863833067cd816Chris Lattner Diag(AttrName, diag::err_objc_expected_property_attr) << II; 446cd9f4b31c4fe5b77b5519cc17b4583fab912bad1Chris Lattner SkipUntil(tok::r_paren); 447cd9f4b31c4fe5b77b5519cc17b4583fab912bad1Chris Lattner return; 448cd9f4b31c4fe5b77b5519cc17b4583fab912bad1Chris Lattner } 44982a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian 450156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner if (Tok.isNot(tok::comma)) 451156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner break; 452dd5b5f2bb73d037745940431b71eb98393d12d4fChris Lattner 453156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner ConsumeToken(); 454d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian } 455156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner 456156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner MatchRHSPunctuation(tok::r_paren, LHSLoc); 457d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian} 458d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian 4593536b443bc50d58a79f14fca9b6842541a434854Steve Naroff/// objc-method-proto: 460ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// objc-instance-method objc-method-decl objc-method-attributes[opt] 4613536b443bc50d58a79f14fca9b6842541a434854Steve Naroff/// objc-class-method objc-method-decl objc-method-attributes[opt] 462294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 463294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-instance-method: '-' 464294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-class-method: '+' 465294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 4664985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-method-attributes: [OBJC2] 4674985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// __attribute__((deprecated)) 4684985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// 46900933591a2795d09dd1acff12a2d21bce7cb12c5Fariborz JahanianParser::DeclTy *Parser::ParseObjCMethodPrototype(DeclTy *IDecl, 470cb53b361bce341c8591333c6997f62e480acc0b4Chris Lattner tok::ObjCKeywordKind MethodImplKind) { 471df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner assert((Tok.is(tok::minus) || Tok.is(tok::plus)) && "expected +/-"); 472294494e1cce92043562b4680c613df7fd028c02eSteve Naroff 473294494e1cce92043562b4680c613df7fd028c02eSteve Naroff tok::TokenKind methodType = Tok.getKind(); 474bef1185418705e16012b3dd50cd7c260c8d6b79cSteve Naroff SourceLocation mLoc = ConsumeToken(); 475294494e1cce92043562b4680c613df7fd028c02eSteve Naroff 4761f7b6f88f18d7f6b10265acec5d41c4ed1897487Fariborz Jahanian DeclTy *MDecl = ParseObjCMethodDecl(mLoc, methodType, IDecl, MethodImplKind); 4773536b443bc50d58a79f14fca9b6842541a434854Steve Naroff // Since this rule is used for both method declarations and definitions, 4782bd42fadafddc8acf744b57a970bdc96a077c617Steve Naroff // the caller is (optionally) responsible for consuming the ';'. 479f28b264437053fb0deacc9ba02b18a0966f7290aSteve Naroff return MDecl; 480294494e1cce92043562b4680c613df7fd028c02eSteve Naroff} 481294494e1cce92043562b4680c613df7fd028c02eSteve Naroff 482294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-selector: 483294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// identifier 484294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// one of 485294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// enum struct union if else while do for switch case default 486294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// break continue return goto asm sizeof typeof __alignof 487294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// unsigned long const short volatile signed restrict _Complex 488294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// in out inout bycopy byref oneway int char float double void _Bool 489294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 4904b6c9051c6522894978c9ba6a819a659d102db36Fariborz JahanianIdentifierInfo *Parser::ParseObjCSelector(SourceLocation &SelectorLoc) { 491ff38491c18b060526d754765b952f4a497a89416Chris Lattner switch (Tok.getKind()) { 492ff38491c18b060526d754765b952f4a497a89416Chris Lattner default: 493ff38491c18b060526d754765b952f4a497a89416Chris Lattner return 0; 494ff38491c18b060526d754765b952f4a497a89416Chris Lattner case tok::identifier: 495ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_asm: 496ff38491c18b060526d754765b952f4a497a89416Chris Lattner case tok::kw_auto: 4979298d9655aed28b2d9f6cc65c81401b209f03fdcChris Lattner case tok::kw_bool: 498ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_break: 499ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_case: 500ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_catch: 501ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_char: 502ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_class: 503ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_const: 504ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_const_cast: 505ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_continue: 506ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_default: 507ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_delete: 508ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_do: 509ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_double: 510ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_dynamic_cast: 511ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_else: 512ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_enum: 513ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_explicit: 514ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_export: 515ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_extern: 516ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_false: 517ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_float: 518ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_for: 519ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_friend: 520ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_goto: 521ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_if: 522ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_inline: 523ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_int: 524ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_long: 525ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_mutable: 526ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_namespace: 527ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_new: 528ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_operator: 529ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_private: 530ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_protected: 531ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_public: 532ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_register: 533ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_reinterpret_cast: 534ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_restrict: 535ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_return: 536ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_short: 537ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_signed: 538ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_sizeof: 539ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_static: 540ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_static_cast: 541ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_struct: 542ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_switch: 543ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_template: 544ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_this: 545ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_throw: 546ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_true: 547ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_try: 548ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_typedef: 549ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_typeid: 550ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_typename: 551ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_typeof: 552ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_union: 553ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_unsigned: 554ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_using: 555ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_virtual: 556ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_void: 557ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_volatile: 558ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_wchar_t: 559ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_while: 560ff38491c18b060526d754765b952f4a497a89416Chris Lattner case tok::kw__Bool: 561ff38491c18b060526d754765b952f4a497a89416Chris Lattner case tok::kw__Complex: 562ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw___alignof: 563ff38491c18b060526d754765b952f4a497a89416Chris Lattner IdentifierInfo *II = Tok.getIdentifierInfo(); 5644b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian SelectorLoc = ConsumeToken(); 565ff38491c18b060526d754765b952f4a497a89416Chris Lattner return II; 566d064951b0dcc95f8604d0d69ae82d9ecbd38c796Fariborz Jahanian } 567294494e1cce92043562b4680c613df7fd028c02eSteve Naroff} 568294494e1cce92043562b4680c613df7fd028c02eSteve Naroff 5690196cab54007ff072ec2642da8911c6b7e8d3fb5Fariborz Jahanian/// objc-for-collection-in: 'in' 5700196cab54007ff072ec2642da8911c6b7e8d3fb5Fariborz Jahanian/// 571335a2d4122e41343fe11a775889b8bec5b14be60Fariborz Jahanianbool Parser::isTokIdentifier_in() const { 5723ba5a0f90a03d5e13d02cbee9abd2a1ba01b18bcFariborz Jahanian // FIXME: May have to do additional look-ahead to only allow for 5733ba5a0f90a03d5e13d02cbee9abd2a1ba01b18bcFariborz Jahanian // valid tokens following an 'in'; such as an identifier, unary operators, 5743ba5a0f90a03d5e13d02cbee9abd2a1ba01b18bcFariborz Jahanian // '[' etc. 575335a2d4122e41343fe11a775889b8bec5b14be60Fariborz Jahanian return (getLang().ObjC2 && Tok.is(tok::identifier) && 5765ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner Tok.getIdentifierInfo() == ObjCTypeQuals[objc_in]); 5770196cab54007ff072ec2642da8911c6b7e8d3fb5Fariborz Jahanian} 5780196cab54007ff072ec2642da8911c6b7e8d3fb5Fariborz Jahanian 579a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ParseObjCTypeQualifierList - This routine parses the objective-c's type 580e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner/// qualifier list and builds their bitmask representation in the input 581e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner/// argument. 582294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 583294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-type-qualifiers: 584294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-type-qualifier 585294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-type-qualifiers objc-type-qualifier 586294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 587a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekvoid Parser::ParseObjCTypeQualifierList(ObjCDeclSpec &DS) { 588e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner while (1) { 589cb53b361bce341c8591333c6997f62e480acc0b4Chris Lattner if (Tok.isNot(tok::identifier)) 590e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner return; 591e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner 592e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner const IdentifierInfo *II = Tok.getIdentifierInfo(); 593e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner for (unsigned i = 0; i != objc_NumQuals; ++i) { 594a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek if (II != ObjCTypeQuals[i]) 595e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner continue; 596e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner 597a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCDeclSpec::ObjCDeclQualifier Qual; 598e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner switch (i) { 599e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner default: assert(0 && "Unknown decl qualifier"); 600a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek case objc_in: Qual = ObjCDeclSpec::DQ_In; break; 601a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek case objc_out: Qual = ObjCDeclSpec::DQ_Out; break; 602a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek case objc_inout: Qual = ObjCDeclSpec::DQ_Inout; break; 603a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek case objc_oneway: Qual = ObjCDeclSpec::DQ_Oneway; break; 604a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek case objc_bycopy: Qual = ObjCDeclSpec::DQ_Bycopy; break; 605a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek case objc_byref: Qual = ObjCDeclSpec::DQ_Byref; break; 606e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner } 607a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek DS.setObjCDeclQualifier(Qual); 608e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner ConsumeToken(); 609e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner II = 0; 610e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner break; 611e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner } 612e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner 613e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner // If this wasn't a recognized qualifier, bail out. 614e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner if (II) return; 615e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner } 616e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner} 617e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner 618e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner/// objc-type-name: 619e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner/// '(' objc-type-qualifiers[opt] type-name ')' 620e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner/// '(' objc-type-qualifiers[opt] ')' 621e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner/// 622a526c5c67e5a0473c340903ee542ce570119665fTed KremenekParser::TypeTy *Parser::ParseObjCTypeName(ObjCDeclSpec &DS) { 623df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner assert(Tok.is(tok::l_paren) && "expected ("); 624294494e1cce92043562b4680c613df7fd028c02eSteve Naroff 6254a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner SourceLocation LParenLoc = ConsumeParen(); 626e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner SourceLocation TypeStartLoc = Tok.getLocation(); 627294494e1cce92043562b4680c613df7fd028c02eSteve Naroff 62819d74e1494fe399f0e2a94e9419c095f8214851bFariborz Jahanian // Parse type qualifiers, in, inout, etc. 629a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ParseObjCTypeQualifierList(DS); 6304fa7afd07421e7276d1717e4fdf43a5fdd65a622Steve Naroff 6314a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner TypeTy *Ty = 0; 6324a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner if (isTypeSpecifierQualifier()) 633f28b264437053fb0deacc9ba02b18a0966f7290aSteve Naroff Ty = ParseTypeName(); 634e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner 6354a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner if (Tok.is(tok::r_paren)) 6364a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner ConsumeParen(); 6374a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner else if (Tok.getLocation() == TypeStartLoc) { 638e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner // If we didn't eat any tokens, then this isn't a type. 6391ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_type); 6404a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner SkipUntil(tok::r_paren); 6414a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner } else { 6424a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner // Otherwise, we found *something*, but didn't get a ')' in the right 6434a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner // place. Emit an error then return what we have as the type. 6444a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner MatchRHSPunctuation(tok::r_paren, LParenLoc); 645294494e1cce92043562b4680c613df7fd028c02eSteve Naroff } 646f28b264437053fb0deacc9ba02b18a0966f7290aSteve Naroff return Ty; 647294494e1cce92043562b4680c613df7fd028c02eSteve Naroff} 648294494e1cce92043562b4680c613df7fd028c02eSteve Naroff 649294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-method-decl: 650294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-selector 6514985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-keyword-selector objc-parmlist[opt] 652294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-type-name objc-selector 6534985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-type-name objc-keyword-selector objc-parmlist[opt] 654294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 655294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-keyword-selector: 6567ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// objc-keyword-decl 657294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-keyword-selector objc-keyword-decl 658294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 659294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-keyword-decl: 6607ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// objc-selector ':' objc-type-name objc-keyword-attributes[opt] identifier 6617ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// objc-selector ':' objc-keyword-attributes[opt] identifier 6627ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// ':' objc-type-name objc-keyword-attributes[opt] identifier 6637ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// ':' objc-keyword-attributes[opt] identifier 664294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 6654985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-parmlist: 6664985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-parms objc-ellipsis[opt] 667294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 6684985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-parms: 6694985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-parms , parameter-declaration 670294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 6714985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-ellipsis: 672294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// , ... 673294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 6747ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// objc-keyword-attributes: [OBJC2] 6757ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// __attribute__((unused)) 6767ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// 677bef1185418705e16012b3dd50cd7c260c8d6b79cSteve NaroffParser::DeclTy *Parser::ParseObjCMethodDecl(SourceLocation mLoc, 6781f7b6f88f18d7f6b10265acec5d41c4ed1897487Fariborz Jahanian tok::TokenKind mType, 6791f7b6f88f18d7f6b10265acec5d41c4ed1897487Fariborz Jahanian DeclTy *IDecl, 680cb53b361bce341c8591333c6997f62e480acc0b4Chris Lattner tok::ObjCKeywordKind MethodImplKind) 68168d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff{ 682e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner // Parse the return type if present. 683ff38491c18b060526d754765b952f4a497a89416Chris Lattner TypeTy *ReturnType = 0; 684a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCDeclSpec DSRet; 685df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::l_paren)) 686f1de0ca05e2df6f23bd559028693a12d1ebdaaf6Fariborz Jahanian ReturnType = ParseObjCTypeName(DSRet); 687e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner 688bef1185418705e16012b3dd50cd7c260c8d6b79cSteve Naroff SourceLocation selLoc; 689bef1185418705e16012b3dd50cd7c260c8d6b79cSteve Naroff IdentifierInfo *SelIdent = ParseObjCSelector(selLoc); 690e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner 69184c431088693e216193094d1dbf327a01173f57fSteve Naroff // An unnamed colon is valid. 69284c431088693e216193094d1dbf327a01173f57fSteve Naroff if (!SelIdent && Tok.isNot(tok::colon)) { // missing selector name. 6931ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_selector_for_method) 6941ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner << SourceRange(mLoc, Tok.getLocation()); 695e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner // Skip until we get a ; or {}. 696e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner SkipUntil(tok::r_brace); 697e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner return 0; 698e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner } 699e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner 700439c65892cc8629bbf541e0b8bda6b64cbcc4e6bFariborz Jahanian llvm::SmallVector<Declarator, 8> CargNames; 701df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::colon)) { 702ff38491c18b060526d754765b952f4a497a89416Chris Lattner // If attributes exist after the method, parse them. 703ff38491c18b060526d754765b952f4a497a89416Chris Lattner AttributeList *MethodAttrs = 0; 704df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (getLang().ObjC2 && Tok.is(tok::kw___attribute)) 705ff38491c18b060526d754765b952f4a497a89416Chris Lattner MethodAttrs = ParseAttributes(); 706ff38491c18b060526d754765b952f4a497a89416Chris Lattner 707ff38491c18b060526d754765b952f4a497a89416Chris Lattner Selector Sel = PP.getSelectorTable().getNullarySelector(SelIdent); 708bef1185418705e16012b3dd50cd7c260c8d6b79cSteve Naroff return Actions.ActOnMethodDeclaration(mLoc, Tok.getLocation(), 7091f7b6f88f18d7f6b10265acec5d41c4ed1897487Fariborz Jahanian mType, IDecl, DSRet, ReturnType, Sel, 710439c65892cc8629bbf541e0b8bda6b64cbcc4e6bFariborz Jahanian 0, 0, 0, CargNames, 711439c65892cc8629bbf541e0b8bda6b64cbcc4e6bFariborz Jahanian MethodAttrs, MethodImplKind); 712ff38491c18b060526d754765b952f4a497a89416Chris Lattner } 713f28b264437053fb0deacc9ba02b18a0966f7290aSteve Naroff 71468d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff llvm::SmallVector<IdentifierInfo *, 12> KeyIdents; 71568d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff llvm::SmallVector<Action::TypeTy *, 12> KeyTypes; 716a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek llvm::SmallVector<ObjCDeclSpec, 12> ArgTypeQuals; 71768d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff llvm::SmallVector<IdentifierInfo *, 12> ArgNames; 718ff38491c18b060526d754765b952f4a497a89416Chris Lattner 719ff38491c18b060526d754765b952f4a497a89416Chris Lattner Action::TypeTy *TypeInfo; 720ff38491c18b060526d754765b952f4a497a89416Chris Lattner while (1) { 721ff38491c18b060526d754765b952f4a497a89416Chris Lattner KeyIdents.push_back(SelIdent); 72268d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff 723ff38491c18b060526d754765b952f4a497a89416Chris Lattner // Each iteration parses a single keyword argument. 724df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::colon)) { 725ff38491c18b060526d754765b952f4a497a89416Chris Lattner Diag(Tok, diag::err_expected_colon); 726ff38491c18b060526d754765b952f4a497a89416Chris Lattner break; 727ff38491c18b060526d754765b952f4a497a89416Chris Lattner } 728ff38491c18b060526d754765b952f4a497a89416Chris Lattner ConsumeToken(); // Eat the ':'. 729a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCDeclSpec DSType; 730e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner if (Tok.is(tok::l_paren)) // Parse the argument type. 731f1de0ca05e2df6f23bd559028693a12d1ebdaaf6Fariborz Jahanian TypeInfo = ParseObjCTypeName(DSType); 732ff38491c18b060526d754765b952f4a497a89416Chris Lattner else 733ff38491c18b060526d754765b952f4a497a89416Chris Lattner TypeInfo = 0; 734ff38491c18b060526d754765b952f4a497a89416Chris Lattner KeyTypes.push_back(TypeInfo); 735f1de0ca05e2df6f23bd559028693a12d1ebdaaf6Fariborz Jahanian ArgTypeQuals.push_back(DSType); 736f28b264437053fb0deacc9ba02b18a0966f7290aSteve Naroff 737ff38491c18b060526d754765b952f4a497a89416Chris Lattner // If attributes exist before the argument name, parse them. 738df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (getLang().ObjC2 && Tok.is(tok::kw___attribute)) 739ff38491c18b060526d754765b952f4a497a89416Chris Lattner ParseAttributes(); // FIXME: pass attributes through. 7407ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff 741df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 742ff38491c18b060526d754765b952f4a497a89416Chris Lattner Diag(Tok, diag::err_expected_ident); // missing argument name. 743ff38491c18b060526d754765b952f4a497a89416Chris Lattner break; 7444985aceceb9b9261b876b515d32726175c13a775Steve Naroff } 745ff38491c18b060526d754765b952f4a497a89416Chris Lattner ArgNames.push_back(Tok.getIdentifierInfo()); 746ff38491c18b060526d754765b952f4a497a89416Chris Lattner ConsumeToken(); // Eat the identifier. 747ff38491c18b060526d754765b952f4a497a89416Chris Lattner 748ff38491c18b060526d754765b952f4a497a89416Chris Lattner // Check for another keyword selector. 7494b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian SourceLocation Loc; 7504b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian SelIdent = ParseObjCSelector(Loc); 751df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (!SelIdent && Tok.isNot(tok::colon)) 752ff38491c18b060526d754765b952f4a497a89416Chris Lattner break; 753ff38491c18b060526d754765b952f4a497a89416Chris Lattner // We have a selector or a colon, continue parsing. 754ff38491c18b060526d754765b952f4a497a89416Chris Lattner } 755ff38491c18b060526d754765b952f4a497a89416Chris Lattner 756335eafa5be51f6440672a74c73d588af72e96732Steve Naroff bool isVariadic = false; 757335eafa5be51f6440672a74c73d588af72e96732Steve Naroff 758ff38491c18b060526d754765b952f4a497a89416Chris Lattner // Parse the (optional) parameter list. 759df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner while (Tok.is(tok::comma)) { 760ff38491c18b060526d754765b952f4a497a89416Chris Lattner ConsumeToken(); 761df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::ellipsis)) { 762335eafa5be51f6440672a74c73d588af72e96732Steve Naroff isVariadic = true; 7634985aceceb9b9261b876b515d32726175c13a775Steve Naroff ConsumeToken(); 764ff38491c18b060526d754765b952f4a497a89416Chris Lattner break; 7654985aceceb9b9261b876b515d32726175c13a775Steve Naroff } 766ff38491c18b060526d754765b952f4a497a89416Chris Lattner DeclSpec DS; 767ff38491c18b060526d754765b952f4a497a89416Chris Lattner ParseDeclarationSpecifiers(DS); 768ff38491c18b060526d754765b952f4a497a89416Chris Lattner // Parse the declarator. 769ff38491c18b060526d754765b952f4a497a89416Chris Lattner Declarator ParmDecl(DS, Declarator::PrototypeContext); 770ff38491c18b060526d754765b952f4a497a89416Chris Lattner ParseDeclarator(ParmDecl); 771439c65892cc8629bbf541e0b8bda6b64cbcc4e6bFariborz Jahanian CargNames.push_back(ParmDecl); 7724985aceceb9b9261b876b515d32726175c13a775Steve Naroff } 773ff38491c18b060526d754765b952f4a497a89416Chris Lattner 774ff38491c18b060526d754765b952f4a497a89416Chris Lattner // FIXME: Add support for optional parmameter list... 775e3a2ca7e30601cdd31c77a830f4cc487851e8096Fariborz Jahanian // If attributes exist after the method, parse them. 776ff38491c18b060526d754765b952f4a497a89416Chris Lattner AttributeList *MethodAttrs = 0; 777df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (getLang().ObjC2 && Tok.is(tok::kw___attribute)) 778ff38491c18b060526d754765b952f4a497a89416Chris Lattner MethodAttrs = ParseAttributes(); 779ff38491c18b060526d754765b952f4a497a89416Chris Lattner 780ff38491c18b060526d754765b952f4a497a89416Chris Lattner Selector Sel = PP.getSelectorTable().getSelector(KeyIdents.size(), 781ff38491c18b060526d754765b952f4a497a89416Chris Lattner &KeyIdents[0]); 782bef1185418705e16012b3dd50cd7c260c8d6b79cSteve Naroff return Actions.ActOnMethodDeclaration(mLoc, Tok.getLocation(), 7831f7b6f88f18d7f6b10265acec5d41c4ed1897487Fariborz Jahanian mType, IDecl, DSRet, ReturnType, Sel, 784f1de0ca05e2df6f23bd559028693a12d1ebdaaf6Fariborz Jahanian &ArgTypeQuals[0], &KeyTypes[0], 785439c65892cc8629bbf541e0b8bda6b64cbcc4e6bFariborz Jahanian &ArgNames[0], CargNames, 786439c65892cc8629bbf541e0b8bda6b64cbcc4e6bFariborz Jahanian MethodAttrs, 787335eafa5be51f6440672a74c73d588af72e96732Steve Naroff MethodImplKind, isVariadic); 788294494e1cce92043562b4680c613df7fd028c02eSteve Naroff} 789294494e1cce92043562b4680c613df7fd028c02eSteve Naroff 790dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-refs: 791dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// '<' identifier-list '>' 792dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 7937caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattnerbool Parser:: 794e13b9595dc1e2f4288bec34f3412359f648e84a5Chris LattnerParseObjCProtocolReferences(llvm::SmallVectorImpl<Action::DeclTy*> &Protocols, 795e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner bool WarnOnDeclarations, SourceLocation &EndLoc) { 796e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner assert(Tok.is(tok::less) && "expected <"); 797e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner 798e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner ConsumeToken(); // the "<" 799e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner 800e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner llvm::SmallVector<IdentifierLocPair, 8> ProtocolIdents; 801e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner 802e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner while (1) { 803e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner if (Tok.isNot(tok::identifier)) { 804e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner Diag(Tok, diag::err_expected_ident); 805e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner SkipUntil(tok::greater); 806e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner return true; 807e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner } 808e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner ProtocolIdents.push_back(std::make_pair(Tok.getIdentifierInfo(), 809e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner Tok.getLocation())); 810e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner ConsumeToken(); 811e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner 812e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner if (Tok.isNot(tok::comma)) 813e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner break; 814e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner ConsumeToken(); 815e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner } 816e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner 817e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner // Consume the '>'. 818e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner if (Tok.isNot(tok::greater)) { 819e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner Diag(Tok, diag::err_expected_greater); 820e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner return true; 821e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner } 822e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner 823e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner EndLoc = ConsumeAnyToken(); 824e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner 825e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner // Convert the list of protocols identifiers into a list of protocol decls. 826e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner Actions.FindProtocolDeclaration(WarnOnDeclarations, 827e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner &ProtocolIdents[0], ProtocolIdents.size(), 828e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner Protocols); 829e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner return false; 830e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner} 831e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner 832dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-instance-variables: 833dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// '{' objc-instance-variable-decl-list[opt] '}' 834dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 835dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-instance-variable-decl-list: 836dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-visibility-spec 837dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-instance-variable-decl ';' 838dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// ';' 839dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-instance-variable-decl-list objc-visibility-spec 840dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-instance-variable-decl-list objc-instance-variable-decl ';' 841dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-instance-variable-decl-list ';' 842dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 843dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-visibility-spec: 844dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @private 845dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @protected 846dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @public 847ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff/// @package [OBJC2] 848dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 849dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-instance-variable-decl: 850dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// struct-declaration 851dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 85260fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroffvoid Parser::ParseObjCClassInstanceVariables(DeclTy *interfaceDecl, 85360fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff SourceLocation atLoc) { 854df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner assert(Tok.is(tok::l_brace) && "expected {"); 8557d6402f753916a82d93ef0bf0f703ae4243a52beFariborz Jahanian llvm::SmallVector<DeclTy*, 32> AllIvarDecls; 856e13594279a952537ac903325efff57e3edca79d9Chris Lattner llvm::SmallVector<FieldDeclarator, 8> FieldDeclarators; 857e13594279a952537ac903325efff57e3edca79d9Chris Lattner 8581a0d31a3d7f14ddc6370ba912c778aece6c12cf0Douglas Gregor ParseScope ClassScope(this, Scope::DeclScope|Scope::ClassScope); 85972de6676bd30f9081ee4166bbe07b4c270258ce6Douglas Gregor 860ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff SourceLocation LBraceLoc = ConsumeBrace(); // the "{" 861ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff 862aa847fe3c88ee5e8d180e48537c58b805d48d95dFariborz Jahanian tok::ObjCKeywordKind visibility = tok::objc_protected; 863ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff // While we still have something to read, read the instance variables. 864df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner while (Tok.isNot(tok::r_brace) && Tok.isNot(tok::eof)) { 865ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff // Each iteration of this loop reads one objc-instance-variable-decl. 866ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff 867ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff // Check for extraneous top-level semicolon. 868df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::semi)) { 869ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff Diag(Tok, diag::ext_extra_struct_semi); 870ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff ConsumeToken(); 871ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff continue; 872ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff } 873e13594279a952537ac903325efff57e3edca79d9Chris Lattner 874ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff // Set the default visibility to private. 875df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::at)) { // parse objc-visibility-spec 876ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff ConsumeToken(); // eat the @ sign 877861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff switch (Tok.getObjCKeywordID()) { 878ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff case tok::objc_private: 879ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff case tok::objc_public: 880ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff case tok::objc_protected: 881ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff case tok::objc_package: 882861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff visibility = Tok.getObjCKeywordID(); 883ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff ConsumeToken(); 884ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff continue; 885ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff default: 886ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff Diag(Tok, diag::err_objc_illegal_visibility_spec); 887ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff continue; 888ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff } 889ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff } 890e13594279a952537ac903325efff57e3edca79d9Chris Lattner 891e13594279a952537ac903325efff57e3edca79d9Chris Lattner // Parse all the comma separated declarators. 892e13594279a952537ac903325efff57e3edca79d9Chris Lattner DeclSpec DS; 893e13594279a952537ac903325efff57e3edca79d9Chris Lattner FieldDeclarators.clear(); 894e13594279a952537ac903325efff57e3edca79d9Chris Lattner ParseStructDeclaration(DS, FieldDeclarators); 895e13594279a952537ac903325efff57e3edca79d9Chris Lattner 896e13594279a952537ac903325efff57e3edca79d9Chris Lattner // Convert them all to fields. 897e13594279a952537ac903325efff57e3edca79d9Chris Lattner for (unsigned i = 0, e = FieldDeclarators.size(); i != e; ++i) { 898e13594279a952537ac903325efff57e3edca79d9Chris Lattner FieldDeclarator &FD = FieldDeclarators[i]; 899e13594279a952537ac903325efff57e3edca79d9Chris Lattner // Install the declarator into interfaceDecl. 9001d78cc443084134428c4c333fab25148900c3ca4Fariborz Jahanian DeclTy *Field = Actions.ActOnIvar(CurScope, 901e13594279a952537ac903325efff57e3edca79d9Chris Lattner DS.getSourceRange().getBegin(), 9021d78cc443084134428c4c333fab25148900c3ca4Fariborz Jahanian FD.D, FD.BitfieldSize, visibility); 903e13594279a952537ac903325efff57e3edca79d9Chris Lattner AllIvarDecls.push_back(Field); 9047d6402f753916a82d93ef0bf0f703ae4243a52beFariborz Jahanian } 9053536b443bc50d58a79f14fca9b6842541a434854Steve Naroff 906df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::semi)) { 907ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff ConsumeToken(); 908ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff } else { 909ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff Diag(Tok, diag::err_expected_semi_decl_list); 910ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff // Skip to end of block or statement 911ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff SkipUntil(tok::r_brace, true, true); 912ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff } 913ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff } 91460fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff SourceLocation RBraceLoc = MatchRHSPunctuation(tok::r_brace, LBraceLoc); 9158749be53f53384e7846502791ceda6c657228d07Steve Naroff // Call ActOnFields() even if we don't have any decls. This is useful 9168749be53f53384e7846502791ceda6c657228d07Steve Naroff // for code rewriting tools that need to be aware of the empty list. 9178749be53f53384e7846502791ceda6c657228d07Steve Naroff Actions.ActOnFields(CurScope, atLoc, interfaceDecl, 9188749be53f53384e7846502791ceda6c657228d07Steve Naroff &AllIvarDecls[0], AllIvarDecls.size(), 9191bfe1c2129771c06fb58ae5e8c079ae30e138309Daniel Dunbar LBraceLoc, RBraceLoc, 0); 920ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff return; 9215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 922dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff 923dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-declaration: 924dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-definition 925dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-forward-reference 926dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 927dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-definition: 928dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @protocol identifier 929dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-refs[opt] 9303536b443bc50d58a79f14fca9b6842541a434854Steve Naroff/// objc-interface-decl-list 931dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @end 932dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 933dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-forward-reference: 934dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @protocol identifier-list ';' 935dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 936dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// "@protocol identifier ;" should be resolved as "@protocol 9373536b443bc50d58a79f14fca9b6842541a434854Steve Naroff/// identifier-list ;": objc-interface-decl-list may not start with a 938dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// semicolon in the first alternative if objc-protocol-refs are omitted. 939246e70f69cb8aeb67225c54690f1c6b25abd5a86Daniel DunbarParser::DeclTy *Parser::ParseObjCAtProtocolDeclaration(SourceLocation AtLoc, 940246e70f69cb8aeb67225c54690f1c6b25abd5a86Daniel Dunbar AttributeList *attrList) { 941861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff assert(Tok.isObjCAtKeyword(tok::objc_protocol) && 9427ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff "ParseObjCAtProtocolDeclaration(): Expected @protocol"); 9437ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff ConsumeToken(); // the "protocol" identifier 9447ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff 945df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 9467ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff Diag(Tok, diag::err_expected_ident); // missing protocol name. 9477ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff return 0; 9487ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff } 9497ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff // Save the protocol name, then consume it. 9507ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff IdentifierInfo *protocolName = Tok.getIdentifierInfo(); 9517ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff SourceLocation nameLoc = ConsumeToken(); 9527ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff 953df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::semi)) { // forward declaration of one protocol. 9547caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner IdentifierLocPair ProtoInfo(protocolName, nameLoc); 9557ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff ConsumeToken(); 956bc1c877fe28fb6a825f0b226a0a2da99e713ea03Fariborz Jahanian return Actions.ActOnForwardProtocolDeclaration(AtLoc, &ProtoInfo, 1, 957bc1c877fe28fb6a825f0b226a0a2da99e713ea03Fariborz Jahanian attrList); 9587ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff } 9597caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner 960df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::comma)) { // list of forward declarations. 9617caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner llvm::SmallVector<IdentifierLocPair, 8> ProtocolRefs; 9627caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner ProtocolRefs.push_back(std::make_pair(protocolName, nameLoc)); 9637caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner 9647ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff // Parse the list of forward declarations. 9657ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff while (1) { 9667ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff ConsumeToken(); // the ',' 967df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 9687ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff Diag(Tok, diag::err_expected_ident); 9697ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff SkipUntil(tok::semi); 9707ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff return 0; 9717ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff } 9727caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner ProtocolRefs.push_back(IdentifierLocPair(Tok.getIdentifierInfo(), 9737caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner Tok.getLocation())); 9747ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff ConsumeToken(); // the identifier 9757ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff 976df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::comma)) 9777ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff break; 9787ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff } 9797ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff // Consume the ';'. 9807ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff if (ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@protocol")) 9817ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff return 0; 9827caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner 983e440eb8158e71deb1e4ab11618ae3d680aac6da1Steve Naroff return Actions.ActOnForwardProtocolDeclaration(AtLoc, 98437e58d104d7756f7c18f525b74e46b8eeec8ef81Steve Naroff &ProtocolRefs[0], 985bc1c877fe28fb6a825f0b226a0a2da99e713ea03Fariborz Jahanian ProtocolRefs.size(), 986bc1c877fe28fb6a825f0b226a0a2da99e713ea03Fariborz Jahanian attrList); 9877caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner } 9887caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner 9897ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff // Last, and definitely not least, parse a protocol declaration. 990e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner SourceLocation EndProtoLoc; 9917caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner 992e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner llvm::SmallVector<DeclTy *, 8> ProtocolRefs; 9937caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner if (Tok.is(tok::less) && 994e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner ParseObjCProtocolReferences(ProtocolRefs, true, EndProtoLoc)) 9957caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner return 0; 99625e077d59a8e8e43b65882b69610a3d5e2aaf53cFariborz Jahanian 997e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner DeclTy *ProtoType = 998e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner Actions.ActOnStartProtocolInterface(AtLoc, protocolName, nameLoc, 999e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner &ProtocolRefs[0], ProtocolRefs.size(), 1000246e70f69cb8aeb67225c54690f1c6b25abd5a86Daniel Dunbar EndProtoLoc, attrList); 100125e077d59a8e8e43b65882b69610a3d5e2aaf53cFariborz Jahanian ParseObjCInterfaceDeclList(ProtoType, tok::objc_protocol); 1002bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner return ProtoType; 1003dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff} 1004dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff 1005dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-implementation: 1006dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-implementation-prologue 1007dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-category-implementation-prologue 1008dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1009dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-implementation-prologue: 1010dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @implementation identifier objc-superclass[opt] 1011dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-instance-variables[opt] 1012dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1013dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-category-implementation-prologue: 1014dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @implementation identifier ( identifier ) 1015dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff 1016ac00b7f4a933e60e2f0afd83092339160adc140cFariborz JahanianParser::DeclTy *Parser::ParseObjCAtImplementationDeclaration( 1017ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian SourceLocation atLoc) { 1018ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian assert(Tok.isObjCAtKeyword(tok::objc_implementation) && 1019ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian "ParseObjCAtImplementationDeclaration(): Expected @implementation"); 1020ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); // the "implementation" identifier 1021ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian 1022df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 1023ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian Diag(Tok, diag::err_expected_ident); // missing class or category name. 1024ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian return 0; 1025ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1026ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian // We have a class or category name - consume it. 1027ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian IdentifierInfo *nameId = Tok.getIdentifierInfo(); 1028ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian SourceLocation nameLoc = ConsumeToken(); // consume class or category name 1029ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian 1030df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::l_paren)) { 1031ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian // we have a category implementation. 1032ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian SourceLocation lparenLoc = ConsumeParen(); 1033ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian SourceLocation categoryLoc, rparenLoc; 1034ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian IdentifierInfo *categoryId = 0; 1035ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian 1036df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::identifier)) { 1037ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian categoryId = Tok.getIdentifierInfo(); 1038ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian categoryLoc = ConsumeToken(); 1039ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } else { 1040ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian Diag(Tok, diag::err_expected_ident); // missing category name. 1041ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian return 0; 1042ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1043df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::r_paren)) { 1044ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian Diag(Tok, diag::err_expected_rparen); 1045ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian SkipUntil(tok::r_paren, false); // don't stop at ';' 1046ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian return 0; 1047ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1048ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian rparenLoc = ConsumeParen(); 1049e440eb8158e71deb1e4ab11618ae3d680aac6da1Steve Naroff DeclTy *ImplCatType = Actions.ActOnStartCategoryImplementation( 10508f3fde00ad4d4f943321e338b914ae4740711c84Fariborz Jahanian atLoc, nameId, nameLoc, categoryId, 10518f3fde00ad4d4f943321e338b914ae4740711c84Fariborz Jahanian categoryLoc); 1052a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCImpDecl = ImplCatType; 1053db8f3d3bb96c75440f513c43ac73adace2aae5ffFariborz Jahanian return 0; 1054ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1055ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian // We have a class implementation 1056ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian SourceLocation superClassLoc; 1057ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian IdentifierInfo *superClassId = 0; 1058df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::colon)) { 1059ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian // We have a super class 1060ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); 1061df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 1062ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian Diag(Tok, diag::err_expected_ident); // missing super class name. 1063ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian return 0; 1064ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1065ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian superClassId = Tok.getIdentifierInfo(); 1066ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian superClassLoc = ConsumeToken(); // Consume super class name 1067ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1068e440eb8158e71deb1e4ab11618ae3d680aac6da1Steve Naroff DeclTy *ImplClsType = Actions.ActOnStartClassImplementation( 1069cb53b361bce341c8591333c6997f62e480acc0b4Chris Lattner atLoc, nameId, nameLoc, 1070ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian superClassId, superClassLoc); 1071ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian 107260fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff if (Tok.is(tok::l_brace)) // we have ivars 107360fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff ParseObjCClassInstanceVariables(ImplClsType/*FIXME*/, atLoc); 1074a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCImpDecl = ImplClsType; 1075ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian 1076db8f3d3bb96c75440f513c43ac73adace2aae5ffFariborz Jahanian return 0; 10775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 107860fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff 1079ac00b7f4a933e60e2f0afd83092339160adc140cFariborz JahanianParser::DeclTy *Parser::ParseObjCAtEndDeclaration(SourceLocation atLoc) { 1080ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian assert(Tok.isObjCAtKeyword(tok::objc_end) && 1081ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian "ParseObjCAtEndDeclaration(): Expected @end"); 1082ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); // the "end" identifier 108394cdb25a49bd3716ab56ef6de0ea57d29e686bf2Fariborz Jahanian if (ObjCImpDecl) 1084a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek Actions.ActOnAtEnd(atLoc, ObjCImpDecl); 108594cdb25a49bd3716ab56ef6de0ea57d29e686bf2Fariborz Jahanian else 108694cdb25a49bd3716ab56ef6de0ea57d29e686bf2Fariborz Jahanian Diag(atLoc, diag::warn_expected_implementation); // missing @implementation 1087a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek return ObjCImpDecl; 10885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 1089e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian 1090e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian/// compatibility-alias-decl: 1091e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian/// @compatibility_alias alias-name class-name ';' 1092e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian/// 1093e992af01d14e2e31037562c123af0a71ae1ed374Fariborz JahanianParser::DeclTy *Parser::ParseObjCAtAliasDeclaration(SourceLocation atLoc) { 1094e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian assert(Tok.isObjCAtKeyword(tok::objc_compatibility_alias) && 1095e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian "ParseObjCAtAliasDeclaration(): Expected @compatibility_alias"); 1096e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian ConsumeToken(); // consume compatibility_alias 1097df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 1098e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian Diag(Tok, diag::err_expected_ident); 1099e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian return 0; 1100e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian } 1101243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian IdentifierInfo *aliasId = Tok.getIdentifierInfo(); 1102243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian SourceLocation aliasLoc = ConsumeToken(); // consume alias-name 1103df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 1104e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian Diag(Tok, diag::err_expected_ident); 1105e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian return 0; 1106e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian } 1107243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian IdentifierInfo *classId = Tok.getIdentifierInfo(); 1108243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian SourceLocation classLoc = ConsumeToken(); // consume class-name; 1109243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian if (Tok.isNot(tok::semi)) { 11101ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_semi_after) << "@compatibility_alias"; 1111243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian return 0; 1112243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian } 1113243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian DeclTy *ClsType = Actions.ActOnCompatiblityAlias(atLoc, 1114243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian aliasId, aliasLoc, 1115243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian classId, classLoc); 1116243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian return ClsType; 11175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 11185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1119ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-synthesis: 1120ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// @synthesize property-ivar-list ';' 1121ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// 1122ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-ivar-list: 1123ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-ivar 1124ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-ivar-list ',' property-ivar 1125ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// 1126ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-ivar: 1127ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// identifier 1128ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// identifier '=' identifier 1129ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// 1130ac00b7f4a933e60e2f0afd83092339160adc140cFariborz JahanianParser::DeclTy *Parser::ParseObjCPropertySynthesize(SourceLocation atLoc) { 1131ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian assert(Tok.isObjCAtKeyword(tok::objc_synthesize) && 1132ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian "ParseObjCPropertyDynamic(): Expected '@synthesize'"); 1133f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian SourceLocation loc = ConsumeToken(); // consume synthesize 1134df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 1135ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian Diag(Tok, diag::err_expected_ident); 1136ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian return 0; 1137ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1138df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner while (Tok.is(tok::identifier)) { 1139f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian IdentifierInfo *propertyIvar = 0; 1140f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian IdentifierInfo *propertyId = Tok.getIdentifierInfo(); 1141f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian SourceLocation propertyLoc = ConsumeToken(); // consume property name 1142df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::equal)) { 1143ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian // property '=' ivar-name 1144ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); // consume '=' 1145df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 1146ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian Diag(Tok, diag::err_expected_ident); 1147ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian break; 1148ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1149f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian propertyIvar = Tok.getIdentifierInfo(); 1150ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); // consume ivar-name 1151ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1152f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian Actions.ActOnPropertyImplDecl(atLoc, propertyLoc, true, ObjCImpDecl, 1153f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian propertyId, propertyIvar); 1154df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::comma)) 1155ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian break; 1156ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); // consume ',' 1157ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1158df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::semi)) 11591ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_semi_after) << "@synthesize"; 1160ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian return 0; 1161ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian} 1162ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian 1163ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-dynamic: 1164ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// @dynamic property-list 1165ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// 1166ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-list: 1167ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// identifier 1168ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-list ',' identifier 1169ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// 1170ac00b7f4a933e60e2f0afd83092339160adc140cFariborz JahanianParser::DeclTy *Parser::ParseObjCPropertyDynamic(SourceLocation atLoc) { 1171ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian assert(Tok.isObjCAtKeyword(tok::objc_dynamic) && 1172ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian "ParseObjCPropertyDynamic(): Expected '@dynamic'"); 1173ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian SourceLocation loc = ConsumeToken(); // consume dynamic 1174df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 1175ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian Diag(Tok, diag::err_expected_ident); 1176ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian return 0; 1177ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1178df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner while (Tok.is(tok::identifier)) { 1179c35b9e4e2efad727538c848cf30d4b0eb1031dc9Fariborz Jahanian IdentifierInfo *propertyId = Tok.getIdentifierInfo(); 1180c35b9e4e2efad727538c848cf30d4b0eb1031dc9Fariborz Jahanian SourceLocation propertyLoc = ConsumeToken(); // consume property name 1181c35b9e4e2efad727538c848cf30d4b0eb1031dc9Fariborz Jahanian Actions.ActOnPropertyImplDecl(atLoc, propertyLoc, false, ObjCImpDecl, 1182c35b9e4e2efad727538c848cf30d4b0eb1031dc9Fariborz Jahanian propertyId, 0); 1183c35b9e4e2efad727538c848cf30d4b0eb1031dc9Fariborz Jahanian 1184df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::comma)) 1185ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian break; 1186ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); // consume ',' 1187ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1188df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::semi)) 11891ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_semi_after) << "@dynamic"; 1190ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian return 0; 1191ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian} 1192397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian 1193397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// objc-throw-statement: 1194397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// throw expression[opt]; 1195397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// 119643bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian RedlParser::OwningStmtResult Parser::ParseObjCThrowStmt(SourceLocation atLoc) { 119715faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl OwningExprResult Res(Actions); 1198397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian ConsumeToken(); // consume throw 1199df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::semi)) { 120039f8f159c488a900e5958d5aab3e467af9ec8a2bFariborz Jahanian Res = ParseExpression(); 12010e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Res.isInvalid()) { 1202397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian SkipUntil(tok::semi); 120343bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 1204397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian } 1205397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian } 120639f8f159c488a900e5958d5aab3e467af9ec8a2bFariborz Jahanian ConsumeToken(); // consume ';' 1207e21dd6ffef4585fa43cd3586ed971217d65bf56cSteve Naroff return Actions.ActOnObjCAtThrowStmt(atLoc, move(Res), CurScope); 1208397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian} 1209397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian 1210c385c90c68dfa376650e2facfbb444b2ec9bd110Fariborz Jahanian/// objc-synchronized-statement: 121178a677bbb5fa115fa0995b5783adeeefad67167eFariborz Jahanian/// @synchronized '(' expression ')' compound-statement 1212c385c90c68dfa376650e2facfbb444b2ec9bd110Fariborz Jahanian/// 121343bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian RedlParser::OwningStmtResult 121443bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian RedlParser::ParseObjCSynchronizedStmt(SourceLocation atLoc) { 1215fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian ConsumeToken(); // consume synchronized 1216fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian if (Tok.isNot(tok::l_paren)) { 12171ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_lparen_after) << "@synchronized"; 121843bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 1219fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian } 1220fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian ConsumeParen(); // '(' 12212f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl OwningExprResult Res(ParseExpression()); 12220e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Res.isInvalid()) { 1223fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian SkipUntil(tok::semi); 122443bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 1225fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian } 1226fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian if (Tok.isNot(tok::r_paren)) { 12271ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_lbrace); 122843bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 1229fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian } 1230fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian ConsumeParen(); // ')' 123178a677bbb5fa115fa0995b5783adeeefad67167eFariborz Jahanian if (Tok.isNot(tok::l_brace)) { 12321ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_lbrace); 123343bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 123478a677bbb5fa115fa0995b5783adeeefad67167eFariborz Jahanian } 12353ac438c383a4a9a73c76a05c76ec5d02f10a3c52Steve Naroff // Enter a scope to hold everything within the compound stmt. Compound 12363ac438c383a4a9a73c76a05c76ec5d02f10a3c52Steve Naroff // statements can always hold declarations. 12378935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor ParseScope BodyScope(this, Scope::DeclScope); 12383ac438c383a4a9a73c76a05c76ec5d02f10a3c52Steve Naroff 123961364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl OwningStmtResult SynchBody(ParseCompoundStatementBody()); 12400e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl 12418935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor BodyScope.Exit(); 12420e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (SynchBody.isInvalid()) 1243fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian SynchBody = Actions.ActOnNullStmt(Tok.getLocation()); 124476ad2e85575722e8a38a2bd4648ab4304d9fcd24Sebastian Redl return Actions.ActOnObjCAtSynchronizedStmt(atLoc, move(Res), move(SynchBody)); 1245c385c90c68dfa376650e2facfbb444b2ec9bd110Fariborz Jahanian} 1246c385c90c68dfa376650e2facfbb444b2ec9bd110Fariborz Jahanian 1247397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// objc-try-catch-statement: 1248397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// @try compound-statement objc-catch-list[opt] 1249397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// @try compound-statement objc-catch-list[opt] @finally compound-statement 1250397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// 1251397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// objc-catch-list: 1252397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// @catch ( parameter-declaration ) compound-statement 1253397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// objc-catch-list @catch ( catch-parameter-declaration ) compound-statement 1254397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// catch-parameter-declaration: 1255397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// parameter-declaration 1256397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// '...' [OBJC2] 1257397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// 125843bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian RedlParser::OwningStmtResult Parser::ParseObjCTryStmt(SourceLocation atLoc) { 1259397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian bool catch_or_finally_seen = false; 126043bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl 1261397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian ConsumeToken(); // consume try 1262df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::l_brace)) { 12631ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_lbrace); 126443bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 1265397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian } 126615faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl OwningStmtResult CatchStmts(Actions); 126715faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl OwningStmtResult FinallyStmt(Actions); 12688935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor ParseScope TryScope(this, Scope::DeclScope); 126961364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl OwningStmtResult TryBody(ParseCompoundStatementBody()); 12708935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor TryScope.Exit(); 12710e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (TryBody.isInvalid()) 1272bd49a647afd9cc534fef13cadf652d4e9c396e2bFariborz Jahanian TryBody = Actions.ActOnNullStmt(Tok.getLocation()); 1273a55e52c0802cae3b7c366a05c461d3d15074c1a3Sebastian Redl 1274df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner while (Tok.is(tok::at)) { 12756b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner // At this point, we need to lookahead to determine if this @ is the start 12766b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner // of an @catch or @finally. We don't want to consume the @ token if this 12776b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner // is an @try or @encode or something else. 12786b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner Token AfterAt = GetLookAheadToken(1); 12796b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner if (!AfterAt.isObjCAtKeyword(tok::objc_catch) && 12806b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner !AfterAt.isObjCAtKeyword(tok::objc_finally)) 12816b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner break; 12820e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl 1283161a9c5afaafb4d527b7efba9675a8b2cbbe32e0Fariborz Jahanian SourceLocation AtCatchFinallyLoc = ConsumeToken(); 1284cb53b361bce341c8591333c6997f62e480acc0b4Chris Lattner if (Tok.isObjCAtKeyword(tok::objc_catch)) { 128515faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl OwningStmtResult FirstPart(Actions); 12863b1191d7eaf2f4984564e01ab84b6713a9d80e70Fariborz Jahanian ConsumeToken(); // consume catch 1287df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::l_paren)) { 1288397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian ConsumeParen(); 1289e21dd6ffef4585fa43cd3586ed971217d65bf56cSteve Naroff ParseScope CatchScope(this, Scope::DeclScope|Scope::AtCatchScope); 1290df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::ellipsis)) { 1291397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian DeclSpec DS; 1292397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian ParseDeclarationSpecifiers(DS); 129343bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl // For some odd reason, the name of the exception variable is 1294459a1e2212115f4ff89db7f444df5af41792b18aSteve Naroff // optional. As a result, we need to use PrototypeContext. 1295459a1e2212115f4ff89db7f444df5af41792b18aSteve Naroff Declarator DeclaratorInfo(DS, Declarator::PrototypeContext); 12963b1191d7eaf2f4984564e01ab84b6713a9d80e70Fariborz Jahanian ParseDeclarator(DeclaratorInfo); 1297459a1e2212115f4ff89db7f444df5af41792b18aSteve Naroff if (DeclaratorInfo.getIdentifier()) { 129843bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl DeclTy *aBlockVarDecl = Actions.ActOnDeclarator(CurScope, 1299914701ed49f31323176a784b49df05a0d177d1adDaniel Dunbar DeclaratorInfo, 0); 13000e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl FirstPart = 130143bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl Actions.ActOnDeclStmt(aBlockVarDecl, 1302459a1e2212115f4ff89db7f444df5af41792b18aSteve Naroff DS.getSourceRange().getBegin(), 1303459a1e2212115f4ff89db7f444df5af41792b18aSteve Naroff DeclaratorInfo.getSourceRange().getEnd()); 1304459a1e2212115f4ff89db7f444df5af41792b18aSteve Naroff } 130564515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff } else 1306397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian ConsumeToken(); // consume '...' 13073b1191d7eaf2f4984564e01ab84b6713a9d80e70Fariborz Jahanian SourceLocation RParenLoc = ConsumeParen(); 1308c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner 130915faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl OwningStmtResult CatchBody(Actions, true); 1310c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner if (Tok.is(tok::l_brace)) 1311c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner CatchBody = ParseCompoundStatementBody(); 1312c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner else 1313c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner Diag(Tok, diag::err_expected_lbrace); 13140e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (CatchBody.isInvalid()) 13153b1191d7eaf2f4984564e01ab84b6713a9d80e70Fariborz Jahanian CatchBody = Actions.ActOnNullStmt(Tok.getLocation()); 13160e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl CatchStmts = Actions.ActOnObjCAtCatchStmt(AtCatchFinallyLoc, 131776ad2e85575722e8a38a2bd4648ab4304d9fcd24Sebastian Redl RParenLoc, move(FirstPart), move(CatchBody), 131876ad2e85575722e8a38a2bd4648ab4304d9fcd24Sebastian Redl move(CatchStmts)); 131964515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff } else { 13201ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(AtCatchFinallyLoc, diag::err_expected_lparen_after) 13211ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner << "@catch clause"; 132243bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 1323397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian } 1324397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian catch_or_finally_seen = true; 13256b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner } else { 13266b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner assert(Tok.isObjCAtKeyword(tok::objc_finally) && "Lookahead confused?"); 132764515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff ConsumeToken(); // consume finally 13288935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor ParseScope FinallyScope(this, Scope::DeclScope); 13290e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl 133015faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl OwningStmtResult FinallyBody(Actions, true); 1331c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner if (Tok.is(tok::l_brace)) 1332c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner FinallyBody = ParseCompoundStatementBody(); 1333c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner else 1334c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner Diag(Tok, diag::err_expected_lbrace); 13350e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (FinallyBody.isInvalid()) 1336161a9c5afaafb4d527b7efba9675a8b2cbbe32e0Fariborz Jahanian FinallyBody = Actions.ActOnNullStmt(Tok.getLocation()); 13370e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl FinallyStmt = Actions.ActOnObjCAtFinallyStmt(AtCatchFinallyLoc, 133876ad2e85575722e8a38a2bd4648ab4304d9fcd24Sebastian Redl move(FinallyBody)); 1339397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian catch_or_finally_seen = true; 1340397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian break; 1341397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian } 1342397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian } 1343bd49a647afd9cc534fef13cadf652d4e9c396e2bFariborz Jahanian if (!catch_or_finally_seen) { 1344397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian Diag(atLoc, diag::err_missing_catch_finally); 134543bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 1346bd49a647afd9cc534fef13cadf652d4e9c396e2bFariborz Jahanian } 134776ad2e85575722e8a38a2bd4648ab4304d9fcd24Sebastian Redl return Actions.ActOnObjCAtTryStmt(atLoc, move(TryBody), move(CatchStmts), 134876ad2e85575722e8a38a2bd4648ab4304d9fcd24Sebastian Redl move(FinallyStmt)); 1349397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian} 1350ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian 13513536b443bc50d58a79f14fca9b6842541a434854Steve Naroff/// objc-method-def: objc-method-proto ';'[opt] '{' body '}' 1352ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// 135371c0a951d08dc7a2a057df8c15f22b36f6aa47c7Steve NaroffParser::DeclTy *Parser::ParseObjCMethodDefinition() { 1354a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek DeclTy *MDecl = ParseObjCMethodPrototype(ObjCImpDecl); 1355ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian // parse optional ';' 1356df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::semi)) 1357ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); 1358ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian 1359409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // We should have an opening brace now. 1360df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::l_brace)) { 1361da323adbb99cee19a203ead852d5d9bfebb23fb7Steve Naroff Diag(Tok, diag::err_expected_method_body); 1362409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff 1363409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // Skip over garbage, until we get to '{'. Don't eat the '{'. 1364409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff SkipUntil(tok::l_brace, true, true); 1365409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff 1366409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // If we didn't find the '{', bail out. 1367409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff if (Tok.isNot(tok::l_brace)) 136871c0a951d08dc7a2a057df8c15f22b36f6aa47c7Steve Naroff return 0; 1369ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1370409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff SourceLocation BraceLoc = Tok.getLocation(); 1371409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff 1372409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // Enter a scope for the method body. 13738935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor ParseScope BodyScope(this, Scope::FnScope|Scope::DeclScope); 1374409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff 1375409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // Tell the actions module that we have entered a method definition with the 1376394f3f483fa4e7b472630cfcd03f7840520958c5Steve Naroff // specified Declarator for the method. 1377394f3f483fa4e7b472630cfcd03f7840520958c5Steve Naroff Actions.ObjCActOnStartOfMethodDef(CurScope, MDecl); 137861364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl 137961364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl OwningStmtResult FnBody(ParseCompoundStatementBody()); 138061364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl 1381409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // If the function body could not be parsed, make a bogus compoundstmt. 13820e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (FnBody.isInvalid()) 1383a60528cdac7deee3991c2b48af4df4f315e49e9dSebastian Redl FnBody = Actions.ActOnCompoundStmt(BraceLoc, BraceLoc, 1384a60528cdac7deee3991c2b48af4df4f315e49e9dSebastian Redl MultiStmtArg(Actions), false); 1385798d119415323ebcd029ffe1e0fb442a4ca8adbbSebastian Redl 1386409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // Leave the function body scope. 13878935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor BodyScope.Exit(); 1388798d119415323ebcd029ffe1e0fb442a4ca8adbbSebastian Redl 1389409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // TODO: Pass argument information. 139076ad2e85575722e8a38a2bd4648ab4304d9fcd24Sebastian Redl Actions.ActOnFinishFunctionBody(MDecl, move(FnBody)); 139171c0a951d08dc7a2a057df8c15f22b36f6aa47c7Steve Naroff return MDecl; 13925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 13935508518a2702b00be3b15a26d772bde968972f54Anders Carlsson 139443bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian RedlParser::OwningStmtResult Parser::ParseObjCAtStatement(SourceLocation AtLoc) { 139564515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff if (Tok.isObjCAtKeyword(tok::objc_try)) { 13966b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner return ParseObjCTryStmt(AtLoc); 139764515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff } else if (Tok.isObjCAtKeyword(tok::objc_throw)) 139864515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff return ParseObjCThrowStmt(AtLoc); 139964515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff else if (Tok.isObjCAtKeyword(tok::objc_synchronized)) 140064515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff return ParseObjCSynchronizedStmt(AtLoc); 1401d8c4e15138e69a51754cc259c8a592cc47950c8eSebastian Redl OwningExprResult Res(ParseExpressionWithLeadingAt(AtLoc)); 14020e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Res.isInvalid()) { 140364515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff // If the expression is invalid, skip ahead to the next semicolon. Not 140464515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff // doing this opens us up to the possibility of infinite loops if 140564515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff // ParseExpression does not consume any tokens. 140664515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff SkipUntil(tok::semi); 140743bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 140864515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff } 140964515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff // Otherwise, eat the semicolon. 141064515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff ExpectAndConsume(tok::semi, diag::err_expected_semi_after_expr); 141176ad2e85575722e8a38a2bd4648ab4304d9fcd24Sebastian Redl return Actions.ActOnExprStmt(move(Res)); 141264515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff} 141364515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff 14141d922960e083906a586609ac6978678147250177Sebastian RedlParser::OwningExprResult Parser::ParseObjCAtExpression(SourceLocation AtLoc) { 14155508518a2702b00be3b15a26d772bde968972f54Anders Carlsson switch (Tok.getKind()) { 1416b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner case tok::string_literal: // primary-expression: string-literal 1417b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner case tok::wide_string_literal: 14181d922960e083906a586609ac6978678147250177Sebastian Redl return ParsePostfixExpressionSuffix(ParseObjCStringLiteral(AtLoc)); 1419b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner default: 14204fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner if (Tok.getIdentifierInfo() == 0) 14211d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(AtLoc, diag::err_unexpected_at)); 14222f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl 14234fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner switch (Tok.getIdentifierInfo()->getObjCKeywordID()) { 14244fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner case tok::objc_encode: 14251d922960e083906a586609ac6978678147250177Sebastian Redl return ParsePostfixExpressionSuffix(ParseObjCEncodeExpression(AtLoc)); 14264fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner case tok::objc_protocol: 14271d922960e083906a586609ac6978678147250177Sebastian Redl return ParsePostfixExpressionSuffix(ParseObjCProtocolExpression(AtLoc)); 14284fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner case tok::objc_selector: 14291d922960e083906a586609ac6978678147250177Sebastian Redl return ParsePostfixExpressionSuffix(ParseObjCSelectorExpression(AtLoc)); 14304fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner default: 14311d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(AtLoc, diag::err_unexpected_at)); 14324fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner } 14335508518a2702b00be3b15a26d772bde968972f54Anders Carlsson } 14345508518a2702b00be3b15a26d772bde968972f54Anders Carlsson} 14355508518a2702b00be3b15a26d772bde968972f54Anders Carlsson 14360ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-message-expr: 14370ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// '[' objc-receiver objc-message-args ']' 14380ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// 14390ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-receiver: 14400ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// expression 14410ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// class-name 14420ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// type-name 14431d922960e083906a586609ac6978678147250177Sebastian RedlParser::OwningExprResult Parser::ParseObjCMessageExpression() { 1444699b66138ac307a32e238463e0eff513ff17d337Chris Lattner assert(Tok.is(tok::l_square) && "'[' expected"); 1445699b66138ac307a32e238463e0eff513ff17d337Chris Lattner SourceLocation LBracLoc = ConsumeBracket(); // consume '[' 1446699b66138ac307a32e238463e0eff513ff17d337Chris Lattner 1447699b66138ac307a32e238463e0eff513ff17d337Chris Lattner // Parse receiver 144814dd98a7952c9559e0d17fff8272bf3be67135afChris Lattner if (isTokObjCMessageIdentifierReceiver()) { 1449699b66138ac307a32e238463e0eff513ff17d337Chris Lattner IdentifierInfo *ReceiverName = Tok.getIdentifierInfo(); 14505cb93b8bf009c4b0ae09b71ba85f54b2a7ea8022Steve Naroff SourceLocation NameLoc = ConsumeToken(); 14511d922960e083906a586609ac6978678147250177Sebastian Redl return ParseObjCMessageExpressionBody(LBracLoc, NameLoc, ReceiverName, 14521d922960e083906a586609ac6978678147250177Sebastian Redl ExprArg(Actions)); 1453699b66138ac307a32e238463e0eff513ff17d337Chris Lattner } 1454699b66138ac307a32e238463e0eff513ff17d337Chris Lattner 14552f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl OwningExprResult Res(ParseExpression()); 14560e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Res.isInvalid()) { 14575c749428a9938d5e2e9564b1c9b7a9252c30ee27Chris Lattner SkipUntil(tok::r_square); 14581d922960e083906a586609ac6978678147250177Sebastian Redl return move(Res); 1459699b66138ac307a32e238463e0eff513ff17d337Chris Lattner } 14601d922960e083906a586609ac6978678147250177Sebastian Redl 14610e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(), 146276ad2e85575722e8a38a2bd4648ab4304d9fcd24Sebastian Redl 0, move(Res)); 1463699b66138ac307a32e238463e0eff513ff17d337Chris Lattner} 14641d922960e083906a586609ac6978678147250177Sebastian Redl 1465699b66138ac307a32e238463e0eff513ff17d337Chris Lattner/// ParseObjCMessageExpressionBody - Having parsed "'[' objc-receiver", parse 1466699b66138ac307a32e238463e0eff513ff17d337Chris Lattner/// the rest of a message expression. 14671d922960e083906a586609ac6978678147250177Sebastian Redl/// 14680ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-message-args: 14690ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-selector 14700ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-keywordarg-list 14710ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// 14720ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-keywordarg-list: 14730ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-keywordarg 14740ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-keywordarg-list objc-keywordarg 14750ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// 14760ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-keywordarg: 14770ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// selector-name[opt] ':' objc-keywordexpr 14780ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// 14790ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-keywordexpr: 14800ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// nonempty-expr-list 14810ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// 14820ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// nonempty-expr-list: 14830ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// assignment-expression 14840ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// nonempty-expr-list , assignment-expression 14851d922960e083906a586609ac6978678147250177Sebastian Redl/// 14861d922960e083906a586609ac6978678147250177Sebastian RedlParser::OwningExprResult 1487699b66138ac307a32e238463e0eff513ff17d337Chris LattnerParser::ParseObjCMessageExpressionBody(SourceLocation LBracLoc, 14885cb93b8bf009c4b0ae09b71ba85f54b2a7ea8022Steve Naroff SourceLocation NameLoc, 1489699b66138ac307a32e238463e0eff513ff17d337Chris Lattner IdentifierInfo *ReceiverName, 14901d922960e083906a586609ac6978678147250177Sebastian Redl ExprArg ReceiverExpr) { 1491a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian // Parse objc-selector 14924b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian SourceLocation Loc; 14934b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian IdentifierInfo *selIdent = ParseObjCSelector(Loc); 149468d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff 1495ff975cfab9ada27df86038286d1678084aeb3428Anders Carlsson SourceLocation SelectorLoc = Loc; 1496ff975cfab9ada27df86038286d1678084aeb3428Anders Carlsson 149768d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff llvm::SmallVector<IdentifierInfo *, 12> KeyIdents; 1498a55e52c0802cae3b7c366a05c461d3d15074c1a3Sebastian Redl ExprVector KeyExprs(Actions); 149968d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff 1500df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::colon)) { 1501a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian while (1) { 1502a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian // Each iteration parses a single keyword argument. 150368d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff KeyIdents.push_back(selIdent); 150437387c932855c6d58d70bdd705cd3a9fdcd2a931Steve Naroff 1505df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::colon)) { 1506a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian Diag(Tok, diag::err_expected_colon); 15074fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // We must manually skip to a ']', otherwise the expression skipper will 15084fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // stop at the ']' when it skips to the ';'. We want it to skip beyond 15094fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // the enclosing expression. 15104fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner SkipUntil(tok::r_square); 15111d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(); 1512a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian } 15131d922960e083906a586609ac6978678147250177Sebastian Redl 151468d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff ConsumeToken(); // Eat the ':'. 1515a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian /// Parse the expression after ':' 15162f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl OwningExprResult Res(ParseAssignmentExpression()); 15170e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl 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); 15221d922960e083906a586609ac6978678147250177Sebastian Redl return move(Res); 152337387c932855c6d58d70bdd705cd3a9fdcd2a931Steve Naroff } 15241d922960e083906a586609ac6978678147250177Sebastian Redl 152537387c932855c6d58d70bdd705cd3a9fdcd2a931Steve Naroff // We have a valid expression. 1526effa8d1c97b00a3f53e972b0e61d9aade5ea1c57Sebastian Redl KeyExprs.push_back(Res.release()); 15271d922960e083906a586609ac6978678147250177Sebastian Redl 152837387c932855c6d58d70bdd705cd3a9fdcd2a931Steve Naroff // Check for another keyword selector. 15294b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian selIdent = ParseObjCSelector(Loc); 1530df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (!selIdent && Tok.isNot(tok::colon)) 1531a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian break; 1532a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian // We have a selector or a colon, continue parsing. 1533a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian } 1534a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian // Parse the, optional, argument list, comma separated. 1535df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner while (Tok.is(tok::comma)) { 153649f109c786f99eb7468dac3976db083a65493444Steve Naroff ConsumeToken(); // Eat the ','. 153749f109c786f99eb7468dac3976db083a65493444Steve Naroff /// Parse the expression after ',' 15382f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl OwningExprResult Res(ParseAssignmentExpression()); 15390e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Res.isInvalid()) { 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); 15441d922960e083906a586609ac6978678147250177Sebastian Redl return move(Res); 154549f109c786f99eb7468dac3976db083a65493444Steve Naroff } 15460e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl 154749f109c786f99eb7468dac3976db083a65493444Steve Naroff // We have a valid expression. 1548effa8d1c97b00a3f53e972b0e61d9aade5ea1c57Sebastian Redl KeyExprs.push_back(Res.release()); 1549a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian } 1550a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian } else if (!selIdent) { 1551a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian Diag(Tok, diag::err_expected_ident); // missing selector name. 15521d922960e083906a586609ac6978678147250177Sebastian Redl 15534fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // We must manually skip to a ']', otherwise the expression skipper will 15544fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // stop at the ']' when it skips to the ';'. We want it to skip beyond 15554fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // the enclosing expression. 15564fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner SkipUntil(tok::r_square); 15571d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(); 1558a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian } 15591d922960e083906a586609ac6978678147250177Sebastian Redl 1560df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::r_square)) { 1561a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian Diag(Tok, diag::err_expected_rsquare); 15624fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // We must manually skip to a ']', otherwise the expression skipper will 15634fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // stop at the ']' when it skips to the ';'. We want it to skip beyond 15644fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // the enclosing expression. 15654fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner SkipUntil(tok::r_square); 15661d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(); 1567a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian } 15681d922960e083906a586609ac6978678147250177Sebastian Redl 1569699b66138ac307a32e238463e0eff513ff17d337Chris Lattner SourceLocation RBracLoc = ConsumeBracket(); // consume ']' 15701d922960e083906a586609ac6978678147250177Sebastian Redl 157129238a0bf7cbf5b396efb451a0adb5fe4aa037caSteve Naroff unsigned nKeys = KeyIdents.size(); 1572ff38491c18b060526d754765b952f4a497a89416Chris Lattner if (nKeys == 0) 1573ff38491c18b060526d754765b952f4a497a89416Chris Lattner KeyIdents.push_back(selIdent); 1574ff38491c18b060526d754765b952f4a497a89416Chris Lattner Selector Sel = PP.getSelectorTable().getSelector(nKeys, &KeyIdents[0]); 15751d922960e083906a586609ac6978678147250177Sebastian Redl 1576ff38491c18b060526d754765b952f4a497a89416Chris Lattner // We've just parsed a keyword message. 15771d922960e083906a586609ac6978678147250177Sebastian Redl if (ReceiverName) 15781d922960e083906a586609ac6978678147250177Sebastian Redl return Owned(Actions.ActOnClassMessage(CurScope, ReceiverName, Sel, 1579ff975cfab9ada27df86038286d1678084aeb3428Anders Carlsson LBracLoc, NameLoc, SelectorLoc, 1580ff975cfab9ada27df86038286d1678084aeb3428Anders Carlsson RBracLoc, 15811d922960e083906a586609ac6978678147250177Sebastian Redl KeyExprs.take(), KeyExprs.size())); 15821d922960e083906a586609ac6978678147250177Sebastian Redl return Owned(Actions.ActOnInstanceMessage(ReceiverExpr.release(), Sel, 1583ff975cfab9ada27df86038286d1678084aeb3428Anders Carlsson LBracLoc, SelectorLoc, RBracLoc, 15841d922960e083906a586609ac6978678147250177Sebastian Redl KeyExprs.take(), KeyExprs.size())); 15850ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian} 15860ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian 15871d922960e083906a586609ac6978678147250177Sebastian RedlParser::OwningExprResult Parser::ParseObjCStringLiteral(SourceLocation AtLoc) { 158820df9b7ab9388b2a488c5b1293cd196b1e073b4eSebastian Redl OwningExprResult Res(ParseStringLiteralExpression()); 15891d922960e083906a586609ac6978678147250177Sebastian Redl if (Res.isInvalid()) return move(Res); 15901d922960e083906a586609ac6978678147250177Sebastian Redl 1591b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner // @"foo" @"bar" is a valid concatenated string. Eat any subsequent string 1592b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner // expressions. At this point, we know that the only valid thing that starts 1593b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner // with '@' is an @"". 1594b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner llvm::SmallVector<SourceLocation, 4> AtLocs; 1595a55e52c0802cae3b7c366a05c461d3d15074c1a3Sebastian Redl ExprVector AtStrings(Actions); 1596b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner AtLocs.push_back(AtLoc); 1597effa8d1c97b00a3f53e972b0e61d9aade5ea1c57Sebastian Redl AtStrings.push_back(Res.release()); 15980e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl 1599b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner while (Tok.is(tok::at)) { 1600b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner AtLocs.push_back(ConsumeToken()); // eat the @. 1601b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner 160215faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl // Invalid unless there is a string literal. 160397cf6eb380016db868866faf27a086cd55a316d4Chris Lattner if (!isTokenStringLiteral()) 160497cf6eb380016db868866faf27a086cd55a316d4Chris Lattner return ExprError(Diag(Tok, diag::err_objc_concat_string)); 1605b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner 160697cf6eb380016db868866faf27a086cd55a316d4Chris Lattner OwningExprResult Lit(ParseStringLiteralExpression()); 16070e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Lit.isInvalid()) 16081d922960e083906a586609ac6978678147250177Sebastian Redl return move(Lit); 16090e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl 1610effa8d1c97b00a3f53e972b0e61d9aade5ea1c57Sebastian Redl AtStrings.push_back(Lit.release()); 1611b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner } 16121d922960e083906a586609ac6978678147250177Sebastian Redl 16131d922960e083906a586609ac6978678147250177Sebastian Redl return Owned(Actions.ParseObjCStringLiteral(&AtLocs[0], AtStrings.take(), 16141d922960e083906a586609ac6978678147250177Sebastian Redl AtStrings.size())); 16155508518a2702b00be3b15a26d772bde968972f54Anders Carlsson} 1616f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson 1617f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson/// objc-encode-expression: 1618f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson/// @encode ( type-name ) 16191d922960e083906a586609ac6978678147250177Sebastian RedlParser::OwningExprResult 16201d922960e083906a586609ac6978678147250177Sebastian RedlParser::ParseObjCEncodeExpression(SourceLocation AtLoc) { 1621861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff assert(Tok.isObjCAtKeyword(tok::objc_encode) && "Not an @encode expression!"); 16221d922960e083906a586609ac6978678147250177Sebastian Redl 1623f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson SourceLocation EncLoc = ConsumeToken(); 16241d922960e083906a586609ac6978678147250177Sebastian Redl 16254fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner if (Tok.isNot(tok::l_paren)) 16261d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(Tok, diag::err_expected_lparen_after) << "@encode"); 16271d922960e083906a586609ac6978678147250177Sebastian Redl 1628f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson SourceLocation LParenLoc = ConsumeParen(); 16291d922960e083906a586609ac6978678147250177Sebastian Redl 1630f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson TypeTy *Ty = ParseTypeName(); 16311d922960e083906a586609ac6978678147250177Sebastian Redl 16324988ae3fda10743c8ed8a98cdcb5a783362587b4Anders Carlsson SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); 16331d922960e083906a586609ac6978678147250177Sebastian Redl 16341d922960e083906a586609ac6978678147250177Sebastian Redl return Owned(Actions.ParseObjCEncodeExpression(AtLoc, EncLoc, LParenLoc, Ty, 16351d922960e083906a586609ac6978678147250177Sebastian Redl RParenLoc)); 1636f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson} 163729b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson 163829b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson/// objc-protocol-expression 163929b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson/// @protocol ( protocol-name ) 16401d922960e083906a586609ac6978678147250177Sebastian RedlParser::OwningExprResult 16411d922960e083906a586609ac6978678147250177Sebastian RedlParser::ParseObjCProtocolExpression(SourceLocation AtLoc) { 164229b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson SourceLocation ProtoLoc = ConsumeToken(); 16431d922960e083906a586609ac6978678147250177Sebastian Redl 16444fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner if (Tok.isNot(tok::l_paren)) 16451d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(Tok, diag::err_expected_lparen_after) << "@protocol"); 16461d922960e083906a586609ac6978678147250177Sebastian Redl 164729b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson SourceLocation LParenLoc = ConsumeParen(); 16481d922960e083906a586609ac6978678147250177Sebastian Redl 16494fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner if (Tok.isNot(tok::identifier)) 16501d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(Tok, diag::err_expected_ident)); 16511d922960e083906a586609ac6978678147250177Sebastian Redl 1652390d50a725497e99247dc104a7d2c2a255d3af14Fariborz Jahanian IdentifierInfo *protocolId = Tok.getIdentifierInfo(); 165329b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson ConsumeToken(); 16541d922960e083906a586609ac6978678147250177Sebastian Redl 16554988ae3fda10743c8ed8a98cdcb5a783362587b4Anders Carlsson SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); 165629b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson 16571d922960e083906a586609ac6978678147250177Sebastian Redl return Owned(Actions.ParseObjCProtocolExpression(protocolId, AtLoc, ProtoLoc, 16581d922960e083906a586609ac6978678147250177Sebastian Redl LParenLoc, RParenLoc)); 165929b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson} 1660a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian 1661a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian/// objc-selector-expression 1662a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian/// @selector '(' objc-keyword-selector ')' 16631d922960e083906a586609ac6978678147250177Sebastian RedlParser::OwningExprResult 16641d922960e083906a586609ac6978678147250177Sebastian RedlParser::ParseObjCSelectorExpression(SourceLocation AtLoc) { 1665a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian SourceLocation SelectorLoc = ConsumeToken(); 16661d922960e083906a586609ac6978678147250177Sebastian Redl 16674fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner if (Tok.isNot(tok::l_paren)) 16681d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(Tok, diag::err_expected_lparen_after) << "@selector"); 16691d922960e083906a586609ac6978678147250177Sebastian Redl 1670b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian llvm::SmallVector<IdentifierInfo *, 12> KeyIdents; 1671a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian SourceLocation LParenLoc = ConsumeParen(); 1672a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian SourceLocation sLoc; 1673a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian IdentifierInfo *SelIdent = ParseObjCSelector(sLoc); 16741d922960e083906a586609ac6978678147250177Sebastian Redl if (!SelIdent && Tok.isNot(tok::colon)) // missing selector name. 16751d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(Tok, diag::err_expected_ident)); 16761d922960e083906a586609ac6978678147250177Sebastian Redl 1677b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian KeyIdents.push_back(SelIdent); 1678887407e71fd58de452361b77d72970e32b20ebe0Steve Naroff unsigned nColons = 0; 1679887407e71fd58de452361b77d72970e32b20ebe0Steve Naroff if (Tok.isNot(tok::r_paren)) { 1680a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian while (1) { 16814fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner if (Tok.isNot(tok::colon)) 16821d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(Tok, diag::err_expected_colon)); 16831d922960e083906a586609ac6978678147250177Sebastian Redl 1684cb53b361bce341c8591333c6997f62e480acc0b4Chris Lattner nColons++; 1685a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian ConsumeToken(); // Eat the ':'. 1686a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian if (Tok.is(tok::r_paren)) 1687a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian break; 1688a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian // Check for another keyword selector. 1689a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian SourceLocation Loc; 1690a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian SelIdent = ParseObjCSelector(Loc); 1691b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian KeyIdents.push_back(SelIdent); 1692a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian if (!SelIdent && Tok.isNot(tok::colon)) 1693a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian break; 1694a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian } 1695887407e71fd58de452361b77d72970e32b20ebe0Steve Naroff } 1696a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); 1697887407e71fd58de452361b77d72970e32b20ebe0Steve Naroff Selector Sel = PP.getSelectorTable().getSelector(nColons, &KeyIdents[0]); 16981d922960e083906a586609ac6978678147250177Sebastian Redl return Owned(Actions.ParseObjCSelectorExpression(Sel, AtLoc, SelectorLoc, 16991d922960e083906a586609ac6978678147250177Sebastian Redl LParenLoc, RParenLoc)); 170058065b2d8038a4e9a91ea4813bd1774c0f6efacbGabor Greif } 1701