ParseObjc.cpp revision 63e963cdffca9530f920dbab58b9b4eecb2a582c
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; 641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer while (1) { 66df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Diag(Tok, diag::err_expected_ident); 685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SkipUntil(tok::semi); 69b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ClassNames.push_back(Tok.getIdentifierInfo()); 725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ConsumeToken(); 731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 74df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::comma)) 755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer break; 761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ConsumeToken(); 785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Consume the ';'. 815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@class")) 82b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 84e440eb8158e71deb1e4ab11618ae3d680aac6da1Steve Naroff return Actions.ActOnForwardClassDeclaration(atLoc, 853536b443bc50d58a79f14fca9b6842541a434854Steve Naroff &ClassNames[0], ClassNames.size()); 865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 88dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 89dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-interface: 90dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-interface-attributes[opt] objc-class-interface 91dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-category-interface 92dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 93dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-interface: 941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// '@' 'interface' identifier objc-superclass[opt] 95dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-refs[opt] 961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// objc-class-instance-variables[opt] 97dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-interface-decl-list 98dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @end 99dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 100dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-category-interface: 1011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// '@' 'interface' identifier '(' identifier[opt] ')' 102dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-refs[opt] 103dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-interface-decl-list 104dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @end 105dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 106dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-superclass: 107dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// ':' identifier 108dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 109dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-interface-attributes: 110dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// __attribute__((visibility("default"))) 111dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// __attribute__((visibility("hidden"))) 112dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// __attribute__((deprecated)) 113dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// __attribute__((unavailable)) 114dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// __attribute__((objc_exception)) - used by NSException on 64-bit 115dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 116b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris LattnerParser::DeclPtrTy Parser::ParseObjCAtInterfaceDeclaration( 117dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff SourceLocation atLoc, AttributeList *attrList) { 118861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff assert(Tok.isObjCAtKeyword(tok::objc_interface) && 119dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff "ParseObjCAtInterfaceDeclaration(): Expected @interface"); 120dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff ConsumeToken(); // the "interface" identifier 1211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 122df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 123dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff Diag(Tok, diag::err_expected_ident); // missing class or category name. 124b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 125dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff } 12663e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian 127dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff // We have a class or category name - consume it. 1287ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff IdentifierInfo *nameId = Tok.getIdentifierInfo(); 129dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff SourceLocation nameLoc = ConsumeToken(); 1301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 131df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::l_paren)) { // we have a category. 132dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff SourceLocation lparenLoc = ConsumeParen(); 133dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff SourceLocation categoryLoc, rparenLoc; 134dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff IdentifierInfo *categoryId = 0; 1351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 136527fe23f8cbc6a4da1737a547a2517bc92fa88c8Steve Naroff // For ObjC2, the category name is optional (not an error). 137df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::identifier)) { 138dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff categoryId = Tok.getIdentifierInfo(); 139dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff categoryLoc = ConsumeToken(); 140527fe23f8cbc6a4da1737a547a2517bc92fa88c8Steve Naroff } else if (!getLang().ObjC2) { 141527fe23f8cbc6a4da1737a547a2517bc92fa88c8Steve Naroff Diag(Tok, diag::err_expected_ident); // missing category name. 142b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 143dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff } 144df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::r_paren)) { 145dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff Diag(Tok, diag::err_expected_rparen); 146dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff SkipUntil(tok::r_paren, false); // don't stop at ';' 147b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 148dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff } 149dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff rparenLoc = ConsumeParen(); 1501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 151dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff // Next, we need to check for any protocol references. 15271b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis SourceLocation LAngleLoc, EndProtoLoc; 153b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner llvm::SmallVector<DeclPtrTy, 8> ProtocolRefs; 15471b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis llvm::SmallVector<SourceLocation, 8> ProtocolLocs; 1556bd6d0b9d8944c5e192097bef24f2becb83af172Chris Lattner if (Tok.is(tok::less) && 15671b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis ParseObjCProtocolReferences(ProtocolRefs, ProtocolLocs, true, 15771b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis LAngleLoc, EndProtoLoc)) 158b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 1591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 160dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff if (attrList) // categories don't support attributes. 161dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff Diag(Tok, diag::err_objc_no_attributes_on_category); 1621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 163beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad DeclPtrTy CategoryType = 1641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Actions.ActOnStartCategoryInterface(atLoc, 165beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad nameId, nameLoc, 166beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad categoryId, categoryLoc, 167beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad ProtocolRefs.data(), 168beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad ProtocolRefs.size(), 169beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad EndProtoLoc); 1701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 171fd225cc227143553898f2d3902242d25db9a4902Fariborz Jahanian ParseObjCInterfaceDeclList(CategoryType, tok::objc_not_keyword); 172bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner return CategoryType; 173dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff } 174dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff // Parse a class interface. 175dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff IdentifierInfo *superClassId = 0; 176dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff SourceLocation superClassLoc; 1777ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff 178df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::colon)) { // a super class is specified. 179dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff ConsumeToken(); 180df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 181dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff Diag(Tok, diag::err_expected_ident); // missing super class name. 182b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 183dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff } 184dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff superClassId = Tok.getIdentifierInfo(); 185dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff superClassLoc = ConsumeToken(); 186dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff } 187dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff // Next, we need to check for any protocol references. 188b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner llvm::SmallVector<Action::DeclPtrTy, 8> ProtocolRefs; 18971b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis llvm::SmallVector<SourceLocation, 8> ProtocolLocs; 19071b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis SourceLocation LAngleLoc, EndProtoLoc; 19106036d3709955a53297b4cbe14e20db88f321470Chris Lattner if (Tok.is(tok::less) && 19271b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis ParseObjCProtocolReferences(ProtocolRefs, ProtocolLocs, true, 19371b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis LAngleLoc, EndProtoLoc)) 194b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 1951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DeclPtrTy ClsType = 1971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Actions.ActOnStartClassInterface(atLoc, nameId, nameLoc, 19806036d3709955a53297b4cbe14e20db88f321470Chris Lattner superClassId, superClassLoc, 199beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad ProtocolRefs.data(), ProtocolRefs.size(), 20006036d3709955a53297b4cbe14e20db88f321470Chris Lattner EndProtoLoc, attrList); 2011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 202df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::l_brace)) 20360fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff ParseObjCClassInstanceVariables(ClsType, atLoc); 204dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff 20525e077d59a8e8e43b65882b69610a3d5e2aaf53cFariborz Jahanian ParseObjCInterfaceDeclList(ClsType, tok::objc_interface); 206bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner return ClsType; 207dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff} 208dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff 209dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-interface-decl-list: 210dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// empty 211dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-interface-decl-list objc-property-decl [OBJC2] 212294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-interface-decl-list objc-method-requirement [OBJC2] 2133536b443bc50d58a79f14fca9b6842541a434854Steve Naroff/// objc-interface-decl-list objc-method-proto ';' 214dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-interface-decl-list declaration 215dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-interface-decl-list ';' 216dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 217294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-method-requirement: [OBJC2] 218294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// @required 219294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// @optional 220294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 221b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattnervoid Parser::ParseObjCInterfaceDeclList(DeclPtrTy interfaceDecl, 222cb53b361bce341c8591333c6997f62e480acc0b4Chris Lattner tok::ObjCKeywordKind contextKey) { 223b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner llvm::SmallVector<DeclPtrTy, 32> allMethods; 224b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner llvm::SmallVector<DeclPtrTy, 16> allProperties; 225682bf92db408a6cbc3d37b5496a99b6ef85041ecChris Lattner llvm::SmallVector<DeclGroupPtrTy, 8> allTUVariables; 22600933591a2795d09dd1acff12a2d21bce7cb12c5Fariborz Jahanian tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword; 2271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 228bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner SourceLocation AtEndLoc; 229bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner 230294494e1cce92043562b4680c613df7fd028c02eSteve Naroff while (1) { 231e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner // If this is a method prototype, parse it. 232df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::minus) || Tok.is(tok::plus)) { 2331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DeclPtrTy methodPrototype = 234df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner ParseObjCMethodPrototype(interfaceDecl, MethodImplKind); 23525e077d59a8e8e43b65882b69610a3d5e2aaf53cFariborz Jahanian allMethods.push_back(methodPrototype); 2363536b443bc50d58a79f14fca9b6842541a434854Steve Naroff // Consume the ';' here, since ParseObjCMethodPrototype() is re-used for 2373536b443bc50d58a79f14fca9b6842541a434854Steve Naroff // method definitions. 238b6d74a158a9c002e3c0fcbda8ad8d0ccbb2e5088Chris Lattner ExpectAndConsume(tok::semi, diag::err_expected_semi_after_method_proto, 239b6d74a158a9c002e3c0fcbda8ad8d0ccbb2e5088Chris Lattner "", tok::semi); 240294494e1cce92043562b4680c613df7fd028c02eSteve Naroff continue; 241294494e1cce92043562b4680c613df7fd028c02eSteve Naroff } 2421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 243e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner // Ignore excess semicolons. 244e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner if (Tok.is(tok::semi)) { 245294494e1cce92043562b4680c613df7fd028c02eSteve Naroff ConsumeToken(); 246e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner continue; 247e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner } 2481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 249bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // If we got to the end of the file, exit the loop. 250e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner if (Tok.is(tok::eof)) 251e3a2ca7e30601cdd31c77a830f4cc487851e8096Fariborz Jahanian break; 2521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 253e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner // If we don't have an @ directive, parse it as a function definition. 254e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner if (Tok.isNot(tok::at)) { 2551fd80116b49782c367ff5d5f50a8b76dd8a5d7f7Chris Lattner // The code below does not consume '}'s because it is afraid of eating the 2561fd80116b49782c367ff5d5f50a8b76dd8a5d7f7Chris Lattner // end of a namespace. Because of the way this code is structured, an 2571fd80116b49782c367ff5d5f50a8b76dd8a5d7f7Chris Lattner // erroneous r_brace would cause an infinite loop if not handled here. 2581fd80116b49782c367ff5d5f50a8b76dd8a5d7f7Chris Lattner if (Tok.is(tok::r_brace)) 2591fd80116b49782c367ff5d5f50a8b76dd8a5d7f7Chris Lattner break; 2601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2614985aceceb9b9261b876b515d32726175c13a775Steve Naroff // FIXME: as the name implies, this rule allows function definitions. 2624985aceceb9b9261b876b515d32726175c13a775Steve Naroff // We could pass a flag or check for functions during semantic analysis. 263682bf92db408a6cbc3d37b5496a99b6ef85041ecChris Lattner allTUVariables.push_back(ParseDeclarationOrFunctionDefinition()); 264e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner continue; 265e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner } 2661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 267e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner // Otherwise, we have an @ directive, eat the @. 268e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner SourceLocation AtLoc = ConsumeToken(); // the "@" 269a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner tok::ObjCKeywordKind DirectiveKind = Tok.getObjCKeywordID(); 2701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 271a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner if (DirectiveKind == tok::objc_end) { // @end -> terminate list 272e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner AtEndLoc = AtLoc; 273e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner break; 274bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner } 2751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 276bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // Eat the identifier. 277bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner ConsumeToken(); 278bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner 279a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner switch (DirectiveKind) { 280a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner default: 281bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // FIXME: If someone forgets an @end on a protocol, this loop will 282bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // continue to eat up tons of stuff and spew lots of nonsense errors. It 283bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // would probably be better to bail out if we saw an @class or @interface 284bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // or something like that. 285f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner Diag(AtLoc, diag::err_objc_illegal_interface_qual); 286bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // Skip until we see an '@' or '}' or ';'. 287a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner SkipUntil(tok::r_brace, tok::at); 288a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner break; 2891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 290a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner case tok::objc_required: 291a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner case tok::objc_optional: 292a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner // This is only valid on protocols. 293bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // FIXME: Should this check for ObjC2 being enabled? 294e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner if (contextKey != tok::objc_protocol) 295bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner Diag(AtLoc, diag::err_objc_directive_only_in_protocol); 296a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner else 297bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner MethodImplKind = DirectiveKind; 298a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner break; 2991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 300a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner case tok::objc_property: 301f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner if (!getLang().ObjC2) 302f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner Diag(AtLoc, diag::err_objc_propertoes_require_objc2); 303f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner 304e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner ObjCDeclSpec OCDS; 3051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // Parse property attribute list, if any. 3068ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner if (Tok.is(tok::l_paren)) 307e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner ParseObjCPropertyAttribute(OCDS); 3081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 309bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall struct ObjCPropertyCallback : FieldCallback { 310bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall Parser &P; 311bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall DeclPtrTy IDecl; 312bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall llvm::SmallVectorImpl<DeclPtrTy> &Props; 313bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall ObjCDeclSpec &OCDS; 314bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall SourceLocation AtLoc; 315bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall tok::ObjCKeywordKind MethodImplKind; 316bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall 317bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall ObjCPropertyCallback(Parser &P, DeclPtrTy IDecl, 318bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall llvm::SmallVectorImpl<DeclPtrTy> &Props, 319bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall ObjCDeclSpec &OCDS, SourceLocation AtLoc, 320bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall tok::ObjCKeywordKind MethodImplKind) : 321bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall P(P), IDecl(IDecl), Props(Props), OCDS(OCDS), AtLoc(AtLoc), 322bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall MethodImplKind(MethodImplKind) { 323bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall } 324bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall 325bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall DeclPtrTy invoke(FieldDeclarator &FD) { 326bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall if (FD.D.getIdentifier() == 0) { 327bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall P.Diag(AtLoc, diag::err_objc_property_requires_field_name) 328bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall << FD.D.getSourceRange(); 329bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall return DeclPtrTy(); 330bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall } 331bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall if (FD.BitfieldSize) { 332bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall P.Diag(AtLoc, diag::err_objc_property_bitfield) 333bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall << FD.D.getSourceRange(); 334bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall return DeclPtrTy(); 335bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall } 336bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall 337bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall // Install the property declarator into interfaceDecl. 338bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall IdentifierInfo *SelName = 339bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall OCDS.getGetterName() ? OCDS.getGetterName() : FD.D.getIdentifier(); 340bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall 341bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall Selector GetterSel = 342bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall P.PP.getSelectorTable().getNullarySelector(SelName); 343bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall IdentifierInfo *SetterName = OCDS.getSetterName(); 344bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall Selector SetterSel; 345bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall if (SetterName) 346bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall SetterSel = P.PP.getSelectorTable().getSelector(1, &SetterName); 347bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall else 348bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall SetterSel = SelectorTable::constructSetterName(P.PP.getIdentifierTable(), 349bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall P.PP.getSelectorTable(), 350bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall FD.D.getIdentifier()); 351bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall bool isOverridingProperty = false; 352bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall DeclPtrTy Property = 353bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall P.Actions.ActOnProperty(P.CurScope, AtLoc, FD, OCDS, 354bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall GetterSel, SetterSel, IDecl, 355bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall &isOverridingProperty, 356bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall MethodImplKind); 357bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall if (!isOverridingProperty) 358bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall Props.push_back(Property); 359bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall 360bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall return Property; 361bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall } 362bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall } Callback(*this, interfaceDecl, allProperties, 363bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall OCDS, AtLoc, MethodImplKind); 364bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall 365e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner // Parse all the comma separated declarators. 366e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner DeclSpec DS; 367bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall ParseStructDeclaration(DS, Callback); 3681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 369a1fed7e3beebf9bb1bc85123f283be3eb631c120Chris Lattner ExpectAndConsume(tok::semi, diag::err_expected_semi_decl_list, "", 370a1fed7e3beebf9bb1bc85123f283be3eb631c120Chris Lattner tok::at); 371a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner break; 372f28b264437053fb0deacc9ba02b18a0966f7290aSteve Naroff } 373294494e1cce92043562b4680c613df7fd028c02eSteve Naroff } 374bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner 375bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // We break out of the big loop in two cases: when we see @end or when we see 376bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // EOF. In the former case, eat the @end. In the later case, emit an error. 377bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner if (Tok.isObjCAtKeyword(tok::objc_end)) 378bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner ConsumeToken(); // the "end" identifier 379bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner else 380bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner Diag(Tok, diag::err_objc_missing_end); 3811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 382a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner // Insert collected methods declarations into the @interface object. 383bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // This passes in an invalid SourceLocation for AtEndLoc when EOF is hit. 3848a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek Actions.ActOnAtEnd(AtEndLoc, interfaceDecl, 3851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump allMethods.data(), allMethods.size(), 386beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad allProperties.data(), allProperties.size(), 387beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad allTUVariables.data(), allTUVariables.size()); 388294494e1cce92043562b4680c613df7fd028c02eSteve Naroff} 389294494e1cce92043562b4680c613df7fd028c02eSteve Naroff 390d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// Parse property attribute declarations. 391d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// 392d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// property-attr-decl: '(' property-attrlist ')' 393d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// property-attrlist: 394d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// property-attribute 395d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// property-attrlist ',' property-attribute 396d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// property-attribute: 397d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// getter '=' identifier 398d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// setter '=' identifier ':' 399d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// readonly 400d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// readwrite 401d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// assign 402d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// retain 403d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// copy 404d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// nonatomic 405d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// 4067caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattnervoid Parser::ParseObjCPropertyAttribute(ObjCDeclSpec &DS) { 4078ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner assert(Tok.getKind() == tok::l_paren); 408dd5b5f2bb73d037745940431b71eb98393d12d4fChris Lattner SourceLocation LHSLoc = ConsumeParen(); // consume '(' 4091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 410cd9f4b31c4fe5b77b5519cc17b4583fab912bad1Chris Lattner while (1) { 411ece8e71d12b6f4cb2dc501297afef126dab8ad74Steve Naroff if (Tok.is(tok::code_completion)) { 412ece8e71d12b6f4cb2dc501297afef126dab8ad74Steve Naroff Actions.CodeCompleteObjCProperty(CurScope, DS); 413ece8e71d12b6f4cb2dc501297afef126dab8ad74Steve Naroff ConsumeToken(); 414ece8e71d12b6f4cb2dc501297afef126dab8ad74Steve Naroff } 415d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian const IdentifierInfo *II = Tok.getIdentifierInfo(); 4161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 417f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner // If this is not an identifier at all, bail out early. 418f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner if (II == 0) { 419f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner MatchRHSPunctuation(tok::r_paren, LHSLoc); 420f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner return; 421f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner } 4221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 423156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner SourceLocation AttrName = ConsumeToken(); // consume last attribute name 4241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 42592e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner if (II->isStr("readonly")) 426e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_readonly); 42792e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner else if (II->isStr("assign")) 428e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_assign); 42992e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner else if (II->isStr("readwrite")) 430e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_readwrite); 43192e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner else if (II->isStr("retain")) 432e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_retain); 43392e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner else if (II->isStr("copy")) 434e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_copy); 43592e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner else if (II->isStr("nonatomic")) 436e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_nonatomic); 43792e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner else if (II->isStr("getter") || II->isStr("setter")) { 438e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner // getter/setter require extra treatment. 439156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner if (ExpectAndConsume(tok::equal, diag::err_objc_expected_equal, "", 440156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner tok::r_paren)) 441dd5b5f2bb73d037745940431b71eb98393d12d4fChris Lattner return; 4421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4438ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner if (Tok.isNot(tok::identifier)) { 4441ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_ident); 4458ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner SkipUntil(tok::r_paren); 4468ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner return; 4478ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner } 4481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 449e013d685c6689ac7ae103ee88acf573422d1ed6aDaniel Dunbar if (II->getNameStart()[0] == 's') { 4508ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_setter); 4518ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner DS.setSetterName(Tok.getIdentifierInfo()); 452156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner ConsumeToken(); // consume method name 4531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 454156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner if (ExpectAndConsume(tok::colon, diag::err_expected_colon, "", 455156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner tok::r_paren)) 4568ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner return; 4578ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner } else { 4588ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_getter); 4598ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner DS.setGetterName(Tok.getIdentifierInfo()); 460156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner ConsumeToken(); // consume method name 4618ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner } 462e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner } else { 463a9500f05ba6c09bbd84d342236863833067cd816Chris Lattner Diag(AttrName, diag::err_objc_expected_property_attr) << II; 464cd9f4b31c4fe5b77b5519cc17b4583fab912bad1Chris Lattner SkipUntil(tok::r_paren); 465cd9f4b31c4fe5b77b5519cc17b4583fab912bad1Chris Lattner return; 466cd9f4b31c4fe5b77b5519cc17b4583fab912bad1Chris Lattner } 4671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 468156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner if (Tok.isNot(tok::comma)) 469156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner break; 4701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 471156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner ConsumeToken(); 472d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian } 4731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 474156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner MatchRHSPunctuation(tok::r_paren, LHSLoc); 475d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian} 476d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian 4773536b443bc50d58a79f14fca9b6842541a434854Steve Naroff/// objc-method-proto: 4781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// objc-instance-method objc-method-decl objc-method-attributes[opt] 4793536b443bc50d58a79f14fca9b6842541a434854Steve Naroff/// objc-class-method objc-method-decl objc-method-attributes[opt] 480294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 481294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-instance-method: '-' 482294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-class-method: '+' 483294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 4844985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-method-attributes: [OBJC2] 4854985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// __attribute__((deprecated)) 4864985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// 4871eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpParser::DeclPtrTy Parser::ParseObjCMethodPrototype(DeclPtrTy IDecl, 488b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner tok::ObjCKeywordKind MethodImplKind) { 489df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner assert((Tok.is(tok::minus) || Tok.is(tok::plus)) && "expected +/-"); 490294494e1cce92043562b4680c613df7fd028c02eSteve Naroff 4911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump tok::TokenKind methodType = Tok.getKind(); 492bef1185418705e16012b3dd50cd7c260c8d6b79cSteve Naroff SourceLocation mLoc = ConsumeToken(); 4931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 494b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy MDecl = ParseObjCMethodDecl(mLoc, methodType, IDecl,MethodImplKind); 4953536b443bc50d58a79f14fca9b6842541a434854Steve Naroff // Since this rule is used for both method declarations and definitions, 4962bd42fadafddc8acf744b57a970bdc96a077c617Steve Naroff // the caller is (optionally) responsible for consuming the ';'. 497f28b264437053fb0deacc9ba02b18a0966f7290aSteve Naroff return MDecl; 498294494e1cce92043562b4680c613df7fd028c02eSteve Naroff} 499294494e1cce92043562b4680c613df7fd028c02eSteve Naroff 500294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-selector: 501294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// identifier 502294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// one of 503294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// enum struct union if else while do for switch case default 504294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// break continue return goto asm sizeof typeof __alignof 505294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// unsigned long const short volatile signed restrict _Complex 506294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// in out inout bycopy byref oneway int char float double void _Bool 507294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 5082fc5c2428ecb450a3256c8316b93b8655cb76a0fChris LattnerIdentifierInfo *Parser::ParseObjCSelectorPiece(SourceLocation &SelectorLoc) { 509ff38491c18b060526d754765b952f4a497a89416Chris Lattner switch (Tok.getKind()) { 510ff38491c18b060526d754765b952f4a497a89416Chris Lattner default: 511ff38491c18b060526d754765b952f4a497a89416Chris Lattner return 0; 512ff38491c18b060526d754765b952f4a497a89416Chris Lattner case tok::identifier: 513ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_asm: 514ff38491c18b060526d754765b952f4a497a89416Chris Lattner case tok::kw_auto: 5159298d9655aed28b2d9f6cc65c81401b209f03fdcChris Lattner case tok::kw_bool: 516ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_break: 517ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_case: 518ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_catch: 519ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_char: 520ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_class: 521ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_const: 522ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_const_cast: 523ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_continue: 524ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_default: 525ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_delete: 526ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_do: 527ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_double: 528ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_dynamic_cast: 529ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_else: 530ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_enum: 531ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_explicit: 532ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_export: 533ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_extern: 534ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_false: 535ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_float: 536ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_for: 537ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_friend: 538ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_goto: 539ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_if: 540ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_inline: 541ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_int: 542ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_long: 543ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_mutable: 544ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_namespace: 545ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_new: 546ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_operator: 547ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_private: 548ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_protected: 549ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_public: 550ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_register: 551ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_reinterpret_cast: 552ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_restrict: 553ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_return: 554ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_short: 555ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_signed: 556ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_sizeof: 557ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_static: 558ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_static_cast: 559ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_struct: 560ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_switch: 561ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_template: 562ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_this: 563ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_throw: 564ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_true: 565ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_try: 566ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_typedef: 567ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_typeid: 568ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_typename: 569ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_typeof: 570ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_union: 571ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_unsigned: 572ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_using: 573ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_virtual: 574ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_void: 575ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_volatile: 576ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_wchar_t: 577ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_while: 578ff38491c18b060526d754765b952f4a497a89416Chris Lattner case tok::kw__Bool: 579ff38491c18b060526d754765b952f4a497a89416Chris Lattner case tok::kw__Complex: 580ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw___alignof: 581ff38491c18b060526d754765b952f4a497a89416Chris Lattner IdentifierInfo *II = Tok.getIdentifierInfo(); 5824b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian SelectorLoc = ConsumeToken(); 583ff38491c18b060526d754765b952f4a497a89416Chris Lattner return II; 584d064951b0dcc95f8604d0d69ae82d9ecbd38c796Fariborz Jahanian } 585294494e1cce92043562b4680c613df7fd028c02eSteve Naroff} 586294494e1cce92043562b4680c613df7fd028c02eSteve Naroff 5870196cab54007ff072ec2642da8911c6b7e8d3fb5Fariborz Jahanian/// objc-for-collection-in: 'in' 5880196cab54007ff072ec2642da8911c6b7e8d3fb5Fariborz Jahanian/// 589335a2d4122e41343fe11a775889b8bec5b14be60Fariborz Jahanianbool Parser::isTokIdentifier_in() const { 5903ba5a0f90a03d5e13d02cbee9abd2a1ba01b18bcFariborz Jahanian // FIXME: May have to do additional look-ahead to only allow for 5913ba5a0f90a03d5e13d02cbee9abd2a1ba01b18bcFariborz Jahanian // valid tokens following an 'in'; such as an identifier, unary operators, 5923ba5a0f90a03d5e13d02cbee9abd2a1ba01b18bcFariborz Jahanian // '[' etc. 5931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return (getLang().ObjC2 && Tok.is(tok::identifier) && 5945ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner Tok.getIdentifierInfo() == ObjCTypeQuals[objc_in]); 5950196cab54007ff072ec2642da8911c6b7e8d3fb5Fariborz Jahanian} 5960196cab54007ff072ec2642da8911c6b7e8d3fb5Fariborz Jahanian 597a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ParseObjCTypeQualifierList - This routine parses the objective-c's type 598e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner/// qualifier list and builds their bitmask representation in the input 599e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner/// argument. 600294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 601294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-type-qualifiers: 602294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-type-qualifier 603294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-type-qualifiers objc-type-qualifier 604294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 605a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekvoid Parser::ParseObjCTypeQualifierList(ObjCDeclSpec &DS) { 606e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner while (1) { 607cb53b361bce341c8591333c6997f62e480acc0b4Chris Lattner if (Tok.isNot(tok::identifier)) 608e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner return; 6091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 610e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner const IdentifierInfo *II = Tok.getIdentifierInfo(); 611e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner for (unsigned i = 0; i != objc_NumQuals; ++i) { 612a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek if (II != ObjCTypeQuals[i]) 613e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner continue; 6141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 615a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCDeclSpec::ObjCDeclQualifier Qual; 616e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner switch (i) { 617e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner default: assert(0 && "Unknown decl qualifier"); 618a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek case objc_in: Qual = ObjCDeclSpec::DQ_In; break; 619a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek case objc_out: Qual = ObjCDeclSpec::DQ_Out; break; 620a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek case objc_inout: Qual = ObjCDeclSpec::DQ_Inout; break; 621a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek case objc_oneway: Qual = ObjCDeclSpec::DQ_Oneway; break; 622a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek case objc_bycopy: Qual = ObjCDeclSpec::DQ_Bycopy; break; 623a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek case objc_byref: Qual = ObjCDeclSpec::DQ_Byref; break; 624e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner } 625a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek DS.setObjCDeclQualifier(Qual); 626e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner ConsumeToken(); 627e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner II = 0; 628e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner break; 629e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner } 6301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 631e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner // If this wasn't a recognized qualifier, bail out. 632e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner if (II) return; 633e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner } 634e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner} 635e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner 636e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner/// objc-type-name: 637e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner/// '(' objc-type-qualifiers[opt] type-name ')' 638e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner/// '(' objc-type-qualifiers[opt] ')' 639e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner/// 640a526c5c67e5a0473c340903ee542ce570119665fTed KremenekParser::TypeTy *Parser::ParseObjCTypeName(ObjCDeclSpec &DS) { 641df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner assert(Tok.is(tok::l_paren) && "expected ("); 6421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6434a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner SourceLocation LParenLoc = ConsumeParen(); 644e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner SourceLocation TypeStartLoc = Tok.getLocation(); 6451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 64619d74e1494fe399f0e2a94e9419c095f8214851bFariborz Jahanian // Parse type qualifiers, in, inout, etc. 647a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ParseObjCTypeQualifierList(DS); 6484fa7afd07421e7276d1717e4fdf43a5fdd65a622Steve Naroff 6494a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner TypeTy *Ty = 0; 650809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor if (isTypeSpecifierQualifier()) { 651809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor TypeResult TypeSpec = ParseTypeName(); 652809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor if (!TypeSpec.isInvalid()) 653809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor Ty = TypeSpec.get(); 654809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor } 6551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6564a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner if (Tok.is(tok::r_paren)) 6574a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner ConsumeParen(); 6584a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner else if (Tok.getLocation() == TypeStartLoc) { 659e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner // If we didn't eat any tokens, then this isn't a type. 6601ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_type); 6614a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner SkipUntil(tok::r_paren); 6624a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner } else { 6634a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner // Otherwise, we found *something*, but didn't get a ')' in the right 6644a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner // place. Emit an error then return what we have as the type. 6654a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner MatchRHSPunctuation(tok::r_paren, LParenLoc); 666294494e1cce92043562b4680c613df7fd028c02eSteve Naroff } 667f28b264437053fb0deacc9ba02b18a0966f7290aSteve Naroff return Ty; 668294494e1cce92043562b4680c613df7fd028c02eSteve Naroff} 669294494e1cce92043562b4680c613df7fd028c02eSteve Naroff 670294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-method-decl: 671294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-selector 6724985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-keyword-selector objc-parmlist[opt] 673294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-type-name objc-selector 6744985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-type-name objc-keyword-selector objc-parmlist[opt] 675294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 676294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-keyword-selector: 6771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// objc-keyword-decl 678294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-keyword-selector objc-keyword-decl 679294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 680294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-keyword-decl: 6817ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// objc-selector ':' objc-type-name objc-keyword-attributes[opt] identifier 6827ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// objc-selector ':' objc-keyword-attributes[opt] identifier 6837ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// ':' objc-type-name objc-keyword-attributes[opt] identifier 6847ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// ':' objc-keyword-attributes[opt] identifier 685294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 6864985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-parmlist: 6874985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-parms objc-ellipsis[opt] 688294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 6894985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-parms: 6904985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-parms , parameter-declaration 691294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 6924985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-ellipsis: 693294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// , ... 694294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 6957ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// objc-keyword-attributes: [OBJC2] 6967ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// __attribute__((unused)) 6977ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// 698b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris LattnerParser::DeclPtrTy Parser::ParseObjCMethodDecl(SourceLocation mLoc, 699b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner tok::TokenKind mType, 700b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy IDecl, 701b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner tok::ObjCKeywordKind MethodImplKind) { 70254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ParsingDeclRAIIObject PD(*this); 70354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 704e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner // Parse the return type if present. 705ff38491c18b060526d754765b952f4a497a89416Chris Lattner TypeTy *ReturnType = 0; 706a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCDeclSpec DSRet; 707df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::l_paren)) 708f1de0ca05e2df6f23bd559028693a12d1ebdaaf6Fariborz Jahanian ReturnType = ParseObjCTypeName(DSRet); 7091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 710bef1185418705e16012b3dd50cd7c260c8d6b79cSteve Naroff SourceLocation selLoc; 7112fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner IdentifierInfo *SelIdent = ParseObjCSelectorPiece(selLoc); 712e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner 71384c431088693e216193094d1dbf327a01173f57fSteve Naroff // An unnamed colon is valid. 71484c431088693e216193094d1dbf327a01173f57fSteve Naroff if (!SelIdent && Tok.isNot(tok::colon)) { // missing selector name. 7151ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_selector_for_method) 7161ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner << SourceRange(mLoc, Tok.getLocation()); 717e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner // Skip until we get a ; or {}. 718e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner SkipUntil(tok::r_brace); 719b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 720e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner } 7211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 722439c65892cc8629bbf541e0b8bda6b64cbcc4e6bFariborz Jahanian llvm::SmallVector<Declarator, 8> CargNames; 723df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::colon)) { 724ff38491c18b060526d754765b952f4a497a89416Chris Lattner // If attributes exist after the method, parse them. 725ff38491c18b060526d754765b952f4a497a89416Chris Lattner AttributeList *MethodAttrs = 0; 7261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (getLang().ObjC2 && Tok.is(tok::kw___attribute)) 727ff38491c18b060526d754765b952f4a497a89416Chris Lattner MethodAttrs = ParseAttributes(); 7281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 729ff38491c18b060526d754765b952f4a497a89416Chris Lattner Selector Sel = PP.getSelectorTable().getNullarySelector(SelIdent); 73054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall DeclPtrTy Result 73154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall = Actions.ActOnMethodDeclaration(mLoc, Tok.getLocation(), 7321f7b6f88f18d7f6b10265acec5d41c4ed1897487Fariborz Jahanian mType, IDecl, DSRet, ReturnType, Sel, 7331c6a3cc88177c67498fccdf14cfdf09959214e41Ted Kremenek 0, CargNames, MethodAttrs, 7341c6a3cc88177c67498fccdf14cfdf09959214e41Ted Kremenek MethodImplKind); 73554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall PD.complete(Result); 73654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall return Result; 737ff38491c18b060526d754765b952f4a497a89416Chris Lattner } 738f28b264437053fb0deacc9ba02b18a0966f7290aSteve Naroff 73968d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff llvm::SmallVector<IdentifierInfo *, 12> KeyIdents; 740e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner llvm::SmallVector<Action::ObjCArgInfo, 12> ArgInfos; 7411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 742ff38491c18b060526d754765b952f4a497a89416Chris Lattner while (1) { 743e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner Action::ObjCArgInfo ArgInfo; 7441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 745ff38491c18b060526d754765b952f4a497a89416Chris Lattner // Each iteration parses a single keyword argument. 746df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::colon)) { 747ff38491c18b060526d754765b952f4a497a89416Chris Lattner Diag(Tok, diag::err_expected_colon); 748ff38491c18b060526d754765b952f4a497a89416Chris Lattner break; 749ff38491c18b060526d754765b952f4a497a89416Chris Lattner } 750ff38491c18b060526d754765b952f4a497a89416Chris Lattner ConsumeToken(); // Eat the ':'. 7511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 752e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner ArgInfo.Type = 0; 753e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner if (Tok.is(tok::l_paren)) // Parse the argument type if present. 754e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner ArgInfo.Type = ParseObjCTypeName(ArgInfo.DeclSpec); 755e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner 756ff38491c18b060526d754765b952f4a497a89416Chris Lattner // If attributes exist before the argument name, parse them. 757e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner ArgInfo.ArgAttrs = 0; 758df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (getLang().ObjC2 && Tok.is(tok::kw___attribute)) 759e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner ArgInfo.ArgAttrs = ParseAttributes(); 7607ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff 761df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 762ff38491c18b060526d754765b952f4a497a89416Chris Lattner Diag(Tok, diag::err_expected_ident); // missing argument name. 763ff38491c18b060526d754765b952f4a497a89416Chris Lattner break; 7644985aceceb9b9261b876b515d32726175c13a775Steve Naroff } 7651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 766e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner ArgInfo.Name = Tok.getIdentifierInfo(); 767e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner ArgInfo.NameLoc = Tok.getLocation(); 768ff38491c18b060526d754765b952f4a497a89416Chris Lattner ConsumeToken(); // Eat the identifier. 7691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 770e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner ArgInfos.push_back(ArgInfo); 771e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner KeyIdents.push_back(SelIdent); 772e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner 773ff38491c18b060526d754765b952f4a497a89416Chris Lattner // Check for another keyword selector. 7744b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian SourceLocation Loc; 7752fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner SelIdent = ParseObjCSelectorPiece(Loc); 776df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (!SelIdent && Tok.isNot(tok::colon)) 777ff38491c18b060526d754765b952f4a497a89416Chris Lattner break; 778ff38491c18b060526d754765b952f4a497a89416Chris Lattner // We have a selector or a colon, continue parsing. 779ff38491c18b060526d754765b952f4a497a89416Chris Lattner } 7801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 781335eafa5be51f6440672a74c73d588af72e96732Steve Naroff bool isVariadic = false; 7821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 783ff38491c18b060526d754765b952f4a497a89416Chris Lattner // Parse the (optional) parameter list. 784df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner while (Tok.is(tok::comma)) { 785ff38491c18b060526d754765b952f4a497a89416Chris Lattner ConsumeToken(); 786df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::ellipsis)) { 787335eafa5be51f6440672a74c73d588af72e96732Steve Naroff isVariadic = true; 7884985aceceb9b9261b876b515d32726175c13a775Steve Naroff ConsumeToken(); 789ff38491c18b060526d754765b952f4a497a89416Chris Lattner break; 7904985aceceb9b9261b876b515d32726175c13a775Steve Naroff } 791ff38491c18b060526d754765b952f4a497a89416Chris Lattner DeclSpec DS; 792ff38491c18b060526d754765b952f4a497a89416Chris Lattner ParseDeclarationSpecifiers(DS); 7931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // Parse the declarator. 794ff38491c18b060526d754765b952f4a497a89416Chris Lattner Declarator ParmDecl(DS, Declarator::PrototypeContext); 795ff38491c18b060526d754765b952f4a497a89416Chris Lattner ParseDeclarator(ParmDecl); 796439c65892cc8629bbf541e0b8bda6b64cbcc4e6bFariborz Jahanian CargNames.push_back(ParmDecl); 7974985aceceb9b9261b876b515d32726175c13a775Steve Naroff } 7981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 799ff38491c18b060526d754765b952f4a497a89416Chris Lattner // FIXME: Add support for optional parmameter list... 800e3a2ca7e30601cdd31c77a830f4cc487851e8096Fariborz Jahanian // If attributes exist after the method, parse them. 801ff38491c18b060526d754765b952f4a497a89416Chris Lattner AttributeList *MethodAttrs = 0; 8021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (getLang().ObjC2 && Tok.is(tok::kw___attribute)) 803ff38491c18b060526d754765b952f4a497a89416Chris Lattner MethodAttrs = ParseAttributes(); 8041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8053688fc679389d67b6755e62406998f9ea84d886aFariborz Jahanian if (KeyIdents.size() == 0) 8063688fc679389d67b6755e62406998f9ea84d886aFariborz Jahanian return DeclPtrTy(); 807ff38491c18b060526d754765b952f4a497a89416Chris Lattner Selector Sel = PP.getSelectorTable().getSelector(KeyIdents.size(), 808ff38491c18b060526d754765b952f4a497a89416Chris Lattner &KeyIdents[0]); 80954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall DeclPtrTy Result 81054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall = Actions.ActOnMethodDeclaration(mLoc, Tok.getLocation(), 8113688fc679389d67b6755e62406998f9ea84d886aFariborz Jahanian mType, IDecl, DSRet, ReturnType, Sel, 8121c6a3cc88177c67498fccdf14cfdf09959214e41Ted Kremenek &ArgInfos[0], CargNames, MethodAttrs, 813335eafa5be51f6440672a74c73d588af72e96732Steve Naroff MethodImplKind, isVariadic); 81454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall PD.complete(Result); 81554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall return Result; 816294494e1cce92043562b4680c613df7fd028c02eSteve Naroff} 817294494e1cce92043562b4680c613df7fd028c02eSteve Naroff 818dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-refs: 819dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// '<' identifier-list '>' 820dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 8217caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattnerbool Parser:: 822b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris LattnerParseObjCProtocolReferences(llvm::SmallVectorImpl<Action::DeclPtrTy> &Protocols, 82371b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis llvm::SmallVectorImpl<SourceLocation> &ProtocolLocs, 82471b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis bool WarnOnDeclarations, 82571b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis SourceLocation &LAngleLoc, SourceLocation &EndLoc) { 826e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner assert(Tok.is(tok::less) && "expected <"); 8271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 82871b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis LAngleLoc = ConsumeToken(); // the "<" 8291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 830e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner llvm::SmallVector<IdentifierLocPair, 8> ProtocolIdents; 8311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 832e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner while (1) { 833e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner if (Tok.isNot(tok::identifier)) { 834e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner Diag(Tok, diag::err_expected_ident); 835e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner SkipUntil(tok::greater); 836e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner return true; 837e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner } 838e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner ProtocolIdents.push_back(std::make_pair(Tok.getIdentifierInfo(), 839e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner Tok.getLocation())); 84071b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis ProtocolLocs.push_back(Tok.getLocation()); 841e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner ConsumeToken(); 8421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 843e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner if (Tok.isNot(tok::comma)) 844e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner break; 845e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner ConsumeToken(); 846e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner } 8471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 848e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner // Consume the '>'. 849e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner if (Tok.isNot(tok::greater)) { 850e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner Diag(Tok, diag::err_expected_greater); 851e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner return true; 852e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner } 8531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 854e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner EndLoc = ConsumeAnyToken(); 8551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 856e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner // Convert the list of protocols identifiers into a list of protocol decls. 857e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner Actions.FindProtocolDeclaration(WarnOnDeclarations, 858e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner &ProtocolIdents[0], ProtocolIdents.size(), 859e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner Protocols); 860e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner return false; 861e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner} 862e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner 863dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-instance-variables: 864dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// '{' objc-instance-variable-decl-list[opt] '}' 865dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 866dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-instance-variable-decl-list: 867dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-visibility-spec 868dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-instance-variable-decl ';' 869dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// ';' 870dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-instance-variable-decl-list objc-visibility-spec 871dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-instance-variable-decl-list objc-instance-variable-decl ';' 872dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-instance-variable-decl-list ';' 873dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 874dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-visibility-spec: 875dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @private 876dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @protected 877dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @public 878ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff/// @package [OBJC2] 879dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 880dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-instance-variable-decl: 8811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// struct-declaration 882dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 883b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattnervoid Parser::ParseObjCClassInstanceVariables(DeclPtrTy interfaceDecl, 88460fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff SourceLocation atLoc) { 885df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner assert(Tok.is(tok::l_brace) && "expected {"); 886b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner llvm::SmallVector<DeclPtrTy, 32> AllIvarDecls; 887e13594279a952537ac903325efff57e3edca79d9Chris Lattner 8881a0d31a3d7f14ddc6370ba912c778aece6c12cf0Douglas Gregor ParseScope ClassScope(this, Scope::DeclScope|Scope::ClassScope); 88972de6676bd30f9081ee4166bbe07b4c270258ce6Douglas Gregor 890ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff SourceLocation LBraceLoc = ConsumeBrace(); // the "{" 8911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 892aa847fe3c88ee5e8d180e48537c58b805d48d95dFariborz Jahanian tok::ObjCKeywordKind visibility = tok::objc_protected; 893ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff // While we still have something to read, read the instance variables. 894df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner while (Tok.isNot(tok::r_brace) && Tok.isNot(tok::eof)) { 895ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff // Each iteration of this loop reads one objc-instance-variable-decl. 8961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 897ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff // Check for extraneous top-level semicolon. 898df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::semi)) { 899c2253f5ca170984fcd4f30f8823148e8cb71336bChris Lattner Diag(Tok, diag::ext_extra_struct_semi) 900c2253f5ca170984fcd4f30f8823148e8cb71336bChris Lattner << CodeModificationHint::CreateRemoval(SourceRange(Tok.getLocation())); 901ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff ConsumeToken(); 902ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff continue; 903ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff } 9041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 905ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff // Set the default visibility to private. 906df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::at)) { // parse objc-visibility-spec 907ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff ConsumeToken(); // eat the @ sign 908861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff switch (Tok.getObjCKeywordID()) { 909ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff case tok::objc_private: 910ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff case tok::objc_public: 911ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff case tok::objc_protected: 912ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff case tok::objc_package: 913861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff visibility = Tok.getObjCKeywordID(); 914ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff ConsumeToken(); 9151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump continue; 916ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff default: 917ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff Diag(Tok, diag::err_objc_illegal_visibility_spec); 918ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff continue; 919ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff } 920ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff } 9211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 922bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall struct ObjCIvarCallback : FieldCallback { 923bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall Parser &P; 924bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall DeclPtrTy IDecl; 925bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall tok::ObjCKeywordKind visibility; 926bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall llvm::SmallVectorImpl<DeclPtrTy> &AllIvarDecls; 927bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall 928bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall ObjCIvarCallback(Parser &P, DeclPtrTy IDecl, tok::ObjCKeywordKind V, 929bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall llvm::SmallVectorImpl<DeclPtrTy> &AllIvarDecls) : 930bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall P(P), IDecl(IDecl), visibility(V), AllIvarDecls(AllIvarDecls) { 931bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall } 932bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall 933bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall DeclPtrTy invoke(FieldDeclarator &FD) { 934bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall // Install the declarator into the interface decl. 935bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall DeclPtrTy Field 936bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall = P.Actions.ActOnIvar(P.CurScope, 937bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall FD.D.getDeclSpec().getSourceRange().getBegin(), 938bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall IDecl, FD.D, FD.BitfieldSize, visibility); 939bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall AllIvarDecls.push_back(Field); 940bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall return Field; 941bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall } 942bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall } Callback(*this, interfaceDecl, visibility, AllIvarDecls); 943bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall 944e13594279a952537ac903325efff57e3edca79d9Chris Lattner // Parse all the comma separated declarators. 945e13594279a952537ac903325efff57e3edca79d9Chris Lattner DeclSpec DS; 946bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall ParseStructDeclaration(DS, Callback); 9471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 948df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::semi)) { 949ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff ConsumeToken(); 950ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff } else { 951ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff Diag(Tok, diag::err_expected_semi_decl_list); 952ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff // Skip to end of block or statement 953ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff SkipUntil(tok::r_brace, true, true); 954ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff } 955ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff } 95660fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff SourceLocation RBraceLoc = MatchRHSPunctuation(tok::r_brace, LBraceLoc); 9578749be53f53384e7846502791ceda6c657228d07Steve Naroff // Call ActOnFields() even if we don't have any decls. This is useful 9588749be53f53384e7846502791ceda6c657228d07Steve Naroff // for code rewriting tools that need to be aware of the empty list. 9598749be53f53384e7846502791ceda6c657228d07Steve Naroff Actions.ActOnFields(CurScope, atLoc, interfaceDecl, 960beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad AllIvarDecls.data(), AllIvarDecls.size(), 9611bfe1c2129771c06fb58ae5e8c079ae30e138309Daniel Dunbar LBraceLoc, RBraceLoc, 0); 962ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff return; 9635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 964dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff 965dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-declaration: 966dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-definition 967dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-forward-reference 968dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 969dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-definition: 9701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// @protocol identifier 9711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// objc-protocol-refs[opt] 9721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// objc-interface-decl-list 973dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @end 974dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 975dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-forward-reference: 976dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @protocol identifier-list ';' 977dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 978dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// "@protocol identifier ;" should be resolved as "@protocol 9793536b443bc50d58a79f14fca9b6842541a434854Steve Naroff/// identifier-list ;": objc-interface-decl-list may not start with a 980dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// semicolon in the first alternative if objc-protocol-refs are omitted. 981b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris LattnerParser::DeclPtrTy Parser::ParseObjCAtProtocolDeclaration(SourceLocation AtLoc, 982b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner AttributeList *attrList) { 983861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff assert(Tok.isObjCAtKeyword(tok::objc_protocol) && 9847ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff "ParseObjCAtProtocolDeclaration(): Expected @protocol"); 9857ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff ConsumeToken(); // the "protocol" identifier 9861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 987df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 9887ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff Diag(Tok, diag::err_expected_ident); // missing protocol name. 989b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 9907ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff } 9917ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff // Save the protocol name, then consume it. 9927ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff IdentifierInfo *protocolName = Tok.getIdentifierInfo(); 9937ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff SourceLocation nameLoc = ConsumeToken(); 9941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 995df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::semi)) { // forward declaration of one protocol. 9967caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner IdentifierLocPair ProtoInfo(protocolName, nameLoc); 9977ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff ConsumeToken(); 9981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return Actions.ActOnForwardProtocolDeclaration(AtLoc, &ProtoInfo, 1, 999bc1c877fe28fb6a825f0b226a0a2da99e713ea03Fariborz Jahanian attrList); 10007ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff } 10011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1002df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::comma)) { // list of forward declarations. 10037caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner llvm::SmallVector<IdentifierLocPair, 8> ProtocolRefs; 10047caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner ProtocolRefs.push_back(std::make_pair(protocolName, nameLoc)); 10057caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner 10067ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff // Parse the list of forward declarations. 10077ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff while (1) { 10087ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff ConsumeToken(); // the ',' 1009df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 10107ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff Diag(Tok, diag::err_expected_ident); 10117ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff SkipUntil(tok::semi); 1012b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 10137ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff } 10147caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner ProtocolRefs.push_back(IdentifierLocPair(Tok.getIdentifierInfo(), 10157caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner Tok.getLocation())); 10167ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff ConsumeToken(); // the identifier 10171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1018df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::comma)) 10197ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff break; 10207ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff } 10217ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff // Consume the ';'. 10227ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff if (ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@protocol")) 1023b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 10241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1025e440eb8158e71deb1e4ab11618ae3d680aac6da1Steve Naroff return Actions.ActOnForwardProtocolDeclaration(AtLoc, 10261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump &ProtocolRefs[0], 1027bc1c877fe28fb6a825f0b226a0a2da99e713ea03Fariborz Jahanian ProtocolRefs.size(), 1028bc1c877fe28fb6a825f0b226a0a2da99e713ea03Fariborz Jahanian attrList); 10297caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner } 10301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10317ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff // Last, and definitely not least, parse a protocol declaration. 103271b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis SourceLocation LAngleLoc, EndProtoLoc; 10337caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner 1034b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner llvm::SmallVector<DeclPtrTy, 8> ProtocolRefs; 103571b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis llvm::SmallVector<SourceLocation, 8> ProtocolLocs; 10367caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner if (Tok.is(tok::less) && 103771b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis ParseObjCProtocolReferences(ProtocolRefs, ProtocolLocs, false, 103871b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis LAngleLoc, EndProtoLoc)) 1039b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 10401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1041b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy ProtoType = 1042e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner Actions.ActOnStartProtocolInterface(AtLoc, protocolName, nameLoc, 1043beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad ProtocolRefs.data(), 1044beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad ProtocolRefs.size(), 1045246e70f69cb8aeb67225c54690f1c6b25abd5a86Daniel Dunbar EndProtoLoc, attrList); 104625e077d59a8e8e43b65882b69610a3d5e2aaf53cFariborz Jahanian ParseObjCInterfaceDeclList(ProtoType, tok::objc_protocol); 1047bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner return ProtoType; 1048dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff} 1049dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff 1050dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-implementation: 1051dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-implementation-prologue 1052dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-category-implementation-prologue 1053dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1054dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-implementation-prologue: 1055dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @implementation identifier objc-superclass[opt] 1056dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-instance-variables[opt] 1057dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1058dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-category-implementation-prologue: 1059dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @implementation identifier ( identifier ) 1060b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris LattnerParser::DeclPtrTy Parser::ParseObjCAtImplementationDeclaration( 1061ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian SourceLocation atLoc) { 1062ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian assert(Tok.isObjCAtKeyword(tok::objc_implementation) && 1063ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian "ParseObjCAtImplementationDeclaration(): Expected @implementation"); 1064ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); // the "implementation" identifier 10651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1066df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 1067ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian Diag(Tok, diag::err_expected_ident); // missing class or category name. 1068b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 1069ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1070ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian // We have a class or category name - consume it. 1071ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian IdentifierInfo *nameId = Tok.getIdentifierInfo(); 1072ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian SourceLocation nameLoc = ConsumeToken(); // consume class or category name 10731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (Tok.is(tok::l_paren)) { 1075ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian // we have a category implementation. 1076ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian SourceLocation lparenLoc = ConsumeParen(); 1077ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian SourceLocation categoryLoc, rparenLoc; 1078ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian IdentifierInfo *categoryId = 0; 10791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1080df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::identifier)) { 1081ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian categoryId = Tok.getIdentifierInfo(); 1082ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian categoryLoc = ConsumeToken(); 1083ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } else { 1084ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian Diag(Tok, diag::err_expected_ident); // missing category name. 1085b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 10861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 1087df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::r_paren)) { 1088ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian Diag(Tok, diag::err_expected_rparen); 1089ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian SkipUntil(tok::r_paren, false); // don't stop at ';' 1090b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 1091ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1092ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian rparenLoc = ConsumeParen(); 1093b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy ImplCatType = Actions.ActOnStartCategoryImplementation( 10941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump atLoc, nameId, nameLoc, categoryId, 10958f3fde00ad4d4f943321e338b914ae4740711c84Fariborz Jahanian categoryLoc); 1096a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCImpDecl = ImplCatType; 109763e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian PendingObjCImpDecl.push_back(ObjCImpDecl); 1098b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 1099ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1100ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian // We have a class implementation 1101ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian SourceLocation superClassLoc; 1102ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian IdentifierInfo *superClassId = 0; 1103df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::colon)) { 1104ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian // We have a super class 1105ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); 1106df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 1107ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian Diag(Tok, diag::err_expected_ident); // missing super class name. 1108b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 1109ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1110ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian superClassId = Tok.getIdentifierInfo(); 1111ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian superClassLoc = ConsumeToken(); // Consume super class name 1112ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1113b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy ImplClsType = Actions.ActOnStartClassImplementation( 1114cb53b361bce341c8591333c6997f62e480acc0b4Chris Lattner atLoc, nameId, nameLoc, 1115ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian superClassId, superClassLoc); 11161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 111760fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff if (Tok.is(tok::l_brace)) // we have ivars 111860fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff ParseObjCClassInstanceVariables(ImplClsType/*FIXME*/, atLoc); 1119a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCImpDecl = ImplClsType; 112063e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian PendingObjCImpDecl.push_back(ObjCImpDecl); 112163e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian 1122b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 11235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 112460fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff 1125b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris LattnerParser::DeclPtrTy Parser::ParseObjCAtEndDeclaration(SourceLocation atLoc) { 1126ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian assert(Tok.isObjCAtKeyword(tok::objc_end) && 1127ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian "ParseObjCAtEndDeclaration(): Expected @end"); 1128b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy Result = ObjCImpDecl; 1129ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); // the "end" identifier 1130a6e3ac514c924879699c6b0b1201028f0091044fFariborz Jahanian if (ObjCImpDecl) { 1131a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek Actions.ActOnAtEnd(atLoc, ObjCImpDecl); 1132b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner ObjCImpDecl = DeclPtrTy(); 113363e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian PendingObjCImpDecl.pop_back(); 1134a6e3ac514c924879699c6b0b1201028f0091044fFariborz Jahanian } 113594cdb25a49bd3716ab56ef6de0ea57d29e686bf2Fariborz Jahanian else 113694cdb25a49bd3716ab56ef6de0ea57d29e686bf2Fariborz Jahanian Diag(atLoc, diag::warn_expected_implementation); // missing @implementation 1137a6e3ac514c924879699c6b0b1201028f0091044fFariborz Jahanian return Result; 11385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 1139e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian 114063e963cdffca9530f920dbab58b9b4eecb2a582cFariborz JahanianParser::DeclGroupPtrTy Parser::RetreivePendingObjCImpDecl() { 114163e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian if (PendingObjCImpDecl.empty()) 114263e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian return Actions.ConvertDeclToDeclGroup(DeclPtrTy()); 114363e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian DeclPtrTy ImpDecl = PendingObjCImpDecl.pop_back_val(); 114463e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian Actions.ActOnAtEnd(SourceLocation(), ImpDecl); 114563e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian return Actions.ConvertDeclToDeclGroup(ImpDecl); 114663e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian} 114763e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian 1148e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian/// compatibility-alias-decl: 1149e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian/// @compatibility_alias alias-name class-name ';' 1150e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian/// 1151b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris LattnerParser::DeclPtrTy Parser::ParseObjCAtAliasDeclaration(SourceLocation atLoc) { 1152e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian assert(Tok.isObjCAtKeyword(tok::objc_compatibility_alias) && 1153e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian "ParseObjCAtAliasDeclaration(): Expected @compatibility_alias"); 1154e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian ConsumeToken(); // consume compatibility_alias 1155df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 1156e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian Diag(Tok, diag::err_expected_ident); 1157b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 1158e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian } 1159243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian IdentifierInfo *aliasId = Tok.getIdentifierInfo(); 1160243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian SourceLocation aliasLoc = ConsumeToken(); // consume alias-name 1161df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 1162e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian Diag(Tok, diag::err_expected_ident); 1163b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 1164e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian } 1165243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian IdentifierInfo *classId = Tok.getIdentifierInfo(); 1166243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian SourceLocation classLoc = ConsumeToken(); // consume class-name; 1167243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian if (Tok.isNot(tok::semi)) { 11681ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_semi_after) << "@compatibility_alias"; 1169b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 1170243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian } 1171b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return Actions.ActOnCompatiblityAlias(atLoc, aliasId, aliasLoc, 1172b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner classId, classLoc); 11735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 11745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1175ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-synthesis: 1176ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// @synthesize property-ivar-list ';' 1177ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// 1178ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-ivar-list: 1179ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-ivar 1180ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-ivar-list ',' property-ivar 1181ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// 1182ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-ivar: 1183ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// identifier 1184ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// identifier '=' identifier 1185ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// 1186b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris LattnerParser::DeclPtrTy Parser::ParseObjCPropertySynthesize(SourceLocation atLoc) { 1187ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian assert(Tok.isObjCAtKeyword(tok::objc_synthesize) && 1188ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian "ParseObjCPropertyDynamic(): Expected '@synthesize'"); 1189f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian SourceLocation loc = ConsumeToken(); // consume synthesize 1190df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 1191ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian Diag(Tok, diag::err_expected_ident); 1192b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 1193ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 11941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1195df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner while (Tok.is(tok::identifier)) { 1196f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian IdentifierInfo *propertyIvar = 0; 1197f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian IdentifierInfo *propertyId = Tok.getIdentifierInfo(); 1198f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian SourceLocation propertyLoc = ConsumeToken(); // consume property name 1199df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::equal)) { 1200ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian // property '=' ivar-name 1201ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); // consume '=' 1202df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 1203ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian Diag(Tok, diag::err_expected_ident); 1204ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian break; 1205ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1206f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian propertyIvar = Tok.getIdentifierInfo(); 1207ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); // consume ivar-name 1208ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1209f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian Actions.ActOnPropertyImplDecl(atLoc, propertyLoc, true, ObjCImpDecl, 1210f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian propertyId, propertyIvar); 1211df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::comma)) 1212ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian break; 1213ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); // consume ',' 1214ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1215df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::semi)) 12161ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_semi_after) << "@synthesize"; 1217d3fdcb5a1bf6bd5e54e18579c054ea3c292a0e28Fariborz Jahanian else 1218d3fdcb5a1bf6bd5e54e18579c054ea3c292a0e28Fariborz Jahanian ConsumeToken(); // consume ';' 1219b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 1220ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian} 1221ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian 1222ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-dynamic: 1223ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// @dynamic property-list 1224ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// 1225ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-list: 1226ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// identifier 1227ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-list ',' identifier 1228ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// 1229b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris LattnerParser::DeclPtrTy Parser::ParseObjCPropertyDynamic(SourceLocation atLoc) { 1230ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian assert(Tok.isObjCAtKeyword(tok::objc_dynamic) && 1231ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian "ParseObjCPropertyDynamic(): Expected '@dynamic'"); 1232ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian SourceLocation loc = ConsumeToken(); // consume dynamic 1233df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 1234ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian Diag(Tok, diag::err_expected_ident); 1235b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 1236ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1237df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner while (Tok.is(tok::identifier)) { 1238c35b9e4e2efad727538c848cf30d4b0eb1031dc9Fariborz Jahanian IdentifierInfo *propertyId = Tok.getIdentifierInfo(); 1239c35b9e4e2efad727538c848cf30d4b0eb1031dc9Fariborz Jahanian SourceLocation propertyLoc = ConsumeToken(); // consume property name 1240c35b9e4e2efad727538c848cf30d4b0eb1031dc9Fariborz Jahanian Actions.ActOnPropertyImplDecl(atLoc, propertyLoc, false, ObjCImpDecl, 1241c35b9e4e2efad727538c848cf30d4b0eb1031dc9Fariborz Jahanian propertyId, 0); 1242c35b9e4e2efad727538c848cf30d4b0eb1031dc9Fariborz Jahanian 1243df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::comma)) 1244ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian break; 1245ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); // consume ',' 1246ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1247df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::semi)) 12481ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_semi_after) << "@dynamic"; 1249b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 1250ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian} 12511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1252397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// objc-throw-statement: 1253397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// throw expression[opt]; 1254397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// 125543bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian RedlParser::OwningStmtResult Parser::ParseObjCThrowStmt(SourceLocation atLoc) { 125615faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl OwningExprResult Res(Actions); 1257397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian ConsumeToken(); // consume throw 1258df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::semi)) { 125939f8f159c488a900e5958d5aab3e467af9ec8a2bFariborz Jahanian Res = ParseExpression(); 12600e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Res.isInvalid()) { 1261397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian SkipUntil(tok::semi); 126243bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 1263397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian } 1264397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian } 126539f8f159c488a900e5958d5aab3e467af9ec8a2bFariborz Jahanian ConsumeToken(); // consume ';' 1266e21dd6ffef4585fa43cd3586ed971217d65bf56cSteve Naroff return Actions.ActOnObjCAtThrowStmt(atLoc, move(Res), CurScope); 1267397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian} 1268397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian 1269c385c90c68dfa376650e2facfbb444b2ec9bd110Fariborz Jahanian/// objc-synchronized-statement: 127078a677bbb5fa115fa0995b5783adeeefad67167eFariborz Jahanian/// @synchronized '(' expression ')' compound-statement 1271c385c90c68dfa376650e2facfbb444b2ec9bd110Fariborz Jahanian/// 127243bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian RedlParser::OwningStmtResult 127343bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian RedlParser::ParseObjCSynchronizedStmt(SourceLocation atLoc) { 1274fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian ConsumeToken(); // consume synchronized 1275fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian if (Tok.isNot(tok::l_paren)) { 12761ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_lparen_after) << "@synchronized"; 127743bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 1278fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian } 1279fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian ConsumeParen(); // '(' 12802f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl OwningExprResult Res(ParseExpression()); 12810e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Res.isInvalid()) { 1282fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian SkipUntil(tok::semi); 128343bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 1284fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian } 1285fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian if (Tok.isNot(tok::r_paren)) { 12861ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_lbrace); 128743bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 1288fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian } 1289fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian ConsumeParen(); // ')' 129078a677bbb5fa115fa0995b5783adeeefad67167eFariborz Jahanian if (Tok.isNot(tok::l_brace)) { 12911ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_lbrace); 129243bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 129378a677bbb5fa115fa0995b5783adeeefad67167eFariborz Jahanian } 12943ac438c383a4a9a73c76a05c76ec5d02f10a3c52Steve Naroff // Enter a scope to hold everything within the compound stmt. Compound 12953ac438c383a4a9a73c76a05c76ec5d02f10a3c52Steve Naroff // statements can always hold declarations. 12968935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor ParseScope BodyScope(this, Scope::DeclScope); 12973ac438c383a4a9a73c76a05c76ec5d02f10a3c52Steve Naroff 129861364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl OwningStmtResult SynchBody(ParseCompoundStatementBody()); 12990e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl 13008935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor BodyScope.Exit(); 13010e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (SynchBody.isInvalid()) 1302fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian SynchBody = Actions.ActOnNullStmt(Tok.getLocation()); 130376ad2e85575722e8a38a2bd4648ab4304d9fcd24Sebastian Redl return Actions.ActOnObjCAtSynchronizedStmt(atLoc, move(Res), move(SynchBody)); 1304c385c90c68dfa376650e2facfbb444b2ec9bd110Fariborz Jahanian} 1305c385c90c68dfa376650e2facfbb444b2ec9bd110Fariborz Jahanian 1306397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// objc-try-catch-statement: 1307397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// @try compound-statement objc-catch-list[opt] 1308397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// @try compound-statement objc-catch-list[opt] @finally compound-statement 1309397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// 1310397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// objc-catch-list: 1311397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// @catch ( parameter-declaration ) compound-statement 1312397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// objc-catch-list @catch ( catch-parameter-declaration ) compound-statement 1313397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// catch-parameter-declaration: 1314397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// parameter-declaration 1315397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// '...' [OBJC2] 1316397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// 131743bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian RedlParser::OwningStmtResult Parser::ParseObjCTryStmt(SourceLocation atLoc) { 1318397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian bool catch_or_finally_seen = false; 131943bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl 1320397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian ConsumeToken(); // consume try 1321df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::l_brace)) { 13221ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_lbrace); 132343bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 1324397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian } 132515faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl OwningStmtResult CatchStmts(Actions); 132615faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl OwningStmtResult FinallyStmt(Actions); 13278935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor ParseScope TryScope(this, Scope::DeclScope); 132861364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl OwningStmtResult TryBody(ParseCompoundStatementBody()); 13298935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor TryScope.Exit(); 13300e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (TryBody.isInvalid()) 1331bd49a647afd9cc534fef13cadf652d4e9c396e2bFariborz Jahanian TryBody = Actions.ActOnNullStmt(Tok.getLocation()); 1332a55e52c0802cae3b7c366a05c461d3d15074c1a3Sebastian Redl 1333df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner while (Tok.is(tok::at)) { 13346b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner // At this point, we need to lookahead to determine if this @ is the start 13356b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner // of an @catch or @finally. We don't want to consume the @ token if this 13366b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner // is an @try or @encode or something else. 13376b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner Token AfterAt = GetLookAheadToken(1); 13386b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner if (!AfterAt.isObjCAtKeyword(tok::objc_catch) && 13396b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner !AfterAt.isObjCAtKeyword(tok::objc_finally)) 13406b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner break; 13410e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl 1342161a9c5afaafb4d527b7efba9675a8b2cbbe32e0Fariborz Jahanian SourceLocation AtCatchFinallyLoc = ConsumeToken(); 1343cb53b361bce341c8591333c6997f62e480acc0b4Chris Lattner if (Tok.isObjCAtKeyword(tok::objc_catch)) { 1344b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy FirstPart; 13453b1191d7eaf2f4984564e01ab84b6713a9d80e70Fariborz Jahanian ConsumeToken(); // consume catch 1346df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::l_paren)) { 1347397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian ConsumeParen(); 1348e21dd6ffef4585fa43cd3586ed971217d65bf56cSteve Naroff ParseScope CatchScope(this, Scope::DeclScope|Scope::AtCatchScope); 1349df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::ellipsis)) { 1350397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian DeclSpec DS; 1351397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian ParseDeclarationSpecifiers(DS); 135243bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl // For some odd reason, the name of the exception variable is 13531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // optional. As a result, we need to use "PrototypeContext", because 13547ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff // we must accept either 'declarator' or 'abstract-declarator' here. 13557ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff Declarator ParmDecl(DS, Declarator::PrototypeContext); 13567ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff ParseDeclarator(ParmDecl); 13577ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff 13587ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff // Inform the actions module about the parameter declarator, so it 13597ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff // gets added to the current scope. 13607ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff FirstPart = Actions.ActOnParamDeclarator(CurScope, ParmDecl); 136164515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff } else 1362397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian ConsumeToken(); // consume '...' 13631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 136493a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff SourceLocation RParenLoc; 13651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 136693a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff if (Tok.is(tok::r_paren)) 136793a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff RParenLoc = ConsumeParen(); 136893a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff else // Skip over garbage, until we get to ')'. Eat the ')'. 136993a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff SkipUntil(tok::r_paren, true, false); 137093a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff 137115faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl OwningStmtResult CatchBody(Actions, true); 1372c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner if (Tok.is(tok::l_brace)) 1373c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner CatchBody = ParseCompoundStatementBody(); 1374c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner else 1375c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner Diag(Tok, diag::err_expected_lbrace); 13760e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (CatchBody.isInvalid()) 13773b1191d7eaf2f4984564e01ab84b6713a9d80e70Fariborz Jahanian CatchBody = Actions.ActOnNullStmt(Tok.getLocation()); 13780e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl CatchStmts = Actions.ActOnObjCAtCatchStmt(AtCatchFinallyLoc, 13797ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff RParenLoc, FirstPart, move(CatchBody), 138076ad2e85575722e8a38a2bd4648ab4304d9fcd24Sebastian Redl move(CatchStmts)); 138164515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff } else { 13821ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(AtCatchFinallyLoc, diag::err_expected_lparen_after) 13831ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner << "@catch clause"; 138443bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 1385397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian } 1386397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian catch_or_finally_seen = true; 13876b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner } else { 13886b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner assert(Tok.isObjCAtKeyword(tok::objc_finally) && "Lookahead confused?"); 138964515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff ConsumeToken(); // consume finally 13908935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor ParseScope FinallyScope(this, Scope::DeclScope); 13910e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl 139215faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl OwningStmtResult FinallyBody(Actions, true); 1393c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner if (Tok.is(tok::l_brace)) 1394c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner FinallyBody = ParseCompoundStatementBody(); 1395c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner else 1396c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner Diag(Tok, diag::err_expected_lbrace); 13970e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (FinallyBody.isInvalid()) 1398161a9c5afaafb4d527b7efba9675a8b2cbbe32e0Fariborz Jahanian FinallyBody = Actions.ActOnNullStmt(Tok.getLocation()); 13990e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl FinallyStmt = Actions.ActOnObjCAtFinallyStmt(AtCatchFinallyLoc, 140076ad2e85575722e8a38a2bd4648ab4304d9fcd24Sebastian Redl move(FinallyBody)); 1401397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian catch_or_finally_seen = true; 1402397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian break; 1403397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian } 1404397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian } 1405bd49a647afd9cc534fef13cadf652d4e9c396e2bFariborz Jahanian if (!catch_or_finally_seen) { 1406397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian Diag(atLoc, diag::err_missing_catch_finally); 140743bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 1408bd49a647afd9cc534fef13cadf652d4e9c396e2bFariborz Jahanian } 140976ad2e85575722e8a38a2bd4648ab4304d9fcd24Sebastian Redl return Actions.ActOnObjCAtTryStmt(atLoc, move(TryBody), move(CatchStmts), 141076ad2e85575722e8a38a2bd4648ab4304d9fcd24Sebastian Redl move(FinallyStmt)); 1411397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian} 1412ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian 14133536b443bc50d58a79f14fca9b6842541a434854Steve Naroff/// objc-method-def: objc-method-proto ';'[opt] '{' body '}' 1414ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// 1415b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris LattnerParser::DeclPtrTy Parser::ParseObjCMethodDefinition() { 1416b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy MDecl = ParseObjCMethodPrototype(ObjCImpDecl); 14171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 141849f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner PrettyStackTraceActionsDecl CrashInfo(MDecl, Tok.getLocation(), Actions, 141949f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner PP.getSourceManager(), 142049f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner "parsing Objective-C method"); 14211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1422ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian // parse optional ';' 1423209a8c2fa23636f6d065d618e7078e164903f5cdFariborz Jahanian if (Tok.is(tok::semi)) { 1424496e45ef3350fabc312c5a807d308c65c50af4dbTed Kremenek if (ObjCImpDecl) { 1425496e45ef3350fabc312c5a807d308c65c50af4dbTed Kremenek Diag(Tok, diag::warn_semicolon_before_method_body) 1426496e45ef3350fabc312c5a807d308c65c50af4dbTed Kremenek << CodeModificationHint::CreateRemoval(SourceRange(Tok.getLocation())); 1427496e45ef3350fabc312c5a807d308c65c50af4dbTed Kremenek } 1428ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); 1429209a8c2fa23636f6d065d618e7078e164903f5cdFariborz Jahanian } 1430ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian 1431409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // We should have an opening brace now. 1432df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::l_brace)) { 1433da323adbb99cee19a203ead852d5d9bfebb23fb7Steve Naroff Diag(Tok, diag::err_expected_method_body); 14341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1435409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // Skip over garbage, until we get to '{'. Don't eat the '{'. 1436409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff SkipUntil(tok::l_brace, true, true); 14371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1438409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // If we didn't find the '{', bail out. 1439409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff if (Tok.isNot(tok::l_brace)) 1440b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 1441ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1442409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff SourceLocation BraceLoc = Tok.getLocation(); 14431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1444409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // Enter a scope for the method body. 14458935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor ParseScope BodyScope(this, Scope::FnScope|Scope::DeclScope); 14461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1447409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // Tell the actions module that we have entered a method definition with the 1448394f3f483fa4e7b472630cfcd03f7840520958c5Steve Naroff // specified Declarator for the method. 1449ebf6443a4f493233f7e8d92b3a991848c8b1c00dSteve Naroff Actions.ActOnStartOfObjCMethodDef(CurScope, MDecl); 145061364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl 145161364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl OwningStmtResult FnBody(ParseCompoundStatementBody()); 145261364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl 1453409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // If the function body could not be parsed, make a bogus compoundstmt. 14540e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (FnBody.isInvalid()) 1455a60528cdac7deee3991c2b48af4df4f315e49e9dSebastian Redl FnBody = Actions.ActOnCompoundStmt(BraceLoc, BraceLoc, 1456a60528cdac7deee3991c2b48af4df4f315e49e9dSebastian Redl MultiStmtArg(Actions), false); 1457798d119415323ebcd029ffe1e0fb442a4ca8adbbSebastian Redl 145832ce8376efb7e0d70e5f7e8fcf685130293f412bSteve Naroff // TODO: Pass argument information. 145932ce8376efb7e0d70e5f7e8fcf685130293f412bSteve Naroff Actions.ActOnFinishFunctionBody(MDecl, move(FnBody)); 14601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1461409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // Leave the function body scope. 14628935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor BodyScope.Exit(); 1463798d119415323ebcd029ffe1e0fb442a4ca8adbbSebastian Redl 146471c0a951d08dc7a2a057df8c15f22b36f6aa47c7Steve Naroff return MDecl; 14655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 14665508518a2702b00be3b15a26d772bde968972f54Anders Carlsson 146743bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian RedlParser::OwningStmtResult Parser::ParseObjCAtStatement(SourceLocation AtLoc) { 146864515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff if (Tok.isObjCAtKeyword(tok::objc_try)) { 14696b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner return ParseObjCTryStmt(AtLoc); 147064515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff } else if (Tok.isObjCAtKeyword(tok::objc_throw)) 147164515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff return ParseObjCThrowStmt(AtLoc); 147264515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff else if (Tok.isObjCAtKeyword(tok::objc_synchronized)) 147364515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff return ParseObjCSynchronizedStmt(AtLoc); 1474d8c4e15138e69a51754cc259c8a592cc47950c8eSebastian Redl OwningExprResult Res(ParseExpressionWithLeadingAt(AtLoc)); 14750e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Res.isInvalid()) { 147664515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff // If the expression is invalid, skip ahead to the next semicolon. Not 147764515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff // doing this opens us up to the possibility of infinite loops if 147864515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff // ParseExpression does not consume any tokens. 147964515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff SkipUntil(tok::semi); 148043bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 148164515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff } 148264515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff // Otherwise, eat the semicolon. 148364515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff ExpectAndConsume(tok::semi, diag::err_expected_semi_after_expr); 14846b1d283fe879fb11d7ce7a69feecf66e77b0eaf3Anders Carlsson return Actions.ActOnExprStmt(Actions.FullExpr(Res)); 148564515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff} 148664515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff 14871d922960e083906a586609ac6978678147250177Sebastian RedlParser::OwningExprResult Parser::ParseObjCAtExpression(SourceLocation AtLoc) { 14885508518a2702b00be3b15a26d772bde968972f54Anders Carlsson switch (Tok.getKind()) { 1489b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner case tok::string_literal: // primary-expression: string-literal 1490b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner case tok::wide_string_literal: 14911d922960e083906a586609ac6978678147250177Sebastian Redl return ParsePostfixExpressionSuffix(ParseObjCStringLiteral(AtLoc)); 1492b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner default: 14934fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner if (Tok.getIdentifierInfo() == 0) 14941d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(AtLoc, diag::err_unexpected_at)); 14952f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl 14964fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner switch (Tok.getIdentifierInfo()->getObjCKeywordID()) { 14974fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner case tok::objc_encode: 14981d922960e083906a586609ac6978678147250177Sebastian Redl return ParsePostfixExpressionSuffix(ParseObjCEncodeExpression(AtLoc)); 14994fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner case tok::objc_protocol: 15001d922960e083906a586609ac6978678147250177Sebastian Redl return ParsePostfixExpressionSuffix(ParseObjCProtocolExpression(AtLoc)); 15014fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner case tok::objc_selector: 15021d922960e083906a586609ac6978678147250177Sebastian Redl return ParsePostfixExpressionSuffix(ParseObjCSelectorExpression(AtLoc)); 15034fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner default: 15041d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(AtLoc, diag::err_unexpected_at)); 15054fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner } 15065508518a2702b00be3b15a26d772bde968972f54Anders Carlsson } 15075508518a2702b00be3b15a26d772bde968972f54Anders Carlsson} 15085508518a2702b00be3b15a26d772bde968972f54Anders Carlsson 15091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// objc-message-expr: 15100ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// '[' objc-receiver objc-message-args ']' 15110ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// 15120ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-receiver: 15130ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// expression 15140ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// class-name 15150ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// type-name 15161d922960e083906a586609ac6978678147250177Sebastian RedlParser::OwningExprResult Parser::ParseObjCMessageExpression() { 1517699b66138ac307a32e238463e0eff513ff17d337Chris Lattner assert(Tok.is(tok::l_square) && "'[' expected"); 1518699b66138ac307a32e238463e0eff513ff17d337Chris Lattner SourceLocation LBracLoc = ConsumeBracket(); // consume '[' 1519699b66138ac307a32e238463e0eff513ff17d337Chris Lattner 1520699b66138ac307a32e238463e0eff513ff17d337Chris Lattner // Parse receiver 152114dd98a7952c9559e0d17fff8272bf3be67135afChris Lattner if (isTokObjCMessageIdentifierReceiver()) { 1522699b66138ac307a32e238463e0eff513ff17d337Chris Lattner IdentifierInfo *ReceiverName = Tok.getIdentifierInfo(); 1523d2869925b5f10e00b13fbf3f41bbb17e4c9adbe0Fariborz Jahanian if (ReceiverName != Ident_super || GetLookAheadToken(1).isNot(tok::period)) { 1524d2869925b5f10e00b13fbf3f41bbb17e4c9adbe0Fariborz Jahanian SourceLocation NameLoc = ConsumeToken(); 1525d2869925b5f10e00b13fbf3f41bbb17e4c9adbe0Fariborz Jahanian return ParseObjCMessageExpressionBody(LBracLoc, NameLoc, ReceiverName, 1526d2869925b5f10e00b13fbf3f41bbb17e4c9adbe0Fariborz Jahanian ExprArg(Actions)); 1527d2869925b5f10e00b13fbf3f41bbb17e4c9adbe0Fariborz Jahanian } 1528699b66138ac307a32e238463e0eff513ff17d337Chris Lattner } 1529699b66138ac307a32e238463e0eff513ff17d337Chris Lattner 15302f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl OwningExprResult Res(ParseExpression()); 15310e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Res.isInvalid()) { 15325c749428a9938d5e2e9564b1c9b7a9252c30ee27Chris Lattner SkipUntil(tok::r_square); 15331d922960e083906a586609ac6978678147250177Sebastian Redl return move(Res); 1534699b66138ac307a32e238463e0eff513ff17d337Chris Lattner } 15351d922960e083906a586609ac6978678147250177Sebastian Redl 15360e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(), 153776ad2e85575722e8a38a2bd4648ab4304d9fcd24Sebastian Redl 0, move(Res)); 1538699b66138ac307a32e238463e0eff513ff17d337Chris Lattner} 15391d922960e083906a586609ac6978678147250177Sebastian Redl 1540699b66138ac307a32e238463e0eff513ff17d337Chris Lattner/// ParseObjCMessageExpressionBody - Having parsed "'[' objc-receiver", parse 1541699b66138ac307a32e238463e0eff513ff17d337Chris Lattner/// the rest of a message expression. 15421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 15430ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-message-args: 15440ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-selector 15450ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-keywordarg-list 15460ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// 15470ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-keywordarg-list: 15480ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-keywordarg 15490ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-keywordarg-list objc-keywordarg 15500ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// 15511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// objc-keywordarg: 15520ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// selector-name[opt] ':' objc-keywordexpr 15530ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// 15540ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-keywordexpr: 15550ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// nonempty-expr-list 15560ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// 15570ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// nonempty-expr-list: 15580ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// assignment-expression 15590ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// nonempty-expr-list , assignment-expression 15601d922960e083906a586609ac6978678147250177Sebastian Redl/// 15611d922960e083906a586609ac6978678147250177Sebastian RedlParser::OwningExprResult 1562699b66138ac307a32e238463e0eff513ff17d337Chris LattnerParser::ParseObjCMessageExpressionBody(SourceLocation LBracLoc, 15635cb93b8bf009c4b0ae09b71ba85f54b2a7ea8022Steve Naroff SourceLocation NameLoc, 1564699b66138ac307a32e238463e0eff513ff17d337Chris Lattner IdentifierInfo *ReceiverName, 15651d922960e083906a586609ac6978678147250177Sebastian Redl ExprArg ReceiverExpr) { 1566c4df6d2c05c647a6a5770ba0c749782b6c023a3aSteve Naroff if (Tok.is(tok::code_completion)) { 1567c4df6d2c05c647a6a5770ba0c749782b6c023a3aSteve Naroff if (ReceiverName) 1568c4df6d2c05c647a6a5770ba0c749782b6c023a3aSteve Naroff Actions.CodeCompleteObjCFactoryMethod(CurScope, ReceiverName); 1569c4df6d2c05c647a6a5770ba0c749782b6c023a3aSteve Naroff else 1570c4df6d2c05c647a6a5770ba0c749782b6c023a3aSteve Naroff Actions.CodeCompleteObjCInstanceMethod(CurScope, ReceiverExpr.release()); 1571c4df6d2c05c647a6a5770ba0c749782b6c023a3aSteve Naroff ConsumeToken(); 1572c4df6d2c05c647a6a5770ba0c749782b6c023a3aSteve Naroff } 1573a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian // Parse objc-selector 15744b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian SourceLocation Loc; 15752fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner IdentifierInfo *selIdent = ParseObjCSelectorPiece(Loc); 157668d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff 1577ff975cfab9ada27df86038286d1678084aeb3428Anders Carlsson SourceLocation SelectorLoc = Loc; 15781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 157968d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff llvm::SmallVector<IdentifierInfo *, 12> KeyIdents; 1580a55e52c0802cae3b7c366a05c461d3d15074c1a3Sebastian Redl ExprVector KeyExprs(Actions); 158168d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff 1582df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::colon)) { 1583a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian while (1) { 1584a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian // Each iteration parses a single keyword argument. 158568d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff KeyIdents.push_back(selIdent); 158637387c932855c6d58d70bdd705cd3a9fdcd2a931Steve Naroff 1587df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::colon)) { 1588a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian Diag(Tok, diag::err_expected_colon); 15894fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // We must manually skip to a ']', otherwise the expression skipper will 15904fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // stop at the ']' when it skips to the ';'. We want it to skip beyond 15914fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // the enclosing expression. 15924fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner SkipUntil(tok::r_square); 15931d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(); 1594a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian } 15951d922960e083906a586609ac6978678147250177Sebastian Redl 159668d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff ConsumeToken(); // Eat the ':'. 15971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// Parse the expression after ':' 15982f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl OwningExprResult Res(ParseAssignmentExpression()); 15990e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Res.isInvalid()) { 16004fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // We must manually skip to a ']', otherwise the expression skipper will 16014fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // stop at the ']' when it skips to the ';'. We want it to skip beyond 16024fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // the enclosing expression. 16034fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner SkipUntil(tok::r_square); 16041d922960e083906a586609ac6978678147250177Sebastian Redl return move(Res); 160537387c932855c6d58d70bdd705cd3a9fdcd2a931Steve Naroff } 16061d922960e083906a586609ac6978678147250177Sebastian Redl 160737387c932855c6d58d70bdd705cd3a9fdcd2a931Steve Naroff // We have a valid expression. 1608effa8d1c97b00a3f53e972b0e61d9aade5ea1c57Sebastian Redl KeyExprs.push_back(Res.release()); 16091d922960e083906a586609ac6978678147250177Sebastian Redl 161037387c932855c6d58d70bdd705cd3a9fdcd2a931Steve Naroff // Check for another keyword selector. 16112fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner selIdent = ParseObjCSelectorPiece(Loc); 1612df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (!selIdent && Tok.isNot(tok::colon)) 1613a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian break; 1614a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian // We have a selector or a colon, continue parsing. 1615a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian } 1616a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian // Parse the, optional, argument list, comma separated. 1617df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner while (Tok.is(tok::comma)) { 161849f109c786f99eb7468dac3976db083a65493444Steve Naroff ConsumeToken(); // Eat the ','. 16191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// Parse the expression after ',' 16202f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl OwningExprResult Res(ParseAssignmentExpression()); 16210e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Res.isInvalid()) { 16224fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // We must manually skip to a ']', otherwise the expression skipper will 16234fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // stop at the ']' when it skips to the ';'. We want it to skip beyond 16244fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // the enclosing expression. 16254fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner SkipUntil(tok::r_square); 16261d922960e083906a586609ac6978678147250177Sebastian Redl return move(Res); 162749f109c786f99eb7468dac3976db083a65493444Steve Naroff } 16280e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl 162949f109c786f99eb7468dac3976db083a65493444Steve Naroff // We have a valid expression. 1630effa8d1c97b00a3f53e972b0e61d9aade5ea1c57Sebastian Redl KeyExprs.push_back(Res.release()); 1631a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian } 1632a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian } else if (!selIdent) { 1633a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian Diag(Tok, diag::err_expected_ident); // missing selector name. 16341d922960e083906a586609ac6978678147250177Sebastian Redl 16354fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // We must manually skip to a ']', otherwise the expression skipper will 16364fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // stop at the ']' when it skips to the ';'. We want it to skip beyond 16374fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // the enclosing expression. 16384fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner SkipUntil(tok::r_square); 16391d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(); 1640a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian } 16411d922960e083906a586609ac6978678147250177Sebastian Redl 1642df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::r_square)) { 1643a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian Diag(Tok, diag::err_expected_rsquare); 16444fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // We must manually skip to a ']', otherwise the expression skipper will 16454fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // stop at the ']' when it skips to the ';'. We want it to skip beyond 16464fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // the enclosing expression. 16474fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner SkipUntil(tok::r_square); 16481d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(); 1649a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian } 16501d922960e083906a586609ac6978678147250177Sebastian Redl 1651699b66138ac307a32e238463e0eff513ff17d337Chris Lattner SourceLocation RBracLoc = ConsumeBracket(); // consume ']' 16521d922960e083906a586609ac6978678147250177Sebastian Redl 165329238a0bf7cbf5b396efb451a0adb5fe4aa037caSteve Naroff unsigned nKeys = KeyIdents.size(); 1654ff38491c18b060526d754765b952f4a497a89416Chris Lattner if (nKeys == 0) 1655ff38491c18b060526d754765b952f4a497a89416Chris Lattner KeyIdents.push_back(selIdent); 1656ff38491c18b060526d754765b952f4a497a89416Chris Lattner Selector Sel = PP.getSelectorTable().getSelector(nKeys, &KeyIdents[0]); 16571d922960e083906a586609ac6978678147250177Sebastian Redl 1658ff38491c18b060526d754765b952f4a497a89416Chris Lattner // We've just parsed a keyword message. 16591d922960e083906a586609ac6978678147250177Sebastian Redl if (ReceiverName) 16601d922960e083906a586609ac6978678147250177Sebastian Redl return Owned(Actions.ActOnClassMessage(CurScope, ReceiverName, Sel, 16611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump LBracLoc, NameLoc, SelectorLoc, 1662ff975cfab9ada27df86038286d1678084aeb3428Anders Carlsson RBracLoc, 16631d922960e083906a586609ac6978678147250177Sebastian Redl KeyExprs.take(), KeyExprs.size())); 16641d922960e083906a586609ac6978678147250177Sebastian Redl return Owned(Actions.ActOnInstanceMessage(ReceiverExpr.release(), Sel, 1665ff975cfab9ada27df86038286d1678084aeb3428Anders Carlsson LBracLoc, SelectorLoc, RBracLoc, 16661d922960e083906a586609ac6978678147250177Sebastian Redl KeyExprs.take(), KeyExprs.size())); 16670ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian} 16680ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian 16691d922960e083906a586609ac6978678147250177Sebastian RedlParser::OwningExprResult Parser::ParseObjCStringLiteral(SourceLocation AtLoc) { 167020df9b7ab9388b2a488c5b1293cd196b1e073b4eSebastian Redl OwningExprResult Res(ParseStringLiteralExpression()); 16711d922960e083906a586609ac6978678147250177Sebastian Redl if (Res.isInvalid()) return move(Res); 16721d922960e083906a586609ac6978678147250177Sebastian Redl 1673b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner // @"foo" @"bar" is a valid concatenated string. Eat any subsequent string 1674b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner // expressions. At this point, we know that the only valid thing that starts 1675b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner // with '@' is an @"". 1676b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner llvm::SmallVector<SourceLocation, 4> AtLocs; 1677a55e52c0802cae3b7c366a05c461d3d15074c1a3Sebastian Redl ExprVector AtStrings(Actions); 1678b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner AtLocs.push_back(AtLoc); 1679effa8d1c97b00a3f53e972b0e61d9aade5ea1c57Sebastian Redl AtStrings.push_back(Res.release()); 16800e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl 1681b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner while (Tok.is(tok::at)) { 1682b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner AtLocs.push_back(ConsumeToken()); // eat the @. 1683b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner 168415faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl // Invalid unless there is a string literal. 168597cf6eb380016db868866faf27a086cd55a316d4Chris Lattner if (!isTokenStringLiteral()) 168697cf6eb380016db868866faf27a086cd55a316d4Chris Lattner return ExprError(Diag(Tok, diag::err_objc_concat_string)); 1687b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner 168897cf6eb380016db868866faf27a086cd55a316d4Chris Lattner OwningExprResult Lit(ParseStringLiteralExpression()); 16890e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Lit.isInvalid()) 16901d922960e083906a586609ac6978678147250177Sebastian Redl return move(Lit); 16910e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl 1692effa8d1c97b00a3f53e972b0e61d9aade5ea1c57Sebastian Redl AtStrings.push_back(Lit.release()); 1693b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner } 16941d922960e083906a586609ac6978678147250177Sebastian Redl 16951d922960e083906a586609ac6978678147250177Sebastian Redl return Owned(Actions.ParseObjCStringLiteral(&AtLocs[0], AtStrings.take(), 16961d922960e083906a586609ac6978678147250177Sebastian Redl AtStrings.size())); 16975508518a2702b00be3b15a26d772bde968972f54Anders Carlsson} 1698f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson 1699f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson/// objc-encode-expression: 1700f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson/// @encode ( type-name ) 17011d922960e083906a586609ac6978678147250177Sebastian RedlParser::OwningExprResult 17021d922960e083906a586609ac6978678147250177Sebastian RedlParser::ParseObjCEncodeExpression(SourceLocation AtLoc) { 1703861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff assert(Tok.isObjCAtKeyword(tok::objc_encode) && "Not an @encode expression!"); 17041d922960e083906a586609ac6978678147250177Sebastian Redl 1705f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson SourceLocation EncLoc = ConsumeToken(); 17061d922960e083906a586609ac6978678147250177Sebastian Redl 17074fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner if (Tok.isNot(tok::l_paren)) 17081d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(Tok, diag::err_expected_lparen_after) << "@encode"); 17091d922960e083906a586609ac6978678147250177Sebastian Redl 1710f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson SourceLocation LParenLoc = ConsumeParen(); 17111d922960e083906a586609ac6978678147250177Sebastian Redl 1712809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor TypeResult Ty = ParseTypeName(); 17131d922960e083906a586609ac6978678147250177Sebastian Redl 17144988ae3fda10743c8ed8a98cdcb5a783362587b4Anders Carlsson SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); 17151d922960e083906a586609ac6978678147250177Sebastian Redl 1716809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor if (Ty.isInvalid()) 1717809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor return ExprError(); 1718809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor 17191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return Owned(Actions.ParseObjCEncodeExpression(AtLoc, EncLoc, LParenLoc, 1720809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor Ty.get(), RParenLoc)); 1721f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson} 172229b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson 172329b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson/// objc-protocol-expression 172429b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson/// @protocol ( protocol-name ) 17251d922960e083906a586609ac6978678147250177Sebastian RedlParser::OwningExprResult 17261d922960e083906a586609ac6978678147250177Sebastian RedlParser::ParseObjCProtocolExpression(SourceLocation AtLoc) { 172729b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson SourceLocation ProtoLoc = ConsumeToken(); 17281d922960e083906a586609ac6978678147250177Sebastian Redl 17294fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner if (Tok.isNot(tok::l_paren)) 17301d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(Tok, diag::err_expected_lparen_after) << "@protocol"); 17311d922960e083906a586609ac6978678147250177Sebastian Redl 173229b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson SourceLocation LParenLoc = ConsumeParen(); 17331d922960e083906a586609ac6978678147250177Sebastian Redl 17344fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner if (Tok.isNot(tok::identifier)) 17351d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(Tok, diag::err_expected_ident)); 17361d922960e083906a586609ac6978678147250177Sebastian Redl 1737390d50a725497e99247dc104a7d2c2a255d3af14Fariborz Jahanian IdentifierInfo *protocolId = Tok.getIdentifierInfo(); 173829b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson ConsumeToken(); 17391d922960e083906a586609ac6978678147250177Sebastian Redl 17404988ae3fda10743c8ed8a98cdcb5a783362587b4Anders Carlsson SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); 174129b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson 17421d922960e083906a586609ac6978678147250177Sebastian Redl return Owned(Actions.ParseObjCProtocolExpression(protocolId, AtLoc, ProtoLoc, 17431d922960e083906a586609ac6978678147250177Sebastian Redl LParenLoc, RParenLoc)); 174429b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson} 1745a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian 1746a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian/// objc-selector-expression 1747a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian/// @selector '(' objc-keyword-selector ')' 17481d922960e083906a586609ac6978678147250177Sebastian RedlParser::OwningExprResult 17491d922960e083906a586609ac6978678147250177Sebastian RedlParser::ParseObjCSelectorExpression(SourceLocation AtLoc) { 1750a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian SourceLocation SelectorLoc = ConsumeToken(); 17511d922960e083906a586609ac6978678147250177Sebastian Redl 17524fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner if (Tok.isNot(tok::l_paren)) 17531d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(Tok, diag::err_expected_lparen_after) << "@selector"); 17541d922960e083906a586609ac6978678147250177Sebastian Redl 1755b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian llvm::SmallVector<IdentifierInfo *, 12> KeyIdents; 1756a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian SourceLocation LParenLoc = ConsumeParen(); 1757a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian SourceLocation sLoc; 17582fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner IdentifierInfo *SelIdent = ParseObjCSelectorPiece(sLoc); 17591d922960e083906a586609ac6978678147250177Sebastian Redl if (!SelIdent && Tok.isNot(tok::colon)) // missing selector name. 17601d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(Tok, diag::err_expected_ident)); 17611d922960e083906a586609ac6978678147250177Sebastian Redl 1762b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian KeyIdents.push_back(SelIdent); 1763887407e71fd58de452361b77d72970e32b20ebe0Steve Naroff unsigned nColons = 0; 1764887407e71fd58de452361b77d72970e32b20ebe0Steve Naroff if (Tok.isNot(tok::r_paren)) { 1765a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian while (1) { 17664fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner if (Tok.isNot(tok::colon)) 17671d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(Tok, diag::err_expected_colon)); 17681d922960e083906a586609ac6978678147250177Sebastian Redl 1769cb53b361bce341c8591333c6997f62e480acc0b4Chris Lattner nColons++; 1770a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian ConsumeToken(); // Eat the ':'. 1771a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian if (Tok.is(tok::r_paren)) 1772a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian break; 1773a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian // Check for another keyword selector. 1774a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian SourceLocation Loc; 17752fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner SelIdent = ParseObjCSelectorPiece(Loc); 1776b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian KeyIdents.push_back(SelIdent); 1777a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian if (!SelIdent && Tok.isNot(tok::colon)) 1778a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian break; 1779a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian } 1780887407e71fd58de452361b77d72970e32b20ebe0Steve Naroff } 1781a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); 1782887407e71fd58de452361b77d72970e32b20ebe0Steve Naroff Selector Sel = PP.getSelectorTable().getSelector(nColons, &KeyIdents[0]); 17831d922960e083906a586609ac6978678147250177Sebastian Redl return Owned(Actions.ParseObjCSelectorExpression(Sel, AtLoc, SelectorLoc, 17841d922960e083906a586609ac6978678147250177Sebastian Redl LParenLoc, RParenLoc)); 178558065b2d8038a4e9a91ea4813bd1774c0f6efacbGabor Greif } 1786