ParseObjc.cpp revision 10af87932fe4bffad539b24d512a33a1803daeae
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 14500d3297d2a21edeac4d46cbcbe21bc2352c2a28Chris Lattner#include "clang/Parse/ParseDiagnostic.h" 1519510856727e0e14a3696b2a72c35163bff2a71fJohn McCall#include "clang/Parse/Parser.h" 160fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor#include "RAIIObjectsForParser.h" 1719510856727e0e14a3696b2a72c35163bff2a71fJohn McCall#include "clang/Sema/DeclSpec.h" 18f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall#include "clang/Sema/PrettyDeclStackTrace.h" 1919510856727e0e14a3696b2a72c35163bff2a71fJohn McCall#include "clang/Sema/Scope.h" 205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "llvm/ADT/SmallVector.h" 215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing namespace clang; 225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 24891dca671a80c865c6def7259f170ba785e4faaaChris Lattner/// ParseObjCAtDirectives - Handle parts of the external-declaration production: 255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// external-declaration: [C99 6.9] 265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// [OBJC] objc-class-definition 2791fa0b7759b575045142abd6ee48c076297ad77bSteve Naroff/// [OBJC] objc-class-declaration 2891fa0b7759b575045142abd6ee48c076297ad77bSteve Naroff/// [OBJC] objc-alias-declaration 2991fa0b7759b575045142abd6ee48c076297ad77bSteve Naroff/// [OBJC] objc-protocol-definition 3091fa0b7759b575045142abd6ee48c076297ad77bSteve Naroff/// [OBJC] objc-method-definition 3191fa0b7759b575045142abd6ee48c076297ad77bSteve Naroff/// [OBJC] '@' 'end' 3295ed7784a335aca53b0c6e952cf31a4cfb633360Fariborz JahanianParser::DeclGroupPtrTy Parser::ParseObjCAtDirectives() { 335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation AtLoc = ConsumeToken(); // the "@" 341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 35c464ae8444edb6d07ea49b7a0eae1674c0fa1bb8Douglas Gregor if (Tok.is(tok::code_completion)) { 36a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian Actions.CodeCompleteObjCAtDirective(getCurScope()); 37dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 38c464ae8444edb6d07ea49b7a0eae1674c0fa1bb8Douglas Gregor } 3995ed7784a335aca53b0c6e952cf31a4cfb633360Fariborz Jahanian 4095ed7784a335aca53b0c6e952cf31a4cfb633360Fariborz Jahanian Decl *SingleDecl = 0; 41861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff switch (Tok.getObjCKeywordID()) { 425ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner case tok::objc_class: 435ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner return ParseObjCAtClassDeclaration(AtLoc); 4495ed7784a335aca53b0c6e952cf31a4cfb633360Fariborz Jahanian break; 457f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall case tok::objc_interface: { 460b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall ParsedAttributes attrs(AttrFactory); 4795ed7784a335aca53b0c6e952cf31a4cfb633360Fariborz Jahanian SingleDecl = ParseObjCAtInterfaceDeclaration(AtLoc, attrs); 4895ed7784a335aca53b0c6e952cf31a4cfb633360Fariborz Jahanian break; 497f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall } 507f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall case tok::objc_protocol: { 510b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall ParsedAttributes attrs(AttrFactory); 5295ed7784a335aca53b0c6e952cf31a4cfb633360Fariborz Jahanian SingleDecl = ParseObjCAtProtocolDeclaration(AtLoc, attrs); 5395ed7784a335aca53b0c6e952cf31a4cfb633360Fariborz Jahanian break; 547f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall } 555ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner case tok::objc_implementation: 5695ed7784a335aca53b0c6e952cf31a4cfb633360Fariborz Jahanian SingleDecl = ParseObjCAtImplementationDeclaration(AtLoc); 5795ed7784a335aca53b0c6e952cf31a4cfb633360Fariborz Jahanian break; 585ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner case tok::objc_end: 5995ed7784a335aca53b0c6e952cf31a4cfb633360Fariborz Jahanian SingleDecl = ParseObjCAtEndDeclaration(AtLoc); 6095ed7784a335aca53b0c6e952cf31a4cfb633360Fariborz Jahanian break; 615ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner case tok::objc_compatibility_alias: 6295ed7784a335aca53b0c6e952cf31a4cfb633360Fariborz Jahanian SingleDecl = ParseObjCAtAliasDeclaration(AtLoc); 6395ed7784a335aca53b0c6e952cf31a4cfb633360Fariborz Jahanian break; 645ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner case tok::objc_synthesize: 6595ed7784a335aca53b0c6e952cf31a4cfb633360Fariborz Jahanian SingleDecl = ParseObjCPropertySynthesize(AtLoc); 6695ed7784a335aca53b0c6e952cf31a4cfb633360Fariborz Jahanian break; 675ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner case tok::objc_dynamic: 6895ed7784a335aca53b0c6e952cf31a4cfb633360Fariborz Jahanian SingleDecl = ParseObjCPropertyDynamic(AtLoc); 6995ed7784a335aca53b0c6e952cf31a4cfb633360Fariborz Jahanian break; 705ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner default: 715ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner Diag(AtLoc, diag::err_unexpected_at); 725ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner SkipUntil(tok::semi); 7395ed7784a335aca53b0c6e952cf31a4cfb633360Fariborz Jahanian SingleDecl = 0; 7495ed7784a335aca53b0c6e952cf31a4cfb633360Fariborz Jahanian break; 755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 7695ed7784a335aca53b0c6e952cf31a4cfb633360Fariborz Jahanian return Actions.ConvertDeclToDeclGroup(SingleDecl); 775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// objc-class-declaration: 815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// '@' 'class' identifier-list ';' 821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 8395ed7784a335aca53b0c6e952cf31a4cfb633360Fariborz JahanianParser::DeclGroupPtrTy 8495ed7784a335aca53b0c6e952cf31a4cfb633360Fariborz JahanianParser::ParseObjCAtClassDeclaration(SourceLocation atLoc) { 855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ConsumeToken(); // the identifier "class" 865f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<IdentifierInfo *, 8> ClassNames; 875f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<SourceLocation, 8> ClassLocs; 88c09cba67d0ad01e53e0fed07322e95dd281bcfd9Ted Kremenek 891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer while (1) { 91df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Diag(Tok, diag::err_expected_ident); 935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SkipUntil(tok::semi); 9495ed7784a335aca53b0c6e952cf31a4cfb633360Fariborz Jahanian return Actions.ConvertDeclToDeclGroup(0); 955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ClassNames.push_back(Tok.getIdentifierInfo()); 97c09cba67d0ad01e53e0fed07322e95dd281bcfd9Ted Kremenek ClassLocs.push_back(Tok.getLocation()); 985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ConsumeToken(); 991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 100df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::comma)) 1015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer break; 1021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ConsumeToken(); 1045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Consume the ';'. 1075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@class")) 10895ed7784a335aca53b0c6e952cf31a4cfb633360Fariborz Jahanian return Actions.ConvertDeclToDeclGroup(0); 1091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 110c09cba67d0ad01e53e0fed07322e95dd281bcfd9Ted Kremenek return Actions.ActOnForwardClassDeclaration(atLoc, ClassNames.data(), 111c09cba67d0ad01e53e0fed07322e95dd281bcfd9Ted Kremenek ClassLocs.data(), 112c09cba67d0ad01e53e0fed07322e95dd281bcfd9Ted Kremenek ClassNames.size()); 1135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 1145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 115dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 116dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-interface: 117dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-interface-attributes[opt] objc-class-interface 118dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-category-interface 119dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 120dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-interface: 1211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// '@' 'interface' identifier objc-superclass[opt] 122dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-refs[opt] 1231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// objc-class-instance-variables[opt] 124dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-interface-decl-list 125dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @end 126dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 127dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-category-interface: 1281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// '@' 'interface' identifier '(' identifier[opt] ')' 129dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-refs[opt] 130dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-interface-decl-list 131dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @end 132dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 133dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-superclass: 134dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// ':' identifier 135dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 136dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-interface-attributes: 137dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// __attribute__((visibility("default"))) 138dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// __attribute__((visibility("hidden"))) 139dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// __attribute__((deprecated)) 140dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// __attribute__((unavailable)) 141dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// __attribute__((objc_exception)) - used by NSException on 64-bit 142dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1437f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCallDecl *Parser::ParseObjCAtInterfaceDeclaration(SourceLocation atLoc, 1447f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall ParsedAttributes &attrs) { 145861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff assert(Tok.isObjCAtKeyword(tok::objc_interface) && 146dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff "ParseObjCAtInterfaceDeclaration(): Expected @interface"); 147dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff ConsumeToken(); // the "interface" identifier 1481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1493b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor // Code completion after '@interface'. 1503b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor if (Tok.is(tok::code_completion)) { 15123c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCInterfaceDecl(getCurScope()); 152dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 1533b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor } 1543b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor 155df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 156dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff Diag(Tok, diag::err_expected_ident); // missing class or category name. 157d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 158dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff } 15963e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian 160dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff // We have a class or category name - consume it. 1617ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff IdentifierInfo *nameId = Tok.getIdentifierInfo(); 162dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff SourceLocation nameLoc = ConsumeToken(); 1635512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian if (Tok.is(tok::l_paren) && 1645512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian !isKnownToBeTypeSpecifier(GetLookAheadToken(1))) { // we have a category. 165dec0984fce504a39a7f085774fb67cfd9957be58Jeffrey Yasskin // TODO(dgregor): Use the return value from the next line to provide better 166dec0984fce504a39a7f085774fb67cfd9957be58Jeffrey Yasskin // recovery. 167dec0984fce504a39a7f085774fb67cfd9957be58Jeffrey Yasskin ConsumeParen(); 168dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff SourceLocation categoryLoc, rparenLoc; 169dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff IdentifierInfo *categoryId = 0; 17033ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor if (Tok.is(tok::code_completion)) { 17123c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCInterfaceCategory(getCurScope(), nameId, nameLoc); 172dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 17333ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor } 17433ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor 175527fe23f8cbc6a4da1737a547a2517bc92fa88c8Steve Naroff // For ObjC2, the category name is optional (not an error). 176df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::identifier)) { 177dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff categoryId = Tok.getIdentifierInfo(); 178dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff categoryLoc = ConsumeToken(); 17905511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian } 18005511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian else if (!getLang().ObjC2) { 181527fe23f8cbc6a4da1737a547a2517bc92fa88c8Steve Naroff Diag(Tok, diag::err_expected_ident); // missing category name. 182d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 183dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff } 184df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::r_paren)) { 185dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff Diag(Tok, diag::err_expected_rparen); 186dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff SkipUntil(tok::r_paren, false); // don't stop at ';' 187d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 188dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff } 189dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff rparenLoc = ConsumeParen(); 1905512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian // Next, we need to check for any protocol references. 1915512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian SourceLocation LAngleLoc, EndProtoLoc; 1925f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<Decl *, 8> ProtocolRefs; 1935f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<SourceLocation, 8> ProtocolLocs; 1945512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian if (Tok.is(tok::less) && 1955512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian ParseObjCProtocolReferences(ProtocolRefs, ProtocolLocs, true, 19671b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis LAngleLoc, EndProtoLoc)) 197d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 19805511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian 1997f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall if (!attrs.empty()) // categories don't support attributes. 2005512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian Diag(Tok, diag::err_objc_no_attributes_on_category); 2015512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian 202d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *CategoryType = 2035512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian Actions.ActOnStartCategoryInterface(atLoc, 2045512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian nameId, nameLoc, 2055512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian categoryId, categoryLoc, 2065512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian ProtocolRefs.data(), 2075512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian ProtocolRefs.size(), 2085512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian ProtocolLocs.data(), 2095512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian EndProtoLoc); 210e6f07f538fd0eddd6c087fcc01d4e4ff19129c71Fariborz Jahanian 211a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian if (Tok.is(tok::l_brace)) 212a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian ParseObjCClassInstanceVariables(CategoryType, tok::objc_private, atLoc); 213a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian 2142f64cfe19e8bf6b6ba1660e38da8c421440457feFariborz Jahanian ParseObjCInterfaceDeclList(tok::objc_not_keyword, CategoryType); 2155512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian return CategoryType; 216dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff } 217dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff // Parse a class interface. 218dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff IdentifierInfo *superClassId = 0; 219dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff SourceLocation superClassLoc; 2207ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff 221df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::colon)) { // a super class is specified. 222dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff ConsumeToken(); 2233b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor 2243b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor // Code completion of superclass names. 2253b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor if (Tok.is(tok::code_completion)) { 22623c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCSuperclass(getCurScope(), nameId, nameLoc); 227dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 2283b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor } 2293b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor 230df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 231dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff Diag(Tok, diag::err_expected_ident); // missing super class name. 232d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 233dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff } 234dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff superClassId = Tok.getIdentifierInfo(); 235dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff superClassLoc = ConsumeToken(); 236dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff } 237dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff // Next, we need to check for any protocol references. 2385f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<Decl *, 8> ProtocolRefs; 2395f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<SourceLocation, 8> ProtocolLocs; 24071b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis SourceLocation LAngleLoc, EndProtoLoc; 24106036d3709955a53297b4cbe14e20db88f321470Chris Lattner if (Tok.is(tok::less) && 24271b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis ParseObjCProtocolReferences(ProtocolRefs, ProtocolLocs, true, 24371b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis LAngleLoc, EndProtoLoc)) 244d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 2451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 246d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ClsType = 2471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Actions.ActOnStartClassInterface(atLoc, nameId, nameLoc, 24806036d3709955a53297b4cbe14e20db88f321470Chris Lattner superClassId, superClassLoc, 249beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad ProtocolRefs.data(), ProtocolRefs.size(), 25018df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor ProtocolLocs.data(), 2517f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall EndProtoLoc, attrs.getList()); 2521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 253df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::l_brace)) 25483c481ade785a919ba21a33f9a8b1b21c1212fb3Fariborz Jahanian ParseObjCClassInstanceVariables(ClsType, tok::objc_protected, atLoc); 255dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff 2562f64cfe19e8bf6b6ba1660e38da8c421440457feFariborz Jahanian ParseObjCInterfaceDeclList(tok::objc_interface, ClsType); 2575512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian return ClsType; 258dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff} 259dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff 260d0014540005f2a5ab837365db6bd40f479406758John McCall/// The Objective-C property callback. This should be defined where 261d0014540005f2a5ab837365db6bd40f479406758John McCall/// it's used, but instead it's been lifted to here to support VS2005. 262d0014540005f2a5ab837365db6bd40f479406758John McCallstruct Parser::ObjCPropertyCallback : FieldCallback { 263d0014540005f2a5ab837365db6bd40f479406758John McCall Parser &P; 2645f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVectorImpl<Decl *> &Props; 265d0014540005f2a5ab837365db6bd40f479406758John McCall ObjCDeclSpec &OCDS; 266d0014540005f2a5ab837365db6bd40f479406758John McCall SourceLocation AtLoc; 267d0014540005f2a5ab837365db6bd40f479406758John McCall tok::ObjCKeywordKind MethodImplKind; 268d0014540005f2a5ab837365db6bd40f479406758John McCall 269a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian ObjCPropertyCallback(Parser &P, 2705f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVectorImpl<Decl *> &Props, 271d0014540005f2a5ab837365db6bd40f479406758John McCall ObjCDeclSpec &OCDS, SourceLocation AtLoc, 272d0014540005f2a5ab837365db6bd40f479406758John McCall tok::ObjCKeywordKind MethodImplKind) : 273a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian P(P), Props(Props), OCDS(OCDS), AtLoc(AtLoc), 274d0014540005f2a5ab837365db6bd40f479406758John McCall MethodImplKind(MethodImplKind) { 275d0014540005f2a5ab837365db6bd40f479406758John McCall } 276d0014540005f2a5ab837365db6bd40f479406758John McCall 277d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *invoke(FieldDeclarator &FD) { 278d0014540005f2a5ab837365db6bd40f479406758John McCall if (FD.D.getIdentifier() == 0) { 279d0014540005f2a5ab837365db6bd40f479406758John McCall P.Diag(AtLoc, diag::err_objc_property_requires_field_name) 280d0014540005f2a5ab837365db6bd40f479406758John McCall << FD.D.getSourceRange(); 281d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 282d0014540005f2a5ab837365db6bd40f479406758John McCall } 283d0014540005f2a5ab837365db6bd40f479406758John McCall if (FD.BitfieldSize) { 284d0014540005f2a5ab837365db6bd40f479406758John McCall P.Diag(AtLoc, diag::err_objc_property_bitfield) 285d0014540005f2a5ab837365db6bd40f479406758John McCall << FD.D.getSourceRange(); 286d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 287d0014540005f2a5ab837365db6bd40f479406758John McCall } 288d0014540005f2a5ab837365db6bd40f479406758John McCall 289d0014540005f2a5ab837365db6bd40f479406758John McCall // Install the property declarator into interfaceDecl. 290d0014540005f2a5ab837365db6bd40f479406758John McCall IdentifierInfo *SelName = 291d0014540005f2a5ab837365db6bd40f479406758John McCall OCDS.getGetterName() ? OCDS.getGetterName() : FD.D.getIdentifier(); 292d0014540005f2a5ab837365db6bd40f479406758John McCall 293d0014540005f2a5ab837365db6bd40f479406758John McCall Selector GetterSel = 294d0014540005f2a5ab837365db6bd40f479406758John McCall P.PP.getSelectorTable().getNullarySelector(SelName); 295d0014540005f2a5ab837365db6bd40f479406758John McCall IdentifierInfo *SetterName = OCDS.getSetterName(); 296d0014540005f2a5ab837365db6bd40f479406758John McCall Selector SetterSel; 297d0014540005f2a5ab837365db6bd40f479406758John McCall if (SetterName) 298d0014540005f2a5ab837365db6bd40f479406758John McCall SetterSel = P.PP.getSelectorTable().getSelector(1, &SetterName); 299d0014540005f2a5ab837365db6bd40f479406758John McCall else 300d0014540005f2a5ab837365db6bd40f479406758John McCall SetterSel = SelectorTable::constructSetterName(P.PP.getIdentifierTable(), 301d0014540005f2a5ab837365db6bd40f479406758John McCall P.PP.getSelectorTable(), 302d0014540005f2a5ab837365db6bd40f479406758John McCall FD.D.getIdentifier()); 303d0014540005f2a5ab837365db6bd40f479406758John McCall bool isOverridingProperty = false; 304d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *Property = 30523c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor P.Actions.ActOnProperty(P.getCurScope(), AtLoc, FD, OCDS, 306a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian GetterSel, SetterSel, 307d0014540005f2a5ab837365db6bd40f479406758John McCall &isOverridingProperty, 308d0014540005f2a5ab837365db6bd40f479406758John McCall MethodImplKind); 309d0014540005f2a5ab837365db6bd40f479406758John McCall if (!isOverridingProperty) 310d0014540005f2a5ab837365db6bd40f479406758John McCall Props.push_back(Property); 311d0014540005f2a5ab837365db6bd40f479406758John McCall 312d0014540005f2a5ab837365db6bd40f479406758John McCall return Property; 313d0014540005f2a5ab837365db6bd40f479406758John McCall } 314d0014540005f2a5ab837365db6bd40f479406758John McCall}; 315d0014540005f2a5ab837365db6bd40f479406758John McCall 316dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-interface-decl-list: 317dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// empty 318dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-interface-decl-list objc-property-decl [OBJC2] 319294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-interface-decl-list objc-method-requirement [OBJC2] 3203536b443bc50d58a79f14fca9b6842541a434854Steve Naroff/// objc-interface-decl-list objc-method-proto ';' 321dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-interface-decl-list declaration 322dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-interface-decl-list ';' 323dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 324294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-method-requirement: [OBJC2] 325294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// @required 326294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// @optional 327294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 3282f64cfe19e8bf6b6ba1660e38da8c421440457feFariborz Jahanianvoid Parser::ParseObjCInterfaceDeclList(tok::ObjCKeywordKind contextKey, 3292f64cfe19e8bf6b6ba1660e38da8c421440457feFariborz Jahanian Decl *CDecl) { 3305f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<Decl *, 32> allMethods; 3315f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<Decl *, 16> allProperties; 3325f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<DeclGroupPtrTy, 8> allTUVariables; 33300933591a2795d09dd1acff12a2d21bce7cb12c5Fariborz Jahanian tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword; 3341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 335782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek SourceRange AtEnd; 3362f64cfe19e8bf6b6ba1660e38da8c421440457feFariborz Jahanian Actions.ActOnObjCContainerStartDefinition(CDecl); 3372f64cfe19e8bf6b6ba1660e38da8c421440457feFariborz Jahanian 338294494e1cce92043562b4680c613df7fd028c02eSteve Naroff while (1) { 339e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner // If this is a method prototype, parse it. 340df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::minus) || Tok.is(tok::plus)) { 341d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *methodPrototype = 342a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian ParseObjCMethodPrototype(MethodImplKind, false); 34325e077d59a8e8e43b65882b69610a3d5e2aaf53cFariborz Jahanian allMethods.push_back(methodPrototype); 3443536b443bc50d58a79f14fca9b6842541a434854Steve Naroff // Consume the ';' here, since ParseObjCMethodPrototype() is re-used for 3453536b443bc50d58a79f14fca9b6842541a434854Steve Naroff // method definitions. 346b6d74a158a9c002e3c0fcbda8ad8d0ccbb2e5088Chris Lattner ExpectAndConsume(tok::semi, diag::err_expected_semi_after_method_proto, 347b6d74a158a9c002e3c0fcbda8ad8d0ccbb2e5088Chris Lattner "", tok::semi); 348294494e1cce92043562b4680c613df7fd028c02eSteve Naroff continue; 349294494e1cce92043562b4680c613df7fd028c02eSteve Naroff } 35005511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian if (Tok.is(tok::l_paren)) { 35105511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian Diag(Tok, diag::err_expected_minus_or_plus); 352d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall ParseObjCMethodDecl(Tok.getLocation(), 353d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall tok::minus, 35490ba78c64d0c24cfbc1bf88728db9775d44d7f9fFariborz Jahanian MethodImplKind, false); 35505511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian continue; 35605511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian } 357e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner // Ignore excess semicolons. 358e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner if (Tok.is(tok::semi)) { 359294494e1cce92043562b4680c613df7fd028c02eSteve Naroff ConsumeToken(); 360e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner continue; 361e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner } 3621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 363bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // If we got to the end of the file, exit the loop. 364e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner if (Tok.is(tok::eof)) 365e3a2ca7e30601cdd31c77a830f4cc487851e8096Fariborz Jahanian break; 3661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 367b6ac2451bfed36206c5cec7217372c4299f67f2bDouglas Gregor // Code completion within an Objective-C interface. 368b6ac2451bfed36206c5cec7217372c4299f67f2bDouglas Gregor if (Tok.is(tok::code_completion)) { 36923c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteOrdinaryName(getCurScope(), 370f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall ObjCImpDecl? Sema::PCC_ObjCImplementation 371f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall : Sema::PCC_ObjCInterface); 372dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 373b6ac2451bfed36206c5cec7217372c4299f67f2bDouglas Gregor } 374b6ac2451bfed36206c5cec7217372c4299f67f2bDouglas Gregor 375e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner // If we don't have an @ directive, parse it as a function definition. 376e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner if (Tok.isNot(tok::at)) { 3771fd80116b49782c367ff5d5f50a8b76dd8a5d7f7Chris Lattner // The code below does not consume '}'s because it is afraid of eating the 3781fd80116b49782c367ff5d5f50a8b76dd8a5d7f7Chris Lattner // end of a namespace. Because of the way this code is structured, an 3791fd80116b49782c367ff5d5f50a8b76dd8a5d7f7Chris Lattner // erroneous r_brace would cause an infinite loop if not handled here. 3801fd80116b49782c367ff5d5f50a8b76dd8a5d7f7Chris Lattner if (Tok.is(tok::r_brace)) 3811fd80116b49782c367ff5d5f50a8b76dd8a5d7f7Chris Lattner break; 3820b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall ParsedAttributes attrs(AttrFactory); 3837f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall allTUVariables.push_back(ParseDeclarationOrFunctionDefinition(attrs)); 384e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner continue; 385e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner } 3861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 387e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner // Otherwise, we have an @ directive, eat the @. 388e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner SourceLocation AtLoc = ConsumeToken(); // the "@" 389c464ae8444edb6d07ea49b7a0eae1674c0fa1bb8Douglas Gregor if (Tok.is(tok::code_completion)) { 390a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian Actions.CodeCompleteObjCAtDirective(getCurScope()); 391dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 392c464ae8444edb6d07ea49b7a0eae1674c0fa1bb8Douglas Gregor break; 393c464ae8444edb6d07ea49b7a0eae1674c0fa1bb8Douglas Gregor } 394c464ae8444edb6d07ea49b7a0eae1674c0fa1bb8Douglas Gregor 395a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner tok::ObjCKeywordKind DirectiveKind = Tok.getObjCKeywordID(); 3961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 397a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner if (DirectiveKind == tok::objc_end) { // @end -> terminate list 398782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek AtEnd.setBegin(AtLoc); 399782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek AtEnd.setEnd(Tok.getLocation()); 400e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner break; 401c3d43b783dfb1a1502aa8b31ab1985cf237b1f77Douglas Gregor } else if (DirectiveKind == tok::objc_not_keyword) { 402c3d43b783dfb1a1502aa8b31ab1985cf237b1f77Douglas Gregor Diag(Tok, diag::err_objc_unknown_at); 403c3d43b783dfb1a1502aa8b31ab1985cf237b1f77Douglas Gregor SkipUntil(tok::semi); 404c3d43b783dfb1a1502aa8b31ab1985cf237b1f77Douglas Gregor continue; 405bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner } 4061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 407bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // Eat the identifier. 408bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner ConsumeToken(); 409bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner 410a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner switch (DirectiveKind) { 411a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner default: 412bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // FIXME: If someone forgets an @end on a protocol, this loop will 413bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // continue to eat up tons of stuff and spew lots of nonsense errors. It 414bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // would probably be better to bail out if we saw an @class or @interface 415bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // or something like that. 416f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner Diag(AtLoc, diag::err_objc_illegal_interface_qual); 417bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // Skip until we see an '@' or '}' or ';'. 418a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner SkipUntil(tok::r_brace, tok::at); 419a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner break; 42046d545e355a4fea2a201652c3c8bbf22a13187a6Fariborz Jahanian 42146d545e355a4fea2a201652c3c8bbf22a13187a6Fariborz Jahanian case tok::objc_implementation: 422df81c2c6ce37f4ae3c45dd01093b6274fa0b6692Fariborz Jahanian case tok::objc_interface: 42346d545e355a4fea2a201652c3c8bbf22a13187a6Fariborz Jahanian Diag(Tok, diag::err_objc_missing_end); 42446d545e355a4fea2a201652c3c8bbf22a13187a6Fariborz Jahanian ConsumeToken(); 42546d545e355a4fea2a201652c3c8bbf22a13187a6Fariborz Jahanian break; 42646d545e355a4fea2a201652c3c8bbf22a13187a6Fariborz Jahanian 427a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner case tok::objc_required: 428a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner case tok::objc_optional: 429a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner // This is only valid on protocols. 430bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // FIXME: Should this check for ObjC2 being enabled? 431e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner if (contextKey != tok::objc_protocol) 432bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner Diag(AtLoc, diag::err_objc_directive_only_in_protocol); 433a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner else 434bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner MethodImplKind = DirectiveKind; 435a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner break; 4361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 437a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner case tok::objc_property: 438f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner if (!getLang().ObjC2) 439b321c0c0ba957d78475e72cebde4028fdaa00f8fChris Lattner Diag(AtLoc, diag::err_objc_properties_require_objc2); 440f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner 441e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner ObjCDeclSpec OCDS; 4421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // Parse property attribute list, if any. 4438ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner if (Tok.is(tok::l_paren)) 444a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian ParseObjCPropertyAttribute(OCDS); 4451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 446a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian ObjCPropertyCallback Callback(*this, allProperties, 447d0014540005f2a5ab837365db6bd40f479406758John McCall OCDS, AtLoc, MethodImplKind); 448bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall 449e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner // Parse all the comma separated declarators. 4500b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall DeclSpec DS(AttrFactory); 451bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall ParseStructDeclaration(DS, Callback); 4521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4537da19ea50d4161fcda40d135735bcf450cabeb50John McCall ExpectAndConsume(tok::semi, diag::err_expected_semi_decl_list); 454a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner break; 455f28b264437053fb0deacc9ba02b18a0966f7290aSteve Naroff } 456294494e1cce92043562b4680c613df7fd028c02eSteve Naroff } 457bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner 458bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // We break out of the big loop in two cases: when we see @end or when we see 459bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // EOF. In the former case, eat the @end. In the later case, emit an error. 460c464ae8444edb6d07ea49b7a0eae1674c0fa1bb8Douglas Gregor if (Tok.is(tok::code_completion)) { 461a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian Actions.CodeCompleteObjCAtDirective(getCurScope()); 462dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 463c464ae8444edb6d07ea49b7a0eae1674c0fa1bb8Douglas Gregor } else if (Tok.isObjCAtKeyword(tok::objc_end)) 464bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner ConsumeToken(); // the "end" identifier 465bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner else 466bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner Diag(Tok, diag::err_objc_missing_end); 4671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 468a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner // Insert collected methods declarations into the @interface object. 469bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // This passes in an invalid SourceLocation for AtEndLoc when EOF is hit. 470a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian Actions.ActOnAtEnd(getCurScope(), AtEnd, 4711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump allMethods.data(), allMethods.size(), 472beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad allProperties.data(), allProperties.size(), 473beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad allTUVariables.data(), allTUVariables.size()); 474294494e1cce92043562b4680c613df7fd028c02eSteve Naroff} 475294494e1cce92043562b4680c613df7fd028c02eSteve Naroff 476d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// Parse property attribute declarations. 477d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// 478d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// property-attr-decl: '(' property-attrlist ')' 479d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// property-attrlist: 480d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// property-attribute 481d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// property-attrlist ',' property-attribute 482d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// property-attribute: 483d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// getter '=' identifier 484d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// setter '=' identifier ':' 485d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// readonly 486d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// readwrite 487d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// assign 488d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// retain 489d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// copy 490d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// nonatomic 491f85e193739c953358c865005855253af4f68a497John McCall/// atomic 492f85e193739c953358c865005855253af4f68a497John McCall/// strong 493f85e193739c953358c865005855253af4f68a497John McCall/// weak 494f85e193739c953358c865005855253af4f68a497John McCall/// unsafe_unretained 495d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// 496a28948f34817476d02412fa204cae038e228c827Fariborz Jahanianvoid Parser::ParseObjCPropertyAttribute(ObjCDeclSpec &DS) { 4978ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner assert(Tok.getKind() == tok::l_paren); 498dd5b5f2bb73d037745940431b71eb98393d12d4fChris Lattner SourceLocation LHSLoc = ConsumeParen(); // consume '(' 4991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 500cd9f4b31c4fe5b77b5519cc17b4583fab912bad1Chris Lattner while (1) { 501ece8e71d12b6f4cb2dc501297afef126dab8ad74Steve Naroff if (Tok.is(tok::code_completion)) { 50223c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCPropertyFlags(getCurScope(), DS); 503dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 504ece8e71d12b6f4cb2dc501297afef126dab8ad74Steve Naroff } 505d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian const IdentifierInfo *II = Tok.getIdentifierInfo(); 5061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 507f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner // If this is not an identifier at all, bail out early. 508f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner if (II == 0) { 509f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner MatchRHSPunctuation(tok::r_paren, LHSLoc); 510f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner return; 511f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner } 5121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 513156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner SourceLocation AttrName = ConsumeToken(); // consume last attribute name 5141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 51592e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner if (II->isStr("readonly")) 516e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_readonly); 51792e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner else if (II->isStr("assign")) 518e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_assign); 519f85e193739c953358c865005855253af4f68a497John McCall else if (II->isStr("unsafe_unretained")) 520f85e193739c953358c865005855253af4f68a497John McCall DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_unsafe_unretained); 52192e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner else if (II->isStr("readwrite")) 522e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_readwrite); 52392e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner else if (II->isStr("retain")) 524e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_retain); 525f85e193739c953358c865005855253af4f68a497John McCall else if (II->isStr("strong")) 526f85e193739c953358c865005855253af4f68a497John McCall DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_strong); 52792e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner else if (II->isStr("copy")) 528e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_copy); 52992e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner else if (II->isStr("nonatomic")) 530e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_nonatomic); 53145937ae10a0f70f74508165aab4f2b63e18ea747Fariborz Jahanian else if (II->isStr("atomic")) 53245937ae10a0f70f74508165aab4f2b63e18ea747Fariborz Jahanian DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_atomic); 533f85e193739c953358c865005855253af4f68a497John McCall else if (II->isStr("weak")) 534f85e193739c953358c865005855253af4f68a497John McCall DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_weak); 53592e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner else if (II->isStr("getter") || II->isStr("setter")) { 53642499be29b620d2eae34beb0f4d0f9da5a9584daAnders Carlsson bool IsSetter = II->getNameStart()[0] == 's'; 53742499be29b620d2eae34beb0f4d0f9da5a9584daAnders Carlsson 538e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner // getter/setter require extra treatment. 53942499be29b620d2eae34beb0f4d0f9da5a9584daAnders Carlsson unsigned DiagID = IsSetter ? diag::err_objc_expected_equal_for_setter : 54042499be29b620d2eae34beb0f4d0f9da5a9584daAnders Carlsson diag::err_objc_expected_equal_for_getter; 54142499be29b620d2eae34beb0f4d0f9da5a9584daAnders Carlsson 54242499be29b620d2eae34beb0f4d0f9da5a9584daAnders Carlsson if (ExpectAndConsume(tok::equal, DiagID, "", tok::r_paren)) 543dd5b5f2bb73d037745940431b71eb98393d12d4fChris Lattner return; 5441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5454ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor if (Tok.is(tok::code_completion)) { 54642499be29b620d2eae34beb0f4d0f9da5a9584daAnders Carlsson if (IsSetter) 547a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian Actions.CodeCompleteObjCPropertySetter(getCurScope()); 5484ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor else 549a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian Actions.CodeCompleteObjCPropertyGetter(getCurScope()); 550dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 5514ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor } 5524ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor 55342499be29b620d2eae34beb0f4d0f9da5a9584daAnders Carlsson 55442499be29b620d2eae34beb0f4d0f9da5a9584daAnders Carlsson SourceLocation SelLoc; 55542499be29b620d2eae34beb0f4d0f9da5a9584daAnders Carlsson IdentifierInfo *SelIdent = ParseObjCSelectorPiece(SelLoc); 55642499be29b620d2eae34beb0f4d0f9da5a9584daAnders Carlsson 55742499be29b620d2eae34beb0f4d0f9da5a9584daAnders Carlsson if (!SelIdent) { 55842499be29b620d2eae34beb0f4d0f9da5a9584daAnders Carlsson Diag(Tok, diag::err_objc_expected_selector_for_getter_setter) 55942499be29b620d2eae34beb0f4d0f9da5a9584daAnders Carlsson << IsSetter; 5608ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner SkipUntil(tok::r_paren); 5618ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner return; 5628ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner } 5631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 56442499be29b620d2eae34beb0f4d0f9da5a9584daAnders Carlsson if (IsSetter) { 5658ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_setter); 56642499be29b620d2eae34beb0f4d0f9da5a9584daAnders Carlsson DS.setSetterName(SelIdent); 5671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 568e0097db2848c463a534c18c235c6d3e53f2f1b87Fariborz Jahanian if (ExpectAndConsume(tok::colon, 569e0097db2848c463a534c18c235c6d3e53f2f1b87Fariborz Jahanian diag::err_expected_colon_after_setter_name, "", 570156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner tok::r_paren)) 5718ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner return; 5728ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner } else { 5738ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_getter); 57442499be29b620d2eae34beb0f4d0f9da5a9584daAnders Carlsson DS.setGetterName(SelIdent); 5758ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner } 576e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner } else { 577a9500f05ba6c09bbd84d342236863833067cd816Chris Lattner Diag(AttrName, diag::err_objc_expected_property_attr) << II; 578cd9f4b31c4fe5b77b5519cc17b4583fab912bad1Chris Lattner SkipUntil(tok::r_paren); 579cd9f4b31c4fe5b77b5519cc17b4583fab912bad1Chris Lattner return; 580cd9f4b31c4fe5b77b5519cc17b4583fab912bad1Chris Lattner } 5811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 582156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner if (Tok.isNot(tok::comma)) 583156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner break; 5841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 585156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner ConsumeToken(); 586d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian } 5871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 588156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner MatchRHSPunctuation(tok::r_paren, LHSLoc); 589d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian} 590d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian 5913536b443bc50d58a79f14fca9b6842541a434854Steve Naroff/// objc-method-proto: 5921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// objc-instance-method objc-method-decl objc-method-attributes[opt] 5933536b443bc50d58a79f14fca9b6842541a434854Steve Naroff/// objc-class-method objc-method-decl objc-method-attributes[opt] 594294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 595294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-instance-method: '-' 596294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-class-method: '+' 597294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 5984985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-method-attributes: [OBJC2] 5994985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// __attribute__((deprecated)) 6004985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// 601a28948f34817476d02412fa204cae038e228c827Fariborz JahanianDecl *Parser::ParseObjCMethodPrototype(tok::ObjCKeywordKind MethodImplKind, 60290ba78c64d0c24cfbc1bf88728db9775d44d7f9fFariborz Jahanian bool MethodDefinition) { 603df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner assert((Tok.is(tok::minus) || Tok.is(tok::plus)) && "expected +/-"); 604294494e1cce92043562b4680c613df7fd028c02eSteve Naroff 6051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump tok::TokenKind methodType = Tok.getKind(); 606bef1185418705e16012b3dd50cd7c260c8d6b79cSteve Naroff SourceLocation mLoc = ConsumeToken(); 607a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian Decl *MDecl = ParseObjCMethodDecl(mLoc, methodType, MethodImplKind, 60890ba78c64d0c24cfbc1bf88728db9775d44d7f9fFariborz Jahanian MethodDefinition); 6093536b443bc50d58a79f14fca9b6842541a434854Steve Naroff // Since this rule is used for both method declarations and definitions, 6102bd42fadafddc8acf744b57a970bdc96a077c617Steve Naroff // the caller is (optionally) responsible for consuming the ';'. 611f28b264437053fb0deacc9ba02b18a0966f7290aSteve Naroff return MDecl; 612294494e1cce92043562b4680c613df7fd028c02eSteve Naroff} 613294494e1cce92043562b4680c613df7fd028c02eSteve Naroff 614294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-selector: 615294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// identifier 616294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// one of 617294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// enum struct union if else while do for switch case default 618294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// break continue return goto asm sizeof typeof __alignof 619294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// unsigned long const short volatile signed restrict _Complex 620294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// in out inout bycopy byref oneway int char float double void _Bool 621294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 6222fc5c2428ecb450a3256c8316b93b8655cb76a0fChris LattnerIdentifierInfo *Parser::ParseObjCSelectorPiece(SourceLocation &SelectorLoc) { 623be74740cc246ce08d42804a684385a42eb814edbFariborz Jahanian 624ff38491c18b060526d754765b952f4a497a89416Chris Lattner switch (Tok.getKind()) { 625ff38491c18b060526d754765b952f4a497a89416Chris Lattner default: 626ff38491c18b060526d754765b952f4a497a89416Chris Lattner return 0; 627afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian case tok::ampamp: 628afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian case tok::ampequal: 629afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian case tok::amp: 630afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian case tok::pipe: 631afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian case tok::tilde: 632afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian case tok::exclaim: 633afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian case tok::exclaimequal: 634afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian case tok::pipepipe: 635afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian case tok::pipeequal: 636afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian case tok::caret: 637afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian case tok::caretequal: { 6383846ca29a8cc1d376a4b695194c29952dbbfb544Fariborz Jahanian std::string ThisTok(PP.getSpelling(Tok)); 639afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian if (isalpha(ThisTok[0])) { 640afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian IdentifierInfo *II = &PP.getIdentifierTable().get(ThisTok.data()); 641afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian Tok.setKind(tok::identifier); 642afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian SelectorLoc = ConsumeToken(); 643afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian return II; 644afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian } 645afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian return 0; 646afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian } 647afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian 648ff38491c18b060526d754765b952f4a497a89416Chris Lattner case tok::identifier: 649ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_asm: 650ff38491c18b060526d754765b952f4a497a89416Chris Lattner case tok::kw_auto: 6519298d9655aed28b2d9f6cc65c81401b209f03fdcChris Lattner case tok::kw_bool: 652ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_break: 653ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_case: 654ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_catch: 655ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_char: 656ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_class: 657ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_const: 658ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_const_cast: 659ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_continue: 660ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_default: 661ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_delete: 662ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_do: 663ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_double: 664ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_dynamic_cast: 665ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_else: 666ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_enum: 667ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_explicit: 668ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_export: 669ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_extern: 670ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_false: 671ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_float: 672ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_for: 673ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_friend: 674ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_goto: 675ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_if: 676ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_inline: 677ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_int: 678ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_long: 679ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_mutable: 680ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_namespace: 681ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_new: 682ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_operator: 683ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_private: 684ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_protected: 685ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_public: 686ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_register: 687ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_reinterpret_cast: 688ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_restrict: 689ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_return: 690ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_short: 691ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_signed: 692ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_sizeof: 693ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_static: 694ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_static_cast: 695ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_struct: 696ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_switch: 697ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_template: 698ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_this: 699ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_throw: 700ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_true: 701ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_try: 702ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_typedef: 703ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_typeid: 704ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_typename: 705ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_typeof: 706ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_union: 707ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_unsigned: 708ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_using: 709ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_virtual: 710ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_void: 711ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_volatile: 712ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_wchar_t: 713ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_while: 714ff38491c18b060526d754765b952f4a497a89416Chris Lattner case tok::kw__Bool: 715ff38491c18b060526d754765b952f4a497a89416Chris Lattner case tok::kw__Complex: 716ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw___alignof: 717ff38491c18b060526d754765b952f4a497a89416Chris Lattner IdentifierInfo *II = Tok.getIdentifierInfo(); 7184b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian SelectorLoc = ConsumeToken(); 719ff38491c18b060526d754765b952f4a497a89416Chris Lattner return II; 720d064951b0dcc95f8604d0d69ae82d9ecbd38c796Fariborz Jahanian } 721294494e1cce92043562b4680c613df7fd028c02eSteve Naroff} 722294494e1cce92043562b4680c613df7fd028c02eSteve Naroff 7230196cab54007ff072ec2642da8911c6b7e8d3fb5Fariborz Jahanian/// objc-for-collection-in: 'in' 7240196cab54007ff072ec2642da8911c6b7e8d3fb5Fariborz Jahanian/// 725335a2d4122e41343fe11a775889b8bec5b14be60Fariborz Jahanianbool Parser::isTokIdentifier_in() const { 7263ba5a0f90a03d5e13d02cbee9abd2a1ba01b18bcFariborz Jahanian // FIXME: May have to do additional look-ahead to only allow for 7273ba5a0f90a03d5e13d02cbee9abd2a1ba01b18bcFariborz Jahanian // valid tokens following an 'in'; such as an identifier, unary operators, 7283ba5a0f90a03d5e13d02cbee9abd2a1ba01b18bcFariborz Jahanian // '[' etc. 7291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return (getLang().ObjC2 && Tok.is(tok::identifier) && 7305ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner Tok.getIdentifierInfo() == ObjCTypeQuals[objc_in]); 7310196cab54007ff072ec2642da8911c6b7e8d3fb5Fariborz Jahanian} 7320196cab54007ff072ec2642da8911c6b7e8d3fb5Fariborz Jahanian 733a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ParseObjCTypeQualifierList - This routine parses the objective-c's type 734e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner/// qualifier list and builds their bitmask representation in the input 735e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner/// argument. 736294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 737294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-type-qualifiers: 738294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-type-qualifier 739294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-type-qualifiers objc-type-qualifier 740294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 741b77cab97f17f946744c920629ca17271308d8ebfDouglas Gregorvoid Parser::ParseObjCTypeQualifierList(ObjCDeclSpec &DS, 742b77cab97f17f946744c920629ca17271308d8ebfDouglas Gregor ObjCTypeNameContext Context) { 743e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner while (1) { 744d32b0225e29fcafb2b2b2a4b1c51dcb1518af9c6Douglas Gregor if (Tok.is(tok::code_completion)) { 745b77cab97f17f946744c920629ca17271308d8ebfDouglas Gregor Actions.CodeCompleteObjCPassingType(getCurScope(), DS, 746b77cab97f17f946744c920629ca17271308d8ebfDouglas Gregor Context == OTN_ParameterType); 747d32b0225e29fcafb2b2b2a4b1c51dcb1518af9c6Douglas Gregor ConsumeCodeCompletionToken(); 748d32b0225e29fcafb2b2b2a4b1c51dcb1518af9c6Douglas Gregor } 749d32b0225e29fcafb2b2b2a4b1c51dcb1518af9c6Douglas Gregor 750cb53b361bce341c8591333c6997f62e480acc0b4Chris Lattner if (Tok.isNot(tok::identifier)) 751e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner return; 7521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 753e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner const IdentifierInfo *II = Tok.getIdentifierInfo(); 754e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner for (unsigned i = 0; i != objc_NumQuals; ++i) { 755a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek if (II != ObjCTypeQuals[i]) 756e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner continue; 7571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 758a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCDeclSpec::ObjCDeclQualifier Qual; 759e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner switch (i) { 760e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner default: assert(0 && "Unknown decl qualifier"); 761a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek case objc_in: Qual = ObjCDeclSpec::DQ_In; break; 762a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek case objc_out: Qual = ObjCDeclSpec::DQ_Out; break; 763a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek case objc_inout: Qual = ObjCDeclSpec::DQ_Inout; break; 764a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek case objc_oneway: Qual = ObjCDeclSpec::DQ_Oneway; break; 765a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek case objc_bycopy: Qual = ObjCDeclSpec::DQ_Bycopy; break; 766a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek case objc_byref: Qual = ObjCDeclSpec::DQ_Byref; break; 767e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner } 768a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek DS.setObjCDeclQualifier(Qual); 769e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner ConsumeToken(); 770e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner II = 0; 771e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner break; 772e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner } 7731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 774e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner // If this wasn't a recognized qualifier, bail out. 775e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner if (II) return; 776e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner } 777e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner} 778e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner 779e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner/// objc-type-name: 780e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner/// '(' objc-type-qualifiers[opt] type-name ')' 781e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner/// '(' objc-type-qualifiers[opt] ')' 782e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner/// 783b77cab97f17f946744c920629ca17271308d8ebfDouglas GregorParsedType Parser::ParseObjCTypeName(ObjCDeclSpec &DS, 784b77cab97f17f946744c920629ca17271308d8ebfDouglas Gregor ObjCTypeNameContext Context) { 785df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner assert(Tok.is(tok::l_paren) && "expected ("); 7861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7874a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner SourceLocation LParenLoc = ConsumeParen(); 788e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner SourceLocation TypeStartLoc = Tok.getLocation(); 7899735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian ObjCDeclContextSwitch ObjCDC(*this); 7909735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian 79119d74e1494fe399f0e2a94e9419c095f8214851bFariborz Jahanian // Parse type qualifiers, in, inout, etc. 792b77cab97f17f946744c920629ca17271308d8ebfDouglas Gregor ParseObjCTypeQualifierList(DS, Context); 7934fa7afd07421e7276d1717e4fdf43a5fdd65a622Steve Naroff 794b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType Ty; 795809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor if (isTypeSpecifierQualifier()) { 796f85e193739c953358c865005855253af4f68a497John McCall TypeResult TypeSpec = 797f85e193739c953358c865005855253af4f68a497John McCall ParseTypeName(0, Declarator::ObjCPrototypeContext, &DS); 798809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor if (!TypeSpec.isInvalid()) 799809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor Ty = TypeSpec.get(); 800809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor } 801f85e193739c953358c865005855253af4f68a497John McCall 8024a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner if (Tok.is(tok::r_paren)) 8034a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner ConsumeParen(); 8044a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner else if (Tok.getLocation() == TypeStartLoc) { 805e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner // If we didn't eat any tokens, then this isn't a type. 8061ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_type); 8074a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner SkipUntil(tok::r_paren); 8084a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner } else { 8094a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner // Otherwise, we found *something*, but didn't get a ')' in the right 8104a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner // place. Emit an error then return what we have as the type. 8114a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner MatchRHSPunctuation(tok::r_paren, LParenLoc); 812294494e1cce92043562b4680c613df7fd028c02eSteve Naroff } 813f28b264437053fb0deacc9ba02b18a0966f7290aSteve Naroff return Ty; 814294494e1cce92043562b4680c613df7fd028c02eSteve Naroff} 815294494e1cce92043562b4680c613df7fd028c02eSteve Naroff 816294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-method-decl: 817294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-selector 8184985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-keyword-selector objc-parmlist[opt] 819294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-type-name objc-selector 8204985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-type-name objc-keyword-selector objc-parmlist[opt] 821294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 822294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-keyword-selector: 8231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// objc-keyword-decl 824294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-keyword-selector objc-keyword-decl 825294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 826294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-keyword-decl: 8277ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// objc-selector ':' objc-type-name objc-keyword-attributes[opt] identifier 8287ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// objc-selector ':' objc-keyword-attributes[opt] identifier 8297ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// ':' objc-type-name objc-keyword-attributes[opt] identifier 8307ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// ':' objc-keyword-attributes[opt] identifier 831294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 8324985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-parmlist: 8334985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-parms objc-ellipsis[opt] 834294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 8354985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-parms: 8364985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-parms , parameter-declaration 837294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 8384985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-ellipsis: 839294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// , ... 840294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 8417ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// objc-keyword-attributes: [OBJC2] 8427ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// __attribute__((unused)) 8437ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// 844d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseObjCMethodDecl(SourceLocation mLoc, 8452ccccb3ff40c64927817a7e1ddf1da8c188ed224Douglas Gregor tok::TokenKind mType, 84690ba78c64d0c24cfbc1bf88728db9775d44d7f9fFariborz Jahanian tok::ObjCKeywordKind MethodImplKind, 84790ba78c64d0c24cfbc1bf88728db9775d44d7f9fFariborz Jahanian bool MethodDefinition) { 84854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ParsingDeclRAIIObject PD(*this); 84954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 850e8f5a1710a7738deff40e10efcd05b1bd6af184fDouglas Gregor if (Tok.is(tok::code_completion)) { 85123c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCMethodDecl(getCurScope(), mType == tok::minus, 852a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian /*ReturnType=*/ ParsedType()); 853dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 854e8f5a1710a7738deff40e10efcd05b1bd6af184fDouglas Gregor } 855e8f5a1710a7738deff40e10efcd05b1bd6af184fDouglas Gregor 856e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner // Parse the return type if present. 857b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ReturnType; 858a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCDeclSpec DSRet; 859df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::l_paren)) 860b77cab97f17f946744c920629ca17271308d8ebfDouglas Gregor ReturnType = ParseObjCTypeName(DSRet, OTN_ResultType); 8611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8629e0493576af77dba1c48858c03e31a2897d0681eTed Kremenek // If attributes exist before the method, parse them. 8630b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall ParsedAttributes methodAttrs(AttrFactory); 8647f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall if (getLang().ObjC2) 8650b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall MaybeParseGNUAttributes(methodAttrs); 8669e0493576af77dba1c48858c03e31a2897d0681eTed Kremenek 867e8f5a1710a7738deff40e10efcd05b1bd6af184fDouglas Gregor if (Tok.is(tok::code_completion)) { 86823c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCMethodDecl(getCurScope(), mType == tok::minus, 869a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian ReturnType); 870dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 871e8f5a1710a7738deff40e10efcd05b1bd6af184fDouglas Gregor } 872e8f5a1710a7738deff40e10efcd05b1bd6af184fDouglas Gregor 8739e0493576af77dba1c48858c03e31a2897d0681eTed Kremenek // Now parse the selector. 874bef1185418705e16012b3dd50cd7c260c8d6b79cSteve Naroff SourceLocation selLoc; 8752fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner IdentifierInfo *SelIdent = ParseObjCSelectorPiece(selLoc); 876e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner 87784c431088693e216193094d1dbf327a01173f57fSteve Naroff // An unnamed colon is valid. 87884c431088693e216193094d1dbf327a01173f57fSteve Naroff if (!SelIdent && Tok.isNot(tok::colon)) { // missing selector name. 8791ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_selector_for_method) 8801ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner << SourceRange(mLoc, Tok.getLocation()); 881e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner // Skip until we get a ; or {}. 882e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner SkipUntil(tok::r_brace); 883d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 884e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner } 8851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8865f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<DeclaratorChunk::ParamInfo, 8> CParamInfo; 887df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::colon)) { 888ff38491c18b060526d754765b952f4a497a89416Chris Lattner // If attributes exist after the method, parse them. 8897f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall if (getLang().ObjC2) 8900b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall MaybeParseGNUAttributes(methodAttrs); 8911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 892ff38491c18b060526d754765b952f4a497a89416Chris Lattner Selector Sel = PP.getSelectorTable().getNullarySelector(SelIdent); 893d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *Result 8947f53253223b29d77f1e9c5c0ce93a19932761b77Fariborz Jahanian = Actions.ActOnMethodDeclaration(getCurScope(), mLoc, Tok.getLocation(), 895a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian mType, DSRet, ReturnType, 896926df6cfabf3eaa4afc990c097fa4619b76a9b57Douglas Gregor selLoc, Sel, 0, 8974f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian CParamInfo.data(), CParamInfo.size(), 8980b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall methodAttrs.getList(), MethodImplKind, 8990b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall false, MethodDefinition); 90054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall PD.complete(Result); 90154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall return Result; 902ff38491c18b060526d754765b952f4a497a89416Chris Lattner } 903f28b264437053fb0deacc9ba02b18a0966f7290aSteve Naroff 9045f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<IdentifierInfo *, 12> KeyIdents; 9055f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<Sema::ObjCArgInfo, 12> ArgInfos; 9067f53253223b29d77f1e9c5c0ce93a19932761b77Fariborz Jahanian ParseScope PrototypeScope(this, 9077f53253223b29d77f1e9c5c0ce93a19932761b77Fariborz Jahanian Scope::FunctionPrototypeScope|Scope::DeclScope); 9080b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall 9090b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall AttributePool allParamAttrs(AttrFactory); 9107f53253223b29d77f1e9c5c0ce93a19932761b77Fariborz Jahanian 911ff38491c18b060526d754765b952f4a497a89416Chris Lattner while (1) { 9120b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall ParsedAttributes paramAttrs(AttrFactory); 913f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Sema::ObjCArgInfo ArgInfo; 9141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 915ff38491c18b060526d754765b952f4a497a89416Chris Lattner // Each iteration parses a single keyword argument. 916df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::colon)) { 917ff38491c18b060526d754765b952f4a497a89416Chris Lattner Diag(Tok, diag::err_expected_colon); 918ff38491c18b060526d754765b952f4a497a89416Chris Lattner break; 919ff38491c18b060526d754765b952f4a497a89416Chris Lattner } 920ff38491c18b060526d754765b952f4a497a89416Chris Lattner ConsumeToken(); // Eat the ':'. 9211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 922b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ArgInfo.Type = ParsedType(); 923e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner if (Tok.is(tok::l_paren)) // Parse the argument type if present. 924b77cab97f17f946744c920629ca17271308d8ebfDouglas Gregor ArgInfo.Type = ParseObjCTypeName(ArgInfo.DeclSpec, OTN_ParameterType); 925e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner 926ff38491c18b060526d754765b952f4a497a89416Chris Lattner // If attributes exist before the argument name, parse them. 927e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner ArgInfo.ArgAttrs = 0; 9287f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall if (getLang().ObjC2) { 9290b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall MaybeParseGNUAttributes(paramAttrs); 9300b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall ArgInfo.ArgAttrs = paramAttrs.getList(); 9317f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall } 9327ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff 93340ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor // Code completion for the next piece of the selector. 93440ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor if (Tok.is(tok::code_completion)) { 93540ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor ConsumeCodeCompletionToken(); 93640ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor KeyIdents.push_back(SelIdent); 93740ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor Actions.CodeCompleteObjCMethodDeclSelector(getCurScope(), 93840ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor mType == tok::minus, 93940ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor /*AtParameterName=*/true, 94040ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor ReturnType, 94140ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor KeyIdents.data(), 94240ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor KeyIdents.size()); 94340ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor KeyIdents.pop_back(); 94440ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor break; 94540ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor } 94640ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor 947df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 948ff38491c18b060526d754765b952f4a497a89416Chris Lattner Diag(Tok, diag::err_expected_ident); // missing argument name. 949ff38491c18b060526d754765b952f4a497a89416Chris Lattner break; 9504985aceceb9b9261b876b515d32726175c13a775Steve Naroff } 9511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 952e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner ArgInfo.Name = Tok.getIdentifierInfo(); 953e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner ArgInfo.NameLoc = Tok.getLocation(); 954ff38491c18b060526d754765b952f4a497a89416Chris Lattner ConsumeToken(); // Eat the identifier. 9551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 956e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner ArgInfos.push_back(ArgInfo); 957e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner KeyIdents.push_back(SelIdent); 958e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner 9590b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall // Make sure the attributes persist. 9600b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall allParamAttrs.takeAllFrom(paramAttrs.getPool()); 9610b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall 9621f5537aaac1e775aff1d523f2cc59a9a3bd6c946Douglas Gregor // Code completion for the next piece of the selector. 9631f5537aaac1e775aff1d523f2cc59a9a3bd6c946Douglas Gregor if (Tok.is(tok::code_completion)) { 9641f5537aaac1e775aff1d523f2cc59a9a3bd6c946Douglas Gregor ConsumeCodeCompletionToken(); 9651f5537aaac1e775aff1d523f2cc59a9a3bd6c946Douglas Gregor Actions.CodeCompleteObjCMethodDeclSelector(getCurScope(), 9661f5537aaac1e775aff1d523f2cc59a9a3bd6c946Douglas Gregor mType == tok::minus, 96740ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor /*AtParameterName=*/false, 9681f5537aaac1e775aff1d523f2cc59a9a3bd6c946Douglas Gregor ReturnType, 9691f5537aaac1e775aff1d523f2cc59a9a3bd6c946Douglas Gregor KeyIdents.data(), 9701f5537aaac1e775aff1d523f2cc59a9a3bd6c946Douglas Gregor KeyIdents.size()); 9711f5537aaac1e775aff1d523f2cc59a9a3bd6c946Douglas Gregor break; 9721f5537aaac1e775aff1d523f2cc59a9a3bd6c946Douglas Gregor } 9731f5537aaac1e775aff1d523f2cc59a9a3bd6c946Douglas Gregor 974ff38491c18b060526d754765b952f4a497a89416Chris Lattner // Check for another keyword selector. 9754b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian SourceLocation Loc; 9762fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner SelIdent = ParseObjCSelectorPiece(Loc); 977df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (!SelIdent && Tok.isNot(tok::colon)) 978ff38491c18b060526d754765b952f4a497a89416Chris Lattner break; 979ff38491c18b060526d754765b952f4a497a89416Chris Lattner // We have a selector or a colon, continue parsing. 980ff38491c18b060526d754765b952f4a497a89416Chris Lattner } 9811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 982335eafa5be51f6440672a74c73d588af72e96732Steve Naroff bool isVariadic = false; 9831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 984ff38491c18b060526d754765b952f4a497a89416Chris Lattner // Parse the (optional) parameter list. 985df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner while (Tok.is(tok::comma)) { 986ff38491c18b060526d754765b952f4a497a89416Chris Lattner ConsumeToken(); 987df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::ellipsis)) { 988335eafa5be51f6440672a74c73d588af72e96732Steve Naroff isVariadic = true; 9894985aceceb9b9261b876b515d32726175c13a775Steve Naroff ConsumeToken(); 990ff38491c18b060526d754765b952f4a497a89416Chris Lattner break; 9914985aceceb9b9261b876b515d32726175c13a775Steve Naroff } 9920b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall DeclSpec DS(AttrFactory); 993ff38491c18b060526d754765b952f4a497a89416Chris Lattner ParseDeclarationSpecifiers(DS); 9941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // Parse the declarator. 995ff38491c18b060526d754765b952f4a497a89416Chris Lattner Declarator ParmDecl(DS, Declarator::PrototypeContext); 996ff38491c18b060526d754765b952f4a497a89416Chris Lattner ParseDeclarator(ParmDecl); 9974f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian IdentifierInfo *ParmII = ParmDecl.getIdentifier(); 998d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *Param = Actions.ActOnParamDeclarator(getCurScope(), ParmDecl); 9994f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian CParamInfo.push_back(DeclaratorChunk::ParamInfo(ParmII, 10004f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian ParmDecl.getIdentifierLoc(), 10014f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian Param, 10024f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian 0)); 10034f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian 10044985aceceb9b9261b876b515d32726175c13a775Steve Naroff } 10051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10069c4bb2c08989265411925a04252fd4f93c26e3b1Cameron Esfahani // FIXME: Add support for optional parameter list... 1007e3a2ca7e30601cdd31c77a830f4cc487851e8096Fariborz Jahanian // If attributes exist after the method, parse them. 10087f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall if (getLang().ObjC2) 10090b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall MaybeParseGNUAttributes(methodAttrs); 10107f53253223b29d77f1e9c5c0ce93a19932761b77Fariborz Jahanian 1011a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian if (KeyIdents.size() == 0) 1012d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 10137f53253223b29d77f1e9c5c0ce93a19932761b77Fariborz Jahanian 1014ff38491c18b060526d754765b952f4a497a89416Chris Lattner Selector Sel = PP.getSelectorTable().getSelector(KeyIdents.size(), 1015ff38491c18b060526d754765b952f4a497a89416Chris Lattner &KeyIdents[0]); 1016d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *Result 10177f53253223b29d77f1e9c5c0ce93a19932761b77Fariborz Jahanian = Actions.ActOnMethodDeclaration(getCurScope(), mLoc, Tok.getLocation(), 1018a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian mType, DSRet, ReturnType, 1019926df6cfabf3eaa4afc990c097fa4619b76a9b57Douglas Gregor selLoc, Sel, &ArgInfos[0], 10204f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian CParamInfo.data(), CParamInfo.size(), 10210b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall methodAttrs.getList(), 102290ba78c64d0c24cfbc1bf88728db9775d44d7f9fFariborz Jahanian MethodImplKind, isVariadic, MethodDefinition); 10237f53253223b29d77f1e9c5c0ce93a19932761b77Fariborz Jahanian 102454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall PD.complete(Result); 102554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall return Result; 1026294494e1cce92043562b4680c613df7fd028c02eSteve Naroff} 1027294494e1cce92043562b4680c613df7fd028c02eSteve Naroff 1028dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-refs: 1029dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// '<' identifier-list '>' 1030dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 10317caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattnerbool Parser:: 10325f9e272e632e951b1efe824cd16acb4d96077930Chris LattnerParseObjCProtocolReferences(SmallVectorImpl<Decl *> &Protocols, 10335f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVectorImpl<SourceLocation> &ProtocolLocs, 103471b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis bool WarnOnDeclarations, 103571b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis SourceLocation &LAngleLoc, SourceLocation &EndLoc) { 1036e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner assert(Tok.is(tok::less) && "expected <"); 10371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 103871b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis LAngleLoc = ConsumeToken(); // the "<" 10391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10405f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<IdentifierLocPair, 8> ProtocolIdents; 10411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1042e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner while (1) { 104355385fe3e723cd675001e45f42d61adde6b7f075Douglas Gregor if (Tok.is(tok::code_completion)) { 104455385fe3e723cd675001e45f42d61adde6b7f075Douglas Gregor Actions.CodeCompleteObjCProtocolReferences(ProtocolIdents.data(), 104555385fe3e723cd675001e45f42d61adde6b7f075Douglas Gregor ProtocolIdents.size()); 1046dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 104755385fe3e723cd675001e45f42d61adde6b7f075Douglas Gregor } 104855385fe3e723cd675001e45f42d61adde6b7f075Douglas Gregor 1049e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner if (Tok.isNot(tok::identifier)) { 1050e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner Diag(Tok, diag::err_expected_ident); 1051e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner SkipUntil(tok::greater); 1052e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner return true; 1053e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner } 1054e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner ProtocolIdents.push_back(std::make_pair(Tok.getIdentifierInfo(), 1055e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner Tok.getLocation())); 105671b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis ProtocolLocs.push_back(Tok.getLocation()); 1057e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner ConsumeToken(); 10581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1059e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner if (Tok.isNot(tok::comma)) 1060e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner break; 1061e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner ConsumeToken(); 1062e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner } 10631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1064e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner // Consume the '>'. 1065e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner if (Tok.isNot(tok::greater)) { 1066e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner Diag(Tok, diag::err_expected_greater); 1067e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner return true; 1068e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner } 10691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1070e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner EndLoc = ConsumeAnyToken(); 10711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1072e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner // Convert the list of protocols identifiers into a list of protocol decls. 1073e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner Actions.FindProtocolDeclaration(WarnOnDeclarations, 1074e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner &ProtocolIdents[0], ProtocolIdents.size(), 1075e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner Protocols); 1076e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner return false; 1077e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner} 1078e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner 10799bd1d8d174a9d15ae343246c8322299248b9e92aDouglas Gregor/// \brief Parse the Objective-C protocol qualifiers that follow a typename 10809bd1d8d174a9d15ae343246c8322299248b9e92aDouglas Gregor/// in a decl-specifier-seq, starting at the '<'. 108146f936e055d763437accd1e5a1bc49e7e5dbc0a3Douglas Gregorbool Parser::ParseObjCProtocolQualifiers(DeclSpec &DS) { 10829bd1d8d174a9d15ae343246c8322299248b9e92aDouglas Gregor assert(Tok.is(tok::less) && "Protocol qualifiers start with '<'"); 10839bd1d8d174a9d15ae343246c8322299248b9e92aDouglas Gregor assert(getLang().ObjC1 && "Protocol qualifiers only exist in Objective-C"); 10849bd1d8d174a9d15ae343246c8322299248b9e92aDouglas Gregor SourceLocation LAngleLoc, EndProtoLoc; 10855f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<Decl *, 8> ProtocolDecl; 10865f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<SourceLocation, 8> ProtocolLocs; 108746f936e055d763437accd1e5a1bc49e7e5dbc0a3Douglas Gregor bool Result = ParseObjCProtocolReferences(ProtocolDecl, ProtocolLocs, false, 108846f936e055d763437accd1e5a1bc49e7e5dbc0a3Douglas Gregor LAngleLoc, EndProtoLoc); 10899bd1d8d174a9d15ae343246c8322299248b9e92aDouglas Gregor DS.setProtocolQualifiers(ProtocolDecl.data(), ProtocolDecl.size(), 10909bd1d8d174a9d15ae343246c8322299248b9e92aDouglas Gregor ProtocolLocs.data(), LAngleLoc); 10919bd1d8d174a9d15ae343246c8322299248b9e92aDouglas Gregor if (EndProtoLoc.isValid()) 10929bd1d8d174a9d15ae343246c8322299248b9e92aDouglas Gregor DS.SetRangeEnd(EndProtoLoc); 109346f936e055d763437accd1e5a1bc49e7e5dbc0a3Douglas Gregor return Result; 10949bd1d8d174a9d15ae343246c8322299248b9e92aDouglas Gregor} 10959bd1d8d174a9d15ae343246c8322299248b9e92aDouglas Gregor 10969bd1d8d174a9d15ae343246c8322299248b9e92aDouglas Gregor 1097dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-instance-variables: 1098dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// '{' objc-instance-variable-decl-list[opt] '}' 1099dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1100dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-instance-variable-decl-list: 1101dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-visibility-spec 1102dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-instance-variable-decl ';' 1103dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// ';' 1104dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-instance-variable-decl-list objc-visibility-spec 1105dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-instance-variable-decl-list objc-instance-variable-decl ';' 1106dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-instance-variable-decl-list ';' 1107dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1108dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-visibility-spec: 1109dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @private 1110dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @protected 1111dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @public 1112ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff/// @package [OBJC2] 1113dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1114dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-instance-variable-decl: 11151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// struct-declaration 1116dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1117d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallvoid Parser::ParseObjCClassInstanceVariables(Decl *interfaceDecl, 111883c481ade785a919ba21a33f9a8b1b21c1212fb3Fariborz Jahanian tok::ObjCKeywordKind visibility, 111960fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff SourceLocation atLoc) { 1120df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner assert(Tok.is(tok::l_brace) && "expected {"); 11215f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<Decl *, 32> AllIvarDecls; 1122a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian 11231a0d31a3d7f14ddc6370ba912c778aece6c12cf0Douglas Gregor ParseScope ClassScope(this, Scope::DeclScope|Scope::ClassScope); 112472de6676bd30f9081ee4166bbe07b4c270258ce6Douglas Gregor 1125ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff SourceLocation LBraceLoc = ConsumeBrace(); // the "{" 11261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1127ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff // While we still have something to read, read the instance variables. 1128df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner while (Tok.isNot(tok::r_brace) && Tok.isNot(tok::eof)) { 1129ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff // Each iteration of this loop reads one objc-instance-variable-decl. 11301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1131ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff // Check for extraneous top-level semicolon. 1132df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::semi)) { 1133f13ca06e57ac094ed05ea08c26a499af1ba0ce88Douglas Gregor Diag(Tok, diag::ext_extra_ivar_semi) 1134849b243d4065f56742a4677d6dc8277609a151f8Douglas Gregor << FixItHint::CreateRemoval(Tok.getLocation()); 1135ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff ConsumeToken(); 1136ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff continue; 1137ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff } 11381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1139ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff // Set the default visibility to private. 1140df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::at)) { // parse objc-visibility-spec 1141ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff ConsumeToken(); // eat the @ sign 1142c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor 1143c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor if (Tok.is(tok::code_completion)) { 114423c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCAtVisibility(getCurScope()); 1145dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 1146c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor } 1147c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor 1148861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff switch (Tok.getObjCKeywordID()) { 1149ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff case tok::objc_private: 1150ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff case tok::objc_public: 1151ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff case tok::objc_protected: 1152ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff case tok::objc_package: 1153861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff visibility = Tok.getObjCKeywordID(); 1154ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff ConsumeToken(); 11551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump continue; 1156ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff default: 1157ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff Diag(Tok, diag::err_objc_illegal_visibility_spec); 1158ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff continue; 1159ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff } 1160ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff } 11611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1162c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor if (Tok.is(tok::code_completion)) { 116323c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteOrdinaryName(getCurScope(), 1164f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Sema::PCC_ObjCInstanceVariableList); 1165dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 1166c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor } 1167c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor 1168bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall struct ObjCIvarCallback : FieldCallback { 1169bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall Parser &P; 1170d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *IDecl; 1171bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall tok::ObjCKeywordKind visibility; 11725f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVectorImpl<Decl *> &AllIvarDecls; 1173bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall 1174d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall ObjCIvarCallback(Parser &P, Decl *IDecl, tok::ObjCKeywordKind V, 11755f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVectorImpl<Decl *> &AllIvarDecls) : 1176bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall P(P), IDecl(IDecl), visibility(V), AllIvarDecls(AllIvarDecls) { 1177bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall } 1178bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall 1179d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *invoke(FieldDeclarator &FD) { 1180a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian P.Actions.ActOnObjCContainerStartDefinition(IDecl); 1181bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall // Install the declarator into the interface decl. 1182d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *Field 118323c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor = P.Actions.ActOnIvar(P.getCurScope(), 1184bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall FD.D.getDeclSpec().getSourceRange().getBegin(), 1185a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian FD.D, FD.BitfieldSize, visibility); 118610af87932fe4bffad539b24d512a33a1803daeaeFariborz Jahanian P.Actions.ActOnObjCContainerFinishDefinition(); 11870bd04596e4645ff145a046dfb3475f39674060d9Fariborz Jahanian if (Field) 11880bd04596e4645ff145a046dfb3475f39674060d9Fariborz Jahanian AllIvarDecls.push_back(Field); 1189bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall return Field; 1190bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall } 1191bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall } Callback(*this, interfaceDecl, visibility, AllIvarDecls); 1192d097be8f81fbf4ed96ac10bae18562dd8202666bFariborz Jahanian 1193e13594279a952537ac903325efff57e3edca79d9Chris Lattner // Parse all the comma separated declarators. 11940b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall DeclSpec DS(AttrFactory); 1195bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall ParseStructDeclaration(DS, Callback); 11961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1197df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::semi)) { 1198ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff ConsumeToken(); 1199ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff } else { 1200ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff Diag(Tok, diag::err_expected_semi_decl_list); 1201ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff // Skip to end of block or statement 1202ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff SkipUntil(tok::r_brace, true, true); 1203ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff } 1204ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff } 120560fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff SourceLocation RBraceLoc = MatchRHSPunctuation(tok::r_brace, LBraceLoc); 1206a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian Actions.ActOnObjCContainerStartDefinition(interfaceDecl); 1207a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian Actions.ActOnLastBitfield(RBraceLoc, AllIvarDecls); 120810af87932fe4bffad539b24d512a33a1803daeaeFariborz Jahanian Actions.ActOnObjCContainerFinishDefinition(); 12098749be53f53384e7846502791ceda6c657228d07Steve Naroff // Call ActOnFields() even if we don't have any decls. This is useful 12108749be53f53384e7846502791ceda6c657228d07Steve Naroff // for code rewriting tools that need to be aware of the empty list. 121123c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.ActOnFields(getCurScope(), atLoc, interfaceDecl, 1212beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad AllIvarDecls.data(), AllIvarDecls.size(), 12131bfe1c2129771c06fb58ae5e8c079ae30e138309Daniel Dunbar LBraceLoc, RBraceLoc, 0); 1214ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff return; 12155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 1216dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff 1217dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-declaration: 1218dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-definition 1219dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-forward-reference 1220dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1221dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-definition: 12221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// @protocol identifier 12231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// objc-protocol-refs[opt] 12241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// objc-interface-decl-list 1225dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @end 1226dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1227dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-forward-reference: 1228dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @protocol identifier-list ';' 1229dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1230dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// "@protocol identifier ;" should be resolved as "@protocol 12313536b443bc50d58a79f14fca9b6842541a434854Steve Naroff/// identifier-list ;": objc-interface-decl-list may not start with a 1232dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// semicolon in the first alternative if objc-protocol-refs are omitted. 1233d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseObjCAtProtocolDeclaration(SourceLocation AtLoc, 12347f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall ParsedAttributes &attrs) { 1235861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff assert(Tok.isObjCAtKeyword(tok::objc_protocol) && 12367ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff "ParseObjCAtProtocolDeclaration(): Expected @protocol"); 12377ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff ConsumeToken(); // the "protocol" identifier 12381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1239083128f6b13dfa4fc615a838c49b516d901b1ac0Douglas Gregor if (Tok.is(tok::code_completion)) { 124023c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCProtocolDecl(getCurScope()); 1241dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 1242083128f6b13dfa4fc615a838c49b516d901b1ac0Douglas Gregor } 1243083128f6b13dfa4fc615a838c49b516d901b1ac0Douglas Gregor 1244df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 12457ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff Diag(Tok, diag::err_expected_ident); // missing protocol name. 1246d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 12477ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff } 12487ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff // Save the protocol name, then consume it. 12497ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff IdentifierInfo *protocolName = Tok.getIdentifierInfo(); 12507ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff SourceLocation nameLoc = ConsumeToken(); 12511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1252df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::semi)) { // forward declaration of one protocol. 12537caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner IdentifierLocPair ProtoInfo(protocolName, nameLoc); 12547ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff ConsumeToken(); 12551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return Actions.ActOnForwardProtocolDeclaration(AtLoc, &ProtoInfo, 1, 12567f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall attrs.getList()); 12577ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff } 12581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1259df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::comma)) { // list of forward declarations. 12605f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<IdentifierLocPair, 8> ProtocolRefs; 12617caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner ProtocolRefs.push_back(std::make_pair(protocolName, nameLoc)); 12627caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner 12637ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff // Parse the list of forward declarations. 12647ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff while (1) { 12657ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff ConsumeToken(); // the ',' 1266df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 12677ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff Diag(Tok, diag::err_expected_ident); 12687ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff SkipUntil(tok::semi); 1269d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 12707ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff } 12717caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner ProtocolRefs.push_back(IdentifierLocPair(Tok.getIdentifierInfo(), 12727caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner Tok.getLocation())); 12737ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff ConsumeToken(); // the identifier 12741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1275df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::comma)) 12767ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff break; 12777ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff } 12787ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff // Consume the ';'. 12797ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff if (ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@protocol")) 1280d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 12811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1282e440eb8158e71deb1e4ab11618ae3d680aac6da1Steve Naroff return Actions.ActOnForwardProtocolDeclaration(AtLoc, 12831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump &ProtocolRefs[0], 1284bc1c877fe28fb6a825f0b226a0a2da99e713ea03Fariborz Jahanian ProtocolRefs.size(), 12857f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall attrs.getList()); 12867caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner } 12871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12887ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff // Last, and definitely not least, parse a protocol declaration. 128971b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis SourceLocation LAngleLoc, EndProtoLoc; 12907caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner 12915f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<Decl *, 8> ProtocolRefs; 12925f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<SourceLocation, 8> ProtocolLocs; 12937caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner if (Tok.is(tok::less) && 129471b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis ParseObjCProtocolReferences(ProtocolRefs, ProtocolLocs, false, 129571b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis LAngleLoc, EndProtoLoc)) 1296d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 12971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1298d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ProtoType = 1299e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner Actions.ActOnStartProtocolInterface(AtLoc, protocolName, nameLoc, 1300beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad ProtocolRefs.data(), 1301beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad ProtocolRefs.size(), 130218df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor ProtocolLocs.data(), 13037f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall EndProtoLoc, attrs.getList()); 1304a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian 13052f64cfe19e8bf6b6ba1660e38da8c421440457feFariborz Jahanian ParseObjCInterfaceDeclList(tok::objc_protocol, ProtoType); 1306bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner return ProtoType; 1307dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff} 1308dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff 1309dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-implementation: 1310dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-implementation-prologue 1311dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-category-implementation-prologue 1312dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1313dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-implementation-prologue: 1314dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @implementation identifier objc-superclass[opt] 1315dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-instance-variables[opt] 1316dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1317dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-category-implementation-prologue: 1318dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @implementation identifier ( identifier ) 1319d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseObjCAtImplementationDeclaration( 1320ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian SourceLocation atLoc) { 1321ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian assert(Tok.isObjCAtKeyword(tok::objc_implementation) && 1322ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian "ParseObjCAtImplementationDeclaration(): Expected @implementation"); 1323ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); // the "implementation" identifier 13241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13253b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor // Code completion after '@implementation'. 13263b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor if (Tok.is(tok::code_completion)) { 132723c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCImplementationDecl(getCurScope()); 1328dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 13293b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor } 13303b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor 1331df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 1332ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian Diag(Tok, diag::err_expected_ident); // missing class or category name. 1333d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 1334ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1335ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian // We have a class or category name - consume it. 1336ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian IdentifierInfo *nameId = Tok.getIdentifierInfo(); 1337ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian SourceLocation nameLoc = ConsumeToken(); // consume class or category name 13381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (Tok.is(tok::l_paren)) { 1340ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian // we have a category implementation. 1341dec0984fce504a39a7f085774fb67cfd9957be58Jeffrey Yasskin ConsumeParen(); 1342ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian SourceLocation categoryLoc, rparenLoc; 1343ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian IdentifierInfo *categoryId = 0; 13441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 134533ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor if (Tok.is(tok::code_completion)) { 134623c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCImplementationCategory(getCurScope(), nameId, nameLoc); 1347dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 134833ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor } 134933ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor 1350df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::identifier)) { 1351ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian categoryId = Tok.getIdentifierInfo(); 1352ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian categoryLoc = ConsumeToken(); 1353ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } else { 1354ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian Diag(Tok, diag::err_expected_ident); // missing category name. 1355d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 13561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 1357df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::r_paren)) { 1358ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian Diag(Tok, diag::err_expected_rparen); 1359ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian SkipUntil(tok::r_paren, false); // don't stop at ';' 1360d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 1361ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1362ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian rparenLoc = ConsumeParen(); 1363d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ImplCatType = Actions.ActOnStartCategoryImplementation( 13641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump atLoc, nameId, nameLoc, categoryId, 13658f3fde00ad4d4f943321e338b914ae4740711c84Fariborz Jahanian categoryLoc); 1366a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian 1367a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian Actions.ActOnObjCContainerStartDefinition(ImplCatType); 1368a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCImpDecl = ImplCatType; 136963e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian PendingObjCImpDecl.push_back(ObjCImpDecl); 1370d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 1371ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1372ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian // We have a class implementation 1373ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian SourceLocation superClassLoc; 1374ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian IdentifierInfo *superClassId = 0; 1375df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::colon)) { 1376ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian // We have a super class 1377ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); 1378df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 1379ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian Diag(Tok, diag::err_expected_ident); // missing super class name. 1380d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 1381ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1382ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian superClassId = Tok.getIdentifierInfo(); 1383ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian superClassLoc = ConsumeToken(); // Consume super class name 1384ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1385d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ImplClsType = Actions.ActOnStartClassImplementation( 1386cb53b361bce341c8591333c6997f62e480acc0b4Chris Lattner atLoc, nameId, nameLoc, 1387ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian superClassId, superClassLoc); 13881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 138960fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff if (Tok.is(tok::l_brace)) // we have ivars 1390a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian ParseObjCClassInstanceVariables(ImplClsType, tok::objc_private, atLoc); 1391a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian 1392a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian Actions.ActOnObjCContainerStartDefinition(ImplClsType); 1393a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCImpDecl = ImplClsType; 139463e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian PendingObjCImpDecl.push_back(ObjCImpDecl); 1395d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 13965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 139760fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff 1398d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseObjCAtEndDeclaration(SourceRange atEnd) { 1399ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian assert(Tok.isObjCAtKeyword(tok::objc_end) && 1400ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian "ParseObjCAtEndDeclaration(): Expected @end"); 1401d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *Result = ObjCImpDecl; 1402ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); // the "end" identifier 1403a6e3ac514c924879699c6b0b1201028f0091044fFariborz Jahanian if (ObjCImpDecl) { 1404a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian Actions.ActOnAtEnd(getCurScope(), atEnd); 1405d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall ObjCImpDecl = 0; 140663e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian PendingObjCImpDecl.pop_back(); 1407a6e3ac514c924879699c6b0b1201028f0091044fFariborz Jahanian } 1408782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek else { 1409782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek // missing @implementation 141064089cece350472c04b420c497ae391443353325Fariborz Jahanian Diag(atEnd.getBegin(), diag::err_expected_implementation); 1411782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek } 1412a6e3ac514c924879699c6b0b1201028f0091044fFariborz Jahanian return Result; 14135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 1414e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian 14153fe104154dd2e8ffb351142d74f308938b5c99bfFariborz JahanianParser::DeclGroupPtrTy Parser::FinishPendingObjCActions() { 14163fe104154dd2e8ffb351142d74f308938b5c99bfFariborz Jahanian Actions.DiagnoseUseOfUnimplementedSelectors(); 141763e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian if (PendingObjCImpDecl.empty()) 1418d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return Actions.ConvertDeclToDeclGroup(0); 1419d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ImpDecl = PendingObjCImpDecl.pop_back_val(); 1420a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian Actions.ActOnAtEnd(getCurScope(), SourceRange()); 142163e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian return Actions.ConvertDeclToDeclGroup(ImpDecl); 142263e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian} 142363e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian 1424e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian/// compatibility-alias-decl: 1425e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian/// @compatibility_alias alias-name class-name ';' 1426e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian/// 1427d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseObjCAtAliasDeclaration(SourceLocation atLoc) { 1428e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian assert(Tok.isObjCAtKeyword(tok::objc_compatibility_alias) && 1429e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian "ParseObjCAtAliasDeclaration(): Expected @compatibility_alias"); 1430e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian ConsumeToken(); // consume compatibility_alias 1431df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 1432e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian Diag(Tok, diag::err_expected_ident); 1433d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 1434e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian } 1435243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian IdentifierInfo *aliasId = Tok.getIdentifierInfo(); 1436243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian SourceLocation aliasLoc = ConsumeToken(); // consume alias-name 1437df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 1438e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian Diag(Tok, diag::err_expected_ident); 1439d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 1440e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian } 1441243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian IdentifierInfo *classId = Tok.getIdentifierInfo(); 1442243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian SourceLocation classLoc = ConsumeToken(); // consume class-name; 1443e6bf90aec0044342ffccd13201b8a3a31a985a4bDouglas Gregor ExpectAndConsume(tok::semi, diag::err_expected_semi_after, 1444e6bf90aec0044342ffccd13201b8a3a31a985a4bDouglas Gregor "@compatibility_alias"); 1445b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return Actions.ActOnCompatiblityAlias(atLoc, aliasId, aliasLoc, 1446b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner classId, classLoc); 14475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 14485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1449ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-synthesis: 1450ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// @synthesize property-ivar-list ';' 1451ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// 1452ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-ivar-list: 1453ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-ivar 1454ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-ivar-list ',' property-ivar 1455ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// 1456ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-ivar: 1457ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// identifier 1458ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// identifier '=' identifier 1459ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// 1460d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseObjCPropertySynthesize(SourceLocation atLoc) { 1461ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian assert(Tok.isObjCAtKeyword(tok::objc_synthesize) && 1462ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian "ParseObjCPropertyDynamic(): Expected '@synthesize'"); 1463dec0984fce504a39a7f085774fb67cfd9957be58Jeffrey Yasskin ConsumeToken(); // consume synthesize 14641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1465b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor while (true) { 1466322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor if (Tok.is(tok::code_completion)) { 1467a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian Actions.CodeCompleteObjCPropertyDefinition(getCurScope()); 1468dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 1469322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor } 1470322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor 1471b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor if (Tok.isNot(tok::identifier)) { 1472b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor Diag(Tok, diag::err_synthesized_property_name); 1473b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor SkipUntil(tok::semi); 1474d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 1475b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor } 1476b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor 1477f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian IdentifierInfo *propertyIvar = 0; 1478f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian IdentifierInfo *propertyId = Tok.getIdentifierInfo(); 1479f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian SourceLocation propertyLoc = ConsumeToken(); // consume property name 1480a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor SourceLocation propertyIvarLoc; 1481df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::equal)) { 1482ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian // property '=' ivar-name 1483ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); // consume '=' 1484322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor 1485322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor if (Tok.is(tok::code_completion)) { 1486a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian Actions.CodeCompleteObjCPropertySynthesizeIvar(getCurScope(), propertyId); 1487dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 1488322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor } 1489322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor 1490df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 1491ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian Diag(Tok, diag::err_expected_ident); 1492ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian break; 1493ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1494f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian propertyIvar = Tok.getIdentifierInfo(); 1495a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor propertyIvarLoc = ConsumeToken(); // consume ivar-name 1496ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1497a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian Actions.ActOnPropertyImplDecl(getCurScope(), atLoc, propertyLoc, true, 1498a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor propertyId, propertyIvar, propertyIvarLoc); 1499df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::comma)) 1500ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian break; 1501ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); // consume ',' 1502ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1503e6bf90aec0044342ffccd13201b8a3a31a985a4bDouglas Gregor ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@synthesize"); 1504d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 1505ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian} 1506ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian 1507ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-dynamic: 1508ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// @dynamic property-list 1509ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// 1510ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-list: 1511ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// identifier 1512ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-list ',' identifier 1513ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// 1514d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseObjCPropertyDynamic(SourceLocation atLoc) { 1515ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian assert(Tok.isObjCAtKeyword(tok::objc_dynamic) && 1516ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian "ParseObjCPropertyDynamic(): Expected '@dynamic'"); 1517dec0984fce504a39a7f085774fb67cfd9957be58Jeffrey Yasskin ConsumeToken(); // consume dynamic 1518424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor while (true) { 1519424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor if (Tok.is(tok::code_completion)) { 1520a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian Actions.CodeCompleteObjCPropertyDefinition(getCurScope()); 1521dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 1522424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor } 1523424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor 1524424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor if (Tok.isNot(tok::identifier)) { 1525424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor Diag(Tok, diag::err_expected_ident); 1526424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor SkipUntil(tok::semi); 1527d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 1528424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor } 1529424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor 1530c35b9e4e2efad727538c848cf30d4b0eb1031dc9Fariborz Jahanian IdentifierInfo *propertyId = Tok.getIdentifierInfo(); 1531c35b9e4e2efad727538c848cf30d4b0eb1031dc9Fariborz Jahanian SourceLocation propertyLoc = ConsumeToken(); // consume property name 1532a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian Actions.ActOnPropertyImplDecl(getCurScope(), atLoc, propertyLoc, false, 1533a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor propertyId, 0, SourceLocation()); 1534c35b9e4e2efad727538c848cf30d4b0eb1031dc9Fariborz Jahanian 1535df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::comma)) 1536ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian break; 1537ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); // consume ',' 1538ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1539e6bf90aec0044342ffccd13201b8a3a31a985a4bDouglas Gregor ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@dynamic"); 1540d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 1541ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian} 15421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1543397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// objc-throw-statement: 1544397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// throw expression[opt]; 1545397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// 154660d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult Parser::ParseObjCThrowStmt(SourceLocation atLoc) { 154760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Res; 1548397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian ConsumeToken(); // consume throw 1549df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::semi)) { 155039f8f159c488a900e5958d5aab3e467af9ec8a2bFariborz Jahanian Res = ParseExpression(); 15510e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Res.isInvalid()) { 1552397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian SkipUntil(tok::semi); 155343bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 1554397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian } 1555397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian } 155602418c7f0cb8bb83f1a1a1fad9bf6104efa83e0eTed Kremenek // consume ';' 155702418c7f0cb8bb83f1a1a1fad9bf6104efa83e0eTed Kremenek ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@throw"); 15589ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return Actions.ActOnObjCAtThrowStmt(atLoc, Res.take(), getCurScope()); 1559397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian} 1560397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian 1561c385c90c68dfa376650e2facfbb444b2ec9bd110Fariborz Jahanian/// objc-synchronized-statement: 156278a677bbb5fa115fa0995b5783adeeefad67167eFariborz Jahanian/// @synchronized '(' expression ')' compound-statement 1563c385c90c68dfa376650e2facfbb444b2ec9bd110Fariborz Jahanian/// 156460d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 156543bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian RedlParser::ParseObjCSynchronizedStmt(SourceLocation atLoc) { 1566fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian ConsumeToken(); // consume synchronized 1567fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian if (Tok.isNot(tok::l_paren)) { 15681ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_lparen_after) << "@synchronized"; 156943bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 1570fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian } 157107524039dce5c820f111a1b3f772b4261f004b4aJohn McCall 157207524039dce5c820f111a1b3f772b4261f004b4aJohn McCall // The operand is surrounded with parentheses. 1573fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian ConsumeParen(); // '(' 157407524039dce5c820f111a1b3f772b4261f004b4aJohn McCall ExprResult operand(ParseExpression()); 157507524039dce5c820f111a1b3f772b4261f004b4aJohn McCall 157607524039dce5c820f111a1b3f772b4261f004b4aJohn McCall if (Tok.is(tok::r_paren)) { 157707524039dce5c820f111a1b3f772b4261f004b4aJohn McCall ConsumeParen(); // ')' 157807524039dce5c820f111a1b3f772b4261f004b4aJohn McCall } else { 157907524039dce5c820f111a1b3f772b4261f004b4aJohn McCall if (!operand.isInvalid()) 158007524039dce5c820f111a1b3f772b4261f004b4aJohn McCall Diag(Tok, diag::err_expected_rparen); 158107524039dce5c820f111a1b3f772b4261f004b4aJohn McCall 158207524039dce5c820f111a1b3f772b4261f004b4aJohn McCall // Skip forward until we see a left brace, but don't consume it. 158307524039dce5c820f111a1b3f772b4261f004b4aJohn McCall SkipUntil(tok::l_brace, true, true); 1584fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian } 158507524039dce5c820f111a1b3f772b4261f004b4aJohn McCall 158607524039dce5c820f111a1b3f772b4261f004b4aJohn McCall // Require a compound statement. 158778a677bbb5fa115fa0995b5783adeeefad67167eFariborz Jahanian if (Tok.isNot(tok::l_brace)) { 158807524039dce5c820f111a1b3f772b4261f004b4aJohn McCall if (!operand.isInvalid()) 158907524039dce5c820f111a1b3f772b4261f004b4aJohn McCall Diag(Tok, diag::err_expected_lbrace); 159043bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 159178a677bbb5fa115fa0995b5783adeeefad67167eFariborz Jahanian } 15923ac438c383a4a9a73c76a05c76ec5d02f10a3c52Steve Naroff 159307524039dce5c820f111a1b3f772b4261f004b4aJohn McCall // Check the @synchronized operand now. 159407524039dce5c820f111a1b3f772b4261f004b4aJohn McCall if (!operand.isInvalid()) 159507524039dce5c820f111a1b3f772b4261f004b4aJohn McCall operand = Actions.ActOnObjCAtSynchronizedOperand(atLoc, operand.take()); 159607524039dce5c820f111a1b3f772b4261f004b4aJohn McCall 159707524039dce5c820f111a1b3f772b4261f004b4aJohn McCall // Parse the compound statement within a new scope. 159807524039dce5c820f111a1b3f772b4261f004b4aJohn McCall ParseScope bodyScope(this, Scope::DeclScope); 159907524039dce5c820f111a1b3f772b4261f004b4aJohn McCall StmtResult body(ParseCompoundStatementBody()); 160007524039dce5c820f111a1b3f772b4261f004b4aJohn McCall bodyScope.Exit(); 160107524039dce5c820f111a1b3f772b4261f004b4aJohn McCall 160207524039dce5c820f111a1b3f772b4261f004b4aJohn McCall // If there was a semantic or parse error earlier with the 160307524039dce5c820f111a1b3f772b4261f004b4aJohn McCall // operand, fail now. 160407524039dce5c820f111a1b3f772b4261f004b4aJohn McCall if (operand.isInvalid()) 160507524039dce5c820f111a1b3f772b4261f004b4aJohn McCall return StmtError(); 160607524039dce5c820f111a1b3f772b4261f004b4aJohn McCall 160707524039dce5c820f111a1b3f772b4261f004b4aJohn McCall if (body.isInvalid()) 160807524039dce5c820f111a1b3f772b4261f004b4aJohn McCall body = Actions.ActOnNullStmt(Tok.getLocation()); 16090e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl 161007524039dce5c820f111a1b3f772b4261f004b4aJohn McCall return Actions.ActOnObjCAtSynchronizedStmt(atLoc, operand.get(), body.get()); 1611c385c90c68dfa376650e2facfbb444b2ec9bd110Fariborz Jahanian} 1612c385c90c68dfa376650e2facfbb444b2ec9bd110Fariborz Jahanian 1613397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// objc-try-catch-statement: 1614397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// @try compound-statement objc-catch-list[opt] 1615397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// @try compound-statement objc-catch-list[opt] @finally compound-statement 1616397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// 1617397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// objc-catch-list: 1618397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// @catch ( parameter-declaration ) compound-statement 1619397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// objc-catch-list @catch ( catch-parameter-declaration ) compound-statement 1620397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// catch-parameter-declaration: 1621397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// parameter-declaration 1622397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// '...' [OBJC2] 1623397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// 162460d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult Parser::ParseObjCTryStmt(SourceLocation atLoc) { 1625397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian bool catch_or_finally_seen = false; 162643bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl 1627397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian ConsumeToken(); // consume try 1628df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::l_brace)) { 16291ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_lbrace); 163043bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 1631397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian } 16328f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor StmtVector CatchStmts(Actions); 163360d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult FinallyStmt; 16348935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor ParseScope TryScope(this, Scope::DeclScope); 163560d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult TryBody(ParseCompoundStatementBody()); 16368935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor TryScope.Exit(); 16370e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (TryBody.isInvalid()) 1638bd49a647afd9cc534fef13cadf652d4e9c396e2bFariborz Jahanian TryBody = Actions.ActOnNullStmt(Tok.getLocation()); 1639a55e52c0802cae3b7c366a05c461d3d15074c1a3Sebastian Redl 1640df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner while (Tok.is(tok::at)) { 16416b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner // At this point, we need to lookahead to determine if this @ is the start 16426b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner // of an @catch or @finally. We don't want to consume the @ token if this 16436b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner // is an @try or @encode or something else. 16446b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner Token AfterAt = GetLookAheadToken(1); 16456b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner if (!AfterAt.isObjCAtKeyword(tok::objc_catch) && 16466b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner !AfterAt.isObjCAtKeyword(tok::objc_finally)) 16476b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner break; 16480e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl 1649161a9c5afaafb4d527b7efba9675a8b2cbbe32e0Fariborz Jahanian SourceLocation AtCatchFinallyLoc = ConsumeToken(); 1650cb53b361bce341c8591333c6997f62e480acc0b4Chris Lattner if (Tok.isObjCAtKeyword(tok::objc_catch)) { 1651d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *FirstPart = 0; 16523b1191d7eaf2f4984564e01ab84b6713a9d80e70Fariborz Jahanian ConsumeToken(); // consume catch 1653df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::l_paren)) { 1654397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian ConsumeParen(); 1655e21dd6ffef4585fa43cd3586ed971217d65bf56cSteve Naroff ParseScope CatchScope(this, Scope::DeclScope|Scope::AtCatchScope); 1656df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::ellipsis)) { 16570b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall DeclSpec DS(AttrFactory); 1658397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian ParseDeclarationSpecifiers(DS); 165917b6399f8461c5b7e1c6f367b0a0dde49f921240Argyrios Kyrtzidis Declarator ParmDecl(DS, Declarator::ObjCCatchContext); 16607ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff ParseDeclarator(ParmDecl); 16617ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff 16624e6c0d19b7c072758922cf80525a81aeefc6e64bDouglas Gregor // Inform the actions module about the declarator, so it 16637ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff // gets added to the current scope. 166423c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor FirstPart = Actions.ActOnObjCExceptionDecl(getCurScope(), ParmDecl); 166564515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff } else 1666397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian ConsumeToken(); // consume '...' 16671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 166893a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff SourceLocation RParenLoc; 16691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 167093a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff if (Tok.is(tok::r_paren)) 167193a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff RParenLoc = ConsumeParen(); 167293a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff else // Skip over garbage, until we get to ')'. Eat the ')'. 167393a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff SkipUntil(tok::r_paren, true, false); 167493a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff 167560d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult CatchBody(true); 1676c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner if (Tok.is(tok::l_brace)) 1677c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner CatchBody = ParseCompoundStatementBody(); 1678c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner else 1679c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner Diag(Tok, diag::err_expected_lbrace); 16800e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (CatchBody.isInvalid()) 16813b1191d7eaf2f4984564e01ab84b6713a9d80e70Fariborz Jahanian CatchBody = Actions.ActOnNullStmt(Tok.getLocation()); 16828f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor 168360d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Catch = Actions.ActOnObjCAtCatchStmt(AtCatchFinallyLoc, 16848f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor RParenLoc, 16858f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor FirstPart, 16869ae2f076ca5ab1feb3ba95629099ec2319833701John McCall CatchBody.take()); 16878f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor if (!Catch.isInvalid()) 16888f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor CatchStmts.push_back(Catch.release()); 16898f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor 169064515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff } else { 16911ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(AtCatchFinallyLoc, diag::err_expected_lparen_after) 16921ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner << "@catch clause"; 169343bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 1694397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian } 1695397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian catch_or_finally_seen = true; 16966b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner } else { 16976b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner assert(Tok.isObjCAtKeyword(tok::objc_finally) && "Lookahead confused?"); 169864515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff ConsumeToken(); // consume finally 16998935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor ParseScope FinallyScope(this, Scope::DeclScope); 17000e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl 170160d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult FinallyBody(true); 1702c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner if (Tok.is(tok::l_brace)) 1703c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner FinallyBody = ParseCompoundStatementBody(); 1704c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner else 1705c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner Diag(Tok, diag::err_expected_lbrace); 17060e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (FinallyBody.isInvalid()) 1707161a9c5afaafb4d527b7efba9675a8b2cbbe32e0Fariborz Jahanian FinallyBody = Actions.ActOnNullStmt(Tok.getLocation()); 17080e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl FinallyStmt = Actions.ActOnObjCAtFinallyStmt(AtCatchFinallyLoc, 17099ae2f076ca5ab1feb3ba95629099ec2319833701John McCall FinallyBody.take()); 1710397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian catch_or_finally_seen = true; 1711397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian break; 1712397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian } 1713397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian } 1714bd49a647afd9cc534fef13cadf652d4e9c396e2bFariborz Jahanian if (!catch_or_finally_seen) { 1715397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian Diag(atLoc, diag::err_missing_catch_finally); 171643bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 1717bd49a647afd9cc534fef13cadf652d4e9c396e2bFariborz Jahanian } 17188f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor 17199ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return Actions.ActOnObjCAtTryStmt(atLoc, TryBody.take(), 17208f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor move_arg(CatchStmts), 17219ae2f076ca5ab1feb3ba95629099ec2319833701John McCall FinallyStmt.take()); 1722397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian} 1723ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian 1724f85e193739c953358c865005855253af4f68a497John McCall/// objc-autoreleasepool-statement: 1725f85e193739c953358c865005855253af4f68a497John McCall/// @autoreleasepool compound-statement 1726f85e193739c953358c865005855253af4f68a497John McCall/// 1727f85e193739c953358c865005855253af4f68a497John McCallStmtResult 1728f85e193739c953358c865005855253af4f68a497John McCallParser::ParseObjCAutoreleasePoolStmt(SourceLocation atLoc) { 1729f85e193739c953358c865005855253af4f68a497John McCall ConsumeToken(); // consume autoreleasepool 1730f85e193739c953358c865005855253af4f68a497John McCall if (Tok.isNot(tok::l_brace)) { 1731f85e193739c953358c865005855253af4f68a497John McCall Diag(Tok, diag::err_expected_lbrace); 1732f85e193739c953358c865005855253af4f68a497John McCall return StmtError(); 1733f85e193739c953358c865005855253af4f68a497John McCall } 1734f85e193739c953358c865005855253af4f68a497John McCall // Enter a scope to hold everything within the compound stmt. Compound 1735f85e193739c953358c865005855253af4f68a497John McCall // statements can always hold declarations. 1736f85e193739c953358c865005855253af4f68a497John McCall ParseScope BodyScope(this, Scope::DeclScope); 1737f85e193739c953358c865005855253af4f68a497John McCall 1738f85e193739c953358c865005855253af4f68a497John McCall StmtResult AutoreleasePoolBody(ParseCompoundStatementBody()); 1739f85e193739c953358c865005855253af4f68a497John McCall 1740f85e193739c953358c865005855253af4f68a497John McCall BodyScope.Exit(); 1741f85e193739c953358c865005855253af4f68a497John McCall if (AutoreleasePoolBody.isInvalid()) 1742f85e193739c953358c865005855253af4f68a497John McCall AutoreleasePoolBody = Actions.ActOnNullStmt(Tok.getLocation()); 1743f85e193739c953358c865005855253af4f68a497John McCall return Actions.ActOnObjCAutoreleasePoolStmt(atLoc, 1744f85e193739c953358c865005855253af4f68a497John McCall AutoreleasePoolBody.take()); 1745f85e193739c953358c865005855253af4f68a497John McCall} 1746f85e193739c953358c865005855253af4f68a497John McCall 17473536b443bc50d58a79f14fca9b6842541a434854Steve Naroff/// objc-method-def: objc-method-proto ';'[opt] '{' body '}' 1748ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// 1749d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseObjCMethodDefinition() { 1750a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian Decl *MDecl = ParseObjCMethodPrototype(); 17511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1752f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall PrettyDeclStackTraceEntry CrashInfo(Actions, MDecl, Tok.getLocation(), 1753f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall "parsing Objective-C method"); 17541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1755ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian // parse optional ';' 1756209a8c2fa23636f6d065d618e7078e164903f5cdFariborz Jahanian if (Tok.is(tok::semi)) { 1757496e45ef3350fabc312c5a807d308c65c50af4dbTed Kremenek if (ObjCImpDecl) { 1758496e45ef3350fabc312c5a807d308c65c50af4dbTed Kremenek Diag(Tok, diag::warn_semicolon_before_method_body) 1759849b243d4065f56742a4677d6dc8277609a151f8Douglas Gregor << FixItHint::CreateRemoval(Tok.getLocation()); 1760496e45ef3350fabc312c5a807d308c65c50af4dbTed Kremenek } 1761ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); 1762209a8c2fa23636f6d065d618e7078e164903f5cdFariborz Jahanian } 1763ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian 1764409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // We should have an opening brace now. 1765df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::l_brace)) { 1766da323adbb99cee19a203ead852d5d9bfebb23fb7Steve Naroff Diag(Tok, diag::err_expected_method_body); 17671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1768409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // Skip over garbage, until we get to '{'. Don't eat the '{'. 1769409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff SkipUntil(tok::l_brace, true, true); 17701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1771409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // If we didn't find the '{', bail out. 1772409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff if (Tok.isNot(tok::l_brace)) 1773d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 1774ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1775409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff SourceLocation BraceLoc = Tok.getLocation(); 17761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1777409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // Enter a scope for the method body. 177815faee19fdb9017dd6d08a690427b18c3b062c2dChris Lattner ParseScope BodyScope(this, 177915faee19fdb9017dd6d08a690427b18c3b062c2dChris Lattner Scope::ObjCMethodScope|Scope::FnScope|Scope::DeclScope); 17801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1781409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // Tell the actions module that we have entered a method definition with the 1782394f3f483fa4e7b472630cfcd03f7840520958c5Steve Naroff // specified Declarator for the method. 178323c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.ActOnStartOfObjCMethodDef(getCurScope(), MDecl); 178461364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl 1785c9977d09a2de7f7d2245973413d4caf86c736640Douglas Gregor if (PP.isCodeCompletionEnabled()) { 1786c9977d09a2de7f7d2245973413d4caf86c736640Douglas Gregor if (trySkippingFunctionBodyForCodeCompletion()) { 1787c9977d09a2de7f7d2245973413d4caf86c736640Douglas Gregor BodyScope.Exit(); 1788b162054ba8f5b64fe87fbc4837933ab23eebd52bArgyrios Kyrtzidis return Actions.ActOnFinishFunctionBody(MDecl, 0); 1789c9977d09a2de7f7d2245973413d4caf86c736640Douglas Gregor } 1790c9977d09a2de7f7d2245973413d4caf86c736640Douglas Gregor } 17910fe5397b26695926a835fa99eceb7fc879b307afArgyrios Kyrtzidis 179260d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult FnBody(ParseCompoundStatementBody()); 179361364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl 1794409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // If the function body could not be parsed, make a bogus compoundstmt. 17950e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (FnBody.isInvalid()) 1796a60528cdac7deee3991c2b48af4df4f315e49e9dSebastian Redl FnBody = Actions.ActOnCompoundStmt(BraceLoc, BraceLoc, 1797a60528cdac7deee3991c2b48af4df4f315e49e9dSebastian Redl MultiStmtArg(Actions), false); 1798798d119415323ebcd029ffe1e0fb442a4ca8adbbSebastian Redl 1799409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // Leave the function body scope. 18008935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor BodyScope.Exit(); 1801c9977d09a2de7f7d2245973413d4caf86c736640Douglas Gregor 1802c9977d09a2de7f7d2245973413d4caf86c736640Douglas Gregor // TODO: Pass argument information. 1803c9977d09a2de7f7d2245973413d4caf86c736640Douglas Gregor Actions.ActOnFinishFunctionBody(MDecl, FnBody.take()); 180471c0a951d08dc7a2a057df8c15f22b36f6aa47c7Steve Naroff return MDecl; 18055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 18065508518a2702b00be3b15a26d772bde968972f54Anders Carlsson 180760d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult Parser::ParseObjCAtStatement(SourceLocation AtLoc) { 18089a0c85e640a08174569a303db22981612f05d385Douglas Gregor if (Tok.is(tok::code_completion)) { 180923c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCAtStatement(getCurScope()); 1810dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 18119a0c85e640a08174569a303db22981612f05d385Douglas Gregor return StmtError(); 18125d8031687d086701b4dadaab3e0de1def448da9dChris Lattner } 18135d8031687d086701b4dadaab3e0de1def448da9dChris Lattner 18145d8031687d086701b4dadaab3e0de1def448da9dChris Lattner if (Tok.isObjCAtKeyword(tok::objc_try)) 18156b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner return ParseObjCTryStmt(AtLoc); 18165d8031687d086701b4dadaab3e0de1def448da9dChris Lattner 18175d8031687d086701b4dadaab3e0de1def448da9dChris Lattner if (Tok.isObjCAtKeyword(tok::objc_throw)) 181864515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff return ParseObjCThrowStmt(AtLoc); 18195d8031687d086701b4dadaab3e0de1def448da9dChris Lattner 18205d8031687d086701b4dadaab3e0de1def448da9dChris Lattner if (Tok.isObjCAtKeyword(tok::objc_synchronized)) 182164515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff return ParseObjCSynchronizedStmt(AtLoc); 1822f85e193739c953358c865005855253af4f68a497John McCall 1823f85e193739c953358c865005855253af4f68a497John McCall if (Tok.isObjCAtKeyword(tok::objc_autoreleasepool)) 1824f85e193739c953358c865005855253af4f68a497John McCall return ParseObjCAutoreleasePoolStmt(AtLoc); 18255d8031687d086701b4dadaab3e0de1def448da9dChris Lattner 182660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Res(ParseExpressionWithLeadingAt(AtLoc)); 18270e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Res.isInvalid()) { 182864515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff // If the expression is invalid, skip ahead to the next semicolon. Not 182964515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff // doing this opens us up to the possibility of infinite loops if 183064515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff // ParseExpression does not consume any tokens. 183164515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff SkipUntil(tok::semi); 183243bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 183364515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff } 18345d8031687d086701b4dadaab3e0de1def448da9dChris Lattner 183564515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff // Otherwise, eat the semicolon. 18369ba23b4ceacd77cd264501690a7a9e94184ef71bDouglas Gregor ExpectAndConsumeSemi(diag::err_expected_semi_after_expr); 18379ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return Actions.ActOnExprStmt(Actions.MakeFullExpr(Res.take())); 183864515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff} 183964515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff 184060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult Parser::ParseObjCAtExpression(SourceLocation AtLoc) { 18415508518a2702b00be3b15a26d772bde968972f54Anders Carlsson switch (Tok.getKind()) { 18429a0c85e640a08174569a303db22981612f05d385Douglas Gregor case tok::code_completion: 184323c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCAtExpression(getCurScope()); 1844dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 18459a0c85e640a08174569a303db22981612f05d385Douglas Gregor return ExprError(); 18469a0c85e640a08174569a303db22981612f05d385Douglas Gregor 1847b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner case tok::string_literal: // primary-expression: string-literal 1848b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner case tok::wide_string_literal: 18491d922960e083906a586609ac6978678147250177Sebastian Redl return ParsePostfixExpressionSuffix(ParseObjCStringLiteral(AtLoc)); 1850b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner default: 18514fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner if (Tok.getIdentifierInfo() == 0) 18521d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(AtLoc, diag::err_unexpected_at)); 18532f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl 18544fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner switch (Tok.getIdentifierInfo()->getObjCKeywordID()) { 18554fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner case tok::objc_encode: 18561d922960e083906a586609ac6978678147250177Sebastian Redl return ParsePostfixExpressionSuffix(ParseObjCEncodeExpression(AtLoc)); 18574fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner case tok::objc_protocol: 18581d922960e083906a586609ac6978678147250177Sebastian Redl return ParsePostfixExpressionSuffix(ParseObjCProtocolExpression(AtLoc)); 18594fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner case tok::objc_selector: 18601d922960e083906a586609ac6978678147250177Sebastian Redl return ParsePostfixExpressionSuffix(ParseObjCSelectorExpression(AtLoc)); 18614fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner default: 18621d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(AtLoc, diag::err_unexpected_at)); 18634fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner } 18645508518a2702b00be3b15a26d772bde968972f54Anders Carlsson } 18655508518a2702b00be3b15a26d772bde968972f54Anders Carlsson} 18665508518a2702b00be3b15a26d772bde968972f54Anders Carlsson 18676aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// \brirg Parse the receiver of an Objective-C++ message send. 18686aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// 18696aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// This routine parses the receiver of a message send in 18706aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// Objective-C++ either as a type or as an expression. Note that this 18716aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// routine must not be called to parse a send to 'super', since it 18726aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// has no way to return such a result. 18736aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// 18746aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// \param IsExpr Whether the receiver was parsed as an expression. 18756aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// 18766aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// \param TypeOrExpr If the receiver was parsed as an expression (\c 18776aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// IsExpr is true), the parsed expression. If the receiver was parsed 18786aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// as a type (\c IsExpr is false), the parsed type. 18796aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// 18806aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// \returns True if an error occurred during parsing or semantic 18816aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// analysis, in which case the arguments do not have valid 18826aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// values. Otherwise, returns false for a successful parse. 18836aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// 18846aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// objc-receiver: [C++] 18856aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// 'super' [not parsed here] 18866aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// expression 18876aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// simple-type-specifier 18886aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// typename-specifier 18896aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregorbool Parser::ParseObjCXXMessageReceiver(bool &IsExpr, void *&TypeOrExpr) { 18900fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor InMessageExpressionRAIIObject InMessage(*this, true); 18910fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor 18926aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor if (Tok.is(tok::identifier) || Tok.is(tok::coloncolon) || 18936aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor Tok.is(tok::kw_typename) || Tok.is(tok::annot_cxxscope)) 18946aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor TryAnnotateTypeOrScopeToken(); 18956aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 18966aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor if (!isCXXSimpleTypeSpecifier()) { 18976aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // objc-receiver: 18986aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // expression 189960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Receiver = ParseExpression(); 19006aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor if (Receiver.isInvalid()) 19016aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor return true; 19026aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 19036aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor IsExpr = true; 19046aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor TypeOrExpr = Receiver.take(); 19056aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor return false; 19066aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor } 19076aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 19086aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // objc-receiver: 19096aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // typename-specifier 19106aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // simple-type-specifier 19116aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // expression (that starts with one of the above) 19120b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall DeclSpec DS(AttrFactory); 19136aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor ParseCXXSimpleTypeSpecifier(DS); 19146aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 19156aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor if (Tok.is(tok::l_paren)) { 19166aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // If we see an opening parentheses at this point, we are 19176aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // actually parsing an expression that starts with a 19186aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // function-style cast, e.g., 19196aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // 19206aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // postfix-expression: 19216aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // simple-type-specifier ( expression-list [opt] ) 19226aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // typename-specifier ( expression-list [opt] ) 19236aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // 19246aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // Parse the remainder of this case, then the (optional) 19256aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // postfix-expression suffix, followed by the (optional) 19266aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // right-hand side of the binary expression. We have an 19276aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // instance method. 192860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Receiver = ParseCXXTypeConstructExpression(DS); 19296aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor if (!Receiver.isInvalid()) 19309ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Receiver = ParsePostfixExpressionSuffix(Receiver.take()); 19316aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor if (!Receiver.isInvalid()) 19329ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Receiver = ParseRHSOfBinaryExpression(Receiver.take(), prec::Comma); 19336aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor if (Receiver.isInvalid()) 19346aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor return true; 19356aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 19366aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor IsExpr = true; 19376aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor TypeOrExpr = Receiver.take(); 19386aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor return false; 19396aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor } 19406aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 19416aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // We have a class message. Turn the simple-type-specifier or 19426aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // typename-specifier we parsed into a type and parse the 19436aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // remainder of the class message. 19446aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor Declarator DeclaratorInfo(DS, Declarator::TypeNameContext); 194523c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor TypeResult Type = Actions.ActOnTypeName(getCurScope(), DeclaratorInfo); 19466aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor if (Type.isInvalid()) 19476aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor return true; 19486aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 19496aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor IsExpr = false; 1950b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall TypeOrExpr = Type.get().getAsOpaquePtr(); 19516aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor return false; 19526aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor} 19536aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 19541b730e847ded503f2e615154035c083c4f94a067Douglas Gregor/// \brief Determine whether the parser is currently referring to a an 19551b730e847ded503f2e615154035c083c4f94a067Douglas Gregor/// Objective-C message send, using a simplified heuristic to avoid overhead. 19561b730e847ded503f2e615154035c083c4f94a067Douglas Gregor/// 19571b730e847ded503f2e615154035c083c4f94a067Douglas Gregor/// This routine will only return true for a subset of valid message-send 19581b730e847ded503f2e615154035c083c4f94a067Douglas Gregor/// expressions. 19591b730e847ded503f2e615154035c083c4f94a067Douglas Gregorbool Parser::isSimpleObjCMessageExpression() { 1960c59cb38810c63a806270385f79ea84e0203754eaChris Lattner assert(Tok.is(tok::l_square) && getLang().ObjC1 && 19611b730e847ded503f2e615154035c083c4f94a067Douglas Gregor "Incorrect start for isSimpleObjCMessageExpression"); 19621b730e847ded503f2e615154035c083c4f94a067Douglas Gregor return GetLookAheadToken(1).is(tok::identifier) && 19631b730e847ded503f2e615154035c083c4f94a067Douglas Gregor GetLookAheadToken(2).is(tok::identifier); 19641b730e847ded503f2e615154035c083c4f94a067Douglas Gregor} 19651b730e847ded503f2e615154035c083c4f94a067Douglas Gregor 19669497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregorbool Parser::isStartOfObjCClassMessageMissingOpenBracket() { 19679497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor if (!getLang().ObjC1 || !NextToken().is(tok::identifier) || 19689497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor InMessageExpression) 19699497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor return false; 19709497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor 19719497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor 19729497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor ParsedType Type; 19739497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor 19749497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor if (Tok.is(tok::annot_typename)) 19759497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor Type = getTypeAnnotation(Tok); 19769497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor else if (Tok.is(tok::identifier)) 19779497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor Type = Actions.getTypeName(*Tok.getIdentifierInfo(), Tok.getLocation(), 19789497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor getCurScope()); 19799497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor else 19809497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor return false; 19819497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor 19829497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor if (!Type.get().isNull() && Type.get()->isObjCObjectOrInterfaceType()) { 19839497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor const Token &AfterNext = GetLookAheadToken(2); 19849497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor if (AfterNext.is(tok::colon) || AfterNext.is(tok::r_square)) { 19859497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor if (Tok.is(tok::identifier)) 19869497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor TryAnnotateTypeOrScopeToken(); 19879497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor 19889497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor return Tok.is(tok::annot_typename); 19899497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor } 19909497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor } 19919497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor 19929497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor return false; 19939497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor} 19949497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor 19951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// objc-message-expr: 19960ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// '[' objc-receiver objc-message-args ']' 19970ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// 19982725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// objc-receiver: [C] 1999eb483eb3ee80300f15d6d13573d82493c2194461Chris Lattner/// 'super' 20000ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// expression 20010ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// class-name 20020ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// type-name 20036aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// 200460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult Parser::ParseObjCMessageExpression() { 2005699b66138ac307a32e238463e0eff513ff17d337Chris Lattner assert(Tok.is(tok::l_square) && "'[' expected"); 2006699b66138ac307a32e238463e0eff513ff17d337Chris Lattner SourceLocation LBracLoc = ConsumeBracket(); // consume '[' 2007699b66138ac307a32e238463e0eff513ff17d337Chris Lattner 20088e254cfe5a6ab4202c7fcc4b64bdd1ca0fe071acDouglas Gregor if (Tok.is(tok::code_completion)) { 200923c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCMessageReceiver(getCurScope()); 20108e254cfe5a6ab4202c7fcc4b64bdd1ca0fe071acDouglas Gregor ConsumeCodeCompletionToken(); 20118e254cfe5a6ab4202c7fcc4b64bdd1ca0fe071acDouglas Gregor SkipUntil(tok::r_square); 20128e254cfe5a6ab4202c7fcc4b64bdd1ca0fe071acDouglas Gregor return ExprError(); 20138e254cfe5a6ab4202c7fcc4b64bdd1ca0fe071acDouglas Gregor } 20148e254cfe5a6ab4202c7fcc4b64bdd1ca0fe071acDouglas Gregor 20150fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor InMessageExpressionRAIIObject InMessage(*this, true); 20160fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor 20176aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor if (getLang().CPlusPlus) { 20186aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // We completely separate the C and C++ cases because C++ requires 20196aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // more complicated (read: slower) parsing. 20206aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 20216aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // Handle send to super. 20226aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // FIXME: This doesn't benefit from the same typo-correction we 20236aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // get in Objective-C. 20246aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor if (Tok.is(tok::identifier) && Tok.getIdentifierInfo() == Ident_super && 202523c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor NextToken().isNot(tok::period) && getCurScope()->isInObjcMethodScope()) 2026b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall return ParseObjCMessageExpressionBody(LBracLoc, ConsumeToken(), 2027b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType(), 0); 20286aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 20296aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // Parse the receiver, which is either a type or an expression. 20306aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor bool IsExpr; 2031304b752a450c0fc5968c20ba25446d0bb7c6f68dNick Lewycky void *TypeOrExpr = NULL; 20326aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor if (ParseObjCXXMessageReceiver(IsExpr, TypeOrExpr)) { 20336aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor SkipUntil(tok::r_square); 20346aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor return ExprError(); 20356aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor } 20366aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 20376aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor if (IsExpr) 2038b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(), 2039b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType(), 20409ae2f076ca5ab1feb3ba95629099ec2319833701John McCall static_cast<Expr*>(TypeOrExpr)); 20416aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 20426aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(), 2043b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType::getFromOpaquePtr(TypeOrExpr), 2044b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall 0); 2045c59cb38810c63a806270385f79ea84e0203754eaChris Lattner } 2046c59cb38810c63a806270385f79ea84e0203754eaChris Lattner 2047c59cb38810c63a806270385f79ea84e0203754eaChris Lattner if (Tok.is(tok::identifier)) { 20481dbca6ea983231b4cab1a8f1edda8f6e13c21f12Douglas Gregor IdentifierInfo *Name = Tok.getIdentifierInfo(); 20491dbca6ea983231b4cab1a8f1edda8f6e13c21f12Douglas Gregor SourceLocation NameLoc = Tok.getLocation(); 2050b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ReceiverType; 205123c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor switch (Actions.getObjCMessageKind(getCurScope(), Name, NameLoc, 20521dbca6ea983231b4cab1a8f1edda8f6e13c21f12Douglas Gregor Name == Ident_super, 20531569f95831a8c99e9f664137bf8f40e47ee3d90fDouglas Gregor NextToken().is(tok::period), 20541569f95831a8c99e9f664137bf8f40e47ee3d90fDouglas Gregor ReceiverType)) { 2055f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall case Sema::ObjCSuperMessage: 2056b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall return ParseObjCMessageExpressionBody(LBracLoc, ConsumeToken(), 2057b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType(), 0); 20582725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor 2059f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall case Sema::ObjCClassMessage: 20601569f95831a8c99e9f664137bf8f40e47ee3d90fDouglas Gregor if (!ReceiverType) { 20612725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor SkipUntil(tok::r_square); 20622725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor return ExprError(); 20632725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor } 20642725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor 20651569f95831a8c99e9f664137bf8f40e47ee3d90fDouglas Gregor ConsumeToken(); // the type name 20661569f95831a8c99e9f664137bf8f40e47ee3d90fDouglas Gregor 20671569f95831a8c99e9f664137bf8f40e47ee3d90fDouglas Gregor return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(), 20689ae2f076ca5ab1feb3ba95629099ec2319833701John McCall ReceiverType, 0); 20691dbca6ea983231b4cab1a8f1edda8f6e13c21f12Douglas Gregor 2070f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall case Sema::ObjCInstanceMessage: 20712725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor // Fall through to parse an expression. 20721dbca6ea983231b4cab1a8f1edda8f6e13c21f12Douglas Gregor break; 2073d2869925b5f10e00b13fbf3f41bbb17e4c9adbe0Fariborz Jahanian } 2074699b66138ac307a32e238463e0eff513ff17d337Chris Lattner } 2075eb483eb3ee80300f15d6d13573d82493c2194461Chris Lattner 2076eb483eb3ee80300f15d6d13573d82493c2194461Chris Lattner // Otherwise, an arbitrary expression can be the receiver of a send. 207760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Res(ParseExpression()); 20780e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Res.isInvalid()) { 20795c749428a9938d5e2e9564b1c9b7a9252c30ee27Chris Lattner SkipUntil(tok::r_square); 20801d922960e083906a586609ac6978678147250177Sebastian Redl return move(Res); 2081699b66138ac307a32e238463e0eff513ff17d337Chris Lattner } 20821d922960e083906a586609ac6978678147250177Sebastian Redl 2083b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(), 2084b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType(), Res.take()); 2085699b66138ac307a32e238463e0eff513ff17d337Chris Lattner} 20861d922960e083906a586609ac6978678147250177Sebastian Redl 20872725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// \brief Parse the remainder of an Objective-C message following the 20882725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// '[' objc-receiver. 20892725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// 20902725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// This routine handles sends to super, class messages (sent to a 20912725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// class name), and instance messages (sent to an object), and the 20922725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// target is represented by \p SuperLoc, \p ReceiverType, or \p 20932725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// ReceiverExpr, respectively. Only one of these parameters may have 20942725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// a valid value. 20952725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// 20962725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// \param LBracLoc The location of the opening '['. 20972725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// 20982725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// \param SuperLoc If this is a send to 'super', the location of the 20992725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// 'super' keyword that indicates a send to the superclass. 21002725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// 21012725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// \param ReceiverType If this is a class message, the type of the 21022725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// class we are sending a message to. 21032725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// 21042725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// \param ReceiverExpr If this is an instance message, the expression 21052725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// used to compute the receiver object. 21061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 21070ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-message-args: 21080ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-selector 21090ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-keywordarg-list 21100ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// 21110ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-keywordarg-list: 21120ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-keywordarg 21130ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-keywordarg-list objc-keywordarg 21140ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// 21151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// objc-keywordarg: 21160ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// selector-name[opt] ':' objc-keywordexpr 21170ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// 21180ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-keywordexpr: 21190ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// nonempty-expr-list 21200ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// 21210ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// nonempty-expr-list: 21220ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// assignment-expression 21230ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// nonempty-expr-list , assignment-expression 21241d922960e083906a586609ac6978678147250177Sebastian Redl/// 212560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 2126699b66138ac307a32e238463e0eff513ff17d337Chris LattnerParser::ParseObjCMessageExpressionBody(SourceLocation LBracLoc, 21272725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor SourceLocation SuperLoc, 2128b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ReceiverType, 21291d922960e083906a586609ac6978678147250177Sebastian Redl ExprArg ReceiverExpr) { 21300fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor InMessageExpressionRAIIObject InMessage(*this, true); 21310fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor 2132c4df6d2c05c647a6a5770ba0c749782b6c023a3aSteve Naroff if (Tok.is(tok::code_completion)) { 21332725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor if (SuperLoc.isValid()) 213470c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor Actions.CodeCompleteObjCSuperMessage(getCurScope(), SuperLoc, 0, 0, 213570c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor false); 21362725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor else if (ReceiverType) 213770c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor Actions.CodeCompleteObjCClassMessage(getCurScope(), ReceiverType, 0, 0, 213870c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor false); 2139c4df6d2c05c647a6a5770ba0c749782b6c023a3aSteve Naroff else 21409ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Actions.CodeCompleteObjCInstanceMessage(getCurScope(), ReceiverExpr, 214170c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor 0, 0, false); 2142dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 2143c4df6d2c05c647a6a5770ba0c749782b6c023a3aSteve Naroff } 2144d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor 2145a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian // Parse objc-selector 21464b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian SourceLocation Loc; 21472fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner IdentifierInfo *selIdent = ParseObjCSelectorPiece(Loc); 214868d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff 2149ff975cfab9ada27df86038286d1678084aeb3428Anders Carlsson SourceLocation SelectorLoc = Loc; 21501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21515f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<IdentifierInfo *, 12> KeyIdents; 2152a55e52c0802cae3b7c366a05c461d3d15074c1a3Sebastian Redl ExprVector KeyExprs(Actions); 215368d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff 2154df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::colon)) { 2155a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian while (1) { 2156a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian // Each iteration parses a single keyword argument. 215768d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff KeyIdents.push_back(selIdent); 215837387c932855c6d58d70bdd705cd3a9fdcd2a931Steve Naroff 2159df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::colon)) { 2160a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian Diag(Tok, diag::err_expected_colon); 21614fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // We must manually skip to a ']', otherwise the expression skipper will 21624fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // stop at the ']' when it skips to the ';'. We want it to skip beyond 21634fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // the enclosing expression. 21644fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner SkipUntil(tok::r_square); 21651d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(); 2166a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian } 21671d922960e083906a586609ac6978678147250177Sebastian Redl 216868d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff ConsumeToken(); // Eat the ':'. 21691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// Parse the expression after ':' 217070c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor 217170c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor if (Tok.is(tok::code_completion)) { 217270c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor if (SuperLoc.isValid()) 217370c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor Actions.CodeCompleteObjCSuperMessage(getCurScope(), SuperLoc, 217470c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor KeyIdents.data(), 217570c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor KeyIdents.size(), 217670c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor /*AtArgumentEpression=*/true); 217770c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor else if (ReceiverType) 217870c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor Actions.CodeCompleteObjCClassMessage(getCurScope(), ReceiverType, 217970c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor KeyIdents.data(), 218070c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor KeyIdents.size(), 218170c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor /*AtArgumentEpression=*/true); 218270c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor else 218370c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor Actions.CodeCompleteObjCInstanceMessage(getCurScope(), ReceiverExpr, 218470c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor KeyIdents.data(), 218570c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor KeyIdents.size(), 218670c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor /*AtArgumentEpression=*/true); 218770c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor 218870c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor ConsumeCodeCompletionToken(); 218970c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor SkipUntil(tok::r_square); 219070c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor return ExprError(); 219170c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor } 219270c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor 219360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Res(ParseAssignmentExpression()); 21940e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Res.isInvalid()) { 21954fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // We must manually skip to a ']', otherwise the expression skipper will 21964fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // stop at the ']' when it skips to the ';'. We want it to skip beyond 21974fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // the enclosing expression. 21984fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner SkipUntil(tok::r_square); 21991d922960e083906a586609ac6978678147250177Sebastian Redl return move(Res); 220037387c932855c6d58d70bdd705cd3a9fdcd2a931Steve Naroff } 22011d922960e083906a586609ac6978678147250177Sebastian Redl 220237387c932855c6d58d70bdd705cd3a9fdcd2a931Steve Naroff // We have a valid expression. 2203effa8d1c97b00a3f53e972b0e61d9aade5ea1c57Sebastian Redl KeyExprs.push_back(Res.release()); 22041d922960e083906a586609ac6978678147250177Sebastian Redl 2205d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor // Code completion after each argument. 2206d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor if (Tok.is(tok::code_completion)) { 22072725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor if (SuperLoc.isValid()) 220823c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCSuperMessage(getCurScope(), SuperLoc, 22092725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor KeyIdents.data(), 221070c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor KeyIdents.size(), 221170c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor /*AtArgumentEpression=*/false); 22122725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor else if (ReceiverType) 221323c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCClassMessage(getCurScope(), ReceiverType, 2214d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor KeyIdents.data(), 221570c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor KeyIdents.size(), 221670c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor /*AtArgumentEpression=*/false); 2217d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor else 22189ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Actions.CodeCompleteObjCInstanceMessage(getCurScope(), ReceiverExpr, 2219d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor KeyIdents.data(), 222070c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor KeyIdents.size(), 222170c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor /*AtArgumentEpression=*/false); 2222dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 222370c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor SkipUntil(tok::r_square); 222470c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor return ExprError(); 2225d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor } 2226d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor 222737387c932855c6d58d70bdd705cd3a9fdcd2a931Steve Naroff // Check for another keyword selector. 22282fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner selIdent = ParseObjCSelectorPiece(Loc); 2229df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (!selIdent && Tok.isNot(tok::colon)) 2230a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian break; 2231a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian // We have a selector or a colon, continue parsing. 2232a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian } 2233a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian // Parse the, optional, argument list, comma separated. 2234df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner while (Tok.is(tok::comma)) { 223549f109c786f99eb7468dac3976db083a65493444Steve Naroff ConsumeToken(); // Eat the ','. 22361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// Parse the expression after ',' 223760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Res(ParseAssignmentExpression()); 22380e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Res.isInvalid()) { 22394fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // We must manually skip to a ']', otherwise the expression skipper will 22404fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // stop at the ']' when it skips to the ';'. We want it to skip beyond 22414fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // the enclosing expression. 22424fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner SkipUntil(tok::r_square); 22431d922960e083906a586609ac6978678147250177Sebastian Redl return move(Res); 224449f109c786f99eb7468dac3976db083a65493444Steve Naroff } 22450e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl 224649f109c786f99eb7468dac3976db083a65493444Steve Naroff // We have a valid expression. 2247effa8d1c97b00a3f53e972b0e61d9aade5ea1c57Sebastian Redl KeyExprs.push_back(Res.release()); 2248a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian } 2249a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian } else if (!selIdent) { 2250a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian Diag(Tok, diag::err_expected_ident); // missing selector name. 22511d922960e083906a586609ac6978678147250177Sebastian Redl 22524fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // We must manually skip to a ']', otherwise the expression skipper will 22534fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // stop at the ']' when it skips to the ';'. We want it to skip beyond 22544fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // the enclosing expression. 22554fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner SkipUntil(tok::r_square); 22561d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(); 2257a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian } 2258809872eca7f6c024e2ab41ddffbbeeae807bf5dcFariborz Jahanian 2259df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::r_square)) { 2260809872eca7f6c024e2ab41ddffbbeeae807bf5dcFariborz Jahanian if (Tok.is(tok::identifier)) 2261809872eca7f6c024e2ab41ddffbbeeae807bf5dcFariborz Jahanian Diag(Tok, diag::err_expected_colon); 2262809872eca7f6c024e2ab41ddffbbeeae807bf5dcFariborz Jahanian else 2263809872eca7f6c024e2ab41ddffbbeeae807bf5dcFariborz Jahanian Diag(Tok, diag::err_expected_rsquare); 22644fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // We must manually skip to a ']', otherwise the expression skipper will 22654fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // stop at the ']' when it skips to the ';'. We want it to skip beyond 22664fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // the enclosing expression. 22674fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner SkipUntil(tok::r_square); 22681d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(); 2269a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian } 22701d922960e083906a586609ac6978678147250177Sebastian Redl 2271699b66138ac307a32e238463e0eff513ff17d337Chris Lattner SourceLocation RBracLoc = ConsumeBracket(); // consume ']' 22721d922960e083906a586609ac6978678147250177Sebastian Redl 227329238a0bf7cbf5b396efb451a0adb5fe4aa037caSteve Naroff unsigned nKeys = KeyIdents.size(); 2274ff38491c18b060526d754765b952f4a497a89416Chris Lattner if (nKeys == 0) 2275ff38491c18b060526d754765b952f4a497a89416Chris Lattner KeyIdents.push_back(selIdent); 2276ff38491c18b060526d754765b952f4a497a89416Chris Lattner Selector Sel = PP.getSelectorTable().getSelector(nKeys, &KeyIdents[0]); 22771d922960e083906a586609ac6978678147250177Sebastian Redl 22782725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor if (SuperLoc.isValid()) 227923c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor return Actions.ActOnSuperMessage(getCurScope(), SuperLoc, Sel, 22802725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor LBracLoc, SelectorLoc, RBracLoc, 2281f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall MultiExprArg(Actions, 2282f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall KeyExprs.take(), 2283f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall KeyExprs.size())); 22842725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor else if (ReceiverType) 228523c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor return Actions.ActOnClassMessage(getCurScope(), ReceiverType, Sel, 22862725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor LBracLoc, SelectorLoc, RBracLoc, 2287f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall MultiExprArg(Actions, 2288f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall KeyExprs.take(), 2289f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall KeyExprs.size())); 22909ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return Actions.ActOnInstanceMessage(getCurScope(), ReceiverExpr, Sel, 22912725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor LBracLoc, SelectorLoc, RBracLoc, 2292f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall MultiExprArg(Actions, 2293f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall KeyExprs.take(), 2294f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall KeyExprs.size())); 22950ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian} 22960ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian 229760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult Parser::ParseObjCStringLiteral(SourceLocation AtLoc) { 229860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Res(ParseStringLiteralExpression()); 22991d922960e083906a586609ac6978678147250177Sebastian Redl if (Res.isInvalid()) return move(Res); 23001d922960e083906a586609ac6978678147250177Sebastian Redl 2301b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner // @"foo" @"bar" is a valid concatenated string. Eat any subsequent string 2302b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner // expressions. At this point, we know that the only valid thing that starts 2303b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner // with '@' is an @"". 23045f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<SourceLocation, 4> AtLocs; 2305a55e52c0802cae3b7c366a05c461d3d15074c1a3Sebastian Redl ExprVector AtStrings(Actions); 2306b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner AtLocs.push_back(AtLoc); 2307effa8d1c97b00a3f53e972b0e61d9aade5ea1c57Sebastian Redl AtStrings.push_back(Res.release()); 23080e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl 2309b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner while (Tok.is(tok::at)) { 2310b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner AtLocs.push_back(ConsumeToken()); // eat the @. 2311b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner 231215faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl // Invalid unless there is a string literal. 231397cf6eb380016db868866faf27a086cd55a316d4Chris Lattner if (!isTokenStringLiteral()) 231497cf6eb380016db868866faf27a086cd55a316d4Chris Lattner return ExprError(Diag(Tok, diag::err_objc_concat_string)); 2315b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner 231660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Lit(ParseStringLiteralExpression()); 23170e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Lit.isInvalid()) 23181d922960e083906a586609ac6978678147250177Sebastian Redl return move(Lit); 23190e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl 2320effa8d1c97b00a3f53e972b0e61d9aade5ea1c57Sebastian Redl AtStrings.push_back(Lit.release()); 2321b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner } 23221d922960e083906a586609ac6978678147250177Sebastian Redl 23231d922960e083906a586609ac6978678147250177Sebastian Redl return Owned(Actions.ParseObjCStringLiteral(&AtLocs[0], AtStrings.take(), 23241d922960e083906a586609ac6978678147250177Sebastian Redl AtStrings.size())); 23255508518a2702b00be3b15a26d772bde968972f54Anders Carlsson} 2326f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson 2327f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson/// objc-encode-expression: 2328f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson/// @encode ( type-name ) 232960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 23301d922960e083906a586609ac6978678147250177Sebastian RedlParser::ParseObjCEncodeExpression(SourceLocation AtLoc) { 2331861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff assert(Tok.isObjCAtKeyword(tok::objc_encode) && "Not an @encode expression!"); 23321d922960e083906a586609ac6978678147250177Sebastian Redl 2333f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson SourceLocation EncLoc = ConsumeToken(); 23341d922960e083906a586609ac6978678147250177Sebastian Redl 23354fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner if (Tok.isNot(tok::l_paren)) 23361d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(Tok, diag::err_expected_lparen_after) << "@encode"); 23371d922960e083906a586609ac6978678147250177Sebastian Redl 2338f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson SourceLocation LParenLoc = ConsumeParen(); 23391d922960e083906a586609ac6978678147250177Sebastian Redl 2340809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor TypeResult Ty = ParseTypeName(); 23411d922960e083906a586609ac6978678147250177Sebastian Redl 23424988ae3fda10743c8ed8a98cdcb5a783362587b4Anders Carlsson SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); 23431d922960e083906a586609ac6978678147250177Sebastian Redl 2344809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor if (Ty.isInvalid()) 2345809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor return ExprError(); 2346809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor 23471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return Owned(Actions.ParseObjCEncodeExpression(AtLoc, EncLoc, LParenLoc, 2348809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor Ty.get(), RParenLoc)); 2349f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson} 235029b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson 235129b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson/// objc-protocol-expression 235229b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson/// @protocol ( protocol-name ) 235360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 23541d922960e083906a586609ac6978678147250177Sebastian RedlParser::ParseObjCProtocolExpression(SourceLocation AtLoc) { 235529b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson SourceLocation ProtoLoc = ConsumeToken(); 23561d922960e083906a586609ac6978678147250177Sebastian Redl 23574fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner if (Tok.isNot(tok::l_paren)) 23581d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(Tok, diag::err_expected_lparen_after) << "@protocol"); 23591d922960e083906a586609ac6978678147250177Sebastian Redl 236029b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson SourceLocation LParenLoc = ConsumeParen(); 23611d922960e083906a586609ac6978678147250177Sebastian Redl 23624fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner if (Tok.isNot(tok::identifier)) 23631d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(Tok, diag::err_expected_ident)); 23641d922960e083906a586609ac6978678147250177Sebastian Redl 2365390d50a725497e99247dc104a7d2c2a255d3af14Fariborz Jahanian IdentifierInfo *protocolId = Tok.getIdentifierInfo(); 236629b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson ConsumeToken(); 23671d922960e083906a586609ac6978678147250177Sebastian Redl 23684988ae3fda10743c8ed8a98cdcb5a783362587b4Anders Carlsson SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); 236929b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson 23701d922960e083906a586609ac6978678147250177Sebastian Redl return Owned(Actions.ParseObjCProtocolExpression(protocolId, AtLoc, ProtoLoc, 23711d922960e083906a586609ac6978678147250177Sebastian Redl LParenLoc, RParenLoc)); 237229b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson} 2373a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian 2374a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian/// objc-selector-expression 2375a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian/// @selector '(' objc-keyword-selector ')' 237660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult Parser::ParseObjCSelectorExpression(SourceLocation AtLoc) { 2377a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian SourceLocation SelectorLoc = ConsumeToken(); 23781d922960e083906a586609ac6978678147250177Sebastian Redl 23794fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner if (Tok.isNot(tok::l_paren)) 23801d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(Tok, diag::err_expected_lparen_after) << "@selector"); 23811d922960e083906a586609ac6978678147250177Sebastian Redl 23825f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<IdentifierInfo *, 12> KeyIdents; 2383a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian SourceLocation LParenLoc = ConsumeParen(); 2384a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian SourceLocation sLoc; 2385458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor 2386458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor if (Tok.is(tok::code_completion)) { 2387458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor Actions.CodeCompleteObjCSelector(getCurScope(), KeyIdents.data(), 2388458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor KeyIdents.size()); 2389458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor ConsumeCodeCompletionToken(); 2390458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor MatchRHSPunctuation(tok::r_paren, LParenLoc); 2391458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor return ExprError(); 2392458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor } 2393458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor 23942fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner IdentifierInfo *SelIdent = ParseObjCSelectorPiece(sLoc); 23955add7541726348b9d1c8e96ac5031b87c41acff0Chris Lattner if (!SelIdent && // missing selector name. 23965add7541726348b9d1c8e96ac5031b87c41acff0Chris Lattner Tok.isNot(tok::colon) && Tok.isNot(tok::coloncolon)) 23971d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(Tok, diag::err_expected_ident)); 23981d922960e083906a586609ac6978678147250177Sebastian Redl 2399b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian KeyIdents.push_back(SelIdent); 2400887407e71fd58de452361b77d72970e32b20ebe0Steve Naroff unsigned nColons = 0; 2401887407e71fd58de452361b77d72970e32b20ebe0Steve Naroff if (Tok.isNot(tok::r_paren)) { 2402a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian while (1) { 24035add7541726348b9d1c8e96ac5031b87c41acff0Chris Lattner if (Tok.is(tok::coloncolon)) { // Handle :: in C++. 24045add7541726348b9d1c8e96ac5031b87c41acff0Chris Lattner ++nColons; 24055add7541726348b9d1c8e96ac5031b87c41acff0Chris Lattner KeyIdents.push_back(0); 24065add7541726348b9d1c8e96ac5031b87c41acff0Chris Lattner } else if (Tok.isNot(tok::colon)) 24071d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(Tok, diag::err_expected_colon)); 24081d922960e083906a586609ac6978678147250177Sebastian Redl 24095add7541726348b9d1c8e96ac5031b87c41acff0Chris Lattner ++nColons; 24103b3e1a9e79703da067d23756e5624a4f487d6278Chris Lattner ConsumeToken(); // Eat the ':' or '::'. 2411a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian if (Tok.is(tok::r_paren)) 2412a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian break; 2413458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor 2414458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor if (Tok.is(tok::code_completion)) { 2415458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor Actions.CodeCompleteObjCSelector(getCurScope(), KeyIdents.data(), 2416458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor KeyIdents.size()); 2417458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor ConsumeCodeCompletionToken(); 2418458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor MatchRHSPunctuation(tok::r_paren, LParenLoc); 2419458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor return ExprError(); 2420458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor } 2421458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor 2422a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian // Check for another keyword selector. 2423a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian SourceLocation Loc; 24242fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner SelIdent = ParseObjCSelectorPiece(Loc); 2425b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian KeyIdents.push_back(SelIdent); 24263b3e1a9e79703da067d23756e5624a4f487d6278Chris Lattner if (!SelIdent && Tok.isNot(tok::colon) && Tok.isNot(tok::coloncolon)) 2427a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian break; 2428a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian } 2429887407e71fd58de452361b77d72970e32b20ebe0Steve Naroff } 2430a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); 2431887407e71fd58de452361b77d72970e32b20ebe0Steve Naroff Selector Sel = PP.getSelectorTable().getSelector(nColons, &KeyIdents[0]); 24321d922960e083906a586609ac6978678147250177Sebastian Redl return Owned(Actions.ParseObjCSelectorExpression(Sel, AtLoc, SelectorLoc, 24331d922960e083906a586609ac6978678147250177Sebastian Redl LParenLoc, RParenLoc)); 243458065b2d8038a4e9a91ea4813bd1774c0f6efacbGabor Greif } 2435