ParseObjc.cpp revision bbd37c62e34db3f5a95c899723484a76c71d7757
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" 17500d3297d2a21edeac4d46cbcbe21bc2352c2a28Chris Lattner#include "clang/Parse/ParseDiagnostic.h" 185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "llvm/ADT/SmallVector.h" 195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing namespace clang; 205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 22891dca671a80c865c6def7259f170ba785e4faaaChris Lattner/// ParseObjCAtDirectives - Handle parts of the external-declaration production: 235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// external-declaration: [C99 6.9] 245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// [OBJC] objc-class-definition 2591fa0b7759b575045142abd6ee48c076297ad77bSteve Naroff/// [OBJC] objc-class-declaration 2691fa0b7759b575045142abd6ee48c076297ad77bSteve Naroff/// [OBJC] objc-alias-declaration 2791fa0b7759b575045142abd6ee48c076297ad77bSteve Naroff/// [OBJC] objc-protocol-definition 2891fa0b7759b575045142abd6ee48c076297ad77bSteve Naroff/// [OBJC] objc-method-definition 2991fa0b7759b575045142abd6ee48c076297ad77bSteve Naroff/// [OBJC] '@' 'end' 30b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris LattnerParser::DeclPtrTy Parser::ParseObjCAtDirectives() { 315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation AtLoc = ConsumeToken(); // the "@" 321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 33861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff switch (Tok.getObjCKeywordID()) { 345ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner case tok::objc_class: 355ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner return ParseObjCAtClassDeclaration(AtLoc); 365ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner case tok::objc_interface: 375ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner return ParseObjCAtInterfaceDeclaration(AtLoc); 385ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner case tok::objc_protocol: 395ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner return ParseObjCAtProtocolDeclaration(AtLoc); 405ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner case tok::objc_implementation: 415ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner return ParseObjCAtImplementationDeclaration(AtLoc); 425ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner case tok::objc_end: 435ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner return ParseObjCAtEndDeclaration(AtLoc); 445ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner case tok::objc_compatibility_alias: 455ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner return ParseObjCAtAliasDeclaration(AtLoc); 465ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner case tok::objc_synthesize: 475ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner return ParseObjCPropertySynthesize(AtLoc); 485ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner case tok::objc_dynamic: 495ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner return ParseObjCPropertyDynamic(AtLoc); 505ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner default: 515ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner Diag(AtLoc, diag::err_unexpected_at); 525ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner SkipUntil(tok::semi); 53b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// objc-class-declaration: 595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// '@' 'class' identifier-list ';' 601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 61b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris LattnerParser::DeclPtrTy Parser::ParseObjCAtClassDeclaration(SourceLocation atLoc) { 625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ConsumeToken(); // the identifier "class" 635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::SmallVector<IdentifierInfo *, 8> ClassNames; 64c09cba67d0ad01e53e0fed07322e95dd281bcfd9Ted Kremenek llvm::SmallVector<SourceLocation, 8> ClassLocs; 65c09cba67d0ad01e53e0fed07322e95dd281bcfd9Ted Kremenek 661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer while (1) { 68df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Diag(Tok, diag::err_expected_ident); 705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SkipUntil(tok::semi); 71b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ClassNames.push_back(Tok.getIdentifierInfo()); 74c09cba67d0ad01e53e0fed07322e95dd281bcfd9Ted Kremenek ClassLocs.push_back(Tok.getLocation()); 755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ConsumeToken(); 761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 77df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::comma)) 785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer break; 791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ConsumeToken(); 815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Consume the ';'. 845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@class")) 85b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 87c09cba67d0ad01e53e0fed07322e95dd281bcfd9Ted Kremenek return Actions.ActOnForwardClassDeclaration(atLoc, ClassNames.data(), 88c09cba67d0ad01e53e0fed07322e95dd281bcfd9Ted Kremenek ClassLocs.data(), 89c09cba67d0ad01e53e0fed07322e95dd281bcfd9Ted Kremenek ClassNames.size()); 905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 92dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 93dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-interface: 94dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-interface-attributes[opt] objc-class-interface 95dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-category-interface 96dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 97dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-interface: 981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// '@' 'interface' identifier objc-superclass[opt] 99dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-refs[opt] 1001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// objc-class-instance-variables[opt] 101dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-interface-decl-list 102dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @end 103dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 104dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-category-interface: 1051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// '@' 'interface' identifier '(' identifier[opt] ')' 106dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-refs[opt] 107dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-interface-decl-list 108dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @end 109dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 110dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-superclass: 111dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// ':' identifier 112dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 113dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-interface-attributes: 114dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// __attribute__((visibility("default"))) 115dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// __attribute__((visibility("hidden"))) 116dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// __attribute__((deprecated)) 117dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// __attribute__((unavailable)) 118dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// __attribute__((objc_exception)) - used by NSException on 64-bit 119dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 120b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris LattnerParser::DeclPtrTy Parser::ParseObjCAtInterfaceDeclaration( 121dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff SourceLocation atLoc, AttributeList *attrList) { 122861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff assert(Tok.isObjCAtKeyword(tok::objc_interface) && 123dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff "ParseObjCAtInterfaceDeclaration(): Expected @interface"); 124dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff ConsumeToken(); // the "interface" identifier 1251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1263b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor // Code completion after '@interface'. 1273b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor if (Tok.is(tok::code_completion)) { 1283b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor Actions.CodeCompleteObjCInterfaceDecl(CurScope); 1293b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor ConsumeToken(); 1303b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor } 1313b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor 132df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 133dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff Diag(Tok, diag::err_expected_ident); // missing class or category name. 134b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 135dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff } 13663e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian 137dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff // We have a class or category name - consume it. 1387ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff IdentifierInfo *nameId = Tok.getIdentifierInfo(); 139dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff SourceLocation nameLoc = ConsumeToken(); 1401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 141df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::l_paren)) { // we have a category. 142dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff SourceLocation lparenLoc = ConsumeParen(); 143dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff SourceLocation categoryLoc, rparenLoc; 144dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff IdentifierInfo *categoryId = 0; 1451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14633ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor if (Tok.is(tok::code_completion)) { 14733ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor Actions.CodeCompleteObjCInterfaceCategory(CurScope, nameId); 14833ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor ConsumeToken(); 14933ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor } 15033ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor 151527fe23f8cbc6a4da1737a547a2517bc92fa88c8Steve Naroff // For ObjC2, the category name is optional (not an error). 152df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::identifier)) { 153dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff categoryId = Tok.getIdentifierInfo(); 154dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff categoryLoc = ConsumeToken(); 155527fe23f8cbc6a4da1737a547a2517bc92fa88c8Steve Naroff } else if (!getLang().ObjC2) { 156527fe23f8cbc6a4da1737a547a2517bc92fa88c8Steve Naroff Diag(Tok, diag::err_expected_ident); // missing category name. 157b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 158dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff } 159df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::r_paren)) { 160dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff Diag(Tok, diag::err_expected_rparen); 161dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff SkipUntil(tok::r_paren, false); // don't stop at ';' 162b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 163dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff } 164dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff rparenLoc = ConsumeParen(); 1651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 166dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff // Next, we need to check for any protocol references. 16771b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis SourceLocation LAngleLoc, EndProtoLoc; 168b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner llvm::SmallVector<DeclPtrTy, 8> ProtocolRefs; 16971b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis llvm::SmallVector<SourceLocation, 8> ProtocolLocs; 1706bd6d0b9d8944c5e192097bef24f2becb83af172Chris Lattner if (Tok.is(tok::less) && 17171b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis ParseObjCProtocolReferences(ProtocolRefs, ProtocolLocs, true, 17271b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis LAngleLoc, EndProtoLoc)) 173b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 1741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 175dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff if (attrList) // categories don't support attributes. 176dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff Diag(Tok, diag::err_objc_no_attributes_on_category); 1771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 178beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad DeclPtrTy CategoryType = 1791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Actions.ActOnStartCategoryInterface(atLoc, 180beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad nameId, nameLoc, 181beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad categoryId, categoryLoc, 182beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad ProtocolRefs.data(), 183beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad ProtocolRefs.size(), 184beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad EndProtoLoc); 1851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 186fd225cc227143553898f2d3902242d25db9a4902Fariborz Jahanian ParseObjCInterfaceDeclList(CategoryType, tok::objc_not_keyword); 187bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner return CategoryType; 188dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff } 189dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff // Parse a class interface. 190dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff IdentifierInfo *superClassId = 0; 191dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff SourceLocation superClassLoc; 1927ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff 193df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::colon)) { // a super class is specified. 194dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff ConsumeToken(); 1953b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor 1963b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor // Code completion of superclass names. 1973b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor if (Tok.is(tok::code_completion)) { 1983b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor Actions.CodeCompleteObjCSuperclass(CurScope, nameId); 1993b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor ConsumeToken(); 2003b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor } 2013b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor 202df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 203dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff Diag(Tok, diag::err_expected_ident); // missing super class name. 204b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 205dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff } 206dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff superClassId = Tok.getIdentifierInfo(); 207dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff superClassLoc = ConsumeToken(); 208dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff } 209dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff // Next, we need to check for any protocol references. 210b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner llvm::SmallVector<Action::DeclPtrTy, 8> ProtocolRefs; 21171b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis llvm::SmallVector<SourceLocation, 8> ProtocolLocs; 21271b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis SourceLocation LAngleLoc, EndProtoLoc; 21306036d3709955a53297b4cbe14e20db88f321470Chris Lattner if (Tok.is(tok::less) && 21471b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis ParseObjCProtocolReferences(ProtocolRefs, ProtocolLocs, true, 21571b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis LAngleLoc, EndProtoLoc)) 216b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 2171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DeclPtrTy ClsType = 2191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Actions.ActOnStartClassInterface(atLoc, nameId, nameLoc, 22006036d3709955a53297b4cbe14e20db88f321470Chris Lattner superClassId, superClassLoc, 221beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad ProtocolRefs.data(), ProtocolRefs.size(), 22206036d3709955a53297b4cbe14e20db88f321470Chris Lattner EndProtoLoc, attrList); 2231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 224df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::l_brace)) 22560fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff ParseObjCClassInstanceVariables(ClsType, atLoc); 226dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff 22725e077d59a8e8e43b65882b69610a3d5e2aaf53cFariborz Jahanian ParseObjCInterfaceDeclList(ClsType, tok::objc_interface); 228bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner return ClsType; 229dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff} 230dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff 231dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-interface-decl-list: 232dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// empty 233dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-interface-decl-list objc-property-decl [OBJC2] 234294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-interface-decl-list objc-method-requirement [OBJC2] 2353536b443bc50d58a79f14fca9b6842541a434854Steve Naroff/// objc-interface-decl-list objc-method-proto ';' 236dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-interface-decl-list declaration 237dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-interface-decl-list ';' 238dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 239294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-method-requirement: [OBJC2] 240294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// @required 241294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// @optional 242294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 243b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattnervoid Parser::ParseObjCInterfaceDeclList(DeclPtrTy interfaceDecl, 244cb53b361bce341c8591333c6997f62e480acc0b4Chris Lattner tok::ObjCKeywordKind contextKey) { 245b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner llvm::SmallVector<DeclPtrTy, 32> allMethods; 246b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner llvm::SmallVector<DeclPtrTy, 16> allProperties; 247682bf92db408a6cbc3d37b5496a99b6ef85041ecChris Lattner llvm::SmallVector<DeclGroupPtrTy, 8> allTUVariables; 24800933591a2795d09dd1acff12a2d21bce7cb12c5Fariborz Jahanian tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword; 2491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 250bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner SourceLocation AtEndLoc; 251bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner 252294494e1cce92043562b4680c613df7fd028c02eSteve Naroff while (1) { 253e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner // If this is a method prototype, parse it. 254df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::minus) || Tok.is(tok::plus)) { 2551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DeclPtrTy methodPrototype = 256df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner ParseObjCMethodPrototype(interfaceDecl, MethodImplKind); 25725e077d59a8e8e43b65882b69610a3d5e2aaf53cFariborz Jahanian allMethods.push_back(methodPrototype); 2583536b443bc50d58a79f14fca9b6842541a434854Steve Naroff // Consume the ';' here, since ParseObjCMethodPrototype() is re-used for 2593536b443bc50d58a79f14fca9b6842541a434854Steve Naroff // method definitions. 260b6d74a158a9c002e3c0fcbda8ad8d0ccbb2e5088Chris Lattner ExpectAndConsume(tok::semi, diag::err_expected_semi_after_method_proto, 261b6d74a158a9c002e3c0fcbda8ad8d0ccbb2e5088Chris Lattner "", tok::semi); 262294494e1cce92043562b4680c613df7fd028c02eSteve Naroff continue; 263294494e1cce92043562b4680c613df7fd028c02eSteve Naroff } 2641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 265e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner // Ignore excess semicolons. 266e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner if (Tok.is(tok::semi)) { 267294494e1cce92043562b4680c613df7fd028c02eSteve Naroff ConsumeToken(); 268e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner continue; 269e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner } 2701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 271bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // If we got to the end of the file, exit the loop. 272e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner if (Tok.is(tok::eof)) 273e3a2ca7e30601cdd31c77a830f4cc487851e8096Fariborz Jahanian break; 2741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 275e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner // If we don't have an @ directive, parse it as a function definition. 276e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner if (Tok.isNot(tok::at)) { 2771fd80116b49782c367ff5d5f50a8b76dd8a5d7f7Chris Lattner // The code below does not consume '}'s because it is afraid of eating the 2781fd80116b49782c367ff5d5f50a8b76dd8a5d7f7Chris Lattner // end of a namespace. Because of the way this code is structured, an 2791fd80116b49782c367ff5d5f50a8b76dd8a5d7f7Chris Lattner // erroneous r_brace would cause an infinite loop if not handled here. 2801fd80116b49782c367ff5d5f50a8b76dd8a5d7f7Chris Lattner if (Tok.is(tok::r_brace)) 2811fd80116b49782c367ff5d5f50a8b76dd8a5d7f7Chris Lattner break; 2821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2834985aceceb9b9261b876b515d32726175c13a775Steve Naroff // FIXME: as the name implies, this rule allows function definitions. 2844985aceceb9b9261b876b515d32726175c13a775Steve Naroff // We could pass a flag or check for functions during semantic analysis. 285bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt allTUVariables.push_back(ParseDeclarationOrFunctionDefinition(0)); 286e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner continue; 287e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner } 2881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 289e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner // Otherwise, we have an @ directive, eat the @. 290e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner SourceLocation AtLoc = ConsumeToken(); // the "@" 291a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner tok::ObjCKeywordKind DirectiveKind = Tok.getObjCKeywordID(); 2921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 293a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner if (DirectiveKind == tok::objc_end) { // @end -> terminate list 294e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner AtEndLoc = AtLoc; 295e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner break; 296bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner } 2971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 298bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // Eat the identifier. 299bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner ConsumeToken(); 300bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner 301a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner switch (DirectiveKind) { 302a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner default: 303bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // FIXME: If someone forgets an @end on a protocol, this loop will 304bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // continue to eat up tons of stuff and spew lots of nonsense errors. It 305bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // would probably be better to bail out if we saw an @class or @interface 306bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // or something like that. 307f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner Diag(AtLoc, diag::err_objc_illegal_interface_qual); 308bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // Skip until we see an '@' or '}' or ';'. 309a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner SkipUntil(tok::r_brace, tok::at); 310a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner break; 3111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 312a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner case tok::objc_required: 313a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner case tok::objc_optional: 314a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner // This is only valid on protocols. 315bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // FIXME: Should this check for ObjC2 being enabled? 316e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner if (contextKey != tok::objc_protocol) 317bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner Diag(AtLoc, diag::err_objc_directive_only_in_protocol); 318a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner else 319bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner MethodImplKind = DirectiveKind; 320a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner break; 3211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 322a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner case tok::objc_property: 323f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner if (!getLang().ObjC2) 324f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner Diag(AtLoc, diag::err_objc_propertoes_require_objc2); 325f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner 326e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner ObjCDeclSpec OCDS; 3271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // Parse property attribute list, if any. 3288ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner if (Tok.is(tok::l_paren)) 3294ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor ParseObjCPropertyAttribute(OCDS, interfaceDecl, 3304ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor allMethods.data(), allMethods.size()); 3311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 332bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall struct ObjCPropertyCallback : FieldCallback { 333bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall Parser &P; 334bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall DeclPtrTy IDecl; 335bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall llvm::SmallVectorImpl<DeclPtrTy> &Props; 336bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall ObjCDeclSpec &OCDS; 337bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall SourceLocation AtLoc; 338bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall tok::ObjCKeywordKind MethodImplKind; 339bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall 340bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall ObjCPropertyCallback(Parser &P, DeclPtrTy IDecl, 341bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall llvm::SmallVectorImpl<DeclPtrTy> &Props, 342bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall ObjCDeclSpec &OCDS, SourceLocation AtLoc, 343bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall tok::ObjCKeywordKind MethodImplKind) : 344bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall P(P), IDecl(IDecl), Props(Props), OCDS(OCDS), AtLoc(AtLoc), 345bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall MethodImplKind(MethodImplKind) { 346bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall } 347bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall 348bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall DeclPtrTy invoke(FieldDeclarator &FD) { 349bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall if (FD.D.getIdentifier() == 0) { 350bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall P.Diag(AtLoc, diag::err_objc_property_requires_field_name) 351bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall << FD.D.getSourceRange(); 352bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall return DeclPtrTy(); 353bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall } 354bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall if (FD.BitfieldSize) { 355bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall P.Diag(AtLoc, diag::err_objc_property_bitfield) 356bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall << FD.D.getSourceRange(); 357bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall return DeclPtrTy(); 358bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall } 359bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall 360bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall // Install the property declarator into interfaceDecl. 361bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall IdentifierInfo *SelName = 362bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall OCDS.getGetterName() ? OCDS.getGetterName() : FD.D.getIdentifier(); 363bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall 364bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall Selector GetterSel = 365bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall P.PP.getSelectorTable().getNullarySelector(SelName); 366bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall IdentifierInfo *SetterName = OCDS.getSetterName(); 367bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall Selector SetterSel; 368bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall if (SetterName) 369bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall SetterSel = P.PP.getSelectorTable().getSelector(1, &SetterName); 370bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall else 371bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall SetterSel = SelectorTable::constructSetterName(P.PP.getIdentifierTable(), 372bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall P.PP.getSelectorTable(), 373bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall FD.D.getIdentifier()); 374bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall bool isOverridingProperty = false; 375bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall DeclPtrTy Property = 376bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall P.Actions.ActOnProperty(P.CurScope, AtLoc, FD, OCDS, 377bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall GetterSel, SetterSel, IDecl, 378bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall &isOverridingProperty, 379bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall MethodImplKind); 380bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall if (!isOverridingProperty) 381bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall Props.push_back(Property); 382bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall 383bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall return Property; 384bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall } 385bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall } Callback(*this, interfaceDecl, allProperties, 386bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall OCDS, AtLoc, MethodImplKind); 387bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall 388e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner // Parse all the comma separated declarators. 389e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner DeclSpec DS; 390bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall ParseStructDeclaration(DS, Callback); 3911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 392a1fed7e3beebf9bb1bc85123f283be3eb631c120Chris Lattner ExpectAndConsume(tok::semi, diag::err_expected_semi_decl_list, "", 393a1fed7e3beebf9bb1bc85123f283be3eb631c120Chris Lattner tok::at); 394a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner break; 395f28b264437053fb0deacc9ba02b18a0966f7290aSteve Naroff } 396294494e1cce92043562b4680c613df7fd028c02eSteve Naroff } 397bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner 398bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // We break out of the big loop in two cases: when we see @end or when we see 399bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // EOF. In the former case, eat the @end. In the later case, emit an error. 400bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner if (Tok.isObjCAtKeyword(tok::objc_end)) 401bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner ConsumeToken(); // the "end" identifier 402bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner else 403bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner Diag(Tok, diag::err_objc_missing_end); 4041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 405a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner // Insert collected methods declarations into the @interface object. 406bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // This passes in an invalid SourceLocation for AtEndLoc when EOF is hit. 4078a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek Actions.ActOnAtEnd(AtEndLoc, interfaceDecl, 4081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump allMethods.data(), allMethods.size(), 409beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad allProperties.data(), allProperties.size(), 410beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad allTUVariables.data(), allTUVariables.size()); 411294494e1cce92043562b4680c613df7fd028c02eSteve Naroff} 412294494e1cce92043562b4680c613df7fd028c02eSteve Naroff 413d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// Parse property attribute declarations. 414d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// 415d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// property-attr-decl: '(' property-attrlist ')' 416d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// property-attrlist: 417d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// property-attribute 418d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// property-attrlist ',' property-attribute 419d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// property-attribute: 420d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// getter '=' identifier 421d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// setter '=' identifier ':' 422d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// readonly 423d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// readwrite 424d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// assign 425d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// retain 426d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// copy 427d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// nonatomic 428d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// 4294ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregorvoid Parser::ParseObjCPropertyAttribute(ObjCDeclSpec &DS, DeclPtrTy ClassDecl, 4304ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor DeclPtrTy *Methods, 4314ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor unsigned NumMethods) { 4328ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner assert(Tok.getKind() == tok::l_paren); 433dd5b5f2bb73d037745940431b71eb98393d12d4fChris Lattner SourceLocation LHSLoc = ConsumeParen(); // consume '(' 4341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 435cd9f4b31c4fe5b77b5519cc17b4583fab912bad1Chris Lattner while (1) { 436ece8e71d12b6f4cb2dc501297afef126dab8ad74Steve Naroff if (Tok.is(tok::code_completion)) { 437a93b108e025ef2480fa867cc533e7781a40a639bDouglas Gregor Actions.CodeCompleteObjCPropertyFlags(CurScope, DS); 438ece8e71d12b6f4cb2dc501297afef126dab8ad74Steve Naroff ConsumeToken(); 439ece8e71d12b6f4cb2dc501297afef126dab8ad74Steve Naroff } 440d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian const IdentifierInfo *II = Tok.getIdentifierInfo(); 4411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 442f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner // If this is not an identifier at all, bail out early. 443f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner if (II == 0) { 444f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner MatchRHSPunctuation(tok::r_paren, LHSLoc); 445f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner return; 446f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner } 4471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 448156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner SourceLocation AttrName = ConsumeToken(); // consume last attribute name 4491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 45092e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner if (II->isStr("readonly")) 451e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_readonly); 45292e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner else if (II->isStr("assign")) 453e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_assign); 45492e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner else if (II->isStr("readwrite")) 455e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_readwrite); 45692e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner else if (II->isStr("retain")) 457e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_retain); 45892e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner else if (II->isStr("copy")) 459e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_copy); 46092e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner else if (II->isStr("nonatomic")) 461e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_nonatomic); 46292e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner else if (II->isStr("getter") || II->isStr("setter")) { 463e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner // getter/setter require extra treatment. 464156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner if (ExpectAndConsume(tok::equal, diag::err_objc_expected_equal, "", 465156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner tok::r_paren)) 466dd5b5f2bb73d037745940431b71eb98393d12d4fChris Lattner return; 4671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4684ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor if (Tok.is(tok::code_completion)) { 4694ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor if (II->getNameStart()[0] == 's') 4704ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor Actions.CodeCompleteObjCPropertySetter(CurScope, ClassDecl, 4714ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor Methods, NumMethods); 4724ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor else 4734ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor Actions.CodeCompleteObjCPropertyGetter(CurScope, ClassDecl, 4744ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor Methods, NumMethods); 4754ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor ConsumeToken(); 4764ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor } 4774ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor 4788ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner if (Tok.isNot(tok::identifier)) { 4791ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_ident); 4808ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner SkipUntil(tok::r_paren); 4818ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner return; 4828ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner } 4831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 484e013d685c6689ac7ae103ee88acf573422d1ed6aDaniel Dunbar if (II->getNameStart()[0] == 's') { 4858ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_setter); 4868ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner DS.setSetterName(Tok.getIdentifierInfo()); 487156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner ConsumeToken(); // consume method name 4881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 489156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner if (ExpectAndConsume(tok::colon, diag::err_expected_colon, "", 490156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner tok::r_paren)) 4918ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner return; 4928ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner } else { 4938ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_getter); 4948ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner DS.setGetterName(Tok.getIdentifierInfo()); 495156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner ConsumeToken(); // consume method name 4968ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner } 497e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner } else { 498a9500f05ba6c09bbd84d342236863833067cd816Chris Lattner Diag(AttrName, diag::err_objc_expected_property_attr) << II; 499cd9f4b31c4fe5b77b5519cc17b4583fab912bad1Chris Lattner SkipUntil(tok::r_paren); 500cd9f4b31c4fe5b77b5519cc17b4583fab912bad1Chris Lattner return; 501cd9f4b31c4fe5b77b5519cc17b4583fab912bad1Chris Lattner } 5021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 503156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner if (Tok.isNot(tok::comma)) 504156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner break; 5051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 506156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner ConsumeToken(); 507d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian } 5081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 509156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner MatchRHSPunctuation(tok::r_paren, LHSLoc); 510d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian} 511d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian 5123536b443bc50d58a79f14fca9b6842541a434854Steve Naroff/// objc-method-proto: 5131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// objc-instance-method objc-method-decl objc-method-attributes[opt] 5143536b443bc50d58a79f14fca9b6842541a434854Steve Naroff/// objc-class-method objc-method-decl objc-method-attributes[opt] 515294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 516294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-instance-method: '-' 517294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-class-method: '+' 518294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 5194985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-method-attributes: [OBJC2] 5204985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// __attribute__((deprecated)) 5214985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// 5221eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpParser::DeclPtrTy Parser::ParseObjCMethodPrototype(DeclPtrTy IDecl, 523b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner tok::ObjCKeywordKind MethodImplKind) { 524df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner assert((Tok.is(tok::minus) || Tok.is(tok::plus)) && "expected +/-"); 525294494e1cce92043562b4680c613df7fd028c02eSteve Naroff 5261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump tok::TokenKind methodType = Tok.getKind(); 527bef1185418705e16012b3dd50cd7c260c8d6b79cSteve Naroff SourceLocation mLoc = ConsumeToken(); 5281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 529b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy MDecl = ParseObjCMethodDecl(mLoc, methodType, IDecl,MethodImplKind); 5303536b443bc50d58a79f14fca9b6842541a434854Steve Naroff // Since this rule is used for both method declarations and definitions, 5312bd42fadafddc8acf744b57a970bdc96a077c617Steve Naroff // the caller is (optionally) responsible for consuming the ';'. 532f28b264437053fb0deacc9ba02b18a0966f7290aSteve Naroff return MDecl; 533294494e1cce92043562b4680c613df7fd028c02eSteve Naroff} 534294494e1cce92043562b4680c613df7fd028c02eSteve Naroff 535294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-selector: 536294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// identifier 537294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// one of 538294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// enum struct union if else while do for switch case default 539294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// break continue return goto asm sizeof typeof __alignof 540294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// unsigned long const short volatile signed restrict _Complex 541294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// in out inout bycopy byref oneway int char float double void _Bool 542294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 5432fc5c2428ecb450a3256c8316b93b8655cb76a0fChris LattnerIdentifierInfo *Parser::ParseObjCSelectorPiece(SourceLocation &SelectorLoc) { 544ff38491c18b060526d754765b952f4a497a89416Chris Lattner switch (Tok.getKind()) { 545ff38491c18b060526d754765b952f4a497a89416Chris Lattner default: 546ff38491c18b060526d754765b952f4a497a89416Chris Lattner return 0; 547ff38491c18b060526d754765b952f4a497a89416Chris Lattner case tok::identifier: 548ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_asm: 549ff38491c18b060526d754765b952f4a497a89416Chris Lattner case tok::kw_auto: 5509298d9655aed28b2d9f6cc65c81401b209f03fdcChris Lattner case tok::kw_bool: 551ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_break: 552ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_case: 553ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_catch: 554ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_char: 555ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_class: 556ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_const: 557ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_const_cast: 558ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_continue: 559ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_default: 560ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_delete: 561ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_do: 562ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_double: 563ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_dynamic_cast: 564ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_else: 565ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_enum: 566ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_explicit: 567ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_export: 568ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_extern: 569ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_false: 570ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_float: 571ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_for: 572ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_friend: 573ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_goto: 574ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_if: 575ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_inline: 576ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_int: 577ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_long: 578ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_mutable: 579ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_namespace: 580ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_new: 581ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_operator: 582ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_private: 583ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_protected: 584ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_public: 585ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_register: 586ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_reinterpret_cast: 587ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_restrict: 588ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_return: 589ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_short: 590ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_signed: 591ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_sizeof: 592ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_static: 593ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_static_cast: 594ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_struct: 595ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_switch: 596ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_template: 597ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_this: 598ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_throw: 599ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_true: 600ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_try: 601ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_typedef: 602ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_typeid: 603ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_typename: 604ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_typeof: 605ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_union: 606ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_unsigned: 607ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_using: 608ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_virtual: 609ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_void: 610ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_volatile: 611ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_wchar_t: 612ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_while: 613ff38491c18b060526d754765b952f4a497a89416Chris Lattner case tok::kw__Bool: 614ff38491c18b060526d754765b952f4a497a89416Chris Lattner case tok::kw__Complex: 615ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw___alignof: 616ff38491c18b060526d754765b952f4a497a89416Chris Lattner IdentifierInfo *II = Tok.getIdentifierInfo(); 6174b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian SelectorLoc = ConsumeToken(); 618ff38491c18b060526d754765b952f4a497a89416Chris Lattner return II; 619d064951b0dcc95f8604d0d69ae82d9ecbd38c796Fariborz Jahanian } 620294494e1cce92043562b4680c613df7fd028c02eSteve Naroff} 621294494e1cce92043562b4680c613df7fd028c02eSteve Naroff 6220196cab54007ff072ec2642da8911c6b7e8d3fb5Fariborz Jahanian/// objc-for-collection-in: 'in' 6230196cab54007ff072ec2642da8911c6b7e8d3fb5Fariborz Jahanian/// 624335a2d4122e41343fe11a775889b8bec5b14be60Fariborz Jahanianbool Parser::isTokIdentifier_in() const { 6253ba5a0f90a03d5e13d02cbee9abd2a1ba01b18bcFariborz Jahanian // FIXME: May have to do additional look-ahead to only allow for 6263ba5a0f90a03d5e13d02cbee9abd2a1ba01b18bcFariborz Jahanian // valid tokens following an 'in'; such as an identifier, unary operators, 6273ba5a0f90a03d5e13d02cbee9abd2a1ba01b18bcFariborz Jahanian // '[' etc. 6281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return (getLang().ObjC2 && Tok.is(tok::identifier) && 6295ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner Tok.getIdentifierInfo() == ObjCTypeQuals[objc_in]); 6300196cab54007ff072ec2642da8911c6b7e8d3fb5Fariborz Jahanian} 6310196cab54007ff072ec2642da8911c6b7e8d3fb5Fariborz Jahanian 632a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ParseObjCTypeQualifierList - This routine parses the objective-c's type 633e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner/// qualifier list and builds their bitmask representation in the input 634e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner/// argument. 635294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 636294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-type-qualifiers: 637294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-type-qualifier 638294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-type-qualifiers objc-type-qualifier 639294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 640a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekvoid Parser::ParseObjCTypeQualifierList(ObjCDeclSpec &DS) { 641e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner while (1) { 642cb53b361bce341c8591333c6997f62e480acc0b4Chris Lattner if (Tok.isNot(tok::identifier)) 643e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner return; 6441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 645e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner const IdentifierInfo *II = Tok.getIdentifierInfo(); 646e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner for (unsigned i = 0; i != objc_NumQuals; ++i) { 647a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek if (II != ObjCTypeQuals[i]) 648e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner continue; 6491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 650a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCDeclSpec::ObjCDeclQualifier Qual; 651e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner switch (i) { 652e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner default: assert(0 && "Unknown decl qualifier"); 653a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek case objc_in: Qual = ObjCDeclSpec::DQ_In; break; 654a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek case objc_out: Qual = ObjCDeclSpec::DQ_Out; break; 655a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek case objc_inout: Qual = ObjCDeclSpec::DQ_Inout; break; 656a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek case objc_oneway: Qual = ObjCDeclSpec::DQ_Oneway; break; 657a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek case objc_bycopy: Qual = ObjCDeclSpec::DQ_Bycopy; break; 658a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek case objc_byref: Qual = ObjCDeclSpec::DQ_Byref; break; 659e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner } 660a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek DS.setObjCDeclQualifier(Qual); 661e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner ConsumeToken(); 662e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner II = 0; 663e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner break; 664e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner } 6651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 666e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner // If this wasn't a recognized qualifier, bail out. 667e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner if (II) return; 668e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner } 669e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner} 670e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner 671e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner/// objc-type-name: 672e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner/// '(' objc-type-qualifiers[opt] type-name ')' 673e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner/// '(' objc-type-qualifiers[opt] ')' 674e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner/// 675a526c5c67e5a0473c340903ee542ce570119665fTed KremenekParser::TypeTy *Parser::ParseObjCTypeName(ObjCDeclSpec &DS) { 676df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner assert(Tok.is(tok::l_paren) && "expected ("); 6771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6784a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner SourceLocation LParenLoc = ConsumeParen(); 679e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner SourceLocation TypeStartLoc = Tok.getLocation(); 6801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 68119d74e1494fe399f0e2a94e9419c095f8214851bFariborz Jahanian // Parse type qualifiers, in, inout, etc. 682a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ParseObjCTypeQualifierList(DS); 6834fa7afd07421e7276d1717e4fdf43a5fdd65a622Steve Naroff 6844a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner TypeTy *Ty = 0; 685809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor if (isTypeSpecifierQualifier()) { 686809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor TypeResult TypeSpec = ParseTypeName(); 687809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor if (!TypeSpec.isInvalid()) 688809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor Ty = TypeSpec.get(); 689809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor } 6901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6914a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner if (Tok.is(tok::r_paren)) 6924a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner ConsumeParen(); 6934a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner else if (Tok.getLocation() == TypeStartLoc) { 694e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner // If we didn't eat any tokens, then this isn't a type. 6951ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_type); 6964a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner SkipUntil(tok::r_paren); 6974a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner } else { 6984a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner // Otherwise, we found *something*, but didn't get a ')' in the right 6994a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner // place. Emit an error then return what we have as the type. 7004a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner MatchRHSPunctuation(tok::r_paren, LParenLoc); 701294494e1cce92043562b4680c613df7fd028c02eSteve Naroff } 702f28b264437053fb0deacc9ba02b18a0966f7290aSteve Naroff return Ty; 703294494e1cce92043562b4680c613df7fd028c02eSteve Naroff} 704294494e1cce92043562b4680c613df7fd028c02eSteve Naroff 705294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-method-decl: 706294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-selector 7074985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-keyword-selector objc-parmlist[opt] 708294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-type-name objc-selector 7094985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-type-name objc-keyword-selector objc-parmlist[opt] 710294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 711294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-keyword-selector: 7121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// objc-keyword-decl 713294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-keyword-selector objc-keyword-decl 714294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 715294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-keyword-decl: 7167ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// objc-selector ':' objc-type-name objc-keyword-attributes[opt] identifier 7177ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// objc-selector ':' objc-keyword-attributes[opt] identifier 7187ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// ':' objc-type-name objc-keyword-attributes[opt] identifier 7197ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// ':' objc-keyword-attributes[opt] identifier 720294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 7214985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-parmlist: 7224985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-parms objc-ellipsis[opt] 723294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 7244985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-parms: 7254985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-parms , parameter-declaration 726294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 7274985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-ellipsis: 728294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// , ... 729294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 7307ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// objc-keyword-attributes: [OBJC2] 7317ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// __attribute__((unused)) 7327ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// 733b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris LattnerParser::DeclPtrTy Parser::ParseObjCMethodDecl(SourceLocation mLoc, 734b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner tok::TokenKind mType, 735b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy IDecl, 736b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner tok::ObjCKeywordKind MethodImplKind) { 73754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ParsingDeclRAIIObject PD(*this); 73854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 739e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner // Parse the return type if present. 740ff38491c18b060526d754765b952f4a497a89416Chris Lattner TypeTy *ReturnType = 0; 741a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCDeclSpec DSRet; 742df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::l_paren)) 743f1de0ca05e2df6f23bd559028693a12d1ebdaaf6Fariborz Jahanian ReturnType = ParseObjCTypeName(DSRet); 7441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 745bef1185418705e16012b3dd50cd7c260c8d6b79cSteve Naroff SourceLocation selLoc; 7462fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner IdentifierInfo *SelIdent = ParseObjCSelectorPiece(selLoc); 747e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner 74884c431088693e216193094d1dbf327a01173f57fSteve Naroff // An unnamed colon is valid. 74984c431088693e216193094d1dbf327a01173f57fSteve Naroff if (!SelIdent && Tok.isNot(tok::colon)) { // missing selector name. 7501ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_selector_for_method) 7511ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner << SourceRange(mLoc, Tok.getLocation()); 752e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner // Skip until we get a ; or {}. 753e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner SkipUntil(tok::r_brace); 754b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 755e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner } 7561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 757439c65892cc8629bbf541e0b8bda6b64cbcc4e6bFariborz Jahanian llvm::SmallVector<Declarator, 8> CargNames; 758df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::colon)) { 759ff38491c18b060526d754765b952f4a497a89416Chris Lattner // If attributes exist after the method, parse them. 760ff38491c18b060526d754765b952f4a497a89416Chris Lattner AttributeList *MethodAttrs = 0; 7611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (getLang().ObjC2 && Tok.is(tok::kw___attribute)) 762bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt MethodAttrs = ParseGNUAttributes(); 7631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 764ff38491c18b060526d754765b952f4a497a89416Chris Lattner Selector Sel = PP.getSelectorTable().getNullarySelector(SelIdent); 76554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall DeclPtrTy Result 76654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall = Actions.ActOnMethodDeclaration(mLoc, Tok.getLocation(), 7671f7b6f88f18d7f6b10265acec5d41c4ed1897487Fariborz Jahanian mType, IDecl, DSRet, ReturnType, Sel, 7681c6a3cc88177c67498fccdf14cfdf09959214e41Ted Kremenek 0, CargNames, MethodAttrs, 7691c6a3cc88177c67498fccdf14cfdf09959214e41Ted Kremenek MethodImplKind); 77054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall PD.complete(Result); 77154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall return Result; 772ff38491c18b060526d754765b952f4a497a89416Chris Lattner } 773f28b264437053fb0deacc9ba02b18a0966f7290aSteve Naroff 77468d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff llvm::SmallVector<IdentifierInfo *, 12> KeyIdents; 775e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner llvm::SmallVector<Action::ObjCArgInfo, 12> ArgInfos; 7761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 777ff38491c18b060526d754765b952f4a497a89416Chris Lattner while (1) { 778e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner Action::ObjCArgInfo ArgInfo; 7791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 780ff38491c18b060526d754765b952f4a497a89416Chris Lattner // Each iteration parses a single keyword argument. 781df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::colon)) { 782ff38491c18b060526d754765b952f4a497a89416Chris Lattner Diag(Tok, diag::err_expected_colon); 783ff38491c18b060526d754765b952f4a497a89416Chris Lattner break; 784ff38491c18b060526d754765b952f4a497a89416Chris Lattner } 785ff38491c18b060526d754765b952f4a497a89416Chris Lattner ConsumeToken(); // Eat the ':'. 7861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 787e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner ArgInfo.Type = 0; 788e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner if (Tok.is(tok::l_paren)) // Parse the argument type if present. 789e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner ArgInfo.Type = ParseObjCTypeName(ArgInfo.DeclSpec); 790e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner 791ff38491c18b060526d754765b952f4a497a89416Chris Lattner // If attributes exist before the argument name, parse them. 792e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner ArgInfo.ArgAttrs = 0; 793df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (getLang().ObjC2 && Tok.is(tok::kw___attribute)) 794bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt ArgInfo.ArgAttrs = ParseGNUAttributes(); 7957ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff 796df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 797ff38491c18b060526d754765b952f4a497a89416Chris Lattner Diag(Tok, diag::err_expected_ident); // missing argument name. 798ff38491c18b060526d754765b952f4a497a89416Chris Lattner break; 7994985aceceb9b9261b876b515d32726175c13a775Steve Naroff } 8001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 801e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner ArgInfo.Name = Tok.getIdentifierInfo(); 802e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner ArgInfo.NameLoc = Tok.getLocation(); 803ff38491c18b060526d754765b952f4a497a89416Chris Lattner ConsumeToken(); // Eat the identifier. 8041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 805e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner ArgInfos.push_back(ArgInfo); 806e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner KeyIdents.push_back(SelIdent); 807e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner 808ff38491c18b060526d754765b952f4a497a89416Chris Lattner // Check for another keyword selector. 8094b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian SourceLocation Loc; 8102fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner SelIdent = ParseObjCSelectorPiece(Loc); 811df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (!SelIdent && Tok.isNot(tok::colon)) 812ff38491c18b060526d754765b952f4a497a89416Chris Lattner break; 813ff38491c18b060526d754765b952f4a497a89416Chris Lattner // We have a selector or a colon, continue parsing. 814ff38491c18b060526d754765b952f4a497a89416Chris Lattner } 8151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 816335eafa5be51f6440672a74c73d588af72e96732Steve Naroff bool isVariadic = false; 8171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 818ff38491c18b060526d754765b952f4a497a89416Chris Lattner // Parse the (optional) parameter list. 819df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner while (Tok.is(tok::comma)) { 820ff38491c18b060526d754765b952f4a497a89416Chris Lattner ConsumeToken(); 821df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::ellipsis)) { 822335eafa5be51f6440672a74c73d588af72e96732Steve Naroff isVariadic = true; 8234985aceceb9b9261b876b515d32726175c13a775Steve Naroff ConsumeToken(); 824ff38491c18b060526d754765b952f4a497a89416Chris Lattner break; 8254985aceceb9b9261b876b515d32726175c13a775Steve Naroff } 826ff38491c18b060526d754765b952f4a497a89416Chris Lattner DeclSpec DS; 827ff38491c18b060526d754765b952f4a497a89416Chris Lattner ParseDeclarationSpecifiers(DS); 8281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // Parse the declarator. 829ff38491c18b060526d754765b952f4a497a89416Chris Lattner Declarator ParmDecl(DS, Declarator::PrototypeContext); 830ff38491c18b060526d754765b952f4a497a89416Chris Lattner ParseDeclarator(ParmDecl); 831439c65892cc8629bbf541e0b8bda6b64cbcc4e6bFariborz Jahanian CargNames.push_back(ParmDecl); 8324985aceceb9b9261b876b515d32726175c13a775Steve Naroff } 8331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 834ff38491c18b060526d754765b952f4a497a89416Chris Lattner // FIXME: Add support for optional parmameter list... 835e3a2ca7e30601cdd31c77a830f4cc487851e8096Fariborz Jahanian // If attributes exist after the method, parse them. 836ff38491c18b060526d754765b952f4a497a89416Chris Lattner AttributeList *MethodAttrs = 0; 8371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (getLang().ObjC2 && Tok.is(tok::kw___attribute)) 838bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt MethodAttrs = ParseGNUAttributes(); 8391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8403688fc679389d67b6755e62406998f9ea84d886aFariborz Jahanian if (KeyIdents.size() == 0) 8413688fc679389d67b6755e62406998f9ea84d886aFariborz Jahanian return DeclPtrTy(); 842ff38491c18b060526d754765b952f4a497a89416Chris Lattner Selector Sel = PP.getSelectorTable().getSelector(KeyIdents.size(), 843ff38491c18b060526d754765b952f4a497a89416Chris Lattner &KeyIdents[0]); 84454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall DeclPtrTy Result 84554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall = Actions.ActOnMethodDeclaration(mLoc, Tok.getLocation(), 8463688fc679389d67b6755e62406998f9ea84d886aFariborz Jahanian mType, IDecl, DSRet, ReturnType, Sel, 8471c6a3cc88177c67498fccdf14cfdf09959214e41Ted Kremenek &ArgInfos[0], CargNames, MethodAttrs, 848335eafa5be51f6440672a74c73d588af72e96732Steve Naroff MethodImplKind, isVariadic); 84954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall PD.complete(Result); 85054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall return Result; 851294494e1cce92043562b4680c613df7fd028c02eSteve Naroff} 852294494e1cce92043562b4680c613df7fd028c02eSteve Naroff 853dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-refs: 854dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// '<' identifier-list '>' 855dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 8567caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattnerbool Parser:: 857b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris LattnerParseObjCProtocolReferences(llvm::SmallVectorImpl<Action::DeclPtrTy> &Protocols, 85871b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis llvm::SmallVectorImpl<SourceLocation> &ProtocolLocs, 85971b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis bool WarnOnDeclarations, 86071b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis SourceLocation &LAngleLoc, SourceLocation &EndLoc) { 861e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner assert(Tok.is(tok::less) && "expected <"); 8621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 86371b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis LAngleLoc = ConsumeToken(); // the "<" 8641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 865e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner llvm::SmallVector<IdentifierLocPair, 8> ProtocolIdents; 8661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 867e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner while (1) { 86855385fe3e723cd675001e45f42d61adde6b7f075Douglas Gregor if (Tok.is(tok::code_completion)) { 86955385fe3e723cd675001e45f42d61adde6b7f075Douglas Gregor Actions.CodeCompleteObjCProtocolReferences(ProtocolIdents.data(), 87055385fe3e723cd675001e45f42d61adde6b7f075Douglas Gregor ProtocolIdents.size()); 87155385fe3e723cd675001e45f42d61adde6b7f075Douglas Gregor ConsumeToken(); 87255385fe3e723cd675001e45f42d61adde6b7f075Douglas Gregor } 87355385fe3e723cd675001e45f42d61adde6b7f075Douglas Gregor 874e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner if (Tok.isNot(tok::identifier)) { 875e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner Diag(Tok, diag::err_expected_ident); 876e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner SkipUntil(tok::greater); 877e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner return true; 878e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner } 879e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner ProtocolIdents.push_back(std::make_pair(Tok.getIdentifierInfo(), 880e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner Tok.getLocation())); 88171b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis ProtocolLocs.push_back(Tok.getLocation()); 882e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner ConsumeToken(); 8831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 884e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner if (Tok.isNot(tok::comma)) 885e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner break; 886e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner ConsumeToken(); 887e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner } 8881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 889e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner // Consume the '>'. 890e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner if (Tok.isNot(tok::greater)) { 891e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner Diag(Tok, diag::err_expected_greater); 892e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner return true; 893e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner } 8941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 895e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner EndLoc = ConsumeAnyToken(); 8961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 897e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner // Convert the list of protocols identifiers into a list of protocol decls. 898e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner Actions.FindProtocolDeclaration(WarnOnDeclarations, 899e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner &ProtocolIdents[0], ProtocolIdents.size(), 900e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner Protocols); 901e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner return false; 902e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner} 903e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner 904dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-instance-variables: 905dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// '{' objc-instance-variable-decl-list[opt] '}' 906dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 907dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-instance-variable-decl-list: 908dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-visibility-spec 909dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-instance-variable-decl ';' 910dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// ';' 911dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-instance-variable-decl-list objc-visibility-spec 912dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-instance-variable-decl-list objc-instance-variable-decl ';' 913dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-instance-variable-decl-list ';' 914dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 915dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-visibility-spec: 916dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @private 917dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @protected 918dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @public 919ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff/// @package [OBJC2] 920dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 921dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-instance-variable-decl: 9221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// struct-declaration 923dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 924b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattnervoid Parser::ParseObjCClassInstanceVariables(DeclPtrTy interfaceDecl, 92560fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff SourceLocation atLoc) { 926df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner assert(Tok.is(tok::l_brace) && "expected {"); 927b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner llvm::SmallVector<DeclPtrTy, 32> AllIvarDecls; 928e13594279a952537ac903325efff57e3edca79d9Chris Lattner 9291a0d31a3d7f14ddc6370ba912c778aece6c12cf0Douglas Gregor ParseScope ClassScope(this, Scope::DeclScope|Scope::ClassScope); 93072de6676bd30f9081ee4166bbe07b4c270258ce6Douglas Gregor 931ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff SourceLocation LBraceLoc = ConsumeBrace(); // the "{" 9321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 933aa847fe3c88ee5e8d180e48537c58b805d48d95dFariborz Jahanian tok::ObjCKeywordKind visibility = tok::objc_protected; 934ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff // While we still have something to read, read the instance variables. 935df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner while (Tok.isNot(tok::r_brace) && Tok.isNot(tok::eof)) { 936ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff // Each iteration of this loop reads one objc-instance-variable-decl. 9371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 938ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff // Check for extraneous top-level semicolon. 939df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::semi)) { 940c2253f5ca170984fcd4f30f8823148e8cb71336bChris Lattner Diag(Tok, diag::ext_extra_struct_semi) 941c2253f5ca170984fcd4f30f8823148e8cb71336bChris Lattner << CodeModificationHint::CreateRemoval(SourceRange(Tok.getLocation())); 942ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff ConsumeToken(); 943ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff continue; 944ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff } 9451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 946ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff // Set the default visibility to private. 947df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::at)) { // parse objc-visibility-spec 948ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff ConsumeToken(); // eat the @ sign 949861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff switch (Tok.getObjCKeywordID()) { 950ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff case tok::objc_private: 951ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff case tok::objc_public: 952ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff case tok::objc_protected: 953ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff case tok::objc_package: 954861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff visibility = Tok.getObjCKeywordID(); 955ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff ConsumeToken(); 9561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump continue; 957ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff default: 958ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff Diag(Tok, diag::err_objc_illegal_visibility_spec); 959ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff continue; 960ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff } 961ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff } 9621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 963bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall struct ObjCIvarCallback : FieldCallback { 964bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall Parser &P; 965bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall DeclPtrTy IDecl; 966bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall tok::ObjCKeywordKind visibility; 967bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall llvm::SmallVectorImpl<DeclPtrTy> &AllIvarDecls; 968bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall 969bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall ObjCIvarCallback(Parser &P, DeclPtrTy IDecl, tok::ObjCKeywordKind V, 970bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall llvm::SmallVectorImpl<DeclPtrTy> &AllIvarDecls) : 971bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall P(P), IDecl(IDecl), visibility(V), AllIvarDecls(AllIvarDecls) { 972bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall } 973bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall 974bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall DeclPtrTy invoke(FieldDeclarator &FD) { 975bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall // Install the declarator into the interface decl. 976bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall DeclPtrTy Field 977bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall = P.Actions.ActOnIvar(P.CurScope, 978bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall FD.D.getDeclSpec().getSourceRange().getBegin(), 979bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall IDecl, FD.D, FD.BitfieldSize, visibility); 980bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall AllIvarDecls.push_back(Field); 981bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall return Field; 982bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall } 983bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall } Callback(*this, interfaceDecl, visibility, AllIvarDecls); 984bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall 985e13594279a952537ac903325efff57e3edca79d9Chris Lattner // Parse all the comma separated declarators. 986e13594279a952537ac903325efff57e3edca79d9Chris Lattner DeclSpec DS; 987bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall ParseStructDeclaration(DS, Callback); 9881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 989df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::semi)) { 990ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff ConsumeToken(); 991ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff } else { 992ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff Diag(Tok, diag::err_expected_semi_decl_list); 993ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff // Skip to end of block or statement 994ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff SkipUntil(tok::r_brace, true, true); 995ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff } 996ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff } 99760fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff SourceLocation RBraceLoc = MatchRHSPunctuation(tok::r_brace, LBraceLoc); 9988749be53f53384e7846502791ceda6c657228d07Steve Naroff // Call ActOnFields() even if we don't have any decls. This is useful 9998749be53f53384e7846502791ceda6c657228d07Steve Naroff // for code rewriting tools that need to be aware of the empty list. 10008749be53f53384e7846502791ceda6c657228d07Steve Naroff Actions.ActOnFields(CurScope, atLoc, interfaceDecl, 1001beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad AllIvarDecls.data(), AllIvarDecls.size(), 10021bfe1c2129771c06fb58ae5e8c079ae30e138309Daniel Dunbar LBraceLoc, RBraceLoc, 0); 1003ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff return; 10045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 1005dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff 1006dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-declaration: 1007dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-definition 1008dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-forward-reference 1009dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1010dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-definition: 10111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// @protocol identifier 10121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// objc-protocol-refs[opt] 10131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// objc-interface-decl-list 1014dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @end 1015dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1016dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-forward-reference: 1017dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @protocol identifier-list ';' 1018dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1019dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// "@protocol identifier ;" should be resolved as "@protocol 10203536b443bc50d58a79f14fca9b6842541a434854Steve Naroff/// identifier-list ;": objc-interface-decl-list may not start with a 1021dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// semicolon in the first alternative if objc-protocol-refs are omitted. 1022b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris LattnerParser::DeclPtrTy Parser::ParseObjCAtProtocolDeclaration(SourceLocation AtLoc, 1023b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner AttributeList *attrList) { 1024861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff assert(Tok.isObjCAtKeyword(tok::objc_protocol) && 10257ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff "ParseObjCAtProtocolDeclaration(): Expected @protocol"); 10267ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff ConsumeToken(); // the "protocol" identifier 10271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1028083128f6b13dfa4fc615a838c49b516d901b1ac0Douglas Gregor if (Tok.is(tok::code_completion)) { 1029083128f6b13dfa4fc615a838c49b516d901b1ac0Douglas Gregor Actions.CodeCompleteObjCProtocolDecl(CurScope); 1030083128f6b13dfa4fc615a838c49b516d901b1ac0Douglas Gregor ConsumeToken(); 1031083128f6b13dfa4fc615a838c49b516d901b1ac0Douglas Gregor } 1032083128f6b13dfa4fc615a838c49b516d901b1ac0Douglas Gregor 1033df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 10347ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff Diag(Tok, diag::err_expected_ident); // missing protocol name. 1035b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 10367ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff } 10377ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff // Save the protocol name, then consume it. 10387ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff IdentifierInfo *protocolName = Tok.getIdentifierInfo(); 10397ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff SourceLocation nameLoc = ConsumeToken(); 10401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1041df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::semi)) { // forward declaration of one protocol. 10427caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner IdentifierLocPair ProtoInfo(protocolName, nameLoc); 10437ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff ConsumeToken(); 10441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return Actions.ActOnForwardProtocolDeclaration(AtLoc, &ProtoInfo, 1, 1045bc1c877fe28fb6a825f0b226a0a2da99e713ea03Fariborz Jahanian attrList); 10467ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff } 10471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1048df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::comma)) { // list of forward declarations. 10497caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner llvm::SmallVector<IdentifierLocPair, 8> ProtocolRefs; 10507caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner ProtocolRefs.push_back(std::make_pair(protocolName, nameLoc)); 10517caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner 10527ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff // Parse the list of forward declarations. 10537ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff while (1) { 10547ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff ConsumeToken(); // the ',' 1055df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 10567ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff Diag(Tok, diag::err_expected_ident); 10577ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff SkipUntil(tok::semi); 1058b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 10597ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff } 10607caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner ProtocolRefs.push_back(IdentifierLocPair(Tok.getIdentifierInfo(), 10617caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner Tok.getLocation())); 10627ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff ConsumeToken(); // the identifier 10631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1064df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::comma)) 10657ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff break; 10667ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff } 10677ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff // Consume the ';'. 10687ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff if (ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@protocol")) 1069b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 10701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1071e440eb8158e71deb1e4ab11618ae3d680aac6da1Steve Naroff return Actions.ActOnForwardProtocolDeclaration(AtLoc, 10721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump &ProtocolRefs[0], 1073bc1c877fe28fb6a825f0b226a0a2da99e713ea03Fariborz Jahanian ProtocolRefs.size(), 1074bc1c877fe28fb6a825f0b226a0a2da99e713ea03Fariborz Jahanian attrList); 10757caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner } 10761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10777ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff // Last, and definitely not least, parse a protocol declaration. 107871b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis SourceLocation LAngleLoc, EndProtoLoc; 10797caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner 1080b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner llvm::SmallVector<DeclPtrTy, 8> ProtocolRefs; 108171b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis llvm::SmallVector<SourceLocation, 8> ProtocolLocs; 10827caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner if (Tok.is(tok::less) && 108371b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis ParseObjCProtocolReferences(ProtocolRefs, ProtocolLocs, false, 108471b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis LAngleLoc, EndProtoLoc)) 1085b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 10861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1087b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy ProtoType = 1088e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner Actions.ActOnStartProtocolInterface(AtLoc, protocolName, nameLoc, 1089beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad ProtocolRefs.data(), 1090beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad ProtocolRefs.size(), 1091246e70f69cb8aeb67225c54690f1c6b25abd5a86Daniel Dunbar EndProtoLoc, attrList); 109225e077d59a8e8e43b65882b69610a3d5e2aaf53cFariborz Jahanian ParseObjCInterfaceDeclList(ProtoType, tok::objc_protocol); 1093bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner return ProtoType; 1094dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff} 1095dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff 1096dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-implementation: 1097dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-implementation-prologue 1098dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-category-implementation-prologue 1099dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1100dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-implementation-prologue: 1101dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @implementation identifier objc-superclass[opt] 1102dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-instance-variables[opt] 1103dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1104dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-category-implementation-prologue: 1105dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @implementation identifier ( identifier ) 1106b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris LattnerParser::DeclPtrTy Parser::ParseObjCAtImplementationDeclaration( 1107ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian SourceLocation atLoc) { 1108ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian assert(Tok.isObjCAtKeyword(tok::objc_implementation) && 1109ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian "ParseObjCAtImplementationDeclaration(): Expected @implementation"); 1110ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); // the "implementation" identifier 11111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11123b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor // Code completion after '@implementation'. 11133b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor if (Tok.is(tok::code_completion)) { 11143b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor Actions.CodeCompleteObjCImplementationDecl(CurScope); 11153b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor ConsumeToken(); 11163b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor } 11173b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor 1118df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 1119ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian Diag(Tok, diag::err_expected_ident); // missing class or category name. 1120b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 1121ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1122ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian // We have a class or category name - consume it. 1123ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian IdentifierInfo *nameId = Tok.getIdentifierInfo(); 1124ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian SourceLocation nameLoc = ConsumeToken(); // consume class or category name 11251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (Tok.is(tok::l_paren)) { 1127ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian // we have a category implementation. 1128ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian SourceLocation lparenLoc = ConsumeParen(); 1129ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian SourceLocation categoryLoc, rparenLoc; 1130ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian IdentifierInfo *categoryId = 0; 11311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 113233ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor if (Tok.is(tok::code_completion)) { 113333ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor Actions.CodeCompleteObjCImplementationCategory(CurScope, nameId); 113433ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor ConsumeToken(); 113533ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor } 113633ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor 1137df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::identifier)) { 1138ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian categoryId = Tok.getIdentifierInfo(); 1139ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian categoryLoc = ConsumeToken(); 1140ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } else { 1141ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian Diag(Tok, diag::err_expected_ident); // missing category name. 1142b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 11431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 1144df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::r_paren)) { 1145ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian Diag(Tok, diag::err_expected_rparen); 1146ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian SkipUntil(tok::r_paren, false); // don't stop at ';' 1147b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 1148ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1149ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian rparenLoc = ConsumeParen(); 1150b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy ImplCatType = Actions.ActOnStartCategoryImplementation( 11511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump atLoc, nameId, nameLoc, categoryId, 11528f3fde00ad4d4f943321e338b914ae4740711c84Fariborz Jahanian categoryLoc); 1153a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCImpDecl = ImplCatType; 115463e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian PendingObjCImpDecl.push_back(ObjCImpDecl); 1155b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 1156ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1157ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian // We have a class implementation 1158ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian SourceLocation superClassLoc; 1159ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian IdentifierInfo *superClassId = 0; 1160df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::colon)) { 1161ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian // We have a super class 1162ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); 1163df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 1164ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian Diag(Tok, diag::err_expected_ident); // missing super class name. 1165b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 1166ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1167ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian superClassId = Tok.getIdentifierInfo(); 1168ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian superClassLoc = ConsumeToken(); // Consume super class name 1169ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1170b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy ImplClsType = Actions.ActOnStartClassImplementation( 1171cb53b361bce341c8591333c6997f62e480acc0b4Chris Lattner atLoc, nameId, nameLoc, 1172ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian superClassId, superClassLoc); 11731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 117460fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff if (Tok.is(tok::l_brace)) // we have ivars 117560fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff ParseObjCClassInstanceVariables(ImplClsType/*FIXME*/, atLoc); 1176a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCImpDecl = ImplClsType; 117763e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian PendingObjCImpDecl.push_back(ObjCImpDecl); 117863e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian 1179b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 11805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 118160fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff 1182b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris LattnerParser::DeclPtrTy Parser::ParseObjCAtEndDeclaration(SourceLocation atLoc) { 1183ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian assert(Tok.isObjCAtKeyword(tok::objc_end) && 1184ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian "ParseObjCAtEndDeclaration(): Expected @end"); 1185b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy Result = ObjCImpDecl; 1186ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); // the "end" identifier 1187a6e3ac514c924879699c6b0b1201028f0091044fFariborz Jahanian if (ObjCImpDecl) { 1188a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek Actions.ActOnAtEnd(atLoc, ObjCImpDecl); 1189b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner ObjCImpDecl = DeclPtrTy(); 119063e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian PendingObjCImpDecl.pop_back(); 1191a6e3ac514c924879699c6b0b1201028f0091044fFariborz Jahanian } 119294cdb25a49bd3716ab56ef6de0ea57d29e686bf2Fariborz Jahanian else 119394cdb25a49bd3716ab56ef6de0ea57d29e686bf2Fariborz Jahanian Diag(atLoc, diag::warn_expected_implementation); // missing @implementation 1194a6e3ac514c924879699c6b0b1201028f0091044fFariborz Jahanian return Result; 11955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 1196e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian 11971ac7104947020a60430ba6f519cd5869af77046fFariborz JahanianParser::DeclGroupPtrTy Parser::RetrievePendingObjCImpDecl() { 119863e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian if (PendingObjCImpDecl.empty()) 119963e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian return Actions.ConvertDeclToDeclGroup(DeclPtrTy()); 120063e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian DeclPtrTy ImpDecl = PendingObjCImpDecl.pop_back_val(); 120163e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian Actions.ActOnAtEnd(SourceLocation(), ImpDecl); 120263e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian return Actions.ConvertDeclToDeclGroup(ImpDecl); 120363e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian} 120463e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian 1205e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian/// compatibility-alias-decl: 1206e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian/// @compatibility_alias alias-name class-name ';' 1207e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian/// 1208b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris LattnerParser::DeclPtrTy Parser::ParseObjCAtAliasDeclaration(SourceLocation atLoc) { 1209e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian assert(Tok.isObjCAtKeyword(tok::objc_compatibility_alias) && 1210e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian "ParseObjCAtAliasDeclaration(): Expected @compatibility_alias"); 1211e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian ConsumeToken(); // consume compatibility_alias 1212df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 1213e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian Diag(Tok, diag::err_expected_ident); 1214b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 1215e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian } 1216243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian IdentifierInfo *aliasId = Tok.getIdentifierInfo(); 1217243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian SourceLocation aliasLoc = ConsumeToken(); // consume alias-name 1218df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 1219e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian Diag(Tok, diag::err_expected_ident); 1220b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 1221e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian } 1222243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian IdentifierInfo *classId = Tok.getIdentifierInfo(); 1223243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian SourceLocation classLoc = ConsumeToken(); // consume class-name; 1224243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian if (Tok.isNot(tok::semi)) { 12251ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_semi_after) << "@compatibility_alias"; 1226b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 1227243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian } 1228b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return Actions.ActOnCompatiblityAlias(atLoc, aliasId, aliasLoc, 1229b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner classId, classLoc); 12305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 12315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1232ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-synthesis: 1233ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// @synthesize property-ivar-list ';' 1234ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// 1235ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-ivar-list: 1236ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-ivar 1237ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-ivar-list ',' property-ivar 1238ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// 1239ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-ivar: 1240ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// identifier 1241ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// identifier '=' identifier 1242ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// 1243b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris LattnerParser::DeclPtrTy Parser::ParseObjCPropertySynthesize(SourceLocation atLoc) { 1244ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian assert(Tok.isObjCAtKeyword(tok::objc_synthesize) && 1245ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian "ParseObjCPropertyDynamic(): Expected '@synthesize'"); 1246f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian SourceLocation loc = ConsumeToken(); // consume synthesize 12471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1248b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor while (true) { 1249322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor if (Tok.is(tok::code_completion)) { 1250424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor Actions.CodeCompleteObjCPropertyDefinition(CurScope, ObjCImpDecl); 1251322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor ConsumeToken(); 1252322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor } 1253322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor 1254b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor if (Tok.isNot(tok::identifier)) { 1255b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor Diag(Tok, diag::err_synthesized_property_name); 1256b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor SkipUntil(tok::semi); 1257b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor return DeclPtrTy(); 1258b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor } 1259b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor 1260f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian IdentifierInfo *propertyIvar = 0; 1261f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian IdentifierInfo *propertyId = Tok.getIdentifierInfo(); 1262f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian SourceLocation propertyLoc = ConsumeToken(); // consume property name 1263df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::equal)) { 1264ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian // property '=' ivar-name 1265ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); // consume '=' 1266322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor 1267322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor if (Tok.is(tok::code_completion)) { 1268322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor Actions.CodeCompleteObjCPropertySynthesizeIvar(CurScope, propertyId, 1269322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor ObjCImpDecl); 1270322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor ConsumeToken(); 1271322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor } 1272322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor 1273df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 1274ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian Diag(Tok, diag::err_expected_ident); 1275ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian break; 1276ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1277f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian propertyIvar = Tok.getIdentifierInfo(); 1278ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); // consume ivar-name 1279ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1280f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian Actions.ActOnPropertyImplDecl(atLoc, propertyLoc, true, ObjCImpDecl, 1281f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian propertyId, propertyIvar); 1282df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::comma)) 1283ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian break; 1284ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); // consume ',' 1285ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1286b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor if (Tok.isNot(tok::semi)) { 12871ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_semi_after) << "@synthesize"; 1288b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor SkipUntil(tok::semi); 1289b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor } 1290d3fdcb5a1bf6bd5e54e18579c054ea3c292a0e28Fariborz Jahanian else 1291d3fdcb5a1bf6bd5e54e18579c054ea3c292a0e28Fariborz Jahanian ConsumeToken(); // consume ';' 1292b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 1293ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian} 1294ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian 1295ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-dynamic: 1296ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// @dynamic property-list 1297ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// 1298ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-list: 1299ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// identifier 1300ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-list ',' identifier 1301ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// 1302b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris LattnerParser::DeclPtrTy Parser::ParseObjCPropertyDynamic(SourceLocation atLoc) { 1303ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian assert(Tok.isObjCAtKeyword(tok::objc_dynamic) && 1304ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian "ParseObjCPropertyDynamic(): Expected '@dynamic'"); 1305ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian SourceLocation loc = ConsumeToken(); // consume dynamic 1306424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor while (true) { 1307424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor if (Tok.is(tok::code_completion)) { 1308424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor Actions.CodeCompleteObjCPropertyDefinition(CurScope, ObjCImpDecl); 1309424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor ConsumeToken(); 1310424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor } 1311424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor 1312424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor if (Tok.isNot(tok::identifier)) { 1313424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor Diag(Tok, diag::err_expected_ident); 1314424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor SkipUntil(tok::semi); 1315424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor return DeclPtrTy(); 1316424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor } 1317424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor 1318c35b9e4e2efad727538c848cf30d4b0eb1031dc9Fariborz Jahanian IdentifierInfo *propertyId = Tok.getIdentifierInfo(); 1319c35b9e4e2efad727538c848cf30d4b0eb1031dc9Fariborz Jahanian SourceLocation propertyLoc = ConsumeToken(); // consume property name 1320c35b9e4e2efad727538c848cf30d4b0eb1031dc9Fariborz Jahanian Actions.ActOnPropertyImplDecl(atLoc, propertyLoc, false, ObjCImpDecl, 1321c35b9e4e2efad727538c848cf30d4b0eb1031dc9Fariborz Jahanian propertyId, 0); 1322c35b9e4e2efad727538c848cf30d4b0eb1031dc9Fariborz Jahanian 1323df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::comma)) 1324ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian break; 1325ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); // consume ',' 1326ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1327df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::semi)) 13281ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_semi_after) << "@dynamic"; 1329b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 1330ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian} 13311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1332397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// objc-throw-statement: 1333397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// throw expression[opt]; 1334397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// 133543bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian RedlParser::OwningStmtResult Parser::ParseObjCThrowStmt(SourceLocation atLoc) { 133615faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl OwningExprResult Res(Actions); 1337397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian ConsumeToken(); // consume throw 1338df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::semi)) { 133939f8f159c488a900e5958d5aab3e467af9ec8a2bFariborz Jahanian Res = ParseExpression(); 13400e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Res.isInvalid()) { 1341397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian SkipUntil(tok::semi); 134243bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 1343397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian } 1344397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian } 134539f8f159c488a900e5958d5aab3e467af9ec8a2bFariborz Jahanian ConsumeToken(); // consume ';' 1346e21dd6ffef4585fa43cd3586ed971217d65bf56cSteve Naroff return Actions.ActOnObjCAtThrowStmt(atLoc, move(Res), CurScope); 1347397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian} 1348397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian 1349c385c90c68dfa376650e2facfbb444b2ec9bd110Fariborz Jahanian/// objc-synchronized-statement: 135078a677bbb5fa115fa0995b5783adeeefad67167eFariborz Jahanian/// @synchronized '(' expression ')' compound-statement 1351c385c90c68dfa376650e2facfbb444b2ec9bd110Fariborz Jahanian/// 135243bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian RedlParser::OwningStmtResult 135343bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian RedlParser::ParseObjCSynchronizedStmt(SourceLocation atLoc) { 1354fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian ConsumeToken(); // consume synchronized 1355fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian if (Tok.isNot(tok::l_paren)) { 13561ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_lparen_after) << "@synchronized"; 135743bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 1358fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian } 1359fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian ConsumeParen(); // '(' 13602f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl OwningExprResult Res(ParseExpression()); 13610e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Res.isInvalid()) { 1362fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian SkipUntil(tok::semi); 136343bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 1364fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian } 1365fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian if (Tok.isNot(tok::r_paren)) { 13661ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_lbrace); 136743bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 1368fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian } 1369fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian ConsumeParen(); // ')' 137078a677bbb5fa115fa0995b5783adeeefad67167eFariborz Jahanian if (Tok.isNot(tok::l_brace)) { 13711ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_lbrace); 137243bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 137378a677bbb5fa115fa0995b5783adeeefad67167eFariborz Jahanian } 13743ac438c383a4a9a73c76a05c76ec5d02f10a3c52Steve Naroff // Enter a scope to hold everything within the compound stmt. Compound 13753ac438c383a4a9a73c76a05c76ec5d02f10a3c52Steve Naroff // statements can always hold declarations. 13768935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor ParseScope BodyScope(this, Scope::DeclScope); 13773ac438c383a4a9a73c76a05c76ec5d02f10a3c52Steve Naroff 137861364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl OwningStmtResult SynchBody(ParseCompoundStatementBody()); 13790e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl 13808935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor BodyScope.Exit(); 13810e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (SynchBody.isInvalid()) 1382fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian SynchBody = Actions.ActOnNullStmt(Tok.getLocation()); 138376ad2e85575722e8a38a2bd4648ab4304d9fcd24Sebastian Redl return Actions.ActOnObjCAtSynchronizedStmt(atLoc, move(Res), move(SynchBody)); 1384c385c90c68dfa376650e2facfbb444b2ec9bd110Fariborz Jahanian} 1385c385c90c68dfa376650e2facfbb444b2ec9bd110Fariborz Jahanian 1386397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// objc-try-catch-statement: 1387397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// @try compound-statement objc-catch-list[opt] 1388397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// @try compound-statement objc-catch-list[opt] @finally compound-statement 1389397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// 1390397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// objc-catch-list: 1391397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// @catch ( parameter-declaration ) compound-statement 1392397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// objc-catch-list @catch ( catch-parameter-declaration ) compound-statement 1393397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// catch-parameter-declaration: 1394397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// parameter-declaration 1395397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// '...' [OBJC2] 1396397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// 139743bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian RedlParser::OwningStmtResult Parser::ParseObjCTryStmt(SourceLocation atLoc) { 1398397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian bool catch_or_finally_seen = false; 139943bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl 1400397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian ConsumeToken(); // consume try 1401df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::l_brace)) { 14021ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_lbrace); 140343bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 1404397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian } 140515faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl OwningStmtResult CatchStmts(Actions); 140615faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl OwningStmtResult FinallyStmt(Actions); 14078935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor ParseScope TryScope(this, Scope::DeclScope); 140861364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl OwningStmtResult TryBody(ParseCompoundStatementBody()); 14098935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor TryScope.Exit(); 14100e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (TryBody.isInvalid()) 1411bd49a647afd9cc534fef13cadf652d4e9c396e2bFariborz Jahanian TryBody = Actions.ActOnNullStmt(Tok.getLocation()); 1412a55e52c0802cae3b7c366a05c461d3d15074c1a3Sebastian Redl 1413df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner while (Tok.is(tok::at)) { 14146b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner // At this point, we need to lookahead to determine if this @ is the start 14156b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner // of an @catch or @finally. We don't want to consume the @ token if this 14166b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner // is an @try or @encode or something else. 14176b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner Token AfterAt = GetLookAheadToken(1); 14186b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner if (!AfterAt.isObjCAtKeyword(tok::objc_catch) && 14196b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner !AfterAt.isObjCAtKeyword(tok::objc_finally)) 14206b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner break; 14210e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl 1422161a9c5afaafb4d527b7efba9675a8b2cbbe32e0Fariborz Jahanian SourceLocation AtCatchFinallyLoc = ConsumeToken(); 1423cb53b361bce341c8591333c6997f62e480acc0b4Chris Lattner if (Tok.isObjCAtKeyword(tok::objc_catch)) { 1424b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy FirstPart; 14253b1191d7eaf2f4984564e01ab84b6713a9d80e70Fariborz Jahanian ConsumeToken(); // consume catch 1426df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::l_paren)) { 1427397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian ConsumeParen(); 1428e21dd6ffef4585fa43cd3586ed971217d65bf56cSteve Naroff ParseScope CatchScope(this, Scope::DeclScope|Scope::AtCatchScope); 1429df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::ellipsis)) { 1430397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian DeclSpec DS; 1431397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian ParseDeclarationSpecifiers(DS); 143243bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl // For some odd reason, the name of the exception variable is 14331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // optional. As a result, we need to use "PrototypeContext", because 14347ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff // we must accept either 'declarator' or 'abstract-declarator' here. 14357ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff Declarator ParmDecl(DS, Declarator::PrototypeContext); 14367ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff ParseDeclarator(ParmDecl); 14377ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff 14387ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff // Inform the actions module about the parameter declarator, so it 14397ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff // gets added to the current scope. 14407ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff FirstPart = Actions.ActOnParamDeclarator(CurScope, ParmDecl); 144164515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff } else 1442397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian ConsumeToken(); // consume '...' 14431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 144493a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff SourceLocation RParenLoc; 14451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 144693a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff if (Tok.is(tok::r_paren)) 144793a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff RParenLoc = ConsumeParen(); 144893a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff else // Skip over garbage, until we get to ')'. Eat the ')'. 144993a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff SkipUntil(tok::r_paren, true, false); 145093a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff 145115faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl OwningStmtResult CatchBody(Actions, true); 1452c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner if (Tok.is(tok::l_brace)) 1453c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner CatchBody = ParseCompoundStatementBody(); 1454c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner else 1455c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner Diag(Tok, diag::err_expected_lbrace); 14560e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (CatchBody.isInvalid()) 14573b1191d7eaf2f4984564e01ab84b6713a9d80e70Fariborz Jahanian CatchBody = Actions.ActOnNullStmt(Tok.getLocation()); 14580e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl CatchStmts = Actions.ActOnObjCAtCatchStmt(AtCatchFinallyLoc, 14597ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff RParenLoc, FirstPart, move(CatchBody), 146076ad2e85575722e8a38a2bd4648ab4304d9fcd24Sebastian Redl move(CatchStmts)); 146164515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff } else { 14621ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(AtCatchFinallyLoc, diag::err_expected_lparen_after) 14631ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner << "@catch clause"; 146443bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 1465397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian } 1466397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian catch_or_finally_seen = true; 14676b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner } else { 14686b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner assert(Tok.isObjCAtKeyword(tok::objc_finally) && "Lookahead confused?"); 146964515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff ConsumeToken(); // consume finally 14708935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor ParseScope FinallyScope(this, Scope::DeclScope); 14710e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl 147215faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl OwningStmtResult FinallyBody(Actions, true); 1473c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner if (Tok.is(tok::l_brace)) 1474c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner FinallyBody = ParseCompoundStatementBody(); 1475c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner else 1476c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner Diag(Tok, diag::err_expected_lbrace); 14770e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (FinallyBody.isInvalid()) 1478161a9c5afaafb4d527b7efba9675a8b2cbbe32e0Fariborz Jahanian FinallyBody = Actions.ActOnNullStmt(Tok.getLocation()); 14790e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl FinallyStmt = Actions.ActOnObjCAtFinallyStmt(AtCatchFinallyLoc, 148076ad2e85575722e8a38a2bd4648ab4304d9fcd24Sebastian Redl move(FinallyBody)); 1481397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian catch_or_finally_seen = true; 1482397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian break; 1483397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian } 1484397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian } 1485bd49a647afd9cc534fef13cadf652d4e9c396e2bFariborz Jahanian if (!catch_or_finally_seen) { 1486397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian Diag(atLoc, diag::err_missing_catch_finally); 148743bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 1488bd49a647afd9cc534fef13cadf652d4e9c396e2bFariborz Jahanian } 148976ad2e85575722e8a38a2bd4648ab4304d9fcd24Sebastian Redl return Actions.ActOnObjCAtTryStmt(atLoc, move(TryBody), move(CatchStmts), 149076ad2e85575722e8a38a2bd4648ab4304d9fcd24Sebastian Redl move(FinallyStmt)); 1491397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian} 1492ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian 14933536b443bc50d58a79f14fca9b6842541a434854Steve Naroff/// objc-method-def: objc-method-proto ';'[opt] '{' body '}' 1494ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// 1495b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris LattnerParser::DeclPtrTy Parser::ParseObjCMethodDefinition() { 1496b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy MDecl = ParseObjCMethodPrototype(ObjCImpDecl); 14971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 149849f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner PrettyStackTraceActionsDecl CrashInfo(MDecl, Tok.getLocation(), Actions, 149949f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner PP.getSourceManager(), 150049f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner "parsing Objective-C method"); 15011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1502ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian // parse optional ';' 1503209a8c2fa23636f6d065d618e7078e164903f5cdFariborz Jahanian if (Tok.is(tok::semi)) { 1504496e45ef3350fabc312c5a807d308c65c50af4dbTed Kremenek if (ObjCImpDecl) { 1505496e45ef3350fabc312c5a807d308c65c50af4dbTed Kremenek Diag(Tok, diag::warn_semicolon_before_method_body) 1506496e45ef3350fabc312c5a807d308c65c50af4dbTed Kremenek << CodeModificationHint::CreateRemoval(SourceRange(Tok.getLocation())); 1507496e45ef3350fabc312c5a807d308c65c50af4dbTed Kremenek } 1508ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); 1509209a8c2fa23636f6d065d618e7078e164903f5cdFariborz Jahanian } 1510ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian 1511409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // We should have an opening brace now. 1512df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::l_brace)) { 1513da323adbb99cee19a203ead852d5d9bfebb23fb7Steve Naroff Diag(Tok, diag::err_expected_method_body); 15141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1515409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // Skip over garbage, until we get to '{'. Don't eat the '{'. 1516409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff SkipUntil(tok::l_brace, true, true); 15171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1518409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // If we didn't find the '{', bail out. 1519409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff if (Tok.isNot(tok::l_brace)) 1520b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 1521ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1522409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff SourceLocation BraceLoc = Tok.getLocation(); 15231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1524409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // Enter a scope for the method body. 15258935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor ParseScope BodyScope(this, Scope::FnScope|Scope::DeclScope); 15261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1527409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // Tell the actions module that we have entered a method definition with the 1528394f3f483fa4e7b472630cfcd03f7840520958c5Steve Naroff // specified Declarator for the method. 1529ebf6443a4f493233f7e8d92b3a991848c8b1c00dSteve Naroff Actions.ActOnStartOfObjCMethodDef(CurScope, MDecl); 153061364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl 153161364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl OwningStmtResult FnBody(ParseCompoundStatementBody()); 153261364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl 1533409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // If the function body could not be parsed, make a bogus compoundstmt. 15340e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (FnBody.isInvalid()) 1535a60528cdac7deee3991c2b48af4df4f315e49e9dSebastian Redl FnBody = Actions.ActOnCompoundStmt(BraceLoc, BraceLoc, 1536a60528cdac7deee3991c2b48af4df4f315e49e9dSebastian Redl MultiStmtArg(Actions), false); 1537798d119415323ebcd029ffe1e0fb442a4ca8adbbSebastian Redl 153832ce8376efb7e0d70e5f7e8fcf685130293f412bSteve Naroff // TODO: Pass argument information. 153932ce8376efb7e0d70e5f7e8fcf685130293f412bSteve Naroff Actions.ActOnFinishFunctionBody(MDecl, move(FnBody)); 15401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1541409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // Leave the function body scope. 15428935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor BodyScope.Exit(); 1543798d119415323ebcd029ffe1e0fb442a4ca8adbbSebastian Redl 154471c0a951d08dc7a2a057df8c15f22b36f6aa47c7Steve Naroff return MDecl; 15455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 15465508518a2702b00be3b15a26d772bde968972f54Anders Carlsson 154743bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian RedlParser::OwningStmtResult Parser::ParseObjCAtStatement(SourceLocation AtLoc) { 154864515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff if (Tok.isObjCAtKeyword(tok::objc_try)) { 15496b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner return ParseObjCTryStmt(AtLoc); 155064515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff } else if (Tok.isObjCAtKeyword(tok::objc_throw)) 155164515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff return ParseObjCThrowStmt(AtLoc); 155264515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff else if (Tok.isObjCAtKeyword(tok::objc_synchronized)) 155364515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff return ParseObjCSynchronizedStmt(AtLoc); 1554d8c4e15138e69a51754cc259c8a592cc47950c8eSebastian Redl OwningExprResult Res(ParseExpressionWithLeadingAt(AtLoc)); 15550e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Res.isInvalid()) { 155664515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff // If the expression is invalid, skip ahead to the next semicolon. Not 155764515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff // doing this opens us up to the possibility of infinite loops if 155864515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff // ParseExpression does not consume any tokens. 155964515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff SkipUntil(tok::semi); 156043bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 156164515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff } 156264515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff // Otherwise, eat the semicolon. 156364515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff ExpectAndConsume(tok::semi, diag::err_expected_semi_after_expr); 15646b1d283fe879fb11d7ce7a69feecf66e77b0eaf3Anders Carlsson return Actions.ActOnExprStmt(Actions.FullExpr(Res)); 156564515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff} 156664515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff 15671d922960e083906a586609ac6978678147250177Sebastian RedlParser::OwningExprResult Parser::ParseObjCAtExpression(SourceLocation AtLoc) { 15685508518a2702b00be3b15a26d772bde968972f54Anders Carlsson switch (Tok.getKind()) { 1569b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner case tok::string_literal: // primary-expression: string-literal 1570b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner case tok::wide_string_literal: 15711d922960e083906a586609ac6978678147250177Sebastian Redl return ParsePostfixExpressionSuffix(ParseObjCStringLiteral(AtLoc)); 1572b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner default: 15734fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner if (Tok.getIdentifierInfo() == 0) 15741d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(AtLoc, diag::err_unexpected_at)); 15752f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl 15764fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner switch (Tok.getIdentifierInfo()->getObjCKeywordID()) { 15774fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner case tok::objc_encode: 15781d922960e083906a586609ac6978678147250177Sebastian Redl return ParsePostfixExpressionSuffix(ParseObjCEncodeExpression(AtLoc)); 15794fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner case tok::objc_protocol: 15801d922960e083906a586609ac6978678147250177Sebastian Redl return ParsePostfixExpressionSuffix(ParseObjCProtocolExpression(AtLoc)); 15814fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner case tok::objc_selector: 15821d922960e083906a586609ac6978678147250177Sebastian Redl return ParsePostfixExpressionSuffix(ParseObjCSelectorExpression(AtLoc)); 15834fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner default: 15841d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(AtLoc, diag::err_unexpected_at)); 15854fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner } 15865508518a2702b00be3b15a26d772bde968972f54Anders Carlsson } 15875508518a2702b00be3b15a26d772bde968972f54Anders Carlsson} 15885508518a2702b00be3b15a26d772bde968972f54Anders Carlsson 15891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// objc-message-expr: 15900ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// '[' objc-receiver objc-message-args ']' 15910ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// 15920ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-receiver: 15930ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// expression 15940ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// class-name 15950ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// type-name 15961d922960e083906a586609ac6978678147250177Sebastian RedlParser::OwningExprResult Parser::ParseObjCMessageExpression() { 1597699b66138ac307a32e238463e0eff513ff17d337Chris Lattner assert(Tok.is(tok::l_square) && "'[' expected"); 1598699b66138ac307a32e238463e0eff513ff17d337Chris Lattner SourceLocation LBracLoc = ConsumeBracket(); // consume '[' 1599699b66138ac307a32e238463e0eff513ff17d337Chris Lattner 1600699b66138ac307a32e238463e0eff513ff17d337Chris Lattner // Parse receiver 160114dd98a7952c9559e0d17fff8272bf3be67135afChris Lattner if (isTokObjCMessageIdentifierReceiver()) { 1602699b66138ac307a32e238463e0eff513ff17d337Chris Lattner IdentifierInfo *ReceiverName = Tok.getIdentifierInfo(); 1603d2869925b5f10e00b13fbf3f41bbb17e4c9adbe0Fariborz Jahanian if (ReceiverName != Ident_super || GetLookAheadToken(1).isNot(tok::period)) { 1604d2869925b5f10e00b13fbf3f41bbb17e4c9adbe0Fariborz Jahanian SourceLocation NameLoc = ConsumeToken(); 1605d2869925b5f10e00b13fbf3f41bbb17e4c9adbe0Fariborz Jahanian return ParseObjCMessageExpressionBody(LBracLoc, NameLoc, ReceiverName, 1606d2869925b5f10e00b13fbf3f41bbb17e4c9adbe0Fariborz Jahanian ExprArg(Actions)); 1607d2869925b5f10e00b13fbf3f41bbb17e4c9adbe0Fariborz Jahanian } 1608699b66138ac307a32e238463e0eff513ff17d337Chris Lattner } 1609699b66138ac307a32e238463e0eff513ff17d337Chris Lattner 16102f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl OwningExprResult Res(ParseExpression()); 16110e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Res.isInvalid()) { 16125c749428a9938d5e2e9564b1c9b7a9252c30ee27Chris Lattner SkipUntil(tok::r_square); 16131d922960e083906a586609ac6978678147250177Sebastian Redl return move(Res); 1614699b66138ac307a32e238463e0eff513ff17d337Chris Lattner } 16151d922960e083906a586609ac6978678147250177Sebastian Redl 16160e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(), 161776ad2e85575722e8a38a2bd4648ab4304d9fcd24Sebastian Redl 0, move(Res)); 1618699b66138ac307a32e238463e0eff513ff17d337Chris Lattner} 16191d922960e083906a586609ac6978678147250177Sebastian Redl 1620699b66138ac307a32e238463e0eff513ff17d337Chris Lattner/// ParseObjCMessageExpressionBody - Having parsed "'[' objc-receiver", parse 1621699b66138ac307a32e238463e0eff513ff17d337Chris Lattner/// the rest of a message expression. 16221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 16230ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-message-args: 16240ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-selector 16250ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-keywordarg-list 16260ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// 16270ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-keywordarg-list: 16280ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-keywordarg 16290ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-keywordarg-list objc-keywordarg 16300ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// 16311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// objc-keywordarg: 16320ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// selector-name[opt] ':' objc-keywordexpr 16330ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// 16340ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-keywordexpr: 16350ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// nonempty-expr-list 16360ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// 16370ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// nonempty-expr-list: 16380ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// assignment-expression 16390ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// nonempty-expr-list , assignment-expression 16401d922960e083906a586609ac6978678147250177Sebastian Redl/// 16411d922960e083906a586609ac6978678147250177Sebastian RedlParser::OwningExprResult 1642699b66138ac307a32e238463e0eff513ff17d337Chris LattnerParser::ParseObjCMessageExpressionBody(SourceLocation LBracLoc, 16435cb93b8bf009c4b0ae09b71ba85f54b2a7ea8022Steve Naroff SourceLocation NameLoc, 1644699b66138ac307a32e238463e0eff513ff17d337Chris Lattner IdentifierInfo *ReceiverName, 16451d922960e083906a586609ac6978678147250177Sebastian Redl ExprArg ReceiverExpr) { 1646c4df6d2c05c647a6a5770ba0c749782b6c023a3aSteve Naroff if (Tok.is(tok::code_completion)) { 1647c4df6d2c05c647a6a5770ba0c749782b6c023a3aSteve Naroff if (ReceiverName) 1648d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor Actions.CodeCompleteObjCClassMessage(CurScope, ReceiverName, NameLoc, 1649d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor 0, 0); 1650c4df6d2c05c647a6a5770ba0c749782b6c023a3aSteve Naroff else 1651d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor Actions.CodeCompleteObjCInstanceMessage(CurScope, ReceiverExpr.get(), 1652d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor 0, 0); 1653c4df6d2c05c647a6a5770ba0c749782b6c023a3aSteve Naroff ConsumeToken(); 1654c4df6d2c05c647a6a5770ba0c749782b6c023a3aSteve Naroff } 1655d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor 1656a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian // Parse objc-selector 16574b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian SourceLocation Loc; 16582fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner IdentifierInfo *selIdent = ParseObjCSelectorPiece(Loc); 165968d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff 1660ff975cfab9ada27df86038286d1678084aeb3428Anders Carlsson SourceLocation SelectorLoc = Loc; 16611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 166268d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff llvm::SmallVector<IdentifierInfo *, 12> KeyIdents; 1663a55e52c0802cae3b7c366a05c461d3d15074c1a3Sebastian Redl ExprVector KeyExprs(Actions); 166468d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff 1665df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::colon)) { 1666a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian while (1) { 1667a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian // Each iteration parses a single keyword argument. 166868d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff KeyIdents.push_back(selIdent); 166937387c932855c6d58d70bdd705cd3a9fdcd2a931Steve Naroff 1670df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::colon)) { 1671a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian Diag(Tok, diag::err_expected_colon); 16724fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // We must manually skip to a ']', otherwise the expression skipper will 16734fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // stop at the ']' when it skips to the ';'. We want it to skip beyond 16744fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // the enclosing expression. 16754fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner SkipUntil(tok::r_square); 16761d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(); 1677a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian } 16781d922960e083906a586609ac6978678147250177Sebastian Redl 167968d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff ConsumeToken(); // Eat the ':'. 16801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// Parse the expression after ':' 16812f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl OwningExprResult Res(ParseAssignmentExpression()); 16820e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Res.isInvalid()) { 16834fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // We must manually skip to a ']', otherwise the expression skipper will 16844fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // stop at the ']' when it skips to the ';'. We want it to skip beyond 16854fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // the enclosing expression. 16864fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner SkipUntil(tok::r_square); 16871d922960e083906a586609ac6978678147250177Sebastian Redl return move(Res); 168837387c932855c6d58d70bdd705cd3a9fdcd2a931Steve Naroff } 16891d922960e083906a586609ac6978678147250177Sebastian Redl 169037387c932855c6d58d70bdd705cd3a9fdcd2a931Steve Naroff // We have a valid expression. 1691effa8d1c97b00a3f53e972b0e61d9aade5ea1c57Sebastian Redl KeyExprs.push_back(Res.release()); 16921d922960e083906a586609ac6978678147250177Sebastian Redl 1693d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor // Code completion after each argument. 1694d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor if (Tok.is(tok::code_completion)) { 1695d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor if (ReceiverName) 1696d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor Actions.CodeCompleteObjCClassMessage(CurScope, ReceiverName, NameLoc, 1697d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor KeyIdents.data(), 1698d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor KeyIdents.size()); 1699d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor else 1700d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor Actions.CodeCompleteObjCInstanceMessage(CurScope, ReceiverExpr.get(), 1701d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor KeyIdents.data(), 1702d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor KeyIdents.size()); 1703d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor ConsumeToken(); 1704d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor } 1705d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor 170637387c932855c6d58d70bdd705cd3a9fdcd2a931Steve Naroff // Check for another keyword selector. 17072fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner selIdent = ParseObjCSelectorPiece(Loc); 1708df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (!selIdent && Tok.isNot(tok::colon)) 1709a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian break; 1710a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian // We have a selector or a colon, continue parsing. 1711a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian } 1712a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian // Parse the, optional, argument list, comma separated. 1713df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner while (Tok.is(tok::comma)) { 171449f109c786f99eb7468dac3976db083a65493444Steve Naroff ConsumeToken(); // Eat the ','. 17151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// Parse the expression after ',' 17162f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl OwningExprResult Res(ParseAssignmentExpression()); 17170e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Res.isInvalid()) { 17184fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // We must manually skip to a ']', otherwise the expression skipper will 17194fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // stop at the ']' when it skips to the ';'. We want it to skip beyond 17204fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // the enclosing expression. 17214fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner SkipUntil(tok::r_square); 17221d922960e083906a586609ac6978678147250177Sebastian Redl return move(Res); 172349f109c786f99eb7468dac3976db083a65493444Steve Naroff } 17240e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl 172549f109c786f99eb7468dac3976db083a65493444Steve Naroff // We have a valid expression. 1726effa8d1c97b00a3f53e972b0e61d9aade5ea1c57Sebastian Redl KeyExprs.push_back(Res.release()); 1727a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian } 1728a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian } else if (!selIdent) { 1729a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian Diag(Tok, diag::err_expected_ident); // missing selector name. 17301d922960e083906a586609ac6978678147250177Sebastian Redl 17314fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // We must manually skip to a ']', otherwise the expression skipper will 17324fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // stop at the ']' when it skips to the ';'. We want it to skip beyond 17334fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // the enclosing expression. 17344fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner SkipUntil(tok::r_square); 17351d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(); 1736a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian } 17371d922960e083906a586609ac6978678147250177Sebastian Redl 1738df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::r_square)) { 1739a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian Diag(Tok, diag::err_expected_rsquare); 17404fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // We must manually skip to a ']', otherwise the expression skipper will 17414fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // stop at the ']' when it skips to the ';'. We want it to skip beyond 17424fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // the enclosing expression. 17434fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner SkipUntil(tok::r_square); 17441d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(); 1745a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian } 17461d922960e083906a586609ac6978678147250177Sebastian Redl 1747699b66138ac307a32e238463e0eff513ff17d337Chris Lattner SourceLocation RBracLoc = ConsumeBracket(); // consume ']' 17481d922960e083906a586609ac6978678147250177Sebastian Redl 174929238a0bf7cbf5b396efb451a0adb5fe4aa037caSteve Naroff unsigned nKeys = KeyIdents.size(); 1750ff38491c18b060526d754765b952f4a497a89416Chris Lattner if (nKeys == 0) 1751ff38491c18b060526d754765b952f4a497a89416Chris Lattner KeyIdents.push_back(selIdent); 1752ff38491c18b060526d754765b952f4a497a89416Chris Lattner Selector Sel = PP.getSelectorTable().getSelector(nKeys, &KeyIdents[0]); 17531d922960e083906a586609ac6978678147250177Sebastian Redl 1754ff38491c18b060526d754765b952f4a497a89416Chris Lattner // We've just parsed a keyword message. 17551d922960e083906a586609ac6978678147250177Sebastian Redl if (ReceiverName) 17561d922960e083906a586609ac6978678147250177Sebastian Redl return Owned(Actions.ActOnClassMessage(CurScope, ReceiverName, Sel, 17571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump LBracLoc, NameLoc, SelectorLoc, 1758ff975cfab9ada27df86038286d1678084aeb3428Anders Carlsson RBracLoc, 17591d922960e083906a586609ac6978678147250177Sebastian Redl KeyExprs.take(), KeyExprs.size())); 17601d922960e083906a586609ac6978678147250177Sebastian Redl return Owned(Actions.ActOnInstanceMessage(ReceiverExpr.release(), Sel, 1761ff975cfab9ada27df86038286d1678084aeb3428Anders Carlsson LBracLoc, SelectorLoc, RBracLoc, 17621d922960e083906a586609ac6978678147250177Sebastian Redl KeyExprs.take(), KeyExprs.size())); 17630ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian} 17640ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian 17651d922960e083906a586609ac6978678147250177Sebastian RedlParser::OwningExprResult Parser::ParseObjCStringLiteral(SourceLocation AtLoc) { 176620df9b7ab9388b2a488c5b1293cd196b1e073b4eSebastian Redl OwningExprResult Res(ParseStringLiteralExpression()); 17671d922960e083906a586609ac6978678147250177Sebastian Redl if (Res.isInvalid()) return move(Res); 17681d922960e083906a586609ac6978678147250177Sebastian Redl 1769b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner // @"foo" @"bar" is a valid concatenated string. Eat any subsequent string 1770b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner // expressions. At this point, we know that the only valid thing that starts 1771b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner // with '@' is an @"". 1772b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner llvm::SmallVector<SourceLocation, 4> AtLocs; 1773a55e52c0802cae3b7c366a05c461d3d15074c1a3Sebastian Redl ExprVector AtStrings(Actions); 1774b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner AtLocs.push_back(AtLoc); 1775effa8d1c97b00a3f53e972b0e61d9aade5ea1c57Sebastian Redl AtStrings.push_back(Res.release()); 17760e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl 1777b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner while (Tok.is(tok::at)) { 1778b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner AtLocs.push_back(ConsumeToken()); // eat the @. 1779b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner 178015faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl // Invalid unless there is a string literal. 178197cf6eb380016db868866faf27a086cd55a316d4Chris Lattner if (!isTokenStringLiteral()) 178297cf6eb380016db868866faf27a086cd55a316d4Chris Lattner return ExprError(Diag(Tok, diag::err_objc_concat_string)); 1783b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner 178497cf6eb380016db868866faf27a086cd55a316d4Chris Lattner OwningExprResult Lit(ParseStringLiteralExpression()); 17850e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Lit.isInvalid()) 17861d922960e083906a586609ac6978678147250177Sebastian Redl return move(Lit); 17870e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl 1788effa8d1c97b00a3f53e972b0e61d9aade5ea1c57Sebastian Redl AtStrings.push_back(Lit.release()); 1789b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner } 17901d922960e083906a586609ac6978678147250177Sebastian Redl 17911d922960e083906a586609ac6978678147250177Sebastian Redl return Owned(Actions.ParseObjCStringLiteral(&AtLocs[0], AtStrings.take(), 17921d922960e083906a586609ac6978678147250177Sebastian Redl AtStrings.size())); 17935508518a2702b00be3b15a26d772bde968972f54Anders Carlsson} 1794f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson 1795f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson/// objc-encode-expression: 1796f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson/// @encode ( type-name ) 17971d922960e083906a586609ac6978678147250177Sebastian RedlParser::OwningExprResult 17981d922960e083906a586609ac6978678147250177Sebastian RedlParser::ParseObjCEncodeExpression(SourceLocation AtLoc) { 1799861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff assert(Tok.isObjCAtKeyword(tok::objc_encode) && "Not an @encode expression!"); 18001d922960e083906a586609ac6978678147250177Sebastian Redl 1801f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson SourceLocation EncLoc = ConsumeToken(); 18021d922960e083906a586609ac6978678147250177Sebastian Redl 18034fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner if (Tok.isNot(tok::l_paren)) 18041d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(Tok, diag::err_expected_lparen_after) << "@encode"); 18051d922960e083906a586609ac6978678147250177Sebastian Redl 1806f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson SourceLocation LParenLoc = ConsumeParen(); 18071d922960e083906a586609ac6978678147250177Sebastian Redl 1808809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor TypeResult Ty = ParseTypeName(); 18091d922960e083906a586609ac6978678147250177Sebastian Redl 18104988ae3fda10743c8ed8a98cdcb5a783362587b4Anders Carlsson SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); 18111d922960e083906a586609ac6978678147250177Sebastian Redl 1812809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor if (Ty.isInvalid()) 1813809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor return ExprError(); 1814809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor 18151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return Owned(Actions.ParseObjCEncodeExpression(AtLoc, EncLoc, LParenLoc, 1816809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor Ty.get(), RParenLoc)); 1817f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson} 181829b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson 181929b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson/// objc-protocol-expression 182029b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson/// @protocol ( protocol-name ) 18211d922960e083906a586609ac6978678147250177Sebastian RedlParser::OwningExprResult 18221d922960e083906a586609ac6978678147250177Sebastian RedlParser::ParseObjCProtocolExpression(SourceLocation AtLoc) { 182329b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson SourceLocation ProtoLoc = ConsumeToken(); 18241d922960e083906a586609ac6978678147250177Sebastian Redl 18254fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner if (Tok.isNot(tok::l_paren)) 18261d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(Tok, diag::err_expected_lparen_after) << "@protocol"); 18271d922960e083906a586609ac6978678147250177Sebastian Redl 182829b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson SourceLocation LParenLoc = ConsumeParen(); 18291d922960e083906a586609ac6978678147250177Sebastian Redl 18304fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner if (Tok.isNot(tok::identifier)) 18311d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(Tok, diag::err_expected_ident)); 18321d922960e083906a586609ac6978678147250177Sebastian Redl 1833390d50a725497e99247dc104a7d2c2a255d3af14Fariborz Jahanian IdentifierInfo *protocolId = Tok.getIdentifierInfo(); 183429b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson ConsumeToken(); 18351d922960e083906a586609ac6978678147250177Sebastian Redl 18364988ae3fda10743c8ed8a98cdcb5a783362587b4Anders Carlsson SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); 183729b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson 18381d922960e083906a586609ac6978678147250177Sebastian Redl return Owned(Actions.ParseObjCProtocolExpression(protocolId, AtLoc, ProtoLoc, 18391d922960e083906a586609ac6978678147250177Sebastian Redl LParenLoc, RParenLoc)); 184029b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson} 1841a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian 1842a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian/// objc-selector-expression 1843a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian/// @selector '(' objc-keyword-selector ')' 18441d922960e083906a586609ac6978678147250177Sebastian RedlParser::OwningExprResult 18451d922960e083906a586609ac6978678147250177Sebastian RedlParser::ParseObjCSelectorExpression(SourceLocation AtLoc) { 1846a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian SourceLocation SelectorLoc = ConsumeToken(); 18471d922960e083906a586609ac6978678147250177Sebastian Redl 18484fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner if (Tok.isNot(tok::l_paren)) 18491d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(Tok, diag::err_expected_lparen_after) << "@selector"); 18501d922960e083906a586609ac6978678147250177Sebastian Redl 1851b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian llvm::SmallVector<IdentifierInfo *, 12> KeyIdents; 1852a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian SourceLocation LParenLoc = ConsumeParen(); 1853a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian SourceLocation sLoc; 18542fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner IdentifierInfo *SelIdent = ParseObjCSelectorPiece(sLoc); 18551d922960e083906a586609ac6978678147250177Sebastian Redl if (!SelIdent && Tok.isNot(tok::colon)) // missing selector name. 18561d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(Tok, diag::err_expected_ident)); 18571d922960e083906a586609ac6978678147250177Sebastian Redl 1858b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian KeyIdents.push_back(SelIdent); 1859887407e71fd58de452361b77d72970e32b20ebe0Steve Naroff unsigned nColons = 0; 1860887407e71fd58de452361b77d72970e32b20ebe0Steve Naroff if (Tok.isNot(tok::r_paren)) { 1861a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian while (1) { 18624fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner if (Tok.isNot(tok::colon)) 18631d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(Tok, diag::err_expected_colon)); 18641d922960e083906a586609ac6978678147250177Sebastian Redl 1865cb53b361bce341c8591333c6997f62e480acc0b4Chris Lattner nColons++; 1866a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian ConsumeToken(); // Eat the ':'. 1867a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian if (Tok.is(tok::r_paren)) 1868a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian break; 1869a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian // Check for another keyword selector. 1870a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian SourceLocation Loc; 18712fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner SelIdent = ParseObjCSelectorPiece(Loc); 1872b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian KeyIdents.push_back(SelIdent); 1873a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian if (!SelIdent && Tok.isNot(tok::colon)) 1874a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian break; 1875a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian } 1876887407e71fd58de452361b77d72970e32b20ebe0Steve Naroff } 1877a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); 1878887407e71fd58de452361b77d72970e32b20ebe0Steve Naroff Selector Sel = PP.getSelectorTable().getSelector(nColons, &KeyIdents[0]); 18791d922960e083906a586609ac6978678147250177Sebastian Redl return Owned(Actions.ParseObjCSelectorExpression(Sel, AtLoc, SelectorLoc, 18801d922960e083906a586609ac6978678147250177Sebastian Redl LParenLoc, RParenLoc)); 188158065b2d8038a4e9a91ea4813bd1774c0f6efacbGabor Greif } 1882