ParseObjc.cpp revision 2edf0a2520313cde900799b1eb9bd11c9c776afe
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()); 377d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis cutOffParsing(); 387d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis return DeclGroupPtrTy(); 39c464ae8444edb6d07ea49b7a0eae1674c0fa1bb8Douglas Gregor } 4095ed7784a335aca53b0c6e952cf31a4cfb633360Fariborz Jahanian 4195ed7784a335aca53b0c6e952cf31a4cfb633360Fariborz Jahanian Decl *SingleDecl = 0; 42861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff switch (Tok.getObjCKeywordID()) { 435ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner case tok::objc_class: 445ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner return ParseObjCAtClassDeclaration(AtLoc); 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); 52bd9482d859a74bf2c45ef8b8aedec61c0e1c8374Douglas Gregor return ParseObjCAtProtocolDeclaration(AtLoc, attrs); 537f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall } 545ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner case tok::objc_implementation: 55849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis return ParseObjCAtImplementationDeclaration(AtLoc); 565ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner case tok::objc_end: 57140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian return ParseObjCAtEndDeclaration(AtLoc); 585ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner case tok::objc_compatibility_alias: 5995ed7784a335aca53b0c6e952cf31a4cfb633360Fariborz Jahanian SingleDecl = ParseObjCAtAliasDeclaration(AtLoc); 6095ed7784a335aca53b0c6e952cf31a4cfb633360Fariborz Jahanian break; 615ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner case tok::objc_synthesize: 6295ed7784a335aca53b0c6e952cf31a4cfb633360Fariborz Jahanian SingleDecl = ParseObjCPropertySynthesize(AtLoc); 6395ed7784a335aca53b0c6e952cf31a4cfb633360Fariborz Jahanian break; 645ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner case tok::objc_dynamic: 6595ed7784a335aca53b0c6e952cf31a4cfb633360Fariborz Jahanian SingleDecl = ParseObjCPropertyDynamic(AtLoc); 6695ed7784a335aca53b0c6e952cf31a4cfb633360Fariborz Jahanian break; 6732ad2ee2618745ce3da51c2ae066ed5f21157c07Ted Kremenek case tok::objc___experimental_modules_import: 684e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (getLangOpts().Modules) 6994ad28b31433058445a27db722f60402ee820beaDouglas Gregor return ParseModuleImport(AtLoc); 7094ad28b31433058445a27db722f60402ee820beaDouglas Gregor 7194ad28b31433058445a27db722f60402ee820beaDouglas Gregor // Fall through 7294ad28b31433058445a27db722f60402ee820beaDouglas Gregor 735ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner default: 745ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner Diag(AtLoc, diag::err_unexpected_at); 755ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner SkipUntil(tok::semi); 7695ed7784a335aca53b0c6e952cf31a4cfb633360Fariborz Jahanian SingleDecl = 0; 7795ed7784a335aca53b0c6e952cf31a4cfb633360Fariborz Jahanian break; 785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 7995ed7784a335aca53b0c6e952cf31a4cfb633360Fariborz Jahanian return Actions.ConvertDeclToDeclGroup(SingleDecl); 805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// objc-class-declaration: 845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// '@' 'class' identifier-list ';' 851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 8695ed7784a335aca53b0c6e952cf31a4cfb633360Fariborz JahanianParser::DeclGroupPtrTy 8795ed7784a335aca53b0c6e952cf31a4cfb633360Fariborz JahanianParser::ParseObjCAtClassDeclaration(SourceLocation atLoc) { 885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ConsumeToken(); // the identifier "class" 895f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<IdentifierInfo *, 8> ClassNames; 905f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<SourceLocation, 8> ClassLocs; 91c09cba67d0ad01e53e0fed07322e95dd281bcfd9Ted Kremenek 921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer while (1) { 94df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Diag(Tok, diag::err_expected_ident); 965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SkipUntil(tok::semi); 9795ed7784a335aca53b0c6e952cf31a4cfb633360Fariborz Jahanian return Actions.ConvertDeclToDeclGroup(0); 985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ClassNames.push_back(Tok.getIdentifierInfo()); 100c09cba67d0ad01e53e0fed07322e95dd281bcfd9Ted Kremenek ClassLocs.push_back(Tok.getLocation()); 1015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ConsumeToken(); 1021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 103df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::comma)) 1045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer break; 1051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ConsumeToken(); 1075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Consume the ';'. 1105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@class")) 11195ed7784a335aca53b0c6e952cf31a4cfb633360Fariborz Jahanian return Actions.ConvertDeclToDeclGroup(0); 1121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 113c09cba67d0ad01e53e0fed07322e95dd281bcfd9Ted Kremenek return Actions.ActOnForwardClassDeclaration(atLoc, ClassNames.data(), 114c09cba67d0ad01e53e0fed07322e95dd281bcfd9Ted Kremenek ClassLocs.data(), 115c09cba67d0ad01e53e0fed07322e95dd281bcfd9Ted Kremenek ClassNames.size()); 1165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 1175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 118d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggenvoid Parser::CheckNestedObjCContexts(SourceLocation AtLoc) 119d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen{ 120d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen Sema::ObjCContainerKind ock = Actions.getObjCContainerKind(); 121d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen if (ock == Sema::OCK_None) 122d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen return; 123d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen 124849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis Decl *Decl = Actions.getObjCDeclContext(); 125849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis if (CurParsedObjCImpl) { 126849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis CurParsedObjCImpl->finish(AtLoc); 127849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis } else { 128849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis Actions.ActOnAtEnd(getCurScope(), AtLoc); 129849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis } 130d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen Diag(AtLoc, diag::err_objc_missing_end) 131d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen << FixItHint::CreateInsertion(AtLoc, "@end\n"); 132d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen if (Decl) 133d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen Diag(Decl->getLocStart(), diag::note_objc_container_start) 134d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen << (int) ock; 135d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen} 136d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen 137dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 138dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-interface: 139dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-interface-attributes[opt] objc-class-interface 140dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-category-interface 141dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 142dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-interface: 1431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// '@' 'interface' identifier objc-superclass[opt] 144dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-refs[opt] 1451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// objc-class-instance-variables[opt] 146dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-interface-decl-list 147dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @end 148dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 149dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-category-interface: 1501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// '@' 'interface' identifier '(' identifier[opt] ')' 151dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-refs[opt] 152dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-interface-decl-list 153dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @end 154dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 155dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-superclass: 156dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// ':' identifier 157dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 158dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-interface-attributes: 159dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// __attribute__((visibility("default"))) 160dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// __attribute__((visibility("hidden"))) 161dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// __attribute__((deprecated)) 162dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// __attribute__((unavailable)) 163dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// __attribute__((objc_exception)) - used by NSException on 64-bit 164b2f6820773aabff3c5c9e0dbb1cbbbda0d80c41fPatrick Beard/// __attribute__((objc_root_class)) 165dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 166d64251fd56577dd5c78903454632361e094c6dc1Erik VerbruggenDecl *Parser::ParseObjCAtInterfaceDeclaration(SourceLocation AtLoc, 1677f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall ParsedAttributes &attrs) { 168861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff assert(Tok.isObjCAtKeyword(tok::objc_interface) && 169dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff "ParseObjCAtInterfaceDeclaration(): Expected @interface"); 170d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen CheckNestedObjCContexts(AtLoc); 171dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff ConsumeToken(); // the "interface" identifier 1721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1733b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor // Code completion after '@interface'. 1743b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor if (Tok.is(tok::code_completion)) { 17523c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCInterfaceDecl(getCurScope()); 1767d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis cutOffParsing(); 1777d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis return 0; 1783b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor } 1793b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor 180df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 181dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff Diag(Tok, diag::err_expected_ident); // missing class or category name. 182d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 183dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff } 18463e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian 185dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff // We have a class or category name - consume it. 1867ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff IdentifierInfo *nameId = Tok.getIdentifierInfo(); 187dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff SourceLocation nameLoc = ConsumeToken(); 1885512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian if (Tok.is(tok::l_paren) && 1895512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian !isKnownToBeTypeSpecifier(GetLookAheadToken(1))) { // we have a category. 1904a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor 1914a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor BalancedDelimiterTracker T(*this, tok::l_paren); 1924a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor T.consumeOpen(); 1934a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor 1944a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor SourceLocation categoryLoc; 195dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff IdentifierInfo *categoryId = 0; 19633ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor if (Tok.is(tok::code_completion)) { 19723c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCInterfaceCategory(getCurScope(), nameId, nameLoc); 1987d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis cutOffParsing(); 1997d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis return 0; 20033ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor } 20133ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor 202527fe23f8cbc6a4da1737a547a2517bc92fa88c8Steve Naroff // For ObjC2, the category name is optional (not an error). 203df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::identifier)) { 204dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff categoryId = Tok.getIdentifierInfo(); 205dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff categoryLoc = ConsumeToken(); 20605511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian } 2074e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie else if (!getLangOpts().ObjC2) { 208527fe23f8cbc6a4da1737a547a2517bc92fa88c8Steve Naroff Diag(Tok, diag::err_expected_ident); // missing category name. 209d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 210dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff } 2114a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor 2124a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor T.consumeClose(); 2134a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor if (T.getCloseLocation().isInvalid()) 214d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 21513d05ac08974ccb41f7da7595d769c158f58fbd6Douglas Gregor 21613d05ac08974ccb41f7da7595d769c158f58fbd6Douglas Gregor if (!attrs.empty()) { // categories don't support attributes. 21713d05ac08974ccb41f7da7595d769c158f58fbd6Douglas Gregor Diag(nameLoc, diag::err_objc_no_attributes_on_category); 21813d05ac08974ccb41f7da7595d769c158f58fbd6Douglas Gregor attrs.clear(); 219dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff } 22013d05ac08974ccb41f7da7595d769c158f58fbd6Douglas Gregor 2215512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian // Next, we need to check for any protocol references. 2225512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian SourceLocation LAngleLoc, EndProtoLoc; 2235f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<Decl *, 8> ProtocolRefs; 2245f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<SourceLocation, 8> ProtocolLocs; 2255512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian if (Tok.is(tok::less) && 2265512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian ParseObjCProtocolReferences(ProtocolRefs, ProtocolLocs, true, 22771b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis LAngleLoc, EndProtoLoc)) 228d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 22905511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian 230d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *CategoryType = 231d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen Actions.ActOnStartCategoryInterface(AtLoc, 2325512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian nameId, nameLoc, 2335512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian categoryId, categoryLoc, 2345512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian ProtocolRefs.data(), 2355512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian ProtocolRefs.size(), 2365512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian ProtocolLocs.data(), 2375512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian EndProtoLoc); 238e6f07f538fd0eddd6c087fcc01d4e4ff19129c71Fariborz Jahanian 239a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian if (Tok.is(tok::l_brace)) 240d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen ParseObjCClassInstanceVariables(CategoryType, tok::objc_private, AtLoc); 241a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian 2422f64cfe19e8bf6b6ba1660e38da8c421440457feFariborz Jahanian ParseObjCInterfaceDeclList(tok::objc_not_keyword, CategoryType); 2435512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian return CategoryType; 244dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff } 245dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff // Parse a class interface. 246dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff IdentifierInfo *superClassId = 0; 247dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff SourceLocation superClassLoc; 2487ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff 249df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::colon)) { // a super class is specified. 250dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff ConsumeToken(); 2513b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor 2523b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor // Code completion of superclass names. 2533b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor if (Tok.is(tok::code_completion)) { 25423c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCSuperclass(getCurScope(), nameId, nameLoc); 2557d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis cutOffParsing(); 2567d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis return 0; 2573b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor } 2583b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor 259df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 260dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff Diag(Tok, diag::err_expected_ident); // missing super class name. 261d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 262dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff } 263dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff superClassId = Tok.getIdentifierInfo(); 264dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff superClassLoc = ConsumeToken(); 265dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff } 266dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff // Next, we need to check for any protocol references. 2675f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<Decl *, 8> ProtocolRefs; 2685f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<SourceLocation, 8> ProtocolLocs; 26971b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis SourceLocation LAngleLoc, EndProtoLoc; 27006036d3709955a53297b4cbe14e20db88f321470Chris Lattner if (Tok.is(tok::less) && 27171b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis ParseObjCProtocolReferences(ProtocolRefs, ProtocolLocs, true, 27271b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis LAngleLoc, EndProtoLoc)) 273d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 2741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 275d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ClsType = 276d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen Actions.ActOnStartClassInterface(AtLoc, nameId, nameLoc, 27706036d3709955a53297b4cbe14e20db88f321470Chris Lattner superClassId, superClassLoc, 278beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad ProtocolRefs.data(), ProtocolRefs.size(), 27918df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor ProtocolLocs.data(), 2807f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall EndProtoLoc, attrs.getList()); 2811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 282df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::l_brace)) 283d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen ParseObjCClassInstanceVariables(ClsType, tok::objc_protected, AtLoc); 284dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff 2852f64cfe19e8bf6b6ba1660e38da8c421440457feFariborz Jahanian ParseObjCInterfaceDeclList(tok::objc_interface, ClsType); 2865512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian return ClsType; 287dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff} 288dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff 289d0014540005f2a5ab837365db6bd40f479406758John McCall/// The Objective-C property callback. This should be defined where 290d0014540005f2a5ab837365db6bd40f479406758John McCall/// it's used, but instead it's been lifted to here to support VS2005. 291d0014540005f2a5ab837365db6bd40f479406758John McCallstruct Parser::ObjCPropertyCallback : FieldCallback { 29299ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikieprivate: 29399ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie virtual void anchor(); 29499ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikiepublic: 295d0014540005f2a5ab837365db6bd40f479406758John McCall Parser &P; 2965f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVectorImpl<Decl *> &Props; 297d0014540005f2a5ab837365db6bd40f479406758John McCall ObjCDeclSpec &OCDS; 298d0014540005f2a5ab837365db6bd40f479406758John McCall SourceLocation AtLoc; 29977bfb8b43ec3f7dee3a71f6e854b03ad29dab84fFariborz Jahanian SourceLocation LParenLoc; 300d0014540005f2a5ab837365db6bd40f479406758John McCall tok::ObjCKeywordKind MethodImplKind; 301d0014540005f2a5ab837365db6bd40f479406758John McCall 302a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian ObjCPropertyCallback(Parser &P, 3035f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVectorImpl<Decl *> &Props, 304d0014540005f2a5ab837365db6bd40f479406758John McCall ObjCDeclSpec &OCDS, SourceLocation AtLoc, 30577bfb8b43ec3f7dee3a71f6e854b03ad29dab84fFariborz Jahanian SourceLocation LParenLoc, 306d0014540005f2a5ab837365db6bd40f479406758John McCall tok::ObjCKeywordKind MethodImplKind) : 30777bfb8b43ec3f7dee3a71f6e854b03ad29dab84fFariborz Jahanian P(P), Props(Props), OCDS(OCDS), AtLoc(AtLoc), LParenLoc(LParenLoc), 308d0014540005f2a5ab837365db6bd40f479406758John McCall MethodImplKind(MethodImplKind) { 309d0014540005f2a5ab837365db6bd40f479406758John McCall } 310d0014540005f2a5ab837365db6bd40f479406758John McCall 311d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *invoke(FieldDeclarator &FD) { 312d0014540005f2a5ab837365db6bd40f479406758John McCall if (FD.D.getIdentifier() == 0) { 313d0014540005f2a5ab837365db6bd40f479406758John McCall P.Diag(AtLoc, diag::err_objc_property_requires_field_name) 314d0014540005f2a5ab837365db6bd40f479406758John McCall << FD.D.getSourceRange(); 315d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 316d0014540005f2a5ab837365db6bd40f479406758John McCall } 317d0014540005f2a5ab837365db6bd40f479406758John McCall if (FD.BitfieldSize) { 318d0014540005f2a5ab837365db6bd40f479406758John McCall P.Diag(AtLoc, diag::err_objc_property_bitfield) 319d0014540005f2a5ab837365db6bd40f479406758John McCall << FD.D.getSourceRange(); 320d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 321d0014540005f2a5ab837365db6bd40f479406758John McCall } 322d0014540005f2a5ab837365db6bd40f479406758John McCall 323d0014540005f2a5ab837365db6bd40f479406758John McCall // Install the property declarator into interfaceDecl. 324d0014540005f2a5ab837365db6bd40f479406758John McCall IdentifierInfo *SelName = 325d0014540005f2a5ab837365db6bd40f479406758John McCall OCDS.getGetterName() ? OCDS.getGetterName() : FD.D.getIdentifier(); 326d0014540005f2a5ab837365db6bd40f479406758John McCall 327d0014540005f2a5ab837365db6bd40f479406758John McCall Selector GetterSel = 328d0014540005f2a5ab837365db6bd40f479406758John McCall P.PP.getSelectorTable().getNullarySelector(SelName); 329d0014540005f2a5ab837365db6bd40f479406758John McCall IdentifierInfo *SetterName = OCDS.getSetterName(); 330d0014540005f2a5ab837365db6bd40f479406758John McCall Selector SetterSel; 331d0014540005f2a5ab837365db6bd40f479406758John McCall if (SetterName) 332d0014540005f2a5ab837365db6bd40f479406758John McCall SetterSel = P.PP.getSelectorTable().getSelector(1, &SetterName); 333d0014540005f2a5ab837365db6bd40f479406758John McCall else 334d0014540005f2a5ab837365db6bd40f479406758John McCall SetterSel = SelectorTable::constructSetterName(P.PP.getIdentifierTable(), 335d0014540005f2a5ab837365db6bd40f479406758John McCall P.PP.getSelectorTable(), 336d0014540005f2a5ab837365db6bd40f479406758John McCall FD.D.getIdentifier()); 337d0014540005f2a5ab837365db6bd40f479406758John McCall bool isOverridingProperty = false; 338d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *Property = 33977bfb8b43ec3f7dee3a71f6e854b03ad29dab84fFariborz Jahanian P.Actions.ActOnProperty(P.getCurScope(), AtLoc, LParenLoc, 34077bfb8b43ec3f7dee3a71f6e854b03ad29dab84fFariborz Jahanian FD, OCDS, 341a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian GetterSel, SetterSel, 342d0014540005f2a5ab837365db6bd40f479406758John McCall &isOverridingProperty, 343d0014540005f2a5ab837365db6bd40f479406758John McCall MethodImplKind); 344d0014540005f2a5ab837365db6bd40f479406758John McCall if (!isOverridingProperty) 345d0014540005f2a5ab837365db6bd40f479406758John McCall Props.push_back(Property); 346d0014540005f2a5ab837365db6bd40f479406758John McCall 347d0014540005f2a5ab837365db6bd40f479406758John McCall return Property; 348d0014540005f2a5ab837365db6bd40f479406758John McCall } 349d0014540005f2a5ab837365db6bd40f479406758John McCall}; 350d0014540005f2a5ab837365db6bd40f479406758John McCall 35199ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikievoid Parser::ObjCPropertyCallback::anchor() { 35299ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie} 35399ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie 354dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-interface-decl-list: 355dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// empty 356dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-interface-decl-list objc-property-decl [OBJC2] 357294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-interface-decl-list objc-method-requirement [OBJC2] 3583536b443bc50d58a79f14fca9b6842541a434854Steve Naroff/// objc-interface-decl-list objc-method-proto ';' 359dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-interface-decl-list declaration 360dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-interface-decl-list ';' 361dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 362294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-method-requirement: [OBJC2] 363294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// @required 364294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// @optional 365294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 3662f64cfe19e8bf6b6ba1660e38da8c421440457feFariborz Jahanianvoid Parser::ParseObjCInterfaceDeclList(tok::ObjCKeywordKind contextKey, 3672f64cfe19e8bf6b6ba1660e38da8c421440457feFariborz Jahanian Decl *CDecl) { 3685f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<Decl *, 32> allMethods; 3695f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<Decl *, 16> allProperties; 3705f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<DeclGroupPtrTy, 8> allTUVariables; 37100933591a2795d09dd1acff12a2d21bce7cb12c5Fariborz Jahanian tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword; 3721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 373782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek SourceRange AtEnd; 3742f64cfe19e8bf6b6ba1660e38da8c421440457feFariborz Jahanian 375294494e1cce92043562b4680c613df7fd028c02eSteve Naroff while (1) { 376e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner // If this is a method prototype, parse it. 377df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::minus) || Tok.is(tok::plus)) { 378d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *methodPrototype = 379a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian ParseObjCMethodPrototype(MethodImplKind, false); 38025e077d59a8e8e43b65882b69610a3d5e2aaf53cFariborz Jahanian allMethods.push_back(methodPrototype); 3813536b443bc50d58a79f14fca9b6842541a434854Steve Naroff // Consume the ';' here, since ParseObjCMethodPrototype() is re-used for 3823536b443bc50d58a79f14fca9b6842541a434854Steve Naroff // method definitions. 3830db9f4dad563a335641f5b9d4a42504d638b6c85Argyrios Kyrtzidis if (ExpectAndConsumeSemi(diag::err_expected_semi_after_method_proto)) { 3840db9f4dad563a335641f5b9d4a42504d638b6c85Argyrios Kyrtzidis // We didn't find a semi and we error'ed out. Skip until a ';' or '@'. 3850db9f4dad563a335641f5b9d4a42504d638b6c85Argyrios Kyrtzidis SkipUntil(tok::at, /*StopAtSemi=*/true, /*DontConsume=*/true); 3860db9f4dad563a335641f5b9d4a42504d638b6c85Argyrios Kyrtzidis if (Tok.is(tok::semi)) 3870db9f4dad563a335641f5b9d4a42504d638b6c85Argyrios Kyrtzidis ConsumeToken(); 3880db9f4dad563a335641f5b9d4a42504d638b6c85Argyrios Kyrtzidis } 389294494e1cce92043562b4680c613df7fd028c02eSteve Naroff continue; 390294494e1cce92043562b4680c613df7fd028c02eSteve Naroff } 39105511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian if (Tok.is(tok::l_paren)) { 39205511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian Diag(Tok, diag::err_expected_minus_or_plus); 393d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall ParseObjCMethodDecl(Tok.getLocation(), 394d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall tok::minus, 39590ba78c64d0c24cfbc1bf88728db9775d44d7f9fFariborz Jahanian MethodImplKind, false); 39605511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian continue; 39705511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian } 398e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner // Ignore excess semicolons. 399e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner if (Tok.is(tok::semi)) { 400294494e1cce92043562b4680c613df7fd028c02eSteve Naroff ConsumeToken(); 401e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner continue; 402e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner } 4031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 404bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // If we got to the end of the file, exit the loop. 405e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner if (Tok.is(tok::eof)) 406e3a2ca7e30601cdd31c77a830f4cc487851e8096Fariborz Jahanian break; 4071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 408b6ac2451bfed36206c5cec7217372c4299f67f2bDouglas Gregor // Code completion within an Objective-C interface. 409b6ac2451bfed36206c5cec7217372c4299f67f2bDouglas Gregor if (Tok.is(tok::code_completion)) { 41023c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteOrdinaryName(getCurScope(), 411849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis CurParsedObjCImpl? Sema::PCC_ObjCImplementation 412f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall : Sema::PCC_ObjCInterface); 4137d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis return cutOffParsing(); 414b6ac2451bfed36206c5cec7217372c4299f67f2bDouglas Gregor } 415b6ac2451bfed36206c5cec7217372c4299f67f2bDouglas Gregor 416e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner // If we don't have an @ directive, parse it as a function definition. 417e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner if (Tok.isNot(tok::at)) { 4181fd80116b49782c367ff5d5f50a8b76dd8a5d7f7Chris Lattner // The code below does not consume '}'s because it is afraid of eating the 4191fd80116b49782c367ff5d5f50a8b76dd8a5d7f7Chris Lattner // end of a namespace. Because of the way this code is structured, an 4201fd80116b49782c367ff5d5f50a8b76dd8a5d7f7Chris Lattner // erroneous r_brace would cause an infinite loop if not handled here. 4211fd80116b49782c367ff5d5f50a8b76dd8a5d7f7Chris Lattner if (Tok.is(tok::r_brace)) 4221fd80116b49782c367ff5d5f50a8b76dd8a5d7f7Chris Lattner break; 4232edf0a2520313cde900799b1eb9bd11c9c776afeSean Hunt ParsedAttributesWithRange attrs(AttrFactory); 4247f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall allTUVariables.push_back(ParseDeclarationOrFunctionDefinition(attrs)); 425e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner continue; 426e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner } 4271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 428e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner // Otherwise, we have an @ directive, eat the @. 429e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner SourceLocation AtLoc = ConsumeToken(); // the "@" 430c464ae8444edb6d07ea49b7a0eae1674c0fa1bb8Douglas Gregor if (Tok.is(tok::code_completion)) { 431a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian Actions.CodeCompleteObjCAtDirective(getCurScope()); 4327d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis return cutOffParsing(); 433c464ae8444edb6d07ea49b7a0eae1674c0fa1bb8Douglas Gregor } 434c464ae8444edb6d07ea49b7a0eae1674c0fa1bb8Douglas Gregor 435a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner tok::ObjCKeywordKind DirectiveKind = Tok.getObjCKeywordID(); 4361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 437a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner if (DirectiveKind == tok::objc_end) { // @end -> terminate list 438782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek AtEnd.setBegin(AtLoc); 439782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek AtEnd.setEnd(Tok.getLocation()); 440e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner break; 441c3d43b783dfb1a1502aa8b31ab1985cf237b1f77Douglas Gregor } else if (DirectiveKind == tok::objc_not_keyword) { 442c3d43b783dfb1a1502aa8b31ab1985cf237b1f77Douglas Gregor Diag(Tok, diag::err_objc_unknown_at); 443c3d43b783dfb1a1502aa8b31ab1985cf237b1f77Douglas Gregor SkipUntil(tok::semi); 444c3d43b783dfb1a1502aa8b31ab1985cf237b1f77Douglas Gregor continue; 445bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner } 4461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 447bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // Eat the identifier. 448bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner ConsumeToken(); 449bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner 450a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner switch (DirectiveKind) { 451a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner default: 452bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // FIXME: If someone forgets an @end on a protocol, this loop will 453bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // continue to eat up tons of stuff and spew lots of nonsense errors. It 454bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // would probably be better to bail out if we saw an @class or @interface 455bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // or something like that. 456f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner Diag(AtLoc, diag::err_objc_illegal_interface_qual); 457bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // Skip until we see an '@' or '}' or ';'. 458a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner SkipUntil(tok::r_brace, tok::at); 459a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner break; 46046d545e355a4fea2a201652c3c8bbf22a13187a6Fariborz Jahanian 46146d545e355a4fea2a201652c3c8bbf22a13187a6Fariborz Jahanian case tok::objc_implementation: 462df81c2c6ce37f4ae3c45dd01093b6274fa0b6692Fariborz Jahanian case tok::objc_interface: 463d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen Diag(AtLoc, diag::err_objc_missing_end) 464d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen << FixItHint::CreateInsertion(AtLoc, "@end\n"); 465d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen Diag(CDecl->getLocStart(), diag::note_objc_container_start) 466d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen << (int) Actions.getObjCContainerKind(); 46746d545e355a4fea2a201652c3c8bbf22a13187a6Fariborz Jahanian ConsumeToken(); 46846d545e355a4fea2a201652c3c8bbf22a13187a6Fariborz Jahanian break; 46946d545e355a4fea2a201652c3c8bbf22a13187a6Fariborz Jahanian 470a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner case tok::objc_required: 471a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner case tok::objc_optional: 472a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner // This is only valid on protocols. 473bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // FIXME: Should this check for ObjC2 being enabled? 474e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner if (contextKey != tok::objc_protocol) 475bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner Diag(AtLoc, diag::err_objc_directive_only_in_protocol); 476a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner else 477bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner MethodImplKind = DirectiveKind; 478a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner break; 4791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 480a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner case tok::objc_property: 4814e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (!getLangOpts().ObjC2) 482b321c0c0ba957d78475e72cebde4028fdaa00f8fChris Lattner Diag(AtLoc, diag::err_objc_properties_require_objc2); 483f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner 484e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner ObjCDeclSpec OCDS; 48577bfb8b43ec3f7dee3a71f6e854b03ad29dab84fFariborz Jahanian SourceLocation LParenLoc; 4861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // Parse property attribute list, if any. 48777bfb8b43ec3f7dee3a71f6e854b03ad29dab84fFariborz Jahanian if (Tok.is(tok::l_paren)) { 48877bfb8b43ec3f7dee3a71f6e854b03ad29dab84fFariborz Jahanian LParenLoc = Tok.getLocation(); 489a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian ParseObjCPropertyAttribute(OCDS); 49077bfb8b43ec3f7dee3a71f6e854b03ad29dab84fFariborz Jahanian } 4911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 492a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian ObjCPropertyCallback Callback(*this, allProperties, 49377bfb8b43ec3f7dee3a71f6e854b03ad29dab84fFariborz Jahanian OCDS, AtLoc, LParenLoc, MethodImplKind); 494bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall 495e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner // Parse all the comma separated declarators. 4960b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall DeclSpec DS(AttrFactory); 497bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall ParseStructDeclaration(DS, Callback); 4981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4997da19ea50d4161fcda40d135735bcf450cabeb50John McCall ExpectAndConsume(tok::semi, diag::err_expected_semi_decl_list); 500a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner break; 501f28b264437053fb0deacc9ba02b18a0966f7290aSteve Naroff } 502294494e1cce92043562b4680c613df7fd028c02eSteve Naroff } 503bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner 504bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // We break out of the big loop in two cases: when we see @end or when we see 505bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // EOF. In the former case, eat the @end. In the later case, emit an error. 506c464ae8444edb6d07ea49b7a0eae1674c0fa1bb8Douglas Gregor if (Tok.is(tok::code_completion)) { 507a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian Actions.CodeCompleteObjCAtDirective(getCurScope()); 5087d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis return cutOffParsing(); 509d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen } else if (Tok.isObjCAtKeyword(tok::objc_end)) { 510bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner ConsumeToken(); // the "end" identifier 511d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen } else { 512d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen Diag(Tok, diag::err_objc_missing_end) 513d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen << FixItHint::CreateInsertion(Tok.getLocation(), "\n@end\n"); 514d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen Diag(CDecl->getLocStart(), diag::note_objc_container_start) 515d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen << (int) Actions.getObjCContainerKind(); 516d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen AtEnd.setBegin(Tok.getLocation()); 517d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen AtEnd.setEnd(Tok.getLocation()); 518d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen } 5191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 520a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner // Insert collected methods declarations into the @interface object. 521bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // This passes in an invalid SourceLocation for AtEndLoc when EOF is hit. 522a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian Actions.ActOnAtEnd(getCurScope(), AtEnd, 5231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump allMethods.data(), allMethods.size(), 524beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad allProperties.data(), allProperties.size(), 525beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad allTUVariables.data(), allTUVariables.size()); 526294494e1cce92043562b4680c613df7fd028c02eSteve Naroff} 527294494e1cce92043562b4680c613df7fd028c02eSteve Naroff 528d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// Parse property attribute declarations. 529d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// 530d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// property-attr-decl: '(' property-attrlist ')' 531d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// property-attrlist: 532d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// property-attribute 533d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// property-attrlist ',' property-attribute 534d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// property-attribute: 535d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// getter '=' identifier 536d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// setter '=' identifier ':' 537d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// readonly 538d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// readwrite 539d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// assign 540d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// retain 541d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// copy 542d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// nonatomic 543f85e193739c953358c865005855253af4f68a497John McCall/// atomic 544f85e193739c953358c865005855253af4f68a497John McCall/// strong 545f85e193739c953358c865005855253af4f68a497John McCall/// weak 546f85e193739c953358c865005855253af4f68a497John McCall/// unsafe_unretained 547d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// 548a28948f34817476d02412fa204cae038e228c827Fariborz Jahanianvoid Parser::ParseObjCPropertyAttribute(ObjCDeclSpec &DS) { 5498ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner assert(Tok.getKind() == tok::l_paren); 5504a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor BalancedDelimiterTracker T(*this, tok::l_paren); 5514a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor T.consumeOpen(); 5521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 553cd9f4b31c4fe5b77b5519cc17b4583fab912bad1Chris Lattner while (1) { 554ece8e71d12b6f4cb2dc501297afef126dab8ad74Steve Naroff if (Tok.is(tok::code_completion)) { 55523c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCPropertyFlags(getCurScope(), DS); 5567d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis return cutOffParsing(); 557ece8e71d12b6f4cb2dc501297afef126dab8ad74Steve Naroff } 558d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian const IdentifierInfo *II = Tok.getIdentifierInfo(); 5591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 560f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner // If this is not an identifier at all, bail out early. 561f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner if (II == 0) { 5624a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor T.consumeClose(); 563f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner return; 564f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner } 5651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 566156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner SourceLocation AttrName = ConsumeToken(); // consume last attribute name 5671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 56892e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner if (II->isStr("readonly")) 569e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_readonly); 57092e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner else if (II->isStr("assign")) 571e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_assign); 572f85e193739c953358c865005855253af4f68a497John McCall else if (II->isStr("unsafe_unretained")) 573f85e193739c953358c865005855253af4f68a497John McCall DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_unsafe_unretained); 57492e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner else if (II->isStr("readwrite")) 575e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_readwrite); 57692e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner else if (II->isStr("retain")) 577e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_retain); 578f85e193739c953358c865005855253af4f68a497John McCall else if (II->isStr("strong")) 579f85e193739c953358c865005855253af4f68a497John McCall DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_strong); 58092e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner else if (II->isStr("copy")) 581e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_copy); 58292e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner else if (II->isStr("nonatomic")) 583e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_nonatomic); 58445937ae10a0f70f74508165aab4f2b63e18ea747Fariborz Jahanian else if (II->isStr("atomic")) 58545937ae10a0f70f74508165aab4f2b63e18ea747Fariborz Jahanian DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_atomic); 586f85e193739c953358c865005855253af4f68a497John McCall else if (II->isStr("weak")) 587f85e193739c953358c865005855253af4f68a497John McCall DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_weak); 58892e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner else if (II->isStr("getter") || II->isStr("setter")) { 58942499be29b620d2eae34beb0f4d0f9da5a9584daAnders Carlsson bool IsSetter = II->getNameStart()[0] == 's'; 59042499be29b620d2eae34beb0f4d0f9da5a9584daAnders Carlsson 591e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner // getter/setter require extra treatment. 59242499be29b620d2eae34beb0f4d0f9da5a9584daAnders Carlsson unsigned DiagID = IsSetter ? diag::err_objc_expected_equal_for_setter : 59342499be29b620d2eae34beb0f4d0f9da5a9584daAnders Carlsson diag::err_objc_expected_equal_for_getter; 59442499be29b620d2eae34beb0f4d0f9da5a9584daAnders Carlsson 59542499be29b620d2eae34beb0f4d0f9da5a9584daAnders Carlsson if (ExpectAndConsume(tok::equal, DiagID, "", tok::r_paren)) 596dd5b5f2bb73d037745940431b71eb98393d12d4fChris Lattner return; 5971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5984ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor if (Tok.is(tok::code_completion)) { 59942499be29b620d2eae34beb0f4d0f9da5a9584daAnders Carlsson if (IsSetter) 600a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian Actions.CodeCompleteObjCPropertySetter(getCurScope()); 6014ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor else 602a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian Actions.CodeCompleteObjCPropertyGetter(getCurScope()); 6037d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis return cutOffParsing(); 6044ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor } 6054ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor 60642499be29b620d2eae34beb0f4d0f9da5a9584daAnders Carlsson 60742499be29b620d2eae34beb0f4d0f9da5a9584daAnders Carlsson SourceLocation SelLoc; 60842499be29b620d2eae34beb0f4d0f9da5a9584daAnders Carlsson IdentifierInfo *SelIdent = ParseObjCSelectorPiece(SelLoc); 60942499be29b620d2eae34beb0f4d0f9da5a9584daAnders Carlsson 61042499be29b620d2eae34beb0f4d0f9da5a9584daAnders Carlsson if (!SelIdent) { 61142499be29b620d2eae34beb0f4d0f9da5a9584daAnders Carlsson Diag(Tok, diag::err_objc_expected_selector_for_getter_setter) 61242499be29b620d2eae34beb0f4d0f9da5a9584daAnders Carlsson << IsSetter; 6138ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner SkipUntil(tok::r_paren); 6148ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner return; 6158ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner } 6161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 61742499be29b620d2eae34beb0f4d0f9da5a9584daAnders Carlsson if (IsSetter) { 6188ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_setter); 61942499be29b620d2eae34beb0f4d0f9da5a9584daAnders Carlsson DS.setSetterName(SelIdent); 6201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 621e0097db2848c463a534c18c235c6d3e53f2f1b87Fariborz Jahanian if (ExpectAndConsume(tok::colon, 622e0097db2848c463a534c18c235c6d3e53f2f1b87Fariborz Jahanian diag::err_expected_colon_after_setter_name, "", 623156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner tok::r_paren)) 6248ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner return; 6258ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner } else { 6268ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_getter); 62742499be29b620d2eae34beb0f4d0f9da5a9584daAnders Carlsson DS.setGetterName(SelIdent); 6288ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner } 629e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner } else { 630a9500f05ba6c09bbd84d342236863833067cd816Chris Lattner Diag(AttrName, diag::err_objc_expected_property_attr) << II; 631cd9f4b31c4fe5b77b5519cc17b4583fab912bad1Chris Lattner SkipUntil(tok::r_paren); 632cd9f4b31c4fe5b77b5519cc17b4583fab912bad1Chris Lattner return; 633cd9f4b31c4fe5b77b5519cc17b4583fab912bad1Chris Lattner } 6341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 635156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner if (Tok.isNot(tok::comma)) 636156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner break; 6371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 638156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner ConsumeToken(); 639d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian } 6401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6414a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor T.consumeClose(); 642d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian} 643d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian 6443536b443bc50d58a79f14fca9b6842541a434854Steve Naroff/// objc-method-proto: 6451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// objc-instance-method objc-method-decl objc-method-attributes[opt] 6463536b443bc50d58a79f14fca9b6842541a434854Steve Naroff/// objc-class-method objc-method-decl objc-method-attributes[opt] 647294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 648294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-instance-method: '-' 649294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-class-method: '+' 650294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 6514985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-method-attributes: [OBJC2] 6524985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// __attribute__((deprecated)) 6534985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// 654a28948f34817476d02412fa204cae038e228c827Fariborz JahanianDecl *Parser::ParseObjCMethodPrototype(tok::ObjCKeywordKind MethodImplKind, 65590ba78c64d0c24cfbc1bf88728db9775d44d7f9fFariborz Jahanian bool MethodDefinition) { 656df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner assert((Tok.is(tok::minus) || Tok.is(tok::plus)) && "expected +/-"); 657294494e1cce92043562b4680c613df7fd028c02eSteve Naroff 6581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump tok::TokenKind methodType = Tok.getKind(); 659bef1185418705e16012b3dd50cd7c260c8d6b79cSteve Naroff SourceLocation mLoc = ConsumeToken(); 660a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian Decl *MDecl = ParseObjCMethodDecl(mLoc, methodType, MethodImplKind, 66190ba78c64d0c24cfbc1bf88728db9775d44d7f9fFariborz Jahanian MethodDefinition); 6623536b443bc50d58a79f14fca9b6842541a434854Steve Naroff // Since this rule is used for both method declarations and definitions, 6632bd42fadafddc8acf744b57a970bdc96a077c617Steve Naroff // the caller is (optionally) responsible for consuming the ';'. 664f28b264437053fb0deacc9ba02b18a0966f7290aSteve Naroff return MDecl; 665294494e1cce92043562b4680c613df7fd028c02eSteve Naroff} 666294494e1cce92043562b4680c613df7fd028c02eSteve Naroff 667294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-selector: 668294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// identifier 669294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// one of 670294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// enum struct union if else while do for switch case default 671294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// break continue return goto asm sizeof typeof __alignof 672294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// unsigned long const short volatile signed restrict _Complex 673294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// in out inout bycopy byref oneway int char float double void _Bool 674294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 6752fc5c2428ecb450a3256c8316b93b8655cb76a0fChris LattnerIdentifierInfo *Parser::ParseObjCSelectorPiece(SourceLocation &SelectorLoc) { 676be74740cc246ce08d42804a684385a42eb814edbFariborz Jahanian 677ff38491c18b060526d754765b952f4a497a89416Chris Lattner switch (Tok.getKind()) { 678ff38491c18b060526d754765b952f4a497a89416Chris Lattner default: 679ff38491c18b060526d754765b952f4a497a89416Chris Lattner return 0; 680afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian case tok::ampamp: 681afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian case tok::ampequal: 682afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian case tok::amp: 683afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian case tok::pipe: 684afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian case tok::tilde: 685afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian case tok::exclaim: 686afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian case tok::exclaimequal: 687afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian case tok::pipepipe: 688afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian case tok::pipeequal: 689afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian case tok::caret: 690afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian case tok::caretequal: { 6913846ca29a8cc1d376a4b695194c29952dbbfb544Fariborz Jahanian std::string ThisTok(PP.getSpelling(Tok)); 692afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian if (isalpha(ThisTok[0])) { 693afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian IdentifierInfo *II = &PP.getIdentifierTable().get(ThisTok.data()); 694afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian Tok.setKind(tok::identifier); 695afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian SelectorLoc = ConsumeToken(); 696afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian return II; 697afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian } 698afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian return 0; 699afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian } 700afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian 701ff38491c18b060526d754765b952f4a497a89416Chris Lattner case tok::identifier: 702ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_asm: 703ff38491c18b060526d754765b952f4a497a89416Chris Lattner case tok::kw_auto: 7049298d9655aed28b2d9f6cc65c81401b209f03fdcChris Lattner case tok::kw_bool: 705ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_break: 706ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_case: 707ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_catch: 708ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_char: 709ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_class: 710ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_const: 711ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_const_cast: 712ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_continue: 713ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_default: 714ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_delete: 715ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_do: 716ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_double: 717ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_dynamic_cast: 718ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_else: 719ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_enum: 720ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_explicit: 721ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_export: 722ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_extern: 723ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_false: 724ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_float: 725ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_for: 726ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_friend: 727ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_goto: 728ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_if: 729ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_inline: 730ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_int: 731ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_long: 732ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_mutable: 733ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_namespace: 734ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_new: 735ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_operator: 736ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_private: 737ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_protected: 738ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_public: 739ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_register: 740ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_reinterpret_cast: 741ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_restrict: 742ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_return: 743ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_short: 744ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_signed: 745ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_sizeof: 746ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_static: 747ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_static_cast: 748ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_struct: 749ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_switch: 750ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_template: 751ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_this: 752ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_throw: 753ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_true: 754ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_try: 755ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_typedef: 756ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_typeid: 757ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_typename: 758ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_typeof: 759ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_union: 760ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_unsigned: 761ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_using: 762ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_virtual: 763ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_void: 764ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_volatile: 765ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_wchar_t: 766ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_while: 767ff38491c18b060526d754765b952f4a497a89416Chris Lattner case tok::kw__Bool: 768ff38491c18b060526d754765b952f4a497a89416Chris Lattner case tok::kw__Complex: 769ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw___alignof: 770ff38491c18b060526d754765b952f4a497a89416Chris Lattner IdentifierInfo *II = Tok.getIdentifierInfo(); 7714b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian SelectorLoc = ConsumeToken(); 772ff38491c18b060526d754765b952f4a497a89416Chris Lattner return II; 773d064951b0dcc95f8604d0d69ae82d9ecbd38c796Fariborz Jahanian } 774294494e1cce92043562b4680c613df7fd028c02eSteve Naroff} 775294494e1cce92043562b4680c613df7fd028c02eSteve Naroff 7760196cab54007ff072ec2642da8911c6b7e8d3fb5Fariborz Jahanian/// objc-for-collection-in: 'in' 7770196cab54007ff072ec2642da8911c6b7e8d3fb5Fariborz Jahanian/// 778335a2d4122e41343fe11a775889b8bec5b14be60Fariborz Jahanianbool Parser::isTokIdentifier_in() const { 7793ba5a0f90a03d5e13d02cbee9abd2a1ba01b18bcFariborz Jahanian // FIXME: May have to do additional look-ahead to only allow for 7803ba5a0f90a03d5e13d02cbee9abd2a1ba01b18bcFariborz Jahanian // valid tokens following an 'in'; such as an identifier, unary operators, 7813ba5a0f90a03d5e13d02cbee9abd2a1ba01b18bcFariborz Jahanian // '[' etc. 7824e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie return (getLangOpts().ObjC2 && Tok.is(tok::identifier) && 7835ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner Tok.getIdentifierInfo() == ObjCTypeQuals[objc_in]); 7840196cab54007ff072ec2642da8911c6b7e8d3fb5Fariborz Jahanian} 7850196cab54007ff072ec2642da8911c6b7e8d3fb5Fariborz Jahanian 786a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ParseObjCTypeQualifierList - This routine parses the objective-c's type 787e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner/// qualifier list and builds their bitmask representation in the input 788e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner/// argument. 789294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 790294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-type-qualifiers: 791294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-type-qualifier 792294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-type-qualifiers objc-type-qualifier 793294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 794b77cab97f17f946744c920629ca17271308d8ebfDouglas Gregorvoid Parser::ParseObjCTypeQualifierList(ObjCDeclSpec &DS, 795cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall Declarator::TheContext Context) { 796cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall assert(Context == Declarator::ObjCParameterContext || 797cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall Context == Declarator::ObjCResultContext); 798cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall 799e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner while (1) { 800d32b0225e29fcafb2b2b2a4b1c51dcb1518af9c6Douglas Gregor if (Tok.is(tok::code_completion)) { 801b77cab97f17f946744c920629ca17271308d8ebfDouglas Gregor Actions.CodeCompleteObjCPassingType(getCurScope(), DS, 802cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall Context == Declarator::ObjCParameterContext); 8037d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis return cutOffParsing(); 804d32b0225e29fcafb2b2b2a4b1c51dcb1518af9c6Douglas Gregor } 805d32b0225e29fcafb2b2b2a4b1c51dcb1518af9c6Douglas Gregor 806cb53b361bce341c8591333c6997f62e480acc0b4Chris Lattner if (Tok.isNot(tok::identifier)) 807e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner return; 8081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 809e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner const IdentifierInfo *II = Tok.getIdentifierInfo(); 810e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner for (unsigned i = 0; i != objc_NumQuals; ++i) { 811a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek if (II != ObjCTypeQuals[i]) 812e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner continue; 8131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 814a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCDeclSpec::ObjCDeclQualifier Qual; 815e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner switch (i) { 816b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie default: llvm_unreachable("Unknown decl qualifier"); 817a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek case objc_in: Qual = ObjCDeclSpec::DQ_In; break; 818a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek case objc_out: Qual = ObjCDeclSpec::DQ_Out; break; 819a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek case objc_inout: Qual = ObjCDeclSpec::DQ_Inout; break; 820a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek case objc_oneway: Qual = ObjCDeclSpec::DQ_Oneway; break; 821a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek case objc_bycopy: Qual = ObjCDeclSpec::DQ_Bycopy; break; 822a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek case objc_byref: Qual = ObjCDeclSpec::DQ_Byref; break; 823e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner } 824a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek DS.setObjCDeclQualifier(Qual); 825e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner ConsumeToken(); 826e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner II = 0; 827e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner break; 828e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner } 8291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 830e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner // If this wasn't a recognized qualifier, bail out. 831e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner if (II) return; 832e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner } 833e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner} 834e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner 835cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall/// Take all the decl attributes out of the given list and add 836cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall/// them to the given attribute set. 837cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCallstatic void takeDeclAttributes(ParsedAttributes &attrs, 838cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall AttributeList *list) { 839cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall while (list) { 840cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall AttributeList *cur = list; 841cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall list = cur->getNext(); 842cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall 843cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall if (!cur->isUsedAsTypeAttr()) { 844cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall // Clear out the next pointer. We're really completely 845cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall // destroying the internal invariants of the declarator here, 846cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall // but it doesn't matter because we're done with it. 847cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall cur->setNext(0); 848cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall attrs.add(cur); 849cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall } 850cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall } 851cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall} 852cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall 853cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall/// takeDeclAttributes - Take all the decl attributes from the given 854cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall/// declarator and add them to the given list. 855cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCallstatic void takeDeclAttributes(ParsedAttributes &attrs, 856cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall Declarator &D) { 857cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall // First, take ownership of all attributes. 858cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall attrs.getPool().takeAllFrom(D.getAttributePool()); 859cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall attrs.getPool().takeAllFrom(D.getDeclSpec().getAttributePool()); 860cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall 861cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall // Now actually move the attributes over. 862cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall takeDeclAttributes(attrs, D.getDeclSpec().getAttributes().getList()); 863cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall takeDeclAttributes(attrs, D.getAttributes()); 864cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall for (unsigned i = 0, e = D.getNumTypeObjects(); i != e; ++i) 865cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall takeDeclAttributes(attrs, 866cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall const_cast<AttributeList*>(D.getTypeObject(i).getAttrs())); 867cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall} 868cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall 869e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner/// objc-type-name: 870e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner/// '(' objc-type-qualifiers[opt] type-name ')' 871e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner/// '(' objc-type-qualifiers[opt] ')' 872e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner/// 873b77cab97f17f946744c920629ca17271308d8ebfDouglas GregorParsedType Parser::ParseObjCTypeName(ObjCDeclSpec &DS, 874cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall Declarator::TheContext context, 875cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall ParsedAttributes *paramAttrs) { 876cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall assert(context == Declarator::ObjCParameterContext || 877cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall context == Declarator::ObjCResultContext); 878cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall assert((paramAttrs != 0) == (context == Declarator::ObjCParameterContext)); 879cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall 880df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner assert(Tok.is(tok::l_paren) && "expected ("); 8811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8824a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor BalancedDelimiterTracker T(*this, tok::l_paren); 8834a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor T.consumeOpen(); 8844a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor 885e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner SourceLocation TypeStartLoc = Tok.getLocation(); 8869735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian ObjCDeclContextSwitch ObjCDC(*this); 8879735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian 88819d74e1494fe399f0e2a94e9419c095f8214851bFariborz Jahanian // Parse type qualifiers, in, inout, etc. 889cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall ParseObjCTypeQualifierList(DS, context); 8904fa7afd07421e7276d1717e4fdf43a5fdd65a622Steve Naroff 891b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType Ty; 892809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor if (isTypeSpecifierQualifier()) { 893cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall // Parse an abstract declarator. 894cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall DeclSpec declSpec(AttrFactory); 895cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall declSpec.setObjCQualifiers(&DS); 896cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall ParseSpecifierQualifierList(declSpec); 8976d1de1b8663fe652903bda2927b885d1ec0f2613Fariborz Jahanian declSpec.SetRangeEnd(Tok.getLocation()); 898cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall Declarator declarator(declSpec, context); 899cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall ParseDeclarator(declarator); 900cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall 901cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall // If that's not invalid, extract a type. 902cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall if (!declarator.isInvalidType()) { 903cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall TypeResult type = Actions.ActOnTypeName(getCurScope(), declarator); 904cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall if (!type.isInvalid()) 905cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall Ty = type.get(); 906cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall 907cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall // If we're parsing a parameter, steal all the decl attributes 908cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall // and add them to the decl spec. 909cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall if (context == Declarator::ObjCParameterContext) 910cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall takeDeclAttributes(*paramAttrs, declarator); 911cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall } 912cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall } else if (context == Declarator::ObjCResultContext && 913cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall Tok.is(tok::identifier)) { 914e97179c675b341927807c718be215c8d1aab8acbDouglas Gregor if (!Ident_instancetype) 915e97179c675b341927807c718be215c8d1aab8acbDouglas Gregor Ident_instancetype = PP.getIdentifierInfo("instancetype"); 916e97179c675b341927807c718be215c8d1aab8acbDouglas Gregor 917e97179c675b341927807c718be215c8d1aab8acbDouglas Gregor if (Tok.getIdentifierInfo() == Ident_instancetype) { 918e97179c675b341927807c718be215c8d1aab8acbDouglas Gregor Ty = Actions.ActOnObjCInstanceType(Tok.getLocation()); 919e97179c675b341927807c718be215c8d1aab8acbDouglas Gregor ConsumeToken(); 920e97179c675b341927807c718be215c8d1aab8acbDouglas Gregor } 921809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor } 922e97179c675b341927807c718be215c8d1aab8acbDouglas Gregor 9234a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner if (Tok.is(tok::r_paren)) 9244a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor T.consumeClose(); 9254a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner else if (Tok.getLocation() == TypeStartLoc) { 926e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner // If we didn't eat any tokens, then this isn't a type. 9271ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_type); 9284a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner SkipUntil(tok::r_paren); 9294a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner } else { 9304a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner // Otherwise, we found *something*, but didn't get a ')' in the right 9314a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner // place. Emit an error then return what we have as the type. 9324a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor T.consumeClose(); 933294494e1cce92043562b4680c613df7fd028c02eSteve Naroff } 934f28b264437053fb0deacc9ba02b18a0966f7290aSteve Naroff return Ty; 935294494e1cce92043562b4680c613df7fd028c02eSteve Naroff} 936294494e1cce92043562b4680c613df7fd028c02eSteve Naroff 937294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-method-decl: 938294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-selector 9394985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-keyword-selector objc-parmlist[opt] 940294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-type-name objc-selector 9414985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-type-name objc-keyword-selector objc-parmlist[opt] 942294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 943294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-keyword-selector: 9441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// objc-keyword-decl 945294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-keyword-selector objc-keyword-decl 946294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 947294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-keyword-decl: 9487ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// objc-selector ':' objc-type-name objc-keyword-attributes[opt] identifier 9497ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// objc-selector ':' objc-keyword-attributes[opt] identifier 9507ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// ':' objc-type-name objc-keyword-attributes[opt] identifier 9517ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// ':' objc-keyword-attributes[opt] identifier 952294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 9534985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-parmlist: 9544985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-parms objc-ellipsis[opt] 955294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 9564985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-parms: 9574985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-parms , parameter-declaration 958294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 9594985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-ellipsis: 960294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// , ... 961294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 9627ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// objc-keyword-attributes: [OBJC2] 9637ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// __attribute__((unused)) 9647ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// 965d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseObjCMethodDecl(SourceLocation mLoc, 9662ccccb3ff40c64927817a7e1ddf1da8c188ed224Douglas Gregor tok::TokenKind mType, 96790ba78c64d0c24cfbc1bf88728db9775d44d7f9fFariborz Jahanian tok::ObjCKeywordKind MethodImplKind, 96890ba78c64d0c24cfbc1bf88728db9775d44d7f9fFariborz Jahanian bool MethodDefinition) { 9699257664568bf375b7790131a84d9a4fa30a5b7e3John McCall ParsingDeclRAIIObject PD(*this, ParsingDeclRAIIObject::NoParent); 97054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 971e8f5a1710a7738deff40e10efcd05b1bd6af184fDouglas Gregor if (Tok.is(tok::code_completion)) { 97223c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCMethodDecl(getCurScope(), mType == tok::minus, 973a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian /*ReturnType=*/ ParsedType()); 9747d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis cutOffParsing(); 9757d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis return 0; 976e8f5a1710a7738deff40e10efcd05b1bd6af184fDouglas Gregor } 977e8f5a1710a7738deff40e10efcd05b1bd6af184fDouglas Gregor 978e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner // Parse the return type if present. 979b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ReturnType; 980a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCDeclSpec DSRet; 981df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::l_paren)) 982cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall ReturnType = ParseObjCTypeName(DSRet, Declarator::ObjCResultContext, 0); 9831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9849e0493576af77dba1c48858c03e31a2897d0681eTed Kremenek // If attributes exist before the method, parse them. 9850b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall ParsedAttributes methodAttrs(AttrFactory); 9864e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (getLangOpts().ObjC2) 9870b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall MaybeParseGNUAttributes(methodAttrs); 9889e0493576af77dba1c48858c03e31a2897d0681eTed Kremenek 989e8f5a1710a7738deff40e10efcd05b1bd6af184fDouglas Gregor if (Tok.is(tok::code_completion)) { 99023c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCMethodDecl(getCurScope(), mType == tok::minus, 991a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian ReturnType); 9927d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis cutOffParsing(); 9937d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis return 0; 994e8f5a1710a7738deff40e10efcd05b1bd6af184fDouglas Gregor } 995e8f5a1710a7738deff40e10efcd05b1bd6af184fDouglas Gregor 9969e0493576af77dba1c48858c03e31a2897d0681eTed Kremenek // Now parse the selector. 997bef1185418705e16012b3dd50cd7c260c8d6b79cSteve Naroff SourceLocation selLoc; 9982fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner IdentifierInfo *SelIdent = ParseObjCSelectorPiece(selLoc); 999e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner 100084c431088693e216193094d1dbf327a01173f57fSteve Naroff // An unnamed colon is valid. 100184c431088693e216193094d1dbf327a01173f57fSteve Naroff if (!SelIdent && Tok.isNot(tok::colon)) { // missing selector name. 10021ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_selector_for_method) 10031ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner << SourceRange(mLoc, Tok.getLocation()); 1004e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner // Skip until we get a ; or {}. 1005e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner SkipUntil(tok::r_brace); 1006d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 1007e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner } 10081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10095f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<DeclaratorChunk::ParamInfo, 8> CParamInfo; 1010df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::colon)) { 1011ff38491c18b060526d754765b952f4a497a89416Chris Lattner // If attributes exist after the method, parse them. 10124e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (getLangOpts().ObjC2) 10130b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall MaybeParseGNUAttributes(methodAttrs); 10141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1015ff38491c18b060526d754765b952f4a497a89416Chris Lattner Selector Sel = PP.getSelectorTable().getNullarySelector(SelIdent); 1016d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *Result 10177f53253223b29d77f1e9c5c0ce93a19932761b77Fariborz Jahanian = Actions.ActOnMethodDeclaration(getCurScope(), mLoc, Tok.getLocation(), 1018a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian mType, DSRet, ReturnType, 1019926df6cfabf3eaa4afc990c097fa4619b76a9b57Douglas Gregor selLoc, Sel, 0, 10204f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian CParamInfo.data(), CParamInfo.size(), 10210b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall methodAttrs.getList(), MethodImplKind, 10220b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall false, MethodDefinition); 102354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall PD.complete(Result); 102454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall return Result; 1025ff38491c18b060526d754765b952f4a497a89416Chris Lattner } 1026f28b264437053fb0deacc9ba02b18a0966f7290aSteve Naroff 10275f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<IdentifierInfo *, 12> KeyIdents; 102811d77169555480ee0a04c6e5bc390d8fde41175dArgyrios Kyrtzidis SmallVector<SourceLocation, 12> KeyLocs; 10295f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<Sema::ObjCArgInfo, 12> ArgInfos; 10307f53253223b29d77f1e9c5c0ce93a19932761b77Fariborz Jahanian ParseScope PrototypeScope(this, 10317f53253223b29d77f1e9c5c0ce93a19932761b77Fariborz Jahanian Scope::FunctionPrototypeScope|Scope::DeclScope); 10320b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall 10330b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall AttributePool allParamAttrs(AttrFactory); 10347f53253223b29d77f1e9c5c0ce93a19932761b77Fariborz Jahanian 1035ff38491c18b060526d754765b952f4a497a89416Chris Lattner while (1) { 10360b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall ParsedAttributes paramAttrs(AttrFactory); 1037f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Sema::ObjCArgInfo ArgInfo; 10381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1039ff38491c18b060526d754765b952f4a497a89416Chris Lattner // Each iteration parses a single keyword argument. 1040df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::colon)) { 1041ff38491c18b060526d754765b952f4a497a89416Chris Lattner Diag(Tok, diag::err_expected_colon); 1042ff38491c18b060526d754765b952f4a497a89416Chris Lattner break; 1043ff38491c18b060526d754765b952f4a497a89416Chris Lattner } 1044ff38491c18b060526d754765b952f4a497a89416Chris Lattner ConsumeToken(); // Eat the ':'. 10451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1046b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ArgInfo.Type = ParsedType(); 1047e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner if (Tok.is(tok::l_paren)) // Parse the argument type if present. 1048cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall ArgInfo.Type = ParseObjCTypeName(ArgInfo.DeclSpec, 1049cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall Declarator::ObjCParameterContext, 1050cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall ¶mAttrs); 1051e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner 1052ff38491c18b060526d754765b952f4a497a89416Chris Lattner // If attributes exist before the argument name, parse them. 1053cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall // Regardless, collect all the attributes we've parsed so far. 1054e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner ArgInfo.ArgAttrs = 0; 10554e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (getLangOpts().ObjC2) { 10560b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall MaybeParseGNUAttributes(paramAttrs); 10570b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall ArgInfo.ArgAttrs = paramAttrs.getList(); 10587f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall } 10597ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff 106040ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor // Code completion for the next piece of the selector. 106140ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor if (Tok.is(tok::code_completion)) { 106240ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor KeyIdents.push_back(SelIdent); 106340ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor Actions.CodeCompleteObjCMethodDeclSelector(getCurScope(), 106440ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor mType == tok::minus, 106540ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor /*AtParameterName=*/true, 106640ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor ReturnType, 106740ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor KeyIdents.data(), 106840ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor KeyIdents.size()); 10697d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis cutOffParsing(); 10707d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis return 0; 107140ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor } 107240ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor 1073df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 1074ff38491c18b060526d754765b952f4a497a89416Chris Lattner Diag(Tok, diag::err_expected_ident); // missing argument name. 1075ff38491c18b060526d754765b952f4a497a89416Chris Lattner break; 10764985aceceb9b9261b876b515d32726175c13a775Steve Naroff } 10771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1078e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner ArgInfo.Name = Tok.getIdentifierInfo(); 1079e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner ArgInfo.NameLoc = Tok.getLocation(); 1080ff38491c18b060526d754765b952f4a497a89416Chris Lattner ConsumeToken(); // Eat the identifier. 10811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1082e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner ArgInfos.push_back(ArgInfo); 1083e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner KeyIdents.push_back(SelIdent); 108411d77169555480ee0a04c6e5bc390d8fde41175dArgyrios Kyrtzidis KeyLocs.push_back(selLoc); 1085e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner 10860b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall // Make sure the attributes persist. 10870b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall allParamAttrs.takeAllFrom(paramAttrs.getPool()); 10880b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall 10891f5537aaac1e775aff1d523f2cc59a9a3bd6c946Douglas Gregor // Code completion for the next piece of the selector. 10901f5537aaac1e775aff1d523f2cc59a9a3bd6c946Douglas Gregor if (Tok.is(tok::code_completion)) { 10911f5537aaac1e775aff1d523f2cc59a9a3bd6c946Douglas Gregor Actions.CodeCompleteObjCMethodDeclSelector(getCurScope(), 10921f5537aaac1e775aff1d523f2cc59a9a3bd6c946Douglas Gregor mType == tok::minus, 109340ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor /*AtParameterName=*/false, 10941f5537aaac1e775aff1d523f2cc59a9a3bd6c946Douglas Gregor ReturnType, 10951f5537aaac1e775aff1d523f2cc59a9a3bd6c946Douglas Gregor KeyIdents.data(), 10961f5537aaac1e775aff1d523f2cc59a9a3bd6c946Douglas Gregor KeyIdents.size()); 10977d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis cutOffParsing(); 10987d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis return 0; 10991f5537aaac1e775aff1d523f2cc59a9a3bd6c946Douglas Gregor } 11001f5537aaac1e775aff1d523f2cc59a9a3bd6c946Douglas Gregor 1101ff38491c18b060526d754765b952f4a497a89416Chris Lattner // Check for another keyword selector. 110211d77169555480ee0a04c6e5bc390d8fde41175dArgyrios Kyrtzidis SelIdent = ParseObjCSelectorPiece(selLoc); 1103df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (!SelIdent && Tok.isNot(tok::colon)) 1104ff38491c18b060526d754765b952f4a497a89416Chris Lattner break; 1105ff38491c18b060526d754765b952f4a497a89416Chris Lattner // We have a selector or a colon, continue parsing. 1106ff38491c18b060526d754765b952f4a497a89416Chris Lattner } 11071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1108335eafa5be51f6440672a74c73d588af72e96732Steve Naroff bool isVariadic = false; 110956242baaae6c45b24fbdd5bc56fe4ee516fa9e6bFariborz Jahanian bool cStyleParamWarned = false; 1110ff38491c18b060526d754765b952f4a497a89416Chris Lattner // Parse the (optional) parameter list. 1111df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner while (Tok.is(tok::comma)) { 1112ff38491c18b060526d754765b952f4a497a89416Chris Lattner ConsumeToken(); 1113df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::ellipsis)) { 1114335eafa5be51f6440672a74c73d588af72e96732Steve Naroff isVariadic = true; 11154985aceceb9b9261b876b515d32726175c13a775Steve Naroff ConsumeToken(); 1116ff38491c18b060526d754765b952f4a497a89416Chris Lattner break; 11174985aceceb9b9261b876b515d32726175c13a775Steve Naroff } 111856242baaae6c45b24fbdd5bc56fe4ee516fa9e6bFariborz Jahanian if (!cStyleParamWarned) { 111956242baaae6c45b24fbdd5bc56fe4ee516fa9e6bFariborz Jahanian Diag(Tok, diag::warn_cstyle_param); 112056242baaae6c45b24fbdd5bc56fe4ee516fa9e6bFariborz Jahanian cStyleParamWarned = true; 112156242baaae6c45b24fbdd5bc56fe4ee516fa9e6bFariborz Jahanian } 11220b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall DeclSpec DS(AttrFactory); 1123ff38491c18b060526d754765b952f4a497a89416Chris Lattner ParseDeclarationSpecifiers(DS); 11241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // Parse the declarator. 1125ff38491c18b060526d754765b952f4a497a89416Chris Lattner Declarator ParmDecl(DS, Declarator::PrototypeContext); 1126ff38491c18b060526d754765b952f4a497a89416Chris Lattner ParseDeclarator(ParmDecl); 11274f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian IdentifierInfo *ParmII = ParmDecl.getIdentifier(); 1128d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *Param = Actions.ActOnParamDeclarator(getCurScope(), ParmDecl); 11294f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian CParamInfo.push_back(DeclaratorChunk::ParamInfo(ParmII, 11304f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian ParmDecl.getIdentifierLoc(), 11314f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian Param, 11324f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian 0)); 11334985aceceb9b9261b876b515d32726175c13a775Steve Naroff } 11341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11359c4bb2c08989265411925a04252fd4f93c26e3b1Cameron Esfahani // FIXME: Add support for optional parameter list... 1136e3a2ca7e30601cdd31c77a830f4cc487851e8096Fariborz Jahanian // If attributes exist after the method, parse them. 11374e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (getLangOpts().ObjC2) 11380b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall MaybeParseGNUAttributes(methodAttrs); 11397f53253223b29d77f1e9c5c0ce93a19932761b77Fariborz Jahanian 1140a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian if (KeyIdents.size() == 0) 1141d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 11427f53253223b29d77f1e9c5c0ce93a19932761b77Fariborz Jahanian 1143ff38491c18b060526d754765b952f4a497a89416Chris Lattner Selector Sel = PP.getSelectorTable().getSelector(KeyIdents.size(), 1144ff38491c18b060526d754765b952f4a497a89416Chris Lattner &KeyIdents[0]); 1145d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *Result 11467f53253223b29d77f1e9c5c0ce93a19932761b77Fariborz Jahanian = Actions.ActOnMethodDeclaration(getCurScope(), mLoc, Tok.getLocation(), 1147a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian mType, DSRet, ReturnType, 114811d77169555480ee0a04c6e5bc390d8fde41175dArgyrios Kyrtzidis KeyLocs, Sel, &ArgInfos[0], 11494f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian CParamInfo.data(), CParamInfo.size(), 11500b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall methodAttrs.getList(), 115190ba78c64d0c24cfbc1bf88728db9775d44d7f9fFariborz Jahanian MethodImplKind, isVariadic, MethodDefinition); 11527f53253223b29d77f1e9c5c0ce93a19932761b77Fariborz Jahanian 115354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall PD.complete(Result); 115454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall return Result; 1155294494e1cce92043562b4680c613df7fd028c02eSteve Naroff} 1156294494e1cce92043562b4680c613df7fd028c02eSteve Naroff 1157dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-refs: 1158dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// '<' identifier-list '>' 1159dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 11607caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattnerbool Parser:: 11615f9e272e632e951b1efe824cd16acb4d96077930Chris LattnerParseObjCProtocolReferences(SmallVectorImpl<Decl *> &Protocols, 11625f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVectorImpl<SourceLocation> &ProtocolLocs, 116371b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis bool WarnOnDeclarations, 116471b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis SourceLocation &LAngleLoc, SourceLocation &EndLoc) { 1165e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner assert(Tok.is(tok::less) && "expected <"); 11661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 116771b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis LAngleLoc = ConsumeToken(); // the "<" 11681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11695f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<IdentifierLocPair, 8> ProtocolIdents; 11701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1171e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner while (1) { 117255385fe3e723cd675001e45f42d61adde6b7f075Douglas Gregor if (Tok.is(tok::code_completion)) { 117355385fe3e723cd675001e45f42d61adde6b7f075Douglas Gregor Actions.CodeCompleteObjCProtocolReferences(ProtocolIdents.data(), 117455385fe3e723cd675001e45f42d61adde6b7f075Douglas Gregor ProtocolIdents.size()); 11757d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis cutOffParsing(); 11767d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis return true; 117755385fe3e723cd675001e45f42d61adde6b7f075Douglas Gregor } 117855385fe3e723cd675001e45f42d61adde6b7f075Douglas Gregor 1179e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner if (Tok.isNot(tok::identifier)) { 1180e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner Diag(Tok, diag::err_expected_ident); 1181e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner SkipUntil(tok::greater); 1182e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner return true; 1183e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner } 1184e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner ProtocolIdents.push_back(std::make_pair(Tok.getIdentifierInfo(), 1185e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner Tok.getLocation())); 118671b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis ProtocolLocs.push_back(Tok.getLocation()); 1187e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner ConsumeToken(); 11881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1189e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner if (Tok.isNot(tok::comma)) 1190e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner break; 1191e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner ConsumeToken(); 1192e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner } 11931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1194e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner // Consume the '>'. 1195e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner if (Tok.isNot(tok::greater)) { 1196e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner Diag(Tok, diag::err_expected_greater); 1197e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner return true; 1198e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner } 11991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1200d78ef5b941ce2937228b010e8443f92025f9d683Douglas Gregor EndLoc = ConsumeToken(); 12011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1202e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner // Convert the list of protocols identifiers into a list of protocol decls. 1203e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner Actions.FindProtocolDeclaration(WarnOnDeclarations, 1204e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner &ProtocolIdents[0], ProtocolIdents.size(), 1205e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner Protocols); 1206e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner return false; 1207e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner} 1208e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner 12099bd1d8d174a9d15ae343246c8322299248b9e92aDouglas Gregor/// \brief Parse the Objective-C protocol qualifiers that follow a typename 12109bd1d8d174a9d15ae343246c8322299248b9e92aDouglas Gregor/// in a decl-specifier-seq, starting at the '<'. 121146f936e055d763437accd1e5a1bc49e7e5dbc0a3Douglas Gregorbool Parser::ParseObjCProtocolQualifiers(DeclSpec &DS) { 12129bd1d8d174a9d15ae343246c8322299248b9e92aDouglas Gregor assert(Tok.is(tok::less) && "Protocol qualifiers start with '<'"); 12134e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie assert(getLangOpts().ObjC1 && "Protocol qualifiers only exist in Objective-C"); 12149bd1d8d174a9d15ae343246c8322299248b9e92aDouglas Gregor SourceLocation LAngleLoc, EndProtoLoc; 12155f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<Decl *, 8> ProtocolDecl; 12165f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<SourceLocation, 8> ProtocolLocs; 121746f936e055d763437accd1e5a1bc49e7e5dbc0a3Douglas Gregor bool Result = ParseObjCProtocolReferences(ProtocolDecl, ProtocolLocs, false, 121846f936e055d763437accd1e5a1bc49e7e5dbc0a3Douglas Gregor LAngleLoc, EndProtoLoc); 12199bd1d8d174a9d15ae343246c8322299248b9e92aDouglas Gregor DS.setProtocolQualifiers(ProtocolDecl.data(), ProtocolDecl.size(), 12209bd1d8d174a9d15ae343246c8322299248b9e92aDouglas Gregor ProtocolLocs.data(), LAngleLoc); 12219bd1d8d174a9d15ae343246c8322299248b9e92aDouglas Gregor if (EndProtoLoc.isValid()) 12229bd1d8d174a9d15ae343246c8322299248b9e92aDouglas Gregor DS.SetRangeEnd(EndProtoLoc); 122346f936e055d763437accd1e5a1bc49e7e5dbc0a3Douglas Gregor return Result; 12249bd1d8d174a9d15ae343246c8322299248b9e92aDouglas Gregor} 12259bd1d8d174a9d15ae343246c8322299248b9e92aDouglas Gregor 12269bd1d8d174a9d15ae343246c8322299248b9e92aDouglas Gregor 1227dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-instance-variables: 1228dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// '{' objc-instance-variable-decl-list[opt] '}' 1229dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1230dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-instance-variable-decl-list: 1231dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-visibility-spec 1232dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-instance-variable-decl ';' 1233dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// ';' 1234dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-instance-variable-decl-list objc-visibility-spec 1235dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-instance-variable-decl-list objc-instance-variable-decl ';' 1236dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-instance-variable-decl-list ';' 1237dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1238dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-visibility-spec: 1239dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @private 1240dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @protected 1241dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @public 1242ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff/// @package [OBJC2] 1243dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1244dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-instance-variable-decl: 12451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// struct-declaration 1246dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1247d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallvoid Parser::ParseObjCClassInstanceVariables(Decl *interfaceDecl, 124883c481ade785a919ba21a33f9a8b1b21c1212fb3Fariborz Jahanian tok::ObjCKeywordKind visibility, 124960fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff SourceLocation atLoc) { 1250df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner assert(Tok.is(tok::l_brace) && "expected {"); 12515f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<Decl *, 32> AllIvarDecls; 1252a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian 12531a0d31a3d7f14ddc6370ba912c778aece6c12cf0Douglas Gregor ParseScope ClassScope(this, Scope::DeclScope|Scope::ClassScope); 12543a387441ae339363ee5b254658f295e97bd9e913Argyrios Kyrtzidis ObjCDeclContextSwitch ObjCDC(*this); 125572de6676bd30f9081ee4166bbe07b4c270258ce6Douglas Gregor 12564a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor BalancedDelimiterTracker T(*this, tok::l_brace); 12574a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor T.consumeOpen(); 12581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1259ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff // While we still have something to read, read the instance variables. 1260df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner while (Tok.isNot(tok::r_brace) && Tok.isNot(tok::eof)) { 1261ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff // Each iteration of this loop reads one objc-instance-variable-decl. 12621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1263ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff // Check for extraneous top-level semicolon. 1264df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::semi)) { 12654b0e6f1da341510c1ad83eaf4c836f3134d0156aRichard Trieu ConsumeExtraSemi(InstanceVariableList); 1266ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff continue; 1267ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff } 12681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1269ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff // Set the default visibility to private. 1270df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::at)) { // parse objc-visibility-spec 1271ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff ConsumeToken(); // eat the @ sign 1272c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor 1273c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor if (Tok.is(tok::code_completion)) { 127423c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCAtVisibility(getCurScope()); 12757d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis return cutOffParsing(); 1276c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor } 1277c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor 1278861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff switch (Tok.getObjCKeywordID()) { 1279ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff case tok::objc_private: 1280ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff case tok::objc_public: 1281ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff case tok::objc_protected: 1282ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff case tok::objc_package: 1283861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff visibility = Tok.getObjCKeywordID(); 1284ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff ConsumeToken(); 12851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump continue; 1286ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff default: 1287ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff Diag(Tok, diag::err_objc_illegal_visibility_spec); 1288ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff continue; 1289ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff } 1290ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff } 12911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1292c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor if (Tok.is(tok::code_completion)) { 129323c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteOrdinaryName(getCurScope(), 1294f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Sema::PCC_ObjCInstanceVariableList); 12957d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis return cutOffParsing(); 1296c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor } 1297c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor 1298bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall struct ObjCIvarCallback : FieldCallback { 1299bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall Parser &P; 1300d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *IDecl; 1301bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall tok::ObjCKeywordKind visibility; 13025f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVectorImpl<Decl *> &AllIvarDecls; 1303bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall 1304d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall ObjCIvarCallback(Parser &P, Decl *IDecl, tok::ObjCKeywordKind V, 13055f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVectorImpl<Decl *> &AllIvarDecls) : 1306bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall P(P), IDecl(IDecl), visibility(V), AllIvarDecls(AllIvarDecls) { 1307bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall } 1308bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall 1309d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *invoke(FieldDeclarator &FD) { 1310a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian P.Actions.ActOnObjCContainerStartDefinition(IDecl); 1311bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall // Install the declarator into the interface decl. 1312d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *Field 131323c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor = P.Actions.ActOnIvar(P.getCurScope(), 1314bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall FD.D.getDeclSpec().getSourceRange().getBegin(), 1315a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian FD.D, FD.BitfieldSize, visibility); 131610af87932fe4bffad539b24d512a33a1803daeaeFariborz Jahanian P.Actions.ActOnObjCContainerFinishDefinition(); 13170bd04596e4645ff145a046dfb3475f39674060d9Fariborz Jahanian if (Field) 13180bd04596e4645ff145a046dfb3475f39674060d9Fariborz Jahanian AllIvarDecls.push_back(Field); 1319bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall return Field; 1320bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall } 1321bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall } Callback(*this, interfaceDecl, visibility, AllIvarDecls); 1322d097be8f81fbf4ed96ac10bae18562dd8202666bFariborz Jahanian 1323e13594279a952537ac903325efff57e3edca79d9Chris Lattner // Parse all the comma separated declarators. 13240b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall DeclSpec DS(AttrFactory); 1325bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall ParseStructDeclaration(DS, Callback); 13261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1327df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::semi)) { 1328ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff ConsumeToken(); 1329ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff } else { 1330ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff Diag(Tok, diag::err_expected_semi_decl_list); 1331ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff // Skip to end of block or statement 1332ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff SkipUntil(tok::r_brace, true, true); 1333ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff } 1334ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff } 13354a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor T.consumeClose(); 13364a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor 1337a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian Actions.ActOnObjCContainerStartDefinition(interfaceDecl); 13384a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor Actions.ActOnLastBitfield(T.getCloseLocation(), AllIvarDecls); 133910af87932fe4bffad539b24d512a33a1803daeaeFariborz Jahanian Actions.ActOnObjCContainerFinishDefinition(); 13408749be53f53384e7846502791ceda6c657228d07Steve Naroff // Call ActOnFields() even if we don't have any decls. This is useful 13418749be53f53384e7846502791ceda6c657228d07Steve Naroff // for code rewriting tools that need to be aware of the empty list. 134223c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.ActOnFields(getCurScope(), atLoc, interfaceDecl, 134377b6de07be9186063c12928d2e9785a5d4eecbf6David Blaikie AllIvarDecls, 13444a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor T.getOpenLocation(), T.getCloseLocation(), 0); 1345ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff return; 13465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 1347dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff 1348dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-declaration: 1349dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-definition 1350dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-forward-reference 1351dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1352dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-definition: 135317d26a6c1f2cb921d0000c337b4967699dc928fdJames Dennett/// \@protocol identifier 13541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// objc-protocol-refs[opt] 13551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// objc-interface-decl-list 135617d26a6c1f2cb921d0000c337b4967699dc928fdJames Dennett/// \@end 1357dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1358dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-forward-reference: 135917d26a6c1f2cb921d0000c337b4967699dc928fdJames Dennett/// \@protocol identifier-list ';' 1360dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 136117d26a6c1f2cb921d0000c337b4967699dc928fdJames Dennett/// "\@protocol identifier ;" should be resolved as "\@protocol 13623536b443bc50d58a79f14fca9b6842541a434854Steve Naroff/// identifier-list ;": objc-interface-decl-list may not start with a 1363dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// semicolon in the first alternative if objc-protocol-refs are omitted. 1364bd9482d859a74bf2c45ef8b8aedec61c0e1c8374Douglas GregorParser::DeclGroupPtrTy 1365bd9482d859a74bf2c45ef8b8aedec61c0e1c8374Douglas GregorParser::ParseObjCAtProtocolDeclaration(SourceLocation AtLoc, 1366bd9482d859a74bf2c45ef8b8aedec61c0e1c8374Douglas Gregor ParsedAttributes &attrs) { 1367861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff assert(Tok.isObjCAtKeyword(tok::objc_protocol) && 13687ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff "ParseObjCAtProtocolDeclaration(): Expected @protocol"); 13697ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff ConsumeToken(); // the "protocol" identifier 13701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1371083128f6b13dfa4fc615a838c49b516d901b1ac0Douglas Gregor if (Tok.is(tok::code_completion)) { 137223c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCProtocolDecl(getCurScope()); 13737d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis cutOffParsing(); 1374bd9482d859a74bf2c45ef8b8aedec61c0e1c8374Douglas Gregor return DeclGroupPtrTy(); 1375083128f6b13dfa4fc615a838c49b516d901b1ac0Douglas Gregor } 1376083128f6b13dfa4fc615a838c49b516d901b1ac0Douglas Gregor 1377df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 13787ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff Diag(Tok, diag::err_expected_ident); // missing protocol name. 1379bd9482d859a74bf2c45ef8b8aedec61c0e1c8374Douglas Gregor return DeclGroupPtrTy(); 13807ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff } 13817ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff // Save the protocol name, then consume it. 13827ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff IdentifierInfo *protocolName = Tok.getIdentifierInfo(); 13837ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff SourceLocation nameLoc = ConsumeToken(); 13841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1385df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::semi)) { // forward declaration of one protocol. 13867caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner IdentifierLocPair ProtoInfo(protocolName, nameLoc); 13877ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff ConsumeToken(); 13881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return Actions.ActOnForwardProtocolDeclaration(AtLoc, &ProtoInfo, 1, 13897f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall attrs.getList()); 13907ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff } 13911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 139290ec96f3026480fa41057b05d58f338aed585f62Erik Verbruggen CheckNestedObjCContexts(AtLoc); 139390ec96f3026480fa41057b05d58f338aed585f62Erik Verbruggen 1394df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::comma)) { // list of forward declarations. 13955f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<IdentifierLocPair, 8> ProtocolRefs; 13967caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner ProtocolRefs.push_back(std::make_pair(protocolName, nameLoc)); 13977caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner 13987ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff // Parse the list of forward declarations. 13997ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff while (1) { 14007ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff ConsumeToken(); // the ',' 1401df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 14027ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff Diag(Tok, diag::err_expected_ident); 14037ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff SkipUntil(tok::semi); 1404bd9482d859a74bf2c45ef8b8aedec61c0e1c8374Douglas Gregor return DeclGroupPtrTy(); 14057ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff } 14067caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner ProtocolRefs.push_back(IdentifierLocPair(Tok.getIdentifierInfo(), 14077caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner Tok.getLocation())); 14087ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff ConsumeToken(); // the identifier 14091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1410df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::comma)) 14117ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff break; 14127ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff } 14137ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff // Consume the ';'. 14147ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff if (ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@protocol")) 1415bd9482d859a74bf2c45ef8b8aedec61c0e1c8374Douglas Gregor return DeclGroupPtrTy(); 14161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1417e440eb8158e71deb1e4ab11618ae3d680aac6da1Steve Naroff return Actions.ActOnForwardProtocolDeclaration(AtLoc, 14181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump &ProtocolRefs[0], 1419bc1c877fe28fb6a825f0b226a0a2da99e713ea03Fariborz Jahanian ProtocolRefs.size(), 14207f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall attrs.getList()); 14217caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner } 14221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14237ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff // Last, and definitely not least, parse a protocol declaration. 142471b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis SourceLocation LAngleLoc, EndProtoLoc; 14257caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner 14265f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<Decl *, 8> ProtocolRefs; 14275f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<SourceLocation, 8> ProtocolLocs; 14287caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner if (Tok.is(tok::less) && 142971b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis ParseObjCProtocolReferences(ProtocolRefs, ProtocolLocs, false, 143071b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis LAngleLoc, EndProtoLoc)) 1431bd9482d859a74bf2c45ef8b8aedec61c0e1c8374Douglas Gregor return DeclGroupPtrTy(); 14321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1433d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ProtoType = 1434e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner Actions.ActOnStartProtocolInterface(AtLoc, protocolName, nameLoc, 1435beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad ProtocolRefs.data(), 1436beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad ProtocolRefs.size(), 143718df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor ProtocolLocs.data(), 14387f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall EndProtoLoc, attrs.getList()); 1439a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian 14402f64cfe19e8bf6b6ba1660e38da8c421440457feFariborz Jahanian ParseObjCInterfaceDeclList(tok::objc_protocol, ProtoType); 1441bd9482d859a74bf2c45ef8b8aedec61c0e1c8374Douglas Gregor return Actions.ConvertDeclToDeclGroup(ProtoType); 1442dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff} 1443dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff 1444dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-implementation: 1445dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-implementation-prologue 1446dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-category-implementation-prologue 1447dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1448dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-implementation-prologue: 1449dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @implementation identifier objc-superclass[opt] 1450dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-instance-variables[opt] 1451dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1452dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-category-implementation-prologue: 1453dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @implementation identifier ( identifier ) 1454849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios KyrtzidisParser::DeclGroupPtrTy 1455849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios KyrtzidisParser::ParseObjCAtImplementationDeclaration(SourceLocation AtLoc) { 1456ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian assert(Tok.isObjCAtKeyword(tok::objc_implementation) && 1457ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian "ParseObjCAtImplementationDeclaration(): Expected @implementation"); 1458d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen CheckNestedObjCContexts(AtLoc); 1459ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); // the "implementation" identifier 14601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14613b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor // Code completion after '@implementation'. 14623b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor if (Tok.is(tok::code_completion)) { 146323c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCImplementationDecl(getCurScope()); 14647d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis cutOffParsing(); 1465849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis return DeclGroupPtrTy(); 14663b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor } 14673b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor 1468df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 1469ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian Diag(Tok, diag::err_expected_ident); // missing class or category name. 1470849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis return DeclGroupPtrTy(); 1471ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1472ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian // We have a class or category name - consume it. 1473ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian IdentifierInfo *nameId = Tok.getIdentifierInfo(); 1474ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian SourceLocation nameLoc = ConsumeToken(); // consume class or category name 1475849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis Decl *ObjCImpDecl = 0; 14761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (Tok.is(tok::l_paren)) { 1478ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian // we have a category implementation. 1479dec0984fce504a39a7f085774fb67cfd9957be58Jeffrey Yasskin ConsumeParen(); 1480ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian SourceLocation categoryLoc, rparenLoc; 1481ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian IdentifierInfo *categoryId = 0; 14821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 148333ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor if (Tok.is(tok::code_completion)) { 148423c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCImplementationCategory(getCurScope(), nameId, nameLoc); 14857d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis cutOffParsing(); 1486849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis return DeclGroupPtrTy(); 148733ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor } 148833ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor 1489df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::identifier)) { 1490ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian categoryId = Tok.getIdentifierInfo(); 1491ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian categoryLoc = ConsumeToken(); 1492ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } else { 1493ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian Diag(Tok, diag::err_expected_ident); // missing category name. 1494849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis return DeclGroupPtrTy(); 14951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 1496df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::r_paren)) { 1497ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian Diag(Tok, diag::err_expected_rparen); 1498ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian SkipUntil(tok::r_paren, false); // don't stop at ';' 1499849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis return DeclGroupPtrTy(); 1500ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1501ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian rparenLoc = ConsumeParen(); 1502849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis ObjCImpDecl = Actions.ActOnStartCategoryImplementation( 1503d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen AtLoc, nameId, nameLoc, categoryId, 15048f3fde00ad4d4f943321e338b914ae4740711c84Fariborz Jahanian categoryLoc); 1505a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian 1506849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis } else { 1507849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis // We have a class implementation 1508849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis SourceLocation superClassLoc; 1509849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis IdentifierInfo *superClassId = 0; 1510849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis if (Tok.is(tok::colon)) { 1511849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis // We have a super class 1512849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis ConsumeToken(); 1513849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis if (Tok.isNot(tok::identifier)) { 1514849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis Diag(Tok, diag::err_expected_ident); // missing super class name. 1515849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis return DeclGroupPtrTy(); 1516849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis } 1517849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis superClassId = Tok.getIdentifierInfo(); 1518849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis superClassLoc = ConsumeToken(); // Consume super class name 1519ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1520849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis ObjCImpDecl = Actions.ActOnStartClassImplementation( 1521849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis AtLoc, nameId, nameLoc, 1522849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis superClassId, superClassLoc); 1523849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis 1524849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis if (Tok.is(tok::l_brace)) // we have ivars 1525849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis ParseObjCClassInstanceVariables(ObjCImpDecl, tok::objc_private, AtLoc); 1526ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1527849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis assert(ObjCImpDecl); 15281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1529849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis SmallVector<Decl *, 8> DeclsInGroup; 1530a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian 1531849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis { 1532849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis ObjCImplParsingDataRAII ObjCImplParsing(*this, ObjCImpDecl); 1533849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis while (!ObjCImplParsing.isFinished() && Tok.isNot(tok::eof)) { 1534849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis ParsedAttributesWithRange attrs(AttrFactory); 1535849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis MaybeParseCXX0XAttributes(attrs); 1536849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis MaybeParseMicrosoftAttributes(attrs); 1537849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis if (DeclGroupPtrTy DGP = ParseExternalDeclaration(attrs)) { 1538849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis DeclGroupRef DG = DGP.get(); 1539849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis DeclsInGroup.append(DG.begin(), DG.end()); 1540849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis } 1541849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis } 1542849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis } 1543849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis 1544644af7b50bd0541468b45c197f5b637e934d48a0Argyrios Kyrtzidis return Actions.ActOnFinishObjCImplementation(ObjCImpDecl, DeclsInGroup); 15455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 154660fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff 1547140ab234c23f392d5422691c5de1ee3c15026defFariborz JahanianParser::DeclGroupPtrTy 1548140ab234c23f392d5422691c5de1ee3c15026defFariborz JahanianParser::ParseObjCAtEndDeclaration(SourceRange atEnd) { 1549ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian assert(Tok.isObjCAtKeyword(tok::objc_end) && 1550ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian "ParseObjCAtEndDeclaration(): Expected @end"); 1551ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); // the "end" identifier 1552849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis if (CurParsedObjCImpl) 1553849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis CurParsedObjCImpl->finish(atEnd); 15548697d308c1bdd50e5c45757ac11be701c26e9e97Fariborz Jahanian else 1555782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek // missing @implementation 1556d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen Diag(atEnd.getBegin(), diag::err_expected_objc_container); 1557849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis return DeclGroupPtrTy(); 15585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 1559e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian 1560849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios KyrtzidisParser::ObjCImplParsingDataRAII::~ObjCImplParsingDataRAII() { 1561849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis if (!Finished) { 1562849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis finish(P.Tok.getLocation()); 1563849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis if (P.Tok.is(tok::eof)) { 1564849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis P.Diag(P.Tok, diag::err_objc_missing_end) 1565849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis << FixItHint::CreateInsertion(P.Tok.getLocation(), "\n@end\n"); 1566849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis P.Diag(Dcl->getLocStart(), diag::note_objc_container_start) 1567849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis << Sema::OCK_Implementation; 1568849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis } 1569849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis } 1570849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis P.CurParsedObjCImpl = 0; 1571849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis assert(LateParsedObjCMethods.empty()); 1572849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis} 1573d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen 1574849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidisvoid Parser::ObjCImplParsingDataRAII::finish(SourceRange AtEnd) { 1575849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis assert(!Finished); 1576849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis P.Actions.DefaultSynthesizeProperties(P.getCurScope(), Dcl); 1577849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis for (size_t i = 0; i < LateParsedObjCMethods.size(); ++i) 1578849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis P.ParseLexedObjCMethodDefs(*LateParsedObjCMethods[i]); 1579d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen 1580849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis P.Actions.ActOnAtEnd(P.getCurScope(), AtEnd); 158163e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian 1582849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis /// \brief Clear and free the cached objc methods. 15832fea2242fe7e7c37df1e96316616febeaf4e29ebArgyrios Kyrtzidis for (LateParsedObjCMethodContainer::iterator 15842fea2242fe7e7c37df1e96316616febeaf4e29ebArgyrios Kyrtzidis I = LateParsedObjCMethods.begin(), 15852fea2242fe7e7c37df1e96316616febeaf4e29ebArgyrios Kyrtzidis E = LateParsedObjCMethods.end(); I != E; ++I) 15862fea2242fe7e7c37df1e96316616febeaf4e29ebArgyrios Kyrtzidis delete *I; 15872fea2242fe7e7c37df1e96316616febeaf4e29ebArgyrios Kyrtzidis LateParsedObjCMethods.clear(); 1588849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis 1589849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis Finished = true; 15902fea2242fe7e7c37df1e96316616febeaf4e29ebArgyrios Kyrtzidis} 15912fea2242fe7e7c37df1e96316616febeaf4e29ebArgyrios Kyrtzidis 1592e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian/// compatibility-alias-decl: 1593e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian/// @compatibility_alias alias-name class-name ';' 1594e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian/// 1595d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseObjCAtAliasDeclaration(SourceLocation atLoc) { 1596e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian assert(Tok.isObjCAtKeyword(tok::objc_compatibility_alias) && 1597e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian "ParseObjCAtAliasDeclaration(): Expected @compatibility_alias"); 1598e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian ConsumeToken(); // consume compatibility_alias 1599df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 1600e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian Diag(Tok, diag::err_expected_ident); 1601d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 1602e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian } 1603243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian IdentifierInfo *aliasId = Tok.getIdentifierInfo(); 1604243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian SourceLocation aliasLoc = ConsumeToken(); // consume alias-name 1605df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 1606e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian Diag(Tok, diag::err_expected_ident); 1607d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 1608e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian } 1609243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian IdentifierInfo *classId = Tok.getIdentifierInfo(); 1610243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian SourceLocation classLoc = ConsumeToken(); // consume class-name; 1611e6bf90aec0044342ffccd13201b8a3a31a985a4bDouglas Gregor ExpectAndConsume(tok::semi, diag::err_expected_semi_after, 1612e6bf90aec0044342ffccd13201b8a3a31a985a4bDouglas Gregor "@compatibility_alias"); 1613b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return Actions.ActOnCompatiblityAlias(atLoc, aliasId, aliasLoc, 1614b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner classId, classLoc); 16155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 16165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1617ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-synthesis: 1618ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// @synthesize property-ivar-list ';' 1619ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// 1620ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-ivar-list: 1621ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-ivar 1622ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-ivar-list ',' property-ivar 1623ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// 1624ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-ivar: 1625ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// identifier 1626ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// identifier '=' identifier 1627ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// 1628d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseObjCPropertySynthesize(SourceLocation atLoc) { 1629ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian assert(Tok.isObjCAtKeyword(tok::objc_synthesize) && 1630ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian "ParseObjCPropertyDynamic(): Expected '@synthesize'"); 1631dec0984fce504a39a7f085774fb67cfd9957be58Jeffrey Yasskin ConsumeToken(); // consume synthesize 16321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1633b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor while (true) { 1634322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor if (Tok.is(tok::code_completion)) { 1635a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian Actions.CodeCompleteObjCPropertyDefinition(getCurScope()); 16367d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis cutOffParsing(); 16377d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis return 0; 1638322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor } 1639322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor 1640b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor if (Tok.isNot(tok::identifier)) { 1641b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor Diag(Tok, diag::err_synthesized_property_name); 1642b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor SkipUntil(tok::semi); 1643d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 1644b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor } 1645b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor 1646f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian IdentifierInfo *propertyIvar = 0; 1647f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian IdentifierInfo *propertyId = Tok.getIdentifierInfo(); 1648f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian SourceLocation propertyLoc = ConsumeToken(); // consume property name 1649a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor SourceLocation propertyIvarLoc; 1650df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::equal)) { 1651ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian // property '=' ivar-name 1652ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); // consume '=' 1653322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor 1654322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor if (Tok.is(tok::code_completion)) { 1655a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian Actions.CodeCompleteObjCPropertySynthesizeIvar(getCurScope(), propertyId); 16567d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis cutOffParsing(); 16577d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis return 0; 1658322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor } 1659322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor 1660df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 1661ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian Diag(Tok, diag::err_expected_ident); 1662ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian break; 1663ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1664f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian propertyIvar = Tok.getIdentifierInfo(); 1665a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor propertyIvarLoc = ConsumeToken(); // consume ivar-name 1666ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1667a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian Actions.ActOnPropertyImplDecl(getCurScope(), atLoc, propertyLoc, true, 1668a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor propertyId, propertyIvar, propertyIvarLoc); 1669df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::comma)) 1670ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian break; 1671ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); // consume ',' 1672ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1673e6bf90aec0044342ffccd13201b8a3a31a985a4bDouglas Gregor ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@synthesize"); 1674d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 1675ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian} 1676ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian 1677ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-dynamic: 1678ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// @dynamic property-list 1679ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// 1680ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-list: 1681ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// identifier 1682ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-list ',' identifier 1683ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// 1684d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseObjCPropertyDynamic(SourceLocation atLoc) { 1685ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian assert(Tok.isObjCAtKeyword(tok::objc_dynamic) && 1686ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian "ParseObjCPropertyDynamic(): Expected '@dynamic'"); 1687dec0984fce504a39a7f085774fb67cfd9957be58Jeffrey Yasskin ConsumeToken(); // consume dynamic 1688424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor while (true) { 1689424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor if (Tok.is(tok::code_completion)) { 1690a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian Actions.CodeCompleteObjCPropertyDefinition(getCurScope()); 16917d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis cutOffParsing(); 16927d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis return 0; 1693424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor } 1694424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor 1695424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor if (Tok.isNot(tok::identifier)) { 1696424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor Diag(Tok, diag::err_expected_ident); 1697424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor SkipUntil(tok::semi); 1698d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 1699424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor } 1700424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor 1701c35b9e4e2efad727538c848cf30d4b0eb1031dc9Fariborz Jahanian IdentifierInfo *propertyId = Tok.getIdentifierInfo(); 1702c35b9e4e2efad727538c848cf30d4b0eb1031dc9Fariborz Jahanian SourceLocation propertyLoc = ConsumeToken(); // consume property name 1703a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian Actions.ActOnPropertyImplDecl(getCurScope(), atLoc, propertyLoc, false, 1704a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor propertyId, 0, SourceLocation()); 1705c35b9e4e2efad727538c848cf30d4b0eb1031dc9Fariborz Jahanian 1706df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::comma)) 1707ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian break; 1708ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); // consume ',' 1709ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1710e6bf90aec0044342ffccd13201b8a3a31a985a4bDouglas Gregor ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@dynamic"); 1711d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 1712ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian} 17131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1714397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// objc-throw-statement: 1715397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// throw expression[opt]; 1716397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// 171760d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult Parser::ParseObjCThrowStmt(SourceLocation atLoc) { 171860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Res; 1719397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian ConsumeToken(); // consume throw 1720df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::semi)) { 172139f8f159c488a900e5958d5aab3e467af9ec8a2bFariborz Jahanian Res = ParseExpression(); 17220e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Res.isInvalid()) { 1723397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian SkipUntil(tok::semi); 172443bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 1725397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian } 1726397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian } 172702418c7f0cb8bb83f1a1a1fad9bf6104efa83e0eTed Kremenek // consume ';' 172802418c7f0cb8bb83f1a1a1fad9bf6104efa83e0eTed Kremenek ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@throw"); 17299ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return Actions.ActOnObjCAtThrowStmt(atLoc, Res.take(), getCurScope()); 1730397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian} 1731397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian 1732c385c90c68dfa376650e2facfbb444b2ec9bd110Fariborz Jahanian/// objc-synchronized-statement: 173378a677bbb5fa115fa0995b5783adeeefad67167eFariborz Jahanian/// @synchronized '(' expression ')' compound-statement 1734c385c90c68dfa376650e2facfbb444b2ec9bd110Fariborz Jahanian/// 173560d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 173643bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian RedlParser::ParseObjCSynchronizedStmt(SourceLocation atLoc) { 1737fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian ConsumeToken(); // consume synchronized 1738fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian if (Tok.isNot(tok::l_paren)) { 17391ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_lparen_after) << "@synchronized"; 174043bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 1741fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian } 174207524039dce5c820f111a1b3f772b4261f004b4aJohn McCall 174307524039dce5c820f111a1b3f772b4261f004b4aJohn McCall // The operand is surrounded with parentheses. 1744fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian ConsumeParen(); // '(' 174507524039dce5c820f111a1b3f772b4261f004b4aJohn McCall ExprResult operand(ParseExpression()); 174607524039dce5c820f111a1b3f772b4261f004b4aJohn McCall 174707524039dce5c820f111a1b3f772b4261f004b4aJohn McCall if (Tok.is(tok::r_paren)) { 174807524039dce5c820f111a1b3f772b4261f004b4aJohn McCall ConsumeParen(); // ')' 174907524039dce5c820f111a1b3f772b4261f004b4aJohn McCall } else { 175007524039dce5c820f111a1b3f772b4261f004b4aJohn McCall if (!operand.isInvalid()) 175107524039dce5c820f111a1b3f772b4261f004b4aJohn McCall Diag(Tok, diag::err_expected_rparen); 175207524039dce5c820f111a1b3f772b4261f004b4aJohn McCall 175307524039dce5c820f111a1b3f772b4261f004b4aJohn McCall // Skip forward until we see a left brace, but don't consume it. 175407524039dce5c820f111a1b3f772b4261f004b4aJohn McCall SkipUntil(tok::l_brace, true, true); 1755fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian } 175607524039dce5c820f111a1b3f772b4261f004b4aJohn McCall 175707524039dce5c820f111a1b3f772b4261f004b4aJohn McCall // Require a compound statement. 175878a677bbb5fa115fa0995b5783adeeefad67167eFariborz Jahanian if (Tok.isNot(tok::l_brace)) { 175907524039dce5c820f111a1b3f772b4261f004b4aJohn McCall if (!operand.isInvalid()) 176007524039dce5c820f111a1b3f772b4261f004b4aJohn McCall Diag(Tok, diag::err_expected_lbrace); 176143bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 176278a677bbb5fa115fa0995b5783adeeefad67167eFariborz Jahanian } 17633ac438c383a4a9a73c76a05c76ec5d02f10a3c52Steve Naroff 176407524039dce5c820f111a1b3f772b4261f004b4aJohn McCall // Check the @synchronized operand now. 176507524039dce5c820f111a1b3f772b4261f004b4aJohn McCall if (!operand.isInvalid()) 176607524039dce5c820f111a1b3f772b4261f004b4aJohn McCall operand = Actions.ActOnObjCAtSynchronizedOperand(atLoc, operand.take()); 176707524039dce5c820f111a1b3f772b4261f004b4aJohn McCall 176807524039dce5c820f111a1b3f772b4261f004b4aJohn McCall // Parse the compound statement within a new scope. 176907524039dce5c820f111a1b3f772b4261f004b4aJohn McCall ParseScope bodyScope(this, Scope::DeclScope); 177007524039dce5c820f111a1b3f772b4261f004b4aJohn McCall StmtResult body(ParseCompoundStatementBody()); 177107524039dce5c820f111a1b3f772b4261f004b4aJohn McCall bodyScope.Exit(); 177207524039dce5c820f111a1b3f772b4261f004b4aJohn McCall 177307524039dce5c820f111a1b3f772b4261f004b4aJohn McCall // If there was a semantic or parse error earlier with the 177407524039dce5c820f111a1b3f772b4261f004b4aJohn McCall // operand, fail now. 177507524039dce5c820f111a1b3f772b4261f004b4aJohn McCall if (operand.isInvalid()) 177607524039dce5c820f111a1b3f772b4261f004b4aJohn McCall return StmtError(); 177707524039dce5c820f111a1b3f772b4261f004b4aJohn McCall 177807524039dce5c820f111a1b3f772b4261f004b4aJohn McCall if (body.isInvalid()) 177907524039dce5c820f111a1b3f772b4261f004b4aJohn McCall body = Actions.ActOnNullStmt(Tok.getLocation()); 17800e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl 178107524039dce5c820f111a1b3f772b4261f004b4aJohn McCall return Actions.ActOnObjCAtSynchronizedStmt(atLoc, operand.get(), body.get()); 1782c385c90c68dfa376650e2facfbb444b2ec9bd110Fariborz Jahanian} 1783c385c90c68dfa376650e2facfbb444b2ec9bd110Fariborz Jahanian 1784397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// objc-try-catch-statement: 1785397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// @try compound-statement objc-catch-list[opt] 1786397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// @try compound-statement objc-catch-list[opt] @finally compound-statement 1787397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// 1788397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// objc-catch-list: 1789397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// @catch ( parameter-declaration ) compound-statement 1790397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// objc-catch-list @catch ( catch-parameter-declaration ) compound-statement 1791397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// catch-parameter-declaration: 1792397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// parameter-declaration 1793397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// '...' [OBJC2] 1794397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// 179560d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult Parser::ParseObjCTryStmt(SourceLocation atLoc) { 1796397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian bool catch_or_finally_seen = false; 179743bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl 1798397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian ConsumeToken(); // consume try 1799df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::l_brace)) { 18001ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_lbrace); 180143bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 1802397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian } 18038f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor StmtVector CatchStmts(Actions); 180460d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult FinallyStmt; 18058935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor ParseScope TryScope(this, Scope::DeclScope); 180660d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult TryBody(ParseCompoundStatementBody()); 18078935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor TryScope.Exit(); 18080e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (TryBody.isInvalid()) 1809bd49a647afd9cc534fef13cadf652d4e9c396e2bFariborz Jahanian TryBody = Actions.ActOnNullStmt(Tok.getLocation()); 1810a55e52c0802cae3b7c366a05c461d3d15074c1a3Sebastian Redl 1811df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner while (Tok.is(tok::at)) { 18126b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner // At this point, we need to lookahead to determine if this @ is the start 18136b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner // of an @catch or @finally. We don't want to consume the @ token if this 18146b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner // is an @try or @encode or something else. 18156b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner Token AfterAt = GetLookAheadToken(1); 18166b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner if (!AfterAt.isObjCAtKeyword(tok::objc_catch) && 18176b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner !AfterAt.isObjCAtKeyword(tok::objc_finally)) 18186b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner break; 18190e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl 1820161a9c5afaafb4d527b7efba9675a8b2cbbe32e0Fariborz Jahanian SourceLocation AtCatchFinallyLoc = ConsumeToken(); 1821cb53b361bce341c8591333c6997f62e480acc0b4Chris Lattner if (Tok.isObjCAtKeyword(tok::objc_catch)) { 1822d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *FirstPart = 0; 18233b1191d7eaf2f4984564e01ab84b6713a9d80e70Fariborz Jahanian ConsumeToken(); // consume catch 1824df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::l_paren)) { 1825397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian ConsumeParen(); 1826e21dd6ffef4585fa43cd3586ed971217d65bf56cSteve Naroff ParseScope CatchScope(this, Scope::DeclScope|Scope::AtCatchScope); 1827df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::ellipsis)) { 18280b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall DeclSpec DS(AttrFactory); 1829397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian ParseDeclarationSpecifiers(DS); 183017b6399f8461c5b7e1c6f367b0a0dde49f921240Argyrios Kyrtzidis Declarator ParmDecl(DS, Declarator::ObjCCatchContext); 18317ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff ParseDeclarator(ParmDecl); 18327ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff 18334e6c0d19b7c072758922cf80525a81aeefc6e64bDouglas Gregor // Inform the actions module about the declarator, so it 18347ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff // gets added to the current scope. 183523c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor FirstPart = Actions.ActOnObjCExceptionDecl(getCurScope(), ParmDecl); 183664515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff } else 1837397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian ConsumeToken(); // consume '...' 18381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 183993a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff SourceLocation RParenLoc; 18401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 184193a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff if (Tok.is(tok::r_paren)) 184293a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff RParenLoc = ConsumeParen(); 184393a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff else // Skip over garbage, until we get to ')'. Eat the ')'. 184493a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff SkipUntil(tok::r_paren, true, false); 184593a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff 184660d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult CatchBody(true); 1847c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner if (Tok.is(tok::l_brace)) 1848c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner CatchBody = ParseCompoundStatementBody(); 1849c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner else 1850c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner Diag(Tok, diag::err_expected_lbrace); 18510e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (CatchBody.isInvalid()) 18523b1191d7eaf2f4984564e01ab84b6713a9d80e70Fariborz Jahanian CatchBody = Actions.ActOnNullStmt(Tok.getLocation()); 18538f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor 185460d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Catch = Actions.ActOnObjCAtCatchStmt(AtCatchFinallyLoc, 18558f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor RParenLoc, 18568f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor FirstPart, 18579ae2f076ca5ab1feb3ba95629099ec2319833701John McCall CatchBody.take()); 18588f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor if (!Catch.isInvalid()) 18598f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor CatchStmts.push_back(Catch.release()); 18608f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor 186164515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff } else { 18621ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(AtCatchFinallyLoc, diag::err_expected_lparen_after) 18631ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner << "@catch clause"; 186443bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 1865397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian } 1866397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian catch_or_finally_seen = true; 18676b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner } else { 18686b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner assert(Tok.isObjCAtKeyword(tok::objc_finally) && "Lookahead confused?"); 186964515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff ConsumeToken(); // consume finally 18708935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor ParseScope FinallyScope(this, Scope::DeclScope); 18710e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl 187260d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult FinallyBody(true); 1873c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner if (Tok.is(tok::l_brace)) 1874c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner FinallyBody = ParseCompoundStatementBody(); 1875c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner else 1876c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner Diag(Tok, diag::err_expected_lbrace); 18770e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (FinallyBody.isInvalid()) 1878161a9c5afaafb4d527b7efba9675a8b2cbbe32e0Fariborz Jahanian FinallyBody = Actions.ActOnNullStmt(Tok.getLocation()); 18790e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl FinallyStmt = Actions.ActOnObjCAtFinallyStmt(AtCatchFinallyLoc, 18809ae2f076ca5ab1feb3ba95629099ec2319833701John McCall FinallyBody.take()); 1881397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian catch_or_finally_seen = true; 1882397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian break; 1883397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian } 1884397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian } 1885bd49a647afd9cc534fef13cadf652d4e9c396e2bFariborz Jahanian if (!catch_or_finally_seen) { 1886397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian Diag(atLoc, diag::err_missing_catch_finally); 188743bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 1888bd49a647afd9cc534fef13cadf652d4e9c396e2bFariborz Jahanian } 18898f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor 18909ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return Actions.ActOnObjCAtTryStmt(atLoc, TryBody.take(), 18918f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor move_arg(CatchStmts), 18929ae2f076ca5ab1feb3ba95629099ec2319833701John McCall FinallyStmt.take()); 1893397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian} 1894ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian 1895f85e193739c953358c865005855253af4f68a497John McCall/// objc-autoreleasepool-statement: 1896f85e193739c953358c865005855253af4f68a497John McCall/// @autoreleasepool compound-statement 1897f85e193739c953358c865005855253af4f68a497John McCall/// 1898f85e193739c953358c865005855253af4f68a497John McCallStmtResult 1899f85e193739c953358c865005855253af4f68a497John McCallParser::ParseObjCAutoreleasePoolStmt(SourceLocation atLoc) { 1900f85e193739c953358c865005855253af4f68a497John McCall ConsumeToken(); // consume autoreleasepool 1901f85e193739c953358c865005855253af4f68a497John McCall if (Tok.isNot(tok::l_brace)) { 1902f85e193739c953358c865005855253af4f68a497John McCall Diag(Tok, diag::err_expected_lbrace); 1903f85e193739c953358c865005855253af4f68a497John McCall return StmtError(); 1904f85e193739c953358c865005855253af4f68a497John McCall } 1905f85e193739c953358c865005855253af4f68a497John McCall // Enter a scope to hold everything within the compound stmt. Compound 1906f85e193739c953358c865005855253af4f68a497John McCall // statements can always hold declarations. 1907f85e193739c953358c865005855253af4f68a497John McCall ParseScope BodyScope(this, Scope::DeclScope); 1908f85e193739c953358c865005855253af4f68a497John McCall 1909f85e193739c953358c865005855253af4f68a497John McCall StmtResult AutoreleasePoolBody(ParseCompoundStatementBody()); 1910f85e193739c953358c865005855253af4f68a497John McCall 1911f85e193739c953358c865005855253af4f68a497John McCall BodyScope.Exit(); 1912f85e193739c953358c865005855253af4f68a497John McCall if (AutoreleasePoolBody.isInvalid()) 1913f85e193739c953358c865005855253af4f68a497John McCall AutoreleasePoolBody = Actions.ActOnNullStmt(Tok.getLocation()); 1914f85e193739c953358c865005855253af4f68a497John McCall return Actions.ActOnObjCAutoreleasePoolStmt(atLoc, 1915f85e193739c953358c865005855253af4f68a497John McCall AutoreleasePoolBody.take()); 1916f85e193739c953358c865005855253af4f68a497John McCall} 1917f85e193739c953358c865005855253af4f68a497John McCall 19183536b443bc50d58a79f14fca9b6842541a434854Steve Naroff/// objc-method-def: objc-method-proto ';'[opt] '{' body '}' 1919ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// 1920d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseObjCMethodDefinition() { 1921a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian Decl *MDecl = ParseObjCMethodPrototype(); 19221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1923f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall PrettyDeclStackTraceEntry CrashInfo(Actions, MDecl, Tok.getLocation(), 1924f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall "parsing Objective-C method"); 19251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1926ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian // parse optional ';' 1927209a8c2fa23636f6d065d618e7078e164903f5cdFariborz Jahanian if (Tok.is(tok::semi)) { 1928849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis if (CurParsedObjCImpl) { 1929496e45ef3350fabc312c5a807d308c65c50af4dbTed Kremenek Diag(Tok, diag::warn_semicolon_before_method_body) 1930849b243d4065f56742a4677d6dc8277609a151f8Douglas Gregor << FixItHint::CreateRemoval(Tok.getLocation()); 1931496e45ef3350fabc312c5a807d308c65c50af4dbTed Kremenek } 1932ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); 1933209a8c2fa23636f6d065d618e7078e164903f5cdFariborz Jahanian } 1934ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian 1935409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // We should have an opening brace now. 1936df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::l_brace)) { 1937da323adbb99cee19a203ead852d5d9bfebb23fb7Steve Naroff Diag(Tok, diag::err_expected_method_body); 19381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1939409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // Skip over garbage, until we get to '{'. Don't eat the '{'. 1940409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff SkipUntil(tok::l_brace, true, true); 19411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1942409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // If we didn't find the '{', bail out. 1943409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff if (Tok.isNot(tok::l_brace)) 1944d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 1945ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1946849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis 1947849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis if (!MDecl) { 1948849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis ConsumeBrace(); 1949849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis SkipUntil(tok::r_brace, /*StopAtSemi=*/false); 1950849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis return 0; 1951849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis } 1952849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis 1953140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian // Allow the rest of sema to find private method decl implementations. 1954849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis Actions.AddAnyMethodToGlobalPool(MDecl); 1955849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis 1956849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis if (CurParsedObjCImpl) { 1957849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis // Consume the tokens and store them for later parsing. 1958849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis LexedMethod* LM = new LexedMethod(this, MDecl); 1959849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis CurParsedObjCImpl->LateParsedObjCMethods.push_back(LM); 1960849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis CachedTokens &Toks = LM->Toks; 1961849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis // Begin by storing the '{' token. 1962849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis Toks.push_back(Tok); 1963849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis ConsumeBrace(); 1964849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis // Consume everything up to (and including) the matching right brace. 1965849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis ConsumeAndStoreUntil(tok::r_brace, Toks, /*StopAtSemi=*/false); 1966849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis 1967849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis } else { 1968849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis ConsumeBrace(); 1969849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis SkipUntil(tok::r_brace, /*StopAtSemi=*/false); 1970849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis } 1971849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis 197271c0a951d08dc7a2a057df8c15f22b36f6aa47c7Steve Naroff return MDecl; 19735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 19745508518a2702b00be3b15a26d772bde968972f54Anders Carlsson 197560d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult Parser::ParseObjCAtStatement(SourceLocation AtLoc) { 19769a0c85e640a08174569a303db22981612f05d385Douglas Gregor if (Tok.is(tok::code_completion)) { 197723c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCAtStatement(getCurScope()); 19787d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis cutOffParsing(); 19799a0c85e640a08174569a303db22981612f05d385Douglas Gregor return StmtError(); 19805d8031687d086701b4dadaab3e0de1def448da9dChris Lattner } 19815d8031687d086701b4dadaab3e0de1def448da9dChris Lattner 19825d8031687d086701b4dadaab3e0de1def448da9dChris Lattner if (Tok.isObjCAtKeyword(tok::objc_try)) 19836b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner return ParseObjCTryStmt(AtLoc); 19845d8031687d086701b4dadaab3e0de1def448da9dChris Lattner 19855d8031687d086701b4dadaab3e0de1def448da9dChris Lattner if (Tok.isObjCAtKeyword(tok::objc_throw)) 198664515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff return ParseObjCThrowStmt(AtLoc); 19875d8031687d086701b4dadaab3e0de1def448da9dChris Lattner 19885d8031687d086701b4dadaab3e0de1def448da9dChris Lattner if (Tok.isObjCAtKeyword(tok::objc_synchronized)) 198964515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff return ParseObjCSynchronizedStmt(AtLoc); 1990f85e193739c953358c865005855253af4f68a497John McCall 1991f85e193739c953358c865005855253af4f68a497John McCall if (Tok.isObjCAtKeyword(tok::objc_autoreleasepool)) 1992f85e193739c953358c865005855253af4f68a497John McCall return ParseObjCAutoreleasePoolStmt(AtLoc); 19935d8031687d086701b4dadaab3e0de1def448da9dChris Lattner 199460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Res(ParseExpressionWithLeadingAt(AtLoc)); 19950e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Res.isInvalid()) { 199664515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff // If the expression is invalid, skip ahead to the next semicolon. Not 199764515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff // doing this opens us up to the possibility of infinite loops if 199864515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff // ParseExpression does not consume any tokens. 199964515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff SkipUntil(tok::semi); 200043bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 200164515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff } 20025d8031687d086701b4dadaab3e0de1def448da9dChris Lattner 200364515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff // Otherwise, eat the semicolon. 20049ba23b4ceacd77cd264501690a7a9e94184ef71bDouglas Gregor ExpectAndConsumeSemi(diag::err_expected_semi_after_expr); 20059ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return Actions.ActOnExprStmt(Actions.MakeFullExpr(Res.take())); 200664515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff} 200764515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff 200860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult Parser::ParseObjCAtExpression(SourceLocation AtLoc) { 20095508518a2702b00be3b15a26d772bde968972f54Anders Carlsson switch (Tok.getKind()) { 20109a0c85e640a08174569a303db22981612f05d385Douglas Gregor case tok::code_completion: 201123c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCAtExpression(getCurScope()); 20127d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis cutOffParsing(); 20139a0c85e640a08174569a303db22981612f05d385Douglas Gregor return ExprError(); 20149a0c85e640a08174569a303db22981612f05d385Douglas Gregor 2015ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek case tok::minus: 2016ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek case tok::plus: { 2017ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek tok::TokenKind Kind = Tok.getKind(); 2018ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SourceLocation OpLoc = ConsumeToken(); 2019ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 2020ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (!Tok.is(tok::numeric_constant)) { 2021ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek const char *Symbol = 0; 2022ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek switch (Kind) { 2023ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek case tok::minus: Symbol = "-"; break; 2024ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek case tok::plus: Symbol = "+"; break; 2025ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek default: llvm_unreachable("missing unary operator case"); 2026ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 2027ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Diag(Tok, diag::err_nsnumber_nonliteral_unary) 2028ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek << Symbol; 2029ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return ExprError(); 2030ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 2031ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 2032ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExprResult Lit(Actions.ActOnNumericConstant(Tok)); 2033ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (Lit.isInvalid()) { 2034ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return move(Lit); 2035ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 20368b8d9534f185743fb72c59d4e735794e6e0f4335Benjamin Kramer ConsumeToken(); // Consume the literal token. 2037ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 2038ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Lit = Actions.ActOnUnaryOp(getCurScope(), OpLoc, Kind, Lit.take()); 2039ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (Lit.isInvalid()) 2040ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return move(Lit); 2041ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 2042ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return ParsePostfixExpressionSuffix( 2043ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Actions.BuildObjCNumericLiteral(AtLoc, Lit.take())); 2044ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 2045ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 2046b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner case tok::string_literal: // primary-expression: string-literal 2047b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner case tok::wide_string_literal: 20481d922960e083906a586609ac6978678147250177Sebastian Redl return ParsePostfixExpressionSuffix(ParseObjCStringLiteral(AtLoc)); 2049ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 2050ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek case tok::char_constant: 2051ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return ParsePostfixExpressionSuffix(ParseObjCCharacterLiteral(AtLoc)); 2052ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 2053ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek case tok::numeric_constant: 2054ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return ParsePostfixExpressionSuffix(ParseObjCNumericLiteral(AtLoc)); 2055ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 2056ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek case tok::kw_true: // Objective-C++, etc. 2057ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek case tok::kw___objc_yes: // c/c++/objc/objc++ __objc_yes 2058ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return ParsePostfixExpressionSuffix(ParseObjCBooleanLiteral(AtLoc, true)); 2059ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek case tok::kw_false: // Objective-C++, etc. 2060ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek case tok::kw___objc_no: // c/c++/objc/objc++ __objc_no 2061ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return ParsePostfixExpressionSuffix(ParseObjCBooleanLiteral(AtLoc, false)); 2062ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 2063ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek case tok::l_square: 2064ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // Objective-C array literal 2065ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return ParsePostfixExpressionSuffix(ParseObjCArrayLiteral(AtLoc)); 2066ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 2067ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek case tok::l_brace: 2068ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // Objective-C dictionary literal 2069ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return ParsePostfixExpressionSuffix(ParseObjCDictionaryLiteral(AtLoc)); 2070ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 2071eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard case tok::l_paren: 2072eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard // Objective-C boxed expression 2073eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard return ParsePostfixExpressionSuffix(ParseObjCBoxedExpr(AtLoc)); 2074eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard 2075b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner default: 20764fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner if (Tok.getIdentifierInfo() == 0) 20771d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(AtLoc, diag::err_unexpected_at)); 20782f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl 20794fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner switch (Tok.getIdentifierInfo()->getObjCKeywordID()) { 20804fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner case tok::objc_encode: 20811d922960e083906a586609ac6978678147250177Sebastian Redl return ParsePostfixExpressionSuffix(ParseObjCEncodeExpression(AtLoc)); 20824fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner case tok::objc_protocol: 20831d922960e083906a586609ac6978678147250177Sebastian Redl return ParsePostfixExpressionSuffix(ParseObjCProtocolExpression(AtLoc)); 20844fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner case tok::objc_selector: 20851d922960e083906a586609ac6978678147250177Sebastian Redl return ParsePostfixExpressionSuffix(ParseObjCSelectorExpression(AtLoc)); 20864fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner default: 20871d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(AtLoc, diag::err_unexpected_at)); 20884fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner } 20895508518a2702b00be3b15a26d772bde968972f54Anders Carlsson } 20905508518a2702b00be3b15a26d772bde968972f54Anders Carlsson} 20915508518a2702b00be3b15a26d772bde968972f54Anders Carlsson 20926aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// \brirg Parse the receiver of an Objective-C++ message send. 20936aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// 20946aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// This routine parses the receiver of a message send in 20956aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// Objective-C++ either as a type or as an expression. Note that this 20966aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// routine must not be called to parse a send to 'super', since it 20976aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// has no way to return such a result. 20986aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// 20996aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// \param IsExpr Whether the receiver was parsed as an expression. 21006aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// 21016aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// \param TypeOrExpr If the receiver was parsed as an expression (\c 21026aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// IsExpr is true), the parsed expression. If the receiver was parsed 21036aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// as a type (\c IsExpr is false), the parsed type. 21046aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// 21056aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// \returns True if an error occurred during parsing or semantic 21066aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// analysis, in which case the arguments do not have valid 21076aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// values. Otherwise, returns false for a successful parse. 21086aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// 21096aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// objc-receiver: [C++] 21106aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// 'super' [not parsed here] 21116aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// expression 21126aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// simple-type-specifier 21136aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// typename-specifier 21146aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregorbool Parser::ParseObjCXXMessageReceiver(bool &IsExpr, void *&TypeOrExpr) { 21150fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor InMessageExpressionRAIIObject InMessage(*this, true); 21160fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor 21176aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor if (Tok.is(tok::identifier) || Tok.is(tok::coloncolon) || 21186aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor Tok.is(tok::kw_typename) || Tok.is(tok::annot_cxxscope)) 21196aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor TryAnnotateTypeOrScopeToken(); 21206aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 21217bf33401acf506b0039222834d7259acb80f6311Kaelyn Uhrain if (!Actions.isSimpleTypeSpecifier(Tok.getKind())) { 21226aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // objc-receiver: 21236aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // expression 212460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Receiver = ParseExpression(); 21256aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor if (Receiver.isInvalid()) 21266aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor return true; 21276aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 21286aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor IsExpr = true; 21296aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor TypeOrExpr = Receiver.take(); 21306aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor return false; 21316aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor } 21326aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 21336aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // objc-receiver: 21346aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // typename-specifier 21356aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // simple-type-specifier 21366aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // expression (that starts with one of the above) 21370b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall DeclSpec DS(AttrFactory); 21386aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor ParseCXXSimpleTypeSpecifier(DS); 21396aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 21406aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor if (Tok.is(tok::l_paren)) { 21416aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // If we see an opening parentheses at this point, we are 21426aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // actually parsing an expression that starts with a 21436aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // function-style cast, e.g., 21446aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // 21456aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // postfix-expression: 21466aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // simple-type-specifier ( expression-list [opt] ) 21476aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // typename-specifier ( expression-list [opt] ) 21486aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // 21496aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // Parse the remainder of this case, then the (optional) 21506aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // postfix-expression suffix, followed by the (optional) 21516aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // right-hand side of the binary expression. We have an 21526aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // instance method. 215360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Receiver = ParseCXXTypeConstructExpression(DS); 21546aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor if (!Receiver.isInvalid()) 21559ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Receiver = ParsePostfixExpressionSuffix(Receiver.take()); 21566aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor if (!Receiver.isInvalid()) 21579ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Receiver = ParseRHSOfBinaryExpression(Receiver.take(), prec::Comma); 21586aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor if (Receiver.isInvalid()) 21596aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor return true; 21606aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 21616aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor IsExpr = true; 21626aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor TypeOrExpr = Receiver.take(); 21636aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor return false; 21646aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor } 21656aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 21666aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // We have a class message. Turn the simple-type-specifier or 21676aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // typename-specifier we parsed into a type and parse the 21686aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // remainder of the class message. 21696aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor Declarator DeclaratorInfo(DS, Declarator::TypeNameContext); 217023c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor TypeResult Type = Actions.ActOnTypeName(getCurScope(), DeclaratorInfo); 21716aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor if (Type.isInvalid()) 21726aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor return true; 21736aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 21746aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor IsExpr = false; 2175b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall TypeOrExpr = Type.get().getAsOpaquePtr(); 21766aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor return false; 21776aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor} 21786aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 21791b730e847ded503f2e615154035c083c4f94a067Douglas Gregor/// \brief Determine whether the parser is currently referring to a an 21801b730e847ded503f2e615154035c083c4f94a067Douglas Gregor/// Objective-C message send, using a simplified heuristic to avoid overhead. 21811b730e847ded503f2e615154035c083c4f94a067Douglas Gregor/// 21821b730e847ded503f2e615154035c083c4f94a067Douglas Gregor/// This routine will only return true for a subset of valid message-send 21831b730e847ded503f2e615154035c083c4f94a067Douglas Gregor/// expressions. 21841b730e847ded503f2e615154035c083c4f94a067Douglas Gregorbool Parser::isSimpleObjCMessageExpression() { 21854e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie assert(Tok.is(tok::l_square) && getLangOpts().ObjC1 && 21861b730e847ded503f2e615154035c083c4f94a067Douglas Gregor "Incorrect start for isSimpleObjCMessageExpression"); 21871b730e847ded503f2e615154035c083c4f94a067Douglas Gregor return GetLookAheadToken(1).is(tok::identifier) && 21881b730e847ded503f2e615154035c083c4f94a067Douglas Gregor GetLookAheadToken(2).is(tok::identifier); 21891b730e847ded503f2e615154035c083c4f94a067Douglas Gregor} 21901b730e847ded503f2e615154035c083c4f94a067Douglas Gregor 21919497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregorbool Parser::isStartOfObjCClassMessageMissingOpenBracket() { 21924e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (!getLangOpts().ObjC1 || !NextToken().is(tok::identifier) || 21939497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor InMessageExpression) 21949497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor return false; 21959497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor 21969497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor 21979497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor ParsedType Type; 21989497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor 21999497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor if (Tok.is(tok::annot_typename)) 22009497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor Type = getTypeAnnotation(Tok); 22019497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor else if (Tok.is(tok::identifier)) 22029497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor Type = Actions.getTypeName(*Tok.getIdentifierInfo(), Tok.getLocation(), 22039497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor getCurScope()); 22049497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor else 22059497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor return false; 22069497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor 22079497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor if (!Type.get().isNull() && Type.get()->isObjCObjectOrInterfaceType()) { 22089497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor const Token &AfterNext = GetLookAheadToken(2); 22099497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor if (AfterNext.is(tok::colon) || AfterNext.is(tok::r_square)) { 22109497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor if (Tok.is(tok::identifier)) 22119497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor TryAnnotateTypeOrScopeToken(); 22129497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor 22139497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor return Tok.is(tok::annot_typename); 22149497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor } 22159497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor } 22169497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor 22179497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor return false; 22189497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor} 22199497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor 22201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// objc-message-expr: 22210ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// '[' objc-receiver objc-message-args ']' 22220ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// 22232725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// objc-receiver: [C] 2224eb483eb3ee80300f15d6d13573d82493c2194461Chris Lattner/// 'super' 22250ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// expression 22260ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// class-name 22270ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// type-name 22286aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// 222960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult Parser::ParseObjCMessageExpression() { 2230699b66138ac307a32e238463e0eff513ff17d337Chris Lattner assert(Tok.is(tok::l_square) && "'[' expected"); 2231699b66138ac307a32e238463e0eff513ff17d337Chris Lattner SourceLocation LBracLoc = ConsumeBracket(); // consume '[' 2232699b66138ac307a32e238463e0eff513ff17d337Chris Lattner 22338e254cfe5a6ab4202c7fcc4b64bdd1ca0fe071acDouglas Gregor if (Tok.is(tok::code_completion)) { 223423c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCMessageReceiver(getCurScope()); 22357d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis cutOffParsing(); 22368e254cfe5a6ab4202c7fcc4b64bdd1ca0fe071acDouglas Gregor return ExprError(); 22378e254cfe5a6ab4202c7fcc4b64bdd1ca0fe071acDouglas Gregor } 22388e254cfe5a6ab4202c7fcc4b64bdd1ca0fe071acDouglas Gregor 22390fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor InMessageExpressionRAIIObject InMessage(*this, true); 22400fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor 22414e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (getLangOpts().CPlusPlus) { 22426aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // We completely separate the C and C++ cases because C++ requires 22436aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // more complicated (read: slower) parsing. 22446aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 22456aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // Handle send to super. 22466aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // FIXME: This doesn't benefit from the same typo-correction we 22476aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // get in Objective-C. 22486aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor if (Tok.is(tok::identifier) && Tok.getIdentifierInfo() == Ident_super && 224923c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor NextToken().isNot(tok::period) && getCurScope()->isInObjcMethodScope()) 2250b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall return ParseObjCMessageExpressionBody(LBracLoc, ConsumeToken(), 2251b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType(), 0); 22526aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 22536aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // Parse the receiver, which is either a type or an expression. 22546aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor bool IsExpr; 2255304b752a450c0fc5968c20ba25446d0bb7c6f68dNick Lewycky void *TypeOrExpr = NULL; 22566aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor if (ParseObjCXXMessageReceiver(IsExpr, TypeOrExpr)) { 22576aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor SkipUntil(tok::r_square); 22586aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor return ExprError(); 22596aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor } 22606aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 22616aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor if (IsExpr) 2262b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(), 2263b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType(), 22649ae2f076ca5ab1feb3ba95629099ec2319833701John McCall static_cast<Expr*>(TypeOrExpr)); 22656aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 22666aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(), 2267b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType::getFromOpaquePtr(TypeOrExpr), 2268b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall 0); 2269c59cb38810c63a806270385f79ea84e0203754eaChris Lattner } 2270c59cb38810c63a806270385f79ea84e0203754eaChris Lattner 2271c59cb38810c63a806270385f79ea84e0203754eaChris Lattner if (Tok.is(tok::identifier)) { 22721dbca6ea983231b4cab1a8f1edda8f6e13c21f12Douglas Gregor IdentifierInfo *Name = Tok.getIdentifierInfo(); 22731dbca6ea983231b4cab1a8f1edda8f6e13c21f12Douglas Gregor SourceLocation NameLoc = Tok.getLocation(); 2274b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ReceiverType; 227523c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor switch (Actions.getObjCMessageKind(getCurScope(), Name, NameLoc, 22761dbca6ea983231b4cab1a8f1edda8f6e13c21f12Douglas Gregor Name == Ident_super, 22771569f95831a8c99e9f664137bf8f40e47ee3d90fDouglas Gregor NextToken().is(tok::period), 22781569f95831a8c99e9f664137bf8f40e47ee3d90fDouglas Gregor ReceiverType)) { 2279f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall case Sema::ObjCSuperMessage: 2280b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall return ParseObjCMessageExpressionBody(LBracLoc, ConsumeToken(), 2281b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType(), 0); 22822725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor 2283f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall case Sema::ObjCClassMessage: 22841569f95831a8c99e9f664137bf8f40e47ee3d90fDouglas Gregor if (!ReceiverType) { 22852725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor SkipUntil(tok::r_square); 22862725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor return ExprError(); 22872725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor } 22882725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor 22891569f95831a8c99e9f664137bf8f40e47ee3d90fDouglas Gregor ConsumeToken(); // the type name 22901569f95831a8c99e9f664137bf8f40e47ee3d90fDouglas Gregor 22911569f95831a8c99e9f664137bf8f40e47ee3d90fDouglas Gregor return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(), 22929ae2f076ca5ab1feb3ba95629099ec2319833701John McCall ReceiverType, 0); 22931dbca6ea983231b4cab1a8f1edda8f6e13c21f12Douglas Gregor 2294f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall case Sema::ObjCInstanceMessage: 22952725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor // Fall through to parse an expression. 22961dbca6ea983231b4cab1a8f1edda8f6e13c21f12Douglas Gregor break; 2297d2869925b5f10e00b13fbf3f41bbb17e4c9adbe0Fariborz Jahanian } 2298699b66138ac307a32e238463e0eff513ff17d337Chris Lattner } 2299eb483eb3ee80300f15d6d13573d82493c2194461Chris Lattner 2300eb483eb3ee80300f15d6d13573d82493c2194461Chris Lattner // Otherwise, an arbitrary expression can be the receiver of a send. 230160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Res(ParseExpression()); 23020e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Res.isInvalid()) { 23035c749428a9938d5e2e9564b1c9b7a9252c30ee27Chris Lattner SkipUntil(tok::r_square); 23041d922960e083906a586609ac6978678147250177Sebastian Redl return move(Res); 2305699b66138ac307a32e238463e0eff513ff17d337Chris Lattner } 23061d922960e083906a586609ac6978678147250177Sebastian Redl 2307b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(), 2308b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType(), Res.take()); 2309699b66138ac307a32e238463e0eff513ff17d337Chris Lattner} 23101d922960e083906a586609ac6978678147250177Sebastian Redl 23112725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// \brief Parse the remainder of an Objective-C message following the 23122725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// '[' objc-receiver. 23132725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// 23142725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// This routine handles sends to super, class messages (sent to a 23152725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// class name), and instance messages (sent to an object), and the 23162725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// target is represented by \p SuperLoc, \p ReceiverType, or \p 23172725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// ReceiverExpr, respectively. Only one of these parameters may have 23182725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// a valid value. 23192725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// 23202725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// \param LBracLoc The location of the opening '['. 23212725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// 23222725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// \param SuperLoc If this is a send to 'super', the location of the 23232725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// 'super' keyword that indicates a send to the superclass. 23242725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// 23252725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// \param ReceiverType If this is a class message, the type of the 23262725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// class we are sending a message to. 23272725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// 23282725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// \param ReceiverExpr If this is an instance message, the expression 23292725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// used to compute the receiver object. 23301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 23310ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-message-args: 23320ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-selector 23330ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-keywordarg-list 23340ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// 23350ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-keywordarg-list: 23360ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-keywordarg 23370ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-keywordarg-list objc-keywordarg 23380ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// 23391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// objc-keywordarg: 23400ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// selector-name[opt] ':' objc-keywordexpr 23410ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// 23420ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-keywordexpr: 23430ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// nonempty-expr-list 23440ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// 23450ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// nonempty-expr-list: 23460ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// assignment-expression 23470ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// nonempty-expr-list , assignment-expression 23481d922960e083906a586609ac6978678147250177Sebastian Redl/// 234960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 2350699b66138ac307a32e238463e0eff513ff17d337Chris LattnerParser::ParseObjCMessageExpressionBody(SourceLocation LBracLoc, 23512725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor SourceLocation SuperLoc, 2352b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ReceiverType, 23531d922960e083906a586609ac6978678147250177Sebastian Redl ExprArg ReceiverExpr) { 23540fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor InMessageExpressionRAIIObject InMessage(*this, true); 23550fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor 2356c4df6d2c05c647a6a5770ba0c749782b6c023a3aSteve Naroff if (Tok.is(tok::code_completion)) { 23572725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor if (SuperLoc.isValid()) 235870c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor Actions.CodeCompleteObjCSuperMessage(getCurScope(), SuperLoc, 0, 0, 235970c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor false); 23602725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor else if (ReceiverType) 236170c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor Actions.CodeCompleteObjCClassMessage(getCurScope(), ReceiverType, 0, 0, 236270c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor false); 2363c4df6d2c05c647a6a5770ba0c749782b6c023a3aSteve Naroff else 23649ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Actions.CodeCompleteObjCInstanceMessage(getCurScope(), ReceiverExpr, 236570c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor 0, 0, false); 23667d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis cutOffParsing(); 23677d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis return ExprError(); 2368c4df6d2c05c647a6a5770ba0c749782b6c023a3aSteve Naroff } 2369d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor 2370a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian // Parse objc-selector 23714b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian SourceLocation Loc; 23722fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner IdentifierInfo *selIdent = ParseObjCSelectorPiece(Loc); 237368d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff 23745f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<IdentifierInfo *, 12> KeyIdents; 2375951376242c076c3f62dd78bf672909fc011991dbArgyrios Kyrtzidis SmallVector<SourceLocation, 12> KeyLocs; 2376a55e52c0802cae3b7c366a05c461d3d15074c1a3Sebastian Redl ExprVector KeyExprs(Actions); 237768d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff 2378df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::colon)) { 2379a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian while (1) { 2380a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian // Each iteration parses a single keyword argument. 238168d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff KeyIdents.push_back(selIdent); 2382951376242c076c3f62dd78bf672909fc011991dbArgyrios Kyrtzidis KeyLocs.push_back(Loc); 238337387c932855c6d58d70bdd705cd3a9fdcd2a931Steve Naroff 2384df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::colon)) { 2385a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian Diag(Tok, diag::err_expected_colon); 23864fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // We must manually skip to a ']', otherwise the expression skipper will 23874fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // stop at the ']' when it skips to the ';'. We want it to skip beyond 23884fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // the enclosing expression. 23894fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner SkipUntil(tok::r_square); 23901d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(); 2391a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian } 23921d922960e083906a586609ac6978678147250177Sebastian Redl 239368d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff ConsumeToken(); // Eat the ':'. 23941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// Parse the expression after ':' 239570c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor 239670c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor if (Tok.is(tok::code_completion)) { 239770c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor if (SuperLoc.isValid()) 239870c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor Actions.CodeCompleteObjCSuperMessage(getCurScope(), SuperLoc, 239970c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor KeyIdents.data(), 240070c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor KeyIdents.size(), 240170c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor /*AtArgumentEpression=*/true); 240270c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor else if (ReceiverType) 240370c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor Actions.CodeCompleteObjCClassMessage(getCurScope(), ReceiverType, 240470c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor KeyIdents.data(), 240570c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor KeyIdents.size(), 240670c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor /*AtArgumentEpression=*/true); 240770c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor else 240870c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor Actions.CodeCompleteObjCInstanceMessage(getCurScope(), ReceiverExpr, 240970c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor KeyIdents.data(), 241070c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor KeyIdents.size(), 241170c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor /*AtArgumentEpression=*/true); 241270c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor 24137d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis cutOffParsing(); 241470c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor return ExprError(); 241570c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor } 241670c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor 241760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Res(ParseAssignmentExpression()); 24180e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Res.isInvalid()) { 24194fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // We must manually skip to a ']', otherwise the expression skipper will 24204fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // stop at the ']' when it skips to the ';'. We want it to skip beyond 24214fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // the enclosing expression. 24224fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner SkipUntil(tok::r_square); 24231d922960e083906a586609ac6978678147250177Sebastian Redl return move(Res); 242437387c932855c6d58d70bdd705cd3a9fdcd2a931Steve Naroff } 24251d922960e083906a586609ac6978678147250177Sebastian Redl 242637387c932855c6d58d70bdd705cd3a9fdcd2a931Steve Naroff // We have a valid expression. 2427effa8d1c97b00a3f53e972b0e61d9aade5ea1c57Sebastian Redl KeyExprs.push_back(Res.release()); 24281d922960e083906a586609ac6978678147250177Sebastian Redl 2429d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor // Code completion after each argument. 2430d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor if (Tok.is(tok::code_completion)) { 24312725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor if (SuperLoc.isValid()) 243223c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCSuperMessage(getCurScope(), SuperLoc, 24332725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor KeyIdents.data(), 243470c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor KeyIdents.size(), 243570c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor /*AtArgumentEpression=*/false); 24362725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor else if (ReceiverType) 243723c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCClassMessage(getCurScope(), ReceiverType, 2438d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor KeyIdents.data(), 243970c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor KeyIdents.size(), 244070c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor /*AtArgumentEpression=*/false); 2441d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor else 24429ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Actions.CodeCompleteObjCInstanceMessage(getCurScope(), ReceiverExpr, 2443d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor KeyIdents.data(), 244470c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor KeyIdents.size(), 244570c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor /*AtArgumentEpression=*/false); 24467d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis cutOffParsing(); 244770c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor return ExprError(); 2448d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor } 2449d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor 245037387c932855c6d58d70bdd705cd3a9fdcd2a931Steve Naroff // Check for another keyword selector. 24512fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner selIdent = ParseObjCSelectorPiece(Loc); 2452df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (!selIdent && Tok.isNot(tok::colon)) 2453a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian break; 2454a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian // We have a selector or a colon, continue parsing. 2455a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian } 2456a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian // Parse the, optional, argument list, comma separated. 2457df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner while (Tok.is(tok::comma)) { 245818df0eba838c7609d10edcb845ca6f35698e822cFariborz Jahanian SourceLocation commaLoc = ConsumeToken(); // Eat the ','. 24591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// Parse the expression after ',' 246060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Res(ParseAssignmentExpression()); 24610e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Res.isInvalid()) { 246218df0eba838c7609d10edcb845ca6f35698e822cFariborz Jahanian if (Tok.is(tok::colon)) { 246318df0eba838c7609d10edcb845ca6f35698e822cFariborz Jahanian Diag(commaLoc, diag::note_extra_comma_message_arg) << 246418df0eba838c7609d10edcb845ca6f35698e822cFariborz Jahanian FixItHint::CreateRemoval(commaLoc); 246518df0eba838c7609d10edcb845ca6f35698e822cFariborz Jahanian } 24664fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // We must manually skip to a ']', otherwise the expression skipper will 24674fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // stop at the ']' when it skips to the ';'. We want it to skip beyond 24684fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // the enclosing expression. 24694fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner SkipUntil(tok::r_square); 24701d922960e083906a586609ac6978678147250177Sebastian Redl return move(Res); 247149f109c786f99eb7468dac3976db083a65493444Steve Naroff } 24720e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl 247349f109c786f99eb7468dac3976db083a65493444Steve Naroff // We have a valid expression. 2474effa8d1c97b00a3f53e972b0e61d9aade5ea1c57Sebastian Redl KeyExprs.push_back(Res.release()); 2475a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian } 2476a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian } else if (!selIdent) { 2477a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian Diag(Tok, diag::err_expected_ident); // missing selector name. 24781d922960e083906a586609ac6978678147250177Sebastian Redl 24794fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // We must manually skip to a ']', otherwise the expression skipper will 24804fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // stop at the ']' when it skips to the ';'. We want it to skip beyond 24814fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // the enclosing expression. 24824fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner SkipUntil(tok::r_square); 24831d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(); 2484a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian } 2485809872eca7f6c024e2ab41ddffbbeeae807bf5dcFariborz Jahanian 2486df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::r_square)) { 2487809872eca7f6c024e2ab41ddffbbeeae807bf5dcFariborz Jahanian if (Tok.is(tok::identifier)) 2488809872eca7f6c024e2ab41ddffbbeeae807bf5dcFariborz Jahanian Diag(Tok, diag::err_expected_colon); 2489809872eca7f6c024e2ab41ddffbbeeae807bf5dcFariborz Jahanian else 2490809872eca7f6c024e2ab41ddffbbeeae807bf5dcFariborz Jahanian Diag(Tok, diag::err_expected_rsquare); 24914fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // We must manually skip to a ']', otherwise the expression skipper will 24924fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // stop at the ']' when it skips to the ';'. We want it to skip beyond 24934fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // the enclosing expression. 24944fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner SkipUntil(tok::r_square); 24951d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(); 2496a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian } 24971d922960e083906a586609ac6978678147250177Sebastian Redl 2498699b66138ac307a32e238463e0eff513ff17d337Chris Lattner SourceLocation RBracLoc = ConsumeBracket(); // consume ']' 24991d922960e083906a586609ac6978678147250177Sebastian Redl 250029238a0bf7cbf5b396efb451a0adb5fe4aa037caSteve Naroff unsigned nKeys = KeyIdents.size(); 2501951376242c076c3f62dd78bf672909fc011991dbArgyrios Kyrtzidis if (nKeys == 0) { 2502ff38491c18b060526d754765b952f4a497a89416Chris Lattner KeyIdents.push_back(selIdent); 2503951376242c076c3f62dd78bf672909fc011991dbArgyrios Kyrtzidis KeyLocs.push_back(Loc); 2504951376242c076c3f62dd78bf672909fc011991dbArgyrios Kyrtzidis } 2505ff38491c18b060526d754765b952f4a497a89416Chris Lattner Selector Sel = PP.getSelectorTable().getSelector(nKeys, &KeyIdents[0]); 25061d922960e083906a586609ac6978678147250177Sebastian Redl 25072725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor if (SuperLoc.isValid()) 250823c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor return Actions.ActOnSuperMessage(getCurScope(), SuperLoc, Sel, 2509951376242c076c3f62dd78bf672909fc011991dbArgyrios Kyrtzidis LBracLoc, KeyLocs, RBracLoc, 2510f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall MultiExprArg(Actions, 2511f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall KeyExprs.take(), 2512f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall KeyExprs.size())); 25132725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor else if (ReceiverType) 251423c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor return Actions.ActOnClassMessage(getCurScope(), ReceiverType, Sel, 2515951376242c076c3f62dd78bf672909fc011991dbArgyrios Kyrtzidis LBracLoc, KeyLocs, RBracLoc, 2516f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall MultiExprArg(Actions, 2517f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall KeyExprs.take(), 2518f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall KeyExprs.size())); 25199ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return Actions.ActOnInstanceMessage(getCurScope(), ReceiverExpr, Sel, 2520951376242c076c3f62dd78bf672909fc011991dbArgyrios Kyrtzidis LBracLoc, KeyLocs, RBracLoc, 2521f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall MultiExprArg(Actions, 2522f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall KeyExprs.take(), 2523f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall KeyExprs.size())); 25240ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian} 25250ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian 252660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult Parser::ParseObjCStringLiteral(SourceLocation AtLoc) { 252760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Res(ParseStringLiteralExpression()); 25281d922960e083906a586609ac6978678147250177Sebastian Redl if (Res.isInvalid()) return move(Res); 25291d922960e083906a586609ac6978678147250177Sebastian Redl 2530b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner // @"foo" @"bar" is a valid concatenated string. Eat any subsequent string 2531b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner // expressions. At this point, we know that the only valid thing that starts 2532b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner // with '@' is an @"". 25335f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<SourceLocation, 4> AtLocs; 2534a55e52c0802cae3b7c366a05c461d3d15074c1a3Sebastian Redl ExprVector AtStrings(Actions); 2535b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner AtLocs.push_back(AtLoc); 2536effa8d1c97b00a3f53e972b0e61d9aade5ea1c57Sebastian Redl AtStrings.push_back(Res.release()); 25370e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl 2538b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner while (Tok.is(tok::at)) { 2539b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner AtLocs.push_back(ConsumeToken()); // eat the @. 2540b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner 254115faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl // Invalid unless there is a string literal. 254297cf6eb380016db868866faf27a086cd55a316d4Chris Lattner if (!isTokenStringLiteral()) 254397cf6eb380016db868866faf27a086cd55a316d4Chris Lattner return ExprError(Diag(Tok, diag::err_objc_concat_string)); 2544b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner 254560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Lit(ParseStringLiteralExpression()); 25460e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Lit.isInvalid()) 25471d922960e083906a586609ac6978678147250177Sebastian Redl return move(Lit); 25480e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl 2549effa8d1c97b00a3f53e972b0e61d9aade5ea1c57Sebastian Redl AtStrings.push_back(Lit.release()); 2550b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner } 25511d922960e083906a586609ac6978678147250177Sebastian Redl 25521d922960e083906a586609ac6978678147250177Sebastian Redl return Owned(Actions.ParseObjCStringLiteral(&AtLocs[0], AtStrings.take(), 25531d922960e083906a586609ac6978678147250177Sebastian Redl AtStrings.size())); 25545508518a2702b00be3b15a26d772bde968972f54Anders Carlsson} 2555f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson 2556ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek/// ParseObjCBooleanLiteral - 2557ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek/// objc-scalar-literal : '@' boolean-keyword 2558ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek/// ; 2559ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek/// boolean-keyword: 'true' | 'false' | '__objc_yes' | '__objc_no' 2560ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek/// ; 2561ebcb57a8d298862c65043e88b2429591ab3c58d3Ted KremenekExprResult Parser::ParseObjCBooleanLiteral(SourceLocation AtLoc, 2562ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek bool ArgValue) { 2563ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SourceLocation EndLoc = ConsumeToken(); // consume the keyword. 2564ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return Actions.ActOnObjCBoolLiteral(AtLoc, EndLoc, ArgValue); 2565ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek} 2566ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 2567ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek/// ParseObjCCharacterLiteral - 2568ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek/// objc-scalar-literal : '@' character-literal 2569ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek/// ; 2570ebcb57a8d298862c65043e88b2429591ab3c58d3Ted KremenekExprResult Parser::ParseObjCCharacterLiteral(SourceLocation AtLoc) { 2571ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExprResult Lit(Actions.ActOnCharacterConstant(Tok)); 2572ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (Lit.isInvalid()) { 2573ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return move(Lit); 2574ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 25758b8d9534f185743fb72c59d4e735794e6e0f4335Benjamin Kramer ConsumeToken(); // Consume the literal token. 2576ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return Owned(Actions.BuildObjCNumericLiteral(AtLoc, Lit.take())); 2577ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek} 2578ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 2579ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek/// ParseObjCNumericLiteral - 2580ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek/// objc-scalar-literal : '@' scalar-literal 2581ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek/// ; 2582ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek/// scalar-literal : | numeric-constant /* any numeric constant. */ 2583ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek/// ; 2584ebcb57a8d298862c65043e88b2429591ab3c58d3Ted KremenekExprResult Parser::ParseObjCNumericLiteral(SourceLocation AtLoc) { 2585ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExprResult Lit(Actions.ActOnNumericConstant(Tok)); 2586ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (Lit.isInvalid()) { 2587ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return move(Lit); 2588ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 25898b8d9534f185743fb72c59d4e735794e6e0f4335Benjamin Kramer ConsumeToken(); // Consume the literal token. 2590ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return Owned(Actions.BuildObjCNumericLiteral(AtLoc, Lit.take())); 2591ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek} 2592ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 2593eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard/// ParseObjCBoxedExpr - 2594eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard/// objc-box-expression: 2595eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard/// @( assignment-expression ) 2596eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick BeardExprResult 2597eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick BeardParser::ParseObjCBoxedExpr(SourceLocation AtLoc) { 2598eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard if (Tok.isNot(tok::l_paren)) 2599eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard return ExprError(Diag(Tok, diag::err_expected_lparen_after) << "@"); 2600eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard 2601eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard BalancedDelimiterTracker T(*this, tok::l_paren); 2602eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard T.consumeOpen(); 2603eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard ExprResult ValueExpr(ParseAssignmentExpression()); 2604eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard if (T.consumeClose()) 2605eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard return ExprError(); 2606edd27602f9cede4fee2c81c785b8f295c9d28752Argyrios Kyrtzidis 2607edd27602f9cede4fee2c81c785b8f295c9d28752Argyrios Kyrtzidis if (ValueExpr.isInvalid()) 2608edd27602f9cede4fee2c81c785b8f295c9d28752Argyrios Kyrtzidis return ExprError(); 2609edd27602f9cede4fee2c81c785b8f295c9d28752Argyrios Kyrtzidis 2610eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard // Wrap the sub-expression in a parenthesized expression, to distinguish 2611eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard // a boxed expression from a literal. 2612eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard SourceLocation LPLoc = T.getOpenLocation(), RPLoc = T.getCloseLocation(); 2613eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard ValueExpr = Actions.ActOnParenExpr(LPLoc, RPLoc, ValueExpr.take()); 2614eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard return Owned(Actions.BuildObjCBoxedExpr(SourceRange(AtLoc, RPLoc), 2615eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard ValueExpr.take())); 2616eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard} 2617eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard 2618ebcb57a8d298862c65043e88b2429591ab3c58d3Ted KremenekExprResult Parser::ParseObjCArrayLiteral(SourceLocation AtLoc) { 2619ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExprVector ElementExprs(Actions); // array elements. 2620ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ConsumeBracket(); // consume the l_square. 2621ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 2622ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek while (Tok.isNot(tok::r_square)) { 2623ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // Parse list of array element expressions (all must be id types). 2624ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExprResult Res(ParseAssignmentExpression()); 2625ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (Res.isInvalid()) { 2626ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // We must manually skip to a ']', otherwise the expression skipper will 2627ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // stop at the ']' when it skips to the ';'. We want it to skip beyond 2628ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // the enclosing expression. 2629ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SkipUntil(tok::r_square); 2630ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return move(Res); 2631ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 2632ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 2633ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // Parse the ellipsis that indicates a pack expansion. 2634ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (Tok.is(tok::ellipsis)) 2635ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Res = Actions.ActOnPackExpansion(Res.get(), ConsumeToken()); 2636ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (Res.isInvalid()) 2637ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return true; 2638ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 2639ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ElementExprs.push_back(Res.release()); 2640ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 2641ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (Tok.is(tok::comma)) 2642ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ConsumeToken(); // Eat the ','. 2643ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek else if (Tok.isNot(tok::r_square)) 2644ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return ExprError(Diag(Tok, diag::err_expected_rsquare_or_comma)); 2645ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 2646ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SourceLocation EndLoc = ConsumeBracket(); // location of ']' 2647ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek MultiExprArg Args(Actions, ElementExprs.take(), ElementExprs.size()); 2648ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return Owned(Actions.BuildObjCArrayLiteral(SourceRange(AtLoc, EndLoc), Args)); 2649ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek} 2650ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 2651ebcb57a8d298862c65043e88b2429591ab3c58d3Ted KremenekExprResult Parser::ParseObjCDictionaryLiteral(SourceLocation AtLoc) { 2652ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SmallVector<ObjCDictionaryElement, 4> Elements; // dictionary elements. 2653ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ConsumeBrace(); // consume the l_square. 2654ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek while (Tok.isNot(tok::r_brace)) { 2655ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // Parse the comma separated key : value expressions. 2656ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExprResult KeyExpr; 2657ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek { 2658ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ColonProtectionRAIIObject X(*this); 2659ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek KeyExpr = ParseAssignmentExpression(); 2660ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (KeyExpr.isInvalid()) { 2661ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // We must manually skip to a '}', otherwise the expression skipper will 2662ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // stop at the '}' when it skips to the ';'. We want it to skip beyond 2663ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // the enclosing expression. 2664ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SkipUntil(tok::r_brace); 2665ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return move(KeyExpr); 2666ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 2667ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 2668ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 2669ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (Tok.is(tok::colon)) { 2670ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ConsumeToken(); 2671ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } else { 2672ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return ExprError(Diag(Tok, diag::err_expected_colon)); 2673ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 2674ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 2675ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExprResult ValueExpr(ParseAssignmentExpression()); 2676ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (ValueExpr.isInvalid()) { 2677ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // We must manually skip to a '}', otherwise the expression skipper will 2678ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // stop at the '}' when it skips to the ';'. We want it to skip beyond 2679ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // the enclosing expression. 2680ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SkipUntil(tok::r_brace); 2681ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return move(ValueExpr); 2682ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 2683ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 2684ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // Parse the ellipsis that designates this as a pack expansion. 2685ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SourceLocation EllipsisLoc; 26864e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (Tok.is(tok::ellipsis) && getLangOpts().CPlusPlus) 2687ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek EllipsisLoc = ConsumeToken(); 2688ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 2689ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // We have a valid expression. Collect it in a vector so we can 2690ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // build the argument list. 2691ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ObjCDictionaryElement Element = { 2692ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek KeyExpr.get(), ValueExpr.get(), EllipsisLoc, llvm::Optional<unsigned>() 2693ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek }; 2694ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Elements.push_back(Element); 2695ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 2696ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (Tok.is(tok::comma)) 2697ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ConsumeToken(); // Eat the ','. 2698ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek else if (Tok.isNot(tok::r_brace)) 2699ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return ExprError(Diag(Tok, diag::err_expected_rbrace_or_comma)); 2700ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 2701ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SourceLocation EndLoc = ConsumeBrace(); 2702ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 2703ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // Create the ObjCDictionaryLiteral. 2704ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return Owned(Actions.BuildObjCDictionaryLiteral(SourceRange(AtLoc, EndLoc), 2705ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Elements.data(), 2706ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Elements.size())); 2707ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek} 2708ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 2709f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson/// objc-encode-expression: 2710f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson/// @encode ( type-name ) 271160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 27121d922960e083906a586609ac6978678147250177Sebastian RedlParser::ParseObjCEncodeExpression(SourceLocation AtLoc) { 2713861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff assert(Tok.isObjCAtKeyword(tok::objc_encode) && "Not an @encode expression!"); 27141d922960e083906a586609ac6978678147250177Sebastian Redl 2715f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson SourceLocation EncLoc = ConsumeToken(); 27161d922960e083906a586609ac6978678147250177Sebastian Redl 27174fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner if (Tok.isNot(tok::l_paren)) 27181d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(Tok, diag::err_expected_lparen_after) << "@encode"); 27191d922960e083906a586609ac6978678147250177Sebastian Redl 27204a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor BalancedDelimiterTracker T(*this, tok::l_paren); 27214a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor T.consumeOpen(); 27221d922960e083906a586609ac6978678147250177Sebastian Redl 2723809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor TypeResult Ty = ParseTypeName(); 27241d922960e083906a586609ac6978678147250177Sebastian Redl 27254a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor T.consumeClose(); 27261d922960e083906a586609ac6978678147250177Sebastian Redl 2727809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor if (Ty.isInvalid()) 2728809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor return ExprError(); 2729809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor 27304a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor return Owned(Actions.ParseObjCEncodeExpression(AtLoc, EncLoc, 27314a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor T.getOpenLocation(), Ty.get(), 27324a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor T.getCloseLocation())); 2733f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson} 273429b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson 273529b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson/// objc-protocol-expression 273617d26a6c1f2cb921d0000c337b4967699dc928fdJames Dennett/// \@protocol ( protocol-name ) 273760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 27381d922960e083906a586609ac6978678147250177Sebastian RedlParser::ParseObjCProtocolExpression(SourceLocation AtLoc) { 273929b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson SourceLocation ProtoLoc = ConsumeToken(); 27401d922960e083906a586609ac6978678147250177Sebastian Redl 27414fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner if (Tok.isNot(tok::l_paren)) 27421d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(Tok, diag::err_expected_lparen_after) << "@protocol"); 27431d922960e083906a586609ac6978678147250177Sebastian Redl 27444a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor BalancedDelimiterTracker T(*this, tok::l_paren); 27454a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor T.consumeOpen(); 27461d922960e083906a586609ac6978678147250177Sebastian Redl 27474fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner if (Tok.isNot(tok::identifier)) 27481d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(Tok, diag::err_expected_ident)); 27491d922960e083906a586609ac6978678147250177Sebastian Redl 2750390d50a725497e99247dc104a7d2c2a255d3af14Fariborz Jahanian IdentifierInfo *protocolId = Tok.getIdentifierInfo(); 27517d24e289bea2accaaed79c6ca3e5cdd0c204ddc1Argyrios Kyrtzidis SourceLocation ProtoIdLoc = ConsumeToken(); 27521d922960e083906a586609ac6978678147250177Sebastian Redl 27534a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor T.consumeClose(); 275429b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson 27551d922960e083906a586609ac6978678147250177Sebastian Redl return Owned(Actions.ParseObjCProtocolExpression(protocolId, AtLoc, ProtoLoc, 27564a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor T.getOpenLocation(), 27577d24e289bea2accaaed79c6ca3e5cdd0c204ddc1Argyrios Kyrtzidis ProtoIdLoc, 27584a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor T.getCloseLocation())); 275929b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson} 2760a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian 2761a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian/// objc-selector-expression 2762a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian/// @selector '(' objc-keyword-selector ')' 276360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult Parser::ParseObjCSelectorExpression(SourceLocation AtLoc) { 2764a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian SourceLocation SelectorLoc = ConsumeToken(); 27651d922960e083906a586609ac6978678147250177Sebastian Redl 27664fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner if (Tok.isNot(tok::l_paren)) 27671d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(Tok, diag::err_expected_lparen_after) << "@selector"); 27681d922960e083906a586609ac6978678147250177Sebastian Redl 27695f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<IdentifierInfo *, 12> KeyIdents; 2770a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian SourceLocation sLoc; 2771458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor 27724a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor BalancedDelimiterTracker T(*this, tok::l_paren); 27734a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor T.consumeOpen(); 27744a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor 2775458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor if (Tok.is(tok::code_completion)) { 2776458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor Actions.CodeCompleteObjCSelector(getCurScope(), KeyIdents.data(), 2777458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor KeyIdents.size()); 27787d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis cutOffParsing(); 2779458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor return ExprError(); 2780458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor } 2781458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor 27822fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner IdentifierInfo *SelIdent = ParseObjCSelectorPiece(sLoc); 27835add7541726348b9d1c8e96ac5031b87c41acff0Chris Lattner if (!SelIdent && // missing selector name. 27845add7541726348b9d1c8e96ac5031b87c41acff0Chris Lattner Tok.isNot(tok::colon) && Tok.isNot(tok::coloncolon)) 27851d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(Tok, diag::err_expected_ident)); 27861d922960e083906a586609ac6978678147250177Sebastian Redl 2787b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian KeyIdents.push_back(SelIdent); 2788887407e71fd58de452361b77d72970e32b20ebe0Steve Naroff unsigned nColons = 0; 2789887407e71fd58de452361b77d72970e32b20ebe0Steve Naroff if (Tok.isNot(tok::r_paren)) { 2790a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian while (1) { 27915add7541726348b9d1c8e96ac5031b87c41acff0Chris Lattner if (Tok.is(tok::coloncolon)) { // Handle :: in C++. 27925add7541726348b9d1c8e96ac5031b87c41acff0Chris Lattner ++nColons; 27935add7541726348b9d1c8e96ac5031b87c41acff0Chris Lattner KeyIdents.push_back(0); 27945add7541726348b9d1c8e96ac5031b87c41acff0Chris Lattner } else if (Tok.isNot(tok::colon)) 27951d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(Tok, diag::err_expected_colon)); 27961d922960e083906a586609ac6978678147250177Sebastian Redl 27975add7541726348b9d1c8e96ac5031b87c41acff0Chris Lattner ++nColons; 27983b3e1a9e79703da067d23756e5624a4f487d6278Chris Lattner ConsumeToken(); // Eat the ':' or '::'. 2799a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian if (Tok.is(tok::r_paren)) 2800a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian break; 2801458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor 2802458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor if (Tok.is(tok::code_completion)) { 2803458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor Actions.CodeCompleteObjCSelector(getCurScope(), KeyIdents.data(), 2804458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor KeyIdents.size()); 28057d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis cutOffParsing(); 2806458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor return ExprError(); 2807458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor } 2808458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor 2809a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian // Check for another keyword selector. 2810a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian SourceLocation Loc; 28112fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner SelIdent = ParseObjCSelectorPiece(Loc); 2812b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian KeyIdents.push_back(SelIdent); 28133b3e1a9e79703da067d23756e5624a4f487d6278Chris Lattner if (!SelIdent && Tok.isNot(tok::colon) && Tok.isNot(tok::coloncolon)) 2814a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian break; 2815a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian } 2816887407e71fd58de452361b77d72970e32b20ebe0Steve Naroff } 28174a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor T.consumeClose(); 2818887407e71fd58de452361b77d72970e32b20ebe0Steve Naroff Selector Sel = PP.getSelectorTable().getSelector(nColons, &KeyIdents[0]); 28191d922960e083906a586609ac6978678147250177Sebastian Redl return Owned(Actions.ParseObjCSelectorExpression(Sel, AtLoc, SelectorLoc, 28204a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor T.getOpenLocation(), 28214a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor T.getCloseLocation())); 282258065b2d8038a4e9a91ea4813bd1774c0f6efacbGabor Greif } 2823140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian 2824140ab234c23f392d5422691c5de1ee3c15026defFariborz JahanianDecl *Parser::ParseLexedObjCMethodDefs(LexedMethod &LM) { 2825a24195aaf71cee202f92ea4bad50358f3d0b701fArgyrios Kyrtzidis 2826a24195aaf71cee202f92ea4bad50358f3d0b701fArgyrios Kyrtzidis // Save the current token position. 2827a24195aaf71cee202f92ea4bad50358f3d0b701fArgyrios Kyrtzidis SourceLocation OrigLoc = Tok.getLocation(); 2828a24195aaf71cee202f92ea4bad50358f3d0b701fArgyrios Kyrtzidis 2829140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian assert(!LM.Toks.empty() && "ParseLexedObjCMethodDef - Empty body!"); 2830140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian // Append the current token at the end of the new token stream so that it 2831140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian // doesn't get lost. 2832140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian LM.Toks.push_back(Tok); 2833140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian PP.EnterTokenStream(LM.Toks.data(), LM.Toks.size(), true, false); 2834140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian 2835140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian // MDecl might be null due to error in method prototype, etc. 2836140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian Decl *MDecl = LM.D; 2837140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian // Consume the previously pushed token. 2838140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian ConsumeAnyToken(); 2839140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian 2840140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian assert(Tok.is(tok::l_brace) && "Inline objective-c method not starting with '{'"); 2841140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian SourceLocation BraceLoc = Tok.getLocation(); 2842140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian // Enter a scope for the method body. 2843140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian ParseScope BodyScope(this, 2844140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian Scope::ObjCMethodScope|Scope::FnScope|Scope::DeclScope); 2845140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian 2846140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian // Tell the actions module that we have entered a method definition with the 2847140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian // specified Declarator for the method. 2848140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian Actions.ActOnStartOfObjCMethodDef(getCurScope(), MDecl); 2849140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian 28506a91d385618ea4d28236c496f540a26877c95525Erik Verbruggen if (SkipFunctionBodies && trySkippingFunctionBody()) { 28516a91d385618ea4d28236c496f540a26877c95525Erik Verbruggen BodyScope.Exit(); 28526a91d385618ea4d28236c496f540a26877c95525Erik Verbruggen return Actions.ActOnFinishFunctionBody(MDecl, 0); 2853140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian } 2854140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian 2855140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian StmtResult FnBody(ParseCompoundStatementBody()); 2856140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian 2857140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian // If the function body could not be parsed, make a bogus compoundstmt. 2858625bb569df0c34feec0d52c0ec5215f21ef2e054Dmitri Gribenko if (FnBody.isInvalid()) { 2859625bb569df0c34feec0d52c0ec5215f21ef2e054Dmitri Gribenko Sema::CompoundScopeRAII CompoundScope(Actions); 2860140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian FnBody = Actions.ActOnCompoundStmt(BraceLoc, BraceLoc, 2861140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian MultiStmtArg(Actions), false); 2862625bb569df0c34feec0d52c0ec5215f21ef2e054Dmitri Gribenko } 2863140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian 2864140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian // Leave the function body scope. 2865140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian BodyScope.Exit(); 2866140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian 2867a24195aaf71cee202f92ea4bad50358f3d0b701fArgyrios Kyrtzidis MDecl = Actions.ActOnFinishFunctionBody(MDecl, FnBody.take()); 2868a24195aaf71cee202f92ea4bad50358f3d0b701fArgyrios Kyrtzidis 2869a24195aaf71cee202f92ea4bad50358f3d0b701fArgyrios Kyrtzidis if (Tok.getLocation() != OrigLoc) { 2870a24195aaf71cee202f92ea4bad50358f3d0b701fArgyrios Kyrtzidis // Due to parsing error, we either went over the cached tokens or 2871a24195aaf71cee202f92ea4bad50358f3d0b701fArgyrios Kyrtzidis // there are still cached tokens left. If it's the latter case skip the 2872a24195aaf71cee202f92ea4bad50358f3d0b701fArgyrios Kyrtzidis // leftover tokens. 2873a24195aaf71cee202f92ea4bad50358f3d0b701fArgyrios Kyrtzidis // Since this is an uncommon situation that should be avoided, use the 2874a24195aaf71cee202f92ea4bad50358f3d0b701fArgyrios Kyrtzidis // expensive isBeforeInTranslationUnit call. 2875a24195aaf71cee202f92ea4bad50358f3d0b701fArgyrios Kyrtzidis if (PP.getSourceManager().isBeforeInTranslationUnit(Tok.getLocation(), 2876a24195aaf71cee202f92ea4bad50358f3d0b701fArgyrios Kyrtzidis OrigLoc)) 2877a24195aaf71cee202f92ea4bad50358f3d0b701fArgyrios Kyrtzidis while (Tok.getLocation() != OrigLoc && Tok.isNot(tok::eof)) 2878a24195aaf71cee202f92ea4bad50358f3d0b701fArgyrios Kyrtzidis ConsumeAnyToken(); 2879a24195aaf71cee202f92ea4bad50358f3d0b701fArgyrios Kyrtzidis } 2880a24195aaf71cee202f92ea4bad50358f3d0b701fArgyrios Kyrtzidis 2881a24195aaf71cee202f92ea4bad50358f3d0b701fArgyrios Kyrtzidis return MDecl; 2882140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian} 2883