ParseObjc.cpp revision f85e193739c953358c865005855253af4f68a497
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' 32d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseObjCAtDirectives() { 335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation AtLoc = ConsumeToken(); // the "@" 341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 35c464ae8444edb6d07ea49b7a0eae1674c0fa1bb8Douglas Gregor if (Tok.is(tok::code_completion)) { 3623c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCAtDirective(getCurScope(), ObjCImpDecl, false); 37dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 38c464ae8444edb6d07ea49b7a0eae1674c0fa1bb8Douglas Gregor } 39c464ae8444edb6d07ea49b7a0eae1674c0fa1bb8Douglas Gregor 40861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff switch (Tok.getObjCKeywordID()) { 415ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner case tok::objc_class: 425ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner return ParseObjCAtClassDeclaration(AtLoc); 437f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall case tok::objc_interface: { 440b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall ParsedAttributes attrs(AttrFactory); 457f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall return ParseObjCAtInterfaceDeclaration(AtLoc, attrs); 467f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall } 477f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall case tok::objc_protocol: { 480b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall ParsedAttributes attrs(AttrFactory); 497f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall return ParseObjCAtProtocolDeclaration(AtLoc, attrs); 507f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall } 515ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner case tok::objc_implementation: 525ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner return ParseObjCAtImplementationDeclaration(AtLoc); 535ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner case tok::objc_end: 545ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner return ParseObjCAtEndDeclaration(AtLoc); 555ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner case tok::objc_compatibility_alias: 565ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner return ParseObjCAtAliasDeclaration(AtLoc); 575ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner case tok::objc_synthesize: 585ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner return ParseObjCPropertySynthesize(AtLoc); 595ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner case tok::objc_dynamic: 605ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner return ParseObjCPropertyDynamic(AtLoc); 615ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner default: 625ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner Diag(AtLoc, diag::err_unexpected_at); 635ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner SkipUntil(tok::semi); 64d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// objc-class-declaration: 705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// '@' 'class' identifier-list ';' 711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 72d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseObjCAtClassDeclaration(SourceLocation atLoc) { 735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ConsumeToken(); // the identifier "class" 745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::SmallVector<IdentifierInfo *, 8> ClassNames; 75c09cba67d0ad01e53e0fed07322e95dd281bcfd9Ted Kremenek llvm::SmallVector<SourceLocation, 8> ClassLocs; 76c09cba67d0ad01e53e0fed07322e95dd281bcfd9Ted Kremenek 771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer while (1) { 79df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Diag(Tok, diag::err_expected_ident); 815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SkipUntil(tok::semi); 82d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ClassNames.push_back(Tok.getIdentifierInfo()); 85c09cba67d0ad01e53e0fed07322e95dd281bcfd9Ted Kremenek ClassLocs.push_back(Tok.getLocation()); 865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ConsumeToken(); 871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 88df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::comma)) 895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer break; 901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ConsumeToken(); 925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Consume the ';'. 955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@class")) 96d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 98c09cba67d0ad01e53e0fed07322e95dd281bcfd9Ted Kremenek return Actions.ActOnForwardClassDeclaration(atLoc, ClassNames.data(), 99c09cba67d0ad01e53e0fed07322e95dd281bcfd9Ted Kremenek ClassLocs.data(), 100c09cba67d0ad01e53e0fed07322e95dd281bcfd9Ted Kremenek ClassNames.size()); 1015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 1025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 103dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 104dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-interface: 105dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-interface-attributes[opt] objc-class-interface 106dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-category-interface 107dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 108dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-interface: 1091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// '@' 'interface' identifier objc-superclass[opt] 110dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-refs[opt] 1111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// objc-class-instance-variables[opt] 112dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-interface-decl-list 113dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @end 114dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 115dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-category-interface: 1161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// '@' 'interface' identifier '(' identifier[opt] ')' 117dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-refs[opt] 118dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-interface-decl-list 119dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @end 120dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 121dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-superclass: 122dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// ':' identifier 123dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 124dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-interface-attributes: 125dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// __attribute__((visibility("default"))) 126dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// __attribute__((visibility("hidden"))) 127dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// __attribute__((deprecated)) 128dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// __attribute__((unavailable)) 129dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// __attribute__((objc_exception)) - used by NSException on 64-bit 130dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1317f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCallDecl *Parser::ParseObjCAtInterfaceDeclaration(SourceLocation atLoc, 1327f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall ParsedAttributes &attrs) { 133861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff assert(Tok.isObjCAtKeyword(tok::objc_interface) && 134dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff "ParseObjCAtInterfaceDeclaration(): Expected @interface"); 135dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff ConsumeToken(); // the "interface" identifier 1361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1373b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor // Code completion after '@interface'. 1383b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor if (Tok.is(tok::code_completion)) { 13923c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCInterfaceDecl(getCurScope()); 140dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 1413b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor } 1423b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor 143df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 144dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff Diag(Tok, diag::err_expected_ident); // missing class or category name. 145d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 146dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff } 14763e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian 148dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff // We have a class or category name - consume it. 1497ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff IdentifierInfo *nameId = Tok.getIdentifierInfo(); 150dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff SourceLocation nameLoc = ConsumeToken(); 1515512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian if (Tok.is(tok::l_paren) && 1525512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian !isKnownToBeTypeSpecifier(GetLookAheadToken(1))) { // we have a category. 153dec0984fce504a39a7f085774fb67cfd9957be58Jeffrey Yasskin // TODO(dgregor): Use the return value from the next line to provide better 154dec0984fce504a39a7f085774fb67cfd9957be58Jeffrey Yasskin // recovery. 155dec0984fce504a39a7f085774fb67cfd9957be58Jeffrey Yasskin ConsumeParen(); 156dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff SourceLocation categoryLoc, rparenLoc; 157dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff IdentifierInfo *categoryId = 0; 15833ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor if (Tok.is(tok::code_completion)) { 15923c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCInterfaceCategory(getCurScope(), nameId, nameLoc); 160dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 16133ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor } 16233ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor 163527fe23f8cbc6a4da1737a547a2517bc92fa88c8Steve Naroff // For ObjC2, the category name is optional (not an error). 164df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::identifier)) { 165dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff categoryId = Tok.getIdentifierInfo(); 166dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff categoryLoc = ConsumeToken(); 16705511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian } 16805511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian else if (!getLang().ObjC2) { 169527fe23f8cbc6a4da1737a547a2517bc92fa88c8Steve Naroff Diag(Tok, diag::err_expected_ident); // missing category name. 170d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 171dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff } 172df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::r_paren)) { 173dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff Diag(Tok, diag::err_expected_rparen); 174dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff SkipUntil(tok::r_paren, false); // don't stop at ';' 175d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 176dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff } 177dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff rparenLoc = ConsumeParen(); 1785512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian // Next, we need to check for any protocol references. 1795512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian SourceLocation LAngleLoc, EndProtoLoc; 180d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall llvm::SmallVector<Decl *, 8> ProtocolRefs; 1815512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian llvm::SmallVector<SourceLocation, 8> ProtocolLocs; 1825512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian if (Tok.is(tok::less) && 1835512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian ParseObjCProtocolReferences(ProtocolRefs, ProtocolLocs, true, 18471b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis LAngleLoc, EndProtoLoc)) 185d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 18605511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian 1877f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall if (!attrs.empty()) // categories don't support attributes. 1885512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian Diag(Tok, diag::err_objc_no_attributes_on_category); 1895512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian 190d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *CategoryType = 1915512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian Actions.ActOnStartCategoryInterface(atLoc, 1925512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian nameId, nameLoc, 1935512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian categoryId, categoryLoc, 1945512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian ProtocolRefs.data(), 1955512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian ProtocolRefs.size(), 1965512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian ProtocolLocs.data(), 1975512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian EndProtoLoc); 1985512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian if (Tok.is(tok::l_brace)) 19983c481ade785a919ba21a33f9a8b1b21c1212fb3Fariborz Jahanian ParseObjCClassInstanceVariables(CategoryType, tok::objc_private, 20083c481ade785a919ba21a33f9a8b1b21c1212fb3Fariborz Jahanian atLoc); 20183c481ade785a919ba21a33f9a8b1b21c1212fb3Fariborz Jahanian 2025512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian ParseObjCInterfaceDeclList(CategoryType, tok::objc_not_keyword); 2035512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian return CategoryType; 204dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff } 205dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff // Parse a class interface. 206dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff IdentifierInfo *superClassId = 0; 207dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff SourceLocation superClassLoc; 2087ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff 209df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::colon)) { // a super class is specified. 210dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff ConsumeToken(); 2113b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor 2123b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor // Code completion of superclass names. 2133b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor if (Tok.is(tok::code_completion)) { 21423c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCSuperclass(getCurScope(), nameId, nameLoc); 215dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 2163b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor } 2173b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor 218df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 219dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff Diag(Tok, diag::err_expected_ident); // missing super class name. 220d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 221dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff } 222dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff superClassId = Tok.getIdentifierInfo(); 223dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff superClassLoc = ConsumeToken(); 224dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff } 225dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff // Next, we need to check for any protocol references. 226d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall llvm::SmallVector<Decl *, 8> ProtocolRefs; 22771b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis llvm::SmallVector<SourceLocation, 8> ProtocolLocs; 22871b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis SourceLocation LAngleLoc, EndProtoLoc; 22906036d3709955a53297b4cbe14e20db88f321470Chris Lattner if (Tok.is(tok::less) && 23071b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis ParseObjCProtocolReferences(ProtocolRefs, ProtocolLocs, true, 23171b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis LAngleLoc, EndProtoLoc)) 232d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 2331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 234d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ClsType = 2351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Actions.ActOnStartClassInterface(atLoc, nameId, nameLoc, 23606036d3709955a53297b4cbe14e20db88f321470Chris Lattner superClassId, superClassLoc, 237beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad ProtocolRefs.data(), ProtocolRefs.size(), 23818df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor ProtocolLocs.data(), 2397f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall EndProtoLoc, attrs.getList()); 2401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 241df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::l_brace)) 24283c481ade785a919ba21a33f9a8b1b21c1212fb3Fariborz Jahanian ParseObjCClassInstanceVariables(ClsType, tok::objc_protected, atLoc); 243dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff 24425e077d59a8e8e43b65882b69610a3d5e2aaf53cFariborz Jahanian ParseObjCInterfaceDeclList(ClsType, tok::objc_interface); 2455512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian return ClsType; 246dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff} 247dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff 248d0014540005f2a5ab837365db6bd40f479406758John McCall/// The Objective-C property callback. This should be defined where 249d0014540005f2a5ab837365db6bd40f479406758John McCall/// it's used, but instead it's been lifted to here to support VS2005. 250d0014540005f2a5ab837365db6bd40f479406758John McCallstruct Parser::ObjCPropertyCallback : FieldCallback { 251d0014540005f2a5ab837365db6bd40f479406758John McCall Parser &P; 252d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *IDecl; 253d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall llvm::SmallVectorImpl<Decl *> &Props; 254d0014540005f2a5ab837365db6bd40f479406758John McCall ObjCDeclSpec &OCDS; 255d0014540005f2a5ab837365db6bd40f479406758John McCall SourceLocation AtLoc; 256d0014540005f2a5ab837365db6bd40f479406758John McCall tok::ObjCKeywordKind MethodImplKind; 257d0014540005f2a5ab837365db6bd40f479406758John McCall 258d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall ObjCPropertyCallback(Parser &P, Decl *IDecl, 259d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall llvm::SmallVectorImpl<Decl *> &Props, 260d0014540005f2a5ab837365db6bd40f479406758John McCall ObjCDeclSpec &OCDS, SourceLocation AtLoc, 261d0014540005f2a5ab837365db6bd40f479406758John McCall tok::ObjCKeywordKind MethodImplKind) : 262d0014540005f2a5ab837365db6bd40f479406758John McCall P(P), IDecl(IDecl), Props(Props), OCDS(OCDS), AtLoc(AtLoc), 263d0014540005f2a5ab837365db6bd40f479406758John McCall MethodImplKind(MethodImplKind) { 264d0014540005f2a5ab837365db6bd40f479406758John McCall } 265d0014540005f2a5ab837365db6bd40f479406758John McCall 266d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *invoke(FieldDeclarator &FD) { 267d0014540005f2a5ab837365db6bd40f479406758John McCall if (FD.D.getIdentifier() == 0) { 268d0014540005f2a5ab837365db6bd40f479406758John McCall P.Diag(AtLoc, diag::err_objc_property_requires_field_name) 269d0014540005f2a5ab837365db6bd40f479406758John McCall << FD.D.getSourceRange(); 270d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 271d0014540005f2a5ab837365db6bd40f479406758John McCall } 272d0014540005f2a5ab837365db6bd40f479406758John McCall if (FD.BitfieldSize) { 273d0014540005f2a5ab837365db6bd40f479406758John McCall P.Diag(AtLoc, diag::err_objc_property_bitfield) 274d0014540005f2a5ab837365db6bd40f479406758John McCall << FD.D.getSourceRange(); 275d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 276d0014540005f2a5ab837365db6bd40f479406758John McCall } 277d0014540005f2a5ab837365db6bd40f479406758John McCall 278d0014540005f2a5ab837365db6bd40f479406758John McCall // Install the property declarator into interfaceDecl. 279d0014540005f2a5ab837365db6bd40f479406758John McCall IdentifierInfo *SelName = 280d0014540005f2a5ab837365db6bd40f479406758John McCall OCDS.getGetterName() ? OCDS.getGetterName() : FD.D.getIdentifier(); 281d0014540005f2a5ab837365db6bd40f479406758John McCall 282d0014540005f2a5ab837365db6bd40f479406758John McCall Selector GetterSel = 283d0014540005f2a5ab837365db6bd40f479406758John McCall P.PP.getSelectorTable().getNullarySelector(SelName); 284d0014540005f2a5ab837365db6bd40f479406758John McCall IdentifierInfo *SetterName = OCDS.getSetterName(); 285d0014540005f2a5ab837365db6bd40f479406758John McCall Selector SetterSel; 286d0014540005f2a5ab837365db6bd40f479406758John McCall if (SetterName) 287d0014540005f2a5ab837365db6bd40f479406758John McCall SetterSel = P.PP.getSelectorTable().getSelector(1, &SetterName); 288d0014540005f2a5ab837365db6bd40f479406758John McCall else 289d0014540005f2a5ab837365db6bd40f479406758John McCall SetterSel = SelectorTable::constructSetterName(P.PP.getIdentifierTable(), 290d0014540005f2a5ab837365db6bd40f479406758John McCall P.PP.getSelectorTable(), 291d0014540005f2a5ab837365db6bd40f479406758John McCall FD.D.getIdentifier()); 292d0014540005f2a5ab837365db6bd40f479406758John McCall bool isOverridingProperty = false; 293d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *Property = 29423c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor P.Actions.ActOnProperty(P.getCurScope(), AtLoc, FD, OCDS, 295d0014540005f2a5ab837365db6bd40f479406758John McCall GetterSel, SetterSel, IDecl, 296d0014540005f2a5ab837365db6bd40f479406758John McCall &isOverridingProperty, 297d0014540005f2a5ab837365db6bd40f479406758John McCall MethodImplKind); 298d0014540005f2a5ab837365db6bd40f479406758John McCall if (!isOverridingProperty) 299d0014540005f2a5ab837365db6bd40f479406758John McCall Props.push_back(Property); 300d0014540005f2a5ab837365db6bd40f479406758John McCall 301d0014540005f2a5ab837365db6bd40f479406758John McCall return Property; 302d0014540005f2a5ab837365db6bd40f479406758John McCall } 303d0014540005f2a5ab837365db6bd40f479406758John McCall}; 304d0014540005f2a5ab837365db6bd40f479406758John McCall 305dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-interface-decl-list: 306dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// empty 307dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-interface-decl-list objc-property-decl [OBJC2] 308294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-interface-decl-list objc-method-requirement [OBJC2] 3093536b443bc50d58a79f14fca9b6842541a434854Steve Naroff/// objc-interface-decl-list objc-method-proto ';' 310dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-interface-decl-list declaration 311dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-interface-decl-list ';' 312dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 313294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-method-requirement: [OBJC2] 314294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// @required 315294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// @optional 316294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 317d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallvoid Parser::ParseObjCInterfaceDeclList(Decl *interfaceDecl, 318cb53b361bce341c8591333c6997f62e480acc0b4Chris Lattner tok::ObjCKeywordKind contextKey) { 319d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall llvm::SmallVector<Decl *, 32> allMethods; 320d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall llvm::SmallVector<Decl *, 16> allProperties; 321682bf92db408a6cbc3d37b5496a99b6ef85041ecChris Lattner llvm::SmallVector<DeclGroupPtrTy, 8> allTUVariables; 32200933591a2795d09dd1acff12a2d21bce7cb12c5Fariborz Jahanian tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword; 3231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 324782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek SourceRange AtEnd; 325bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner 326294494e1cce92043562b4680c613df7fd028c02eSteve Naroff while (1) { 327e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner // If this is a method prototype, parse it. 328df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::minus) || Tok.is(tok::plus)) { 329d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *methodPrototype = 33090ba78c64d0c24cfbc1bf88728db9775d44d7f9fFariborz Jahanian ParseObjCMethodPrototype(interfaceDecl, MethodImplKind, false); 33125e077d59a8e8e43b65882b69610a3d5e2aaf53cFariborz Jahanian allMethods.push_back(methodPrototype); 3323536b443bc50d58a79f14fca9b6842541a434854Steve Naroff // Consume the ';' here, since ParseObjCMethodPrototype() is re-used for 3333536b443bc50d58a79f14fca9b6842541a434854Steve Naroff // method definitions. 334b6d74a158a9c002e3c0fcbda8ad8d0ccbb2e5088Chris Lattner ExpectAndConsume(tok::semi, diag::err_expected_semi_after_method_proto, 335b6d74a158a9c002e3c0fcbda8ad8d0ccbb2e5088Chris Lattner "", tok::semi); 336294494e1cce92043562b4680c613df7fd028c02eSteve Naroff continue; 337294494e1cce92043562b4680c613df7fd028c02eSteve Naroff } 33805511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian if (Tok.is(tok::l_paren)) { 33905511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian Diag(Tok, diag::err_expected_minus_or_plus); 340d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall ParseObjCMethodDecl(Tok.getLocation(), 341d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall tok::minus, 342d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall interfaceDecl, 34390ba78c64d0c24cfbc1bf88728db9775d44d7f9fFariborz Jahanian MethodImplKind, false); 34405511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian continue; 34505511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian } 346e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner // Ignore excess semicolons. 347e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner if (Tok.is(tok::semi)) { 348294494e1cce92043562b4680c613df7fd028c02eSteve Naroff ConsumeToken(); 349e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner continue; 350e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner } 3511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 352bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // If we got to the end of the file, exit the loop. 353e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner if (Tok.is(tok::eof)) 354e3a2ca7e30601cdd31c77a830f4cc487851e8096Fariborz Jahanian break; 3551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 356b6ac2451bfed36206c5cec7217372c4299f67f2bDouglas Gregor // Code completion within an Objective-C interface. 357b6ac2451bfed36206c5cec7217372c4299f67f2bDouglas Gregor if (Tok.is(tok::code_completion)) { 35823c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteOrdinaryName(getCurScope(), 359f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall ObjCImpDecl? Sema::PCC_ObjCImplementation 360f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall : Sema::PCC_ObjCInterface); 361dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 362b6ac2451bfed36206c5cec7217372c4299f67f2bDouglas Gregor } 363b6ac2451bfed36206c5cec7217372c4299f67f2bDouglas Gregor 364e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner // If we don't have an @ directive, parse it as a function definition. 365e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner if (Tok.isNot(tok::at)) { 3661fd80116b49782c367ff5d5f50a8b76dd8a5d7f7Chris Lattner // The code below does not consume '}'s because it is afraid of eating the 3671fd80116b49782c367ff5d5f50a8b76dd8a5d7f7Chris Lattner // end of a namespace. Because of the way this code is structured, an 3681fd80116b49782c367ff5d5f50a8b76dd8a5d7f7Chris Lattner // erroneous r_brace would cause an infinite loop if not handled here. 3691fd80116b49782c367ff5d5f50a8b76dd8a5d7f7Chris Lattner if (Tok.is(tok::r_brace)) 3701fd80116b49782c367ff5d5f50a8b76dd8a5d7f7Chris Lattner break; 3711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3724985aceceb9b9261b876b515d32726175c13a775Steve Naroff // FIXME: as the name implies, this rule allows function definitions. 3734985aceceb9b9261b876b515d32726175c13a775Steve Naroff // We could pass a flag or check for functions during semantic analysis. 3740b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall ParsedAttributes attrs(AttrFactory); 3757f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall allTUVariables.push_back(ParseDeclarationOrFunctionDefinition(attrs)); 376e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner continue; 377e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner } 3781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 379e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner // Otherwise, we have an @ directive, eat the @. 380e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner SourceLocation AtLoc = ConsumeToken(); // the "@" 381c464ae8444edb6d07ea49b7a0eae1674c0fa1bb8Douglas Gregor if (Tok.is(tok::code_completion)) { 38223c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCAtDirective(getCurScope(), ObjCImpDecl, true); 383dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 384c464ae8444edb6d07ea49b7a0eae1674c0fa1bb8Douglas Gregor break; 385c464ae8444edb6d07ea49b7a0eae1674c0fa1bb8Douglas Gregor } 386c464ae8444edb6d07ea49b7a0eae1674c0fa1bb8Douglas Gregor 387a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner tok::ObjCKeywordKind DirectiveKind = Tok.getObjCKeywordID(); 3881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 389a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner if (DirectiveKind == tok::objc_end) { // @end -> terminate list 390782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek AtEnd.setBegin(AtLoc); 391782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek AtEnd.setEnd(Tok.getLocation()); 392e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner break; 393c3d43b783dfb1a1502aa8b31ab1985cf237b1f77Douglas Gregor } else if (DirectiveKind == tok::objc_not_keyword) { 394c3d43b783dfb1a1502aa8b31ab1985cf237b1f77Douglas Gregor Diag(Tok, diag::err_objc_unknown_at); 395c3d43b783dfb1a1502aa8b31ab1985cf237b1f77Douglas Gregor SkipUntil(tok::semi); 396c3d43b783dfb1a1502aa8b31ab1985cf237b1f77Douglas Gregor continue; 397bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner } 3981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 399bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // Eat the identifier. 400bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner ConsumeToken(); 401bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner 402a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner switch (DirectiveKind) { 403a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner default: 404bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // FIXME: If someone forgets an @end on a protocol, this loop will 405bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // continue to eat up tons of stuff and spew lots of nonsense errors. It 406bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // would probably be better to bail out if we saw an @class or @interface 407bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // or something like that. 408f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner Diag(AtLoc, diag::err_objc_illegal_interface_qual); 409bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // Skip until we see an '@' or '}' or ';'. 410a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner SkipUntil(tok::r_brace, tok::at); 411a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner break; 41246d545e355a4fea2a201652c3c8bbf22a13187a6Fariborz Jahanian 41346d545e355a4fea2a201652c3c8bbf22a13187a6Fariborz Jahanian case tok::objc_implementation: 414df81c2c6ce37f4ae3c45dd01093b6274fa0b6692Fariborz Jahanian case tok::objc_interface: 41546d545e355a4fea2a201652c3c8bbf22a13187a6Fariborz Jahanian Diag(Tok, diag::err_objc_missing_end); 41646d545e355a4fea2a201652c3c8bbf22a13187a6Fariborz Jahanian ConsumeToken(); 41746d545e355a4fea2a201652c3c8bbf22a13187a6Fariborz Jahanian break; 41846d545e355a4fea2a201652c3c8bbf22a13187a6Fariborz Jahanian 419a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner case tok::objc_required: 420a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner case tok::objc_optional: 421a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner // This is only valid on protocols. 422bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // FIXME: Should this check for ObjC2 being enabled? 423e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner if (contextKey != tok::objc_protocol) 424bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner Diag(AtLoc, diag::err_objc_directive_only_in_protocol); 425a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner else 426bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner MethodImplKind = DirectiveKind; 427a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner break; 4281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 429a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner case tok::objc_property: 430f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner if (!getLang().ObjC2) 431b321c0c0ba957d78475e72cebde4028fdaa00f8fChris Lattner Diag(AtLoc, diag::err_objc_properties_require_objc2); 432f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner 433e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner ObjCDeclSpec OCDS; 4341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // Parse property attribute list, if any. 4358ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner if (Tok.is(tok::l_paren)) 436bdb2d5056fd675c27307b34efd371bbba6839e92Douglas Gregor ParseObjCPropertyAttribute(OCDS, interfaceDecl); 4371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 438d0014540005f2a5ab837365db6bd40f479406758John McCall ObjCPropertyCallback Callback(*this, interfaceDecl, allProperties, 439d0014540005f2a5ab837365db6bd40f479406758John McCall OCDS, AtLoc, MethodImplKind); 440bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall 441e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner // Parse all the comma separated declarators. 4420b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall DeclSpec DS(AttrFactory); 443bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall ParseStructDeclaration(DS, Callback); 4441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4457da19ea50d4161fcda40d135735bcf450cabeb50John McCall ExpectAndConsume(tok::semi, diag::err_expected_semi_decl_list); 446a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner break; 447f28b264437053fb0deacc9ba02b18a0966f7290aSteve Naroff } 448294494e1cce92043562b4680c613df7fd028c02eSteve Naroff } 449bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner 450bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // We break out of the big loop in two cases: when we see @end or when we see 451bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // EOF. In the former case, eat the @end. In the later case, emit an error. 452c464ae8444edb6d07ea49b7a0eae1674c0fa1bb8Douglas Gregor if (Tok.is(tok::code_completion)) { 45323c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCAtDirective(getCurScope(), ObjCImpDecl, true); 454dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 455c464ae8444edb6d07ea49b7a0eae1674c0fa1bb8Douglas Gregor } else if (Tok.isObjCAtKeyword(tok::objc_end)) 456bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner ConsumeToken(); // the "end" identifier 457bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner else 458bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner Diag(Tok, diag::err_objc_missing_end); 4591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 460a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner // Insert collected methods declarations into the @interface object. 461bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // This passes in an invalid SourceLocation for AtEndLoc when EOF is hit. 46223c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.ActOnAtEnd(getCurScope(), AtEnd, interfaceDecl, 4631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump allMethods.data(), allMethods.size(), 464beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad allProperties.data(), allProperties.size(), 465beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad allTUVariables.data(), allTUVariables.size()); 466294494e1cce92043562b4680c613df7fd028c02eSteve Naroff} 467294494e1cce92043562b4680c613df7fd028c02eSteve Naroff 468d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// Parse property attribute declarations. 469d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// 470d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// property-attr-decl: '(' property-attrlist ')' 471d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// property-attrlist: 472d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// property-attribute 473d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// property-attrlist ',' property-attribute 474d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// property-attribute: 475d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// getter '=' identifier 476d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// setter '=' identifier ':' 477d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// readonly 478d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// readwrite 479d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// assign 480d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// retain 481d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// copy 482d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// nonatomic 483f85e193739c953358c865005855253af4f68a497John McCall/// atomic 484f85e193739c953358c865005855253af4f68a497John McCall/// strong 485f85e193739c953358c865005855253af4f68a497John McCall/// weak 486f85e193739c953358c865005855253af4f68a497John McCall/// unsafe_unretained 487d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// 488bdb2d5056fd675c27307b34efd371bbba6839e92Douglas Gregorvoid Parser::ParseObjCPropertyAttribute(ObjCDeclSpec &DS, Decl *ClassDecl) { 4898ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner assert(Tok.getKind() == tok::l_paren); 490dd5b5f2bb73d037745940431b71eb98393d12d4fChris Lattner SourceLocation LHSLoc = ConsumeParen(); // consume '(' 4911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 492cd9f4b31c4fe5b77b5519cc17b4583fab912bad1Chris Lattner while (1) { 493ece8e71d12b6f4cb2dc501297afef126dab8ad74Steve Naroff if (Tok.is(tok::code_completion)) { 49423c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCPropertyFlags(getCurScope(), DS); 495dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 496ece8e71d12b6f4cb2dc501297afef126dab8ad74Steve Naroff } 497d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian const IdentifierInfo *II = Tok.getIdentifierInfo(); 4981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 499f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner // If this is not an identifier at all, bail out early. 500f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner if (II == 0) { 501f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner MatchRHSPunctuation(tok::r_paren, LHSLoc); 502f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner return; 503f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner } 5041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 505156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner SourceLocation AttrName = ConsumeToken(); // consume last attribute name 5061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 50792e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner if (II->isStr("readonly")) 508e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_readonly); 50992e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner else if (II->isStr("assign")) 510e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_assign); 511f85e193739c953358c865005855253af4f68a497John McCall else if (II->isStr("unsafe_unretained")) 512f85e193739c953358c865005855253af4f68a497John McCall DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_unsafe_unretained); 51392e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner else if (II->isStr("readwrite")) 514e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_readwrite); 51592e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner else if (II->isStr("retain")) 516e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_retain); 517f85e193739c953358c865005855253af4f68a497John McCall else if (II->isStr("strong")) 518f85e193739c953358c865005855253af4f68a497John McCall DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_strong); 51992e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner else if (II->isStr("copy")) 520e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_copy); 52192e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner else if (II->isStr("nonatomic")) 522e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_nonatomic); 52345937ae10a0f70f74508165aab4f2b63e18ea747Fariborz Jahanian else if (II->isStr("atomic")) 52445937ae10a0f70f74508165aab4f2b63e18ea747Fariborz Jahanian DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_atomic); 525f85e193739c953358c865005855253af4f68a497John McCall else if (II->isStr("weak")) 526f85e193739c953358c865005855253af4f68a497John McCall DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_weak); 52792e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner else if (II->isStr("getter") || II->isStr("setter")) { 52842499be29b620d2eae34beb0f4d0f9da5a9584daAnders Carlsson bool IsSetter = II->getNameStart()[0] == 's'; 52942499be29b620d2eae34beb0f4d0f9da5a9584daAnders Carlsson 530e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner // getter/setter require extra treatment. 53142499be29b620d2eae34beb0f4d0f9da5a9584daAnders Carlsson unsigned DiagID = IsSetter ? diag::err_objc_expected_equal_for_setter : 53242499be29b620d2eae34beb0f4d0f9da5a9584daAnders Carlsson diag::err_objc_expected_equal_for_getter; 53342499be29b620d2eae34beb0f4d0f9da5a9584daAnders Carlsson 53442499be29b620d2eae34beb0f4d0f9da5a9584daAnders Carlsson if (ExpectAndConsume(tok::equal, DiagID, "", tok::r_paren)) 535dd5b5f2bb73d037745940431b71eb98393d12d4fChris Lattner return; 5361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5374ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor if (Tok.is(tok::code_completion)) { 53842499be29b620d2eae34beb0f4d0f9da5a9584daAnders Carlsson if (IsSetter) 539bdb2d5056fd675c27307b34efd371bbba6839e92Douglas Gregor Actions.CodeCompleteObjCPropertySetter(getCurScope(), ClassDecl); 5404ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor else 541bdb2d5056fd675c27307b34efd371bbba6839e92Douglas Gregor Actions.CodeCompleteObjCPropertyGetter(getCurScope(), ClassDecl); 542dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 5434ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor } 5444ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor 54542499be29b620d2eae34beb0f4d0f9da5a9584daAnders Carlsson 54642499be29b620d2eae34beb0f4d0f9da5a9584daAnders Carlsson SourceLocation SelLoc; 54742499be29b620d2eae34beb0f4d0f9da5a9584daAnders Carlsson IdentifierInfo *SelIdent = ParseObjCSelectorPiece(SelLoc); 54842499be29b620d2eae34beb0f4d0f9da5a9584daAnders Carlsson 54942499be29b620d2eae34beb0f4d0f9da5a9584daAnders Carlsson if (!SelIdent) { 55042499be29b620d2eae34beb0f4d0f9da5a9584daAnders Carlsson Diag(Tok, diag::err_objc_expected_selector_for_getter_setter) 55142499be29b620d2eae34beb0f4d0f9da5a9584daAnders Carlsson << IsSetter; 5528ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner SkipUntil(tok::r_paren); 5538ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner return; 5548ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner } 5551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 55642499be29b620d2eae34beb0f4d0f9da5a9584daAnders Carlsson if (IsSetter) { 5578ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_setter); 55842499be29b620d2eae34beb0f4d0f9da5a9584daAnders Carlsson DS.setSetterName(SelIdent); 5591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 560e0097db2848c463a534c18c235c6d3e53f2f1b87Fariborz Jahanian if (ExpectAndConsume(tok::colon, 561e0097db2848c463a534c18c235c6d3e53f2f1b87Fariborz Jahanian diag::err_expected_colon_after_setter_name, "", 562156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner tok::r_paren)) 5638ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner return; 5648ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner } else { 5658ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_getter); 56642499be29b620d2eae34beb0f4d0f9da5a9584daAnders Carlsson DS.setGetterName(SelIdent); 5678ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner } 568e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner } else { 569a9500f05ba6c09bbd84d342236863833067cd816Chris Lattner Diag(AttrName, diag::err_objc_expected_property_attr) << II; 570cd9f4b31c4fe5b77b5519cc17b4583fab912bad1Chris Lattner SkipUntil(tok::r_paren); 571cd9f4b31c4fe5b77b5519cc17b4583fab912bad1Chris Lattner return; 572cd9f4b31c4fe5b77b5519cc17b4583fab912bad1Chris Lattner } 5731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 574156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner if (Tok.isNot(tok::comma)) 575156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner break; 5761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 577156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner ConsumeToken(); 578d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian } 5791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 580156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner MatchRHSPunctuation(tok::r_paren, LHSLoc); 581d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian} 582d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian 5833536b443bc50d58a79f14fca9b6842541a434854Steve Naroff/// objc-method-proto: 5841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// objc-instance-method objc-method-decl objc-method-attributes[opt] 5853536b443bc50d58a79f14fca9b6842541a434854Steve Naroff/// objc-class-method objc-method-decl objc-method-attributes[opt] 586294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 587294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-instance-method: '-' 588294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-class-method: '+' 589294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 5904985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-method-attributes: [OBJC2] 5914985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// __attribute__((deprecated)) 5924985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// 593d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseObjCMethodPrototype(Decl *IDecl, 59490ba78c64d0c24cfbc1bf88728db9775d44d7f9fFariborz Jahanian tok::ObjCKeywordKind MethodImplKind, 59590ba78c64d0c24cfbc1bf88728db9775d44d7f9fFariborz Jahanian bool MethodDefinition) { 596df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner assert((Tok.is(tok::minus) || Tok.is(tok::plus)) && "expected +/-"); 597294494e1cce92043562b4680c613df7fd028c02eSteve Naroff 5981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump tok::TokenKind methodType = Tok.getKind(); 599bef1185418705e16012b3dd50cd7c260c8d6b79cSteve Naroff SourceLocation mLoc = ConsumeToken(); 60090ba78c64d0c24cfbc1bf88728db9775d44d7f9fFariborz Jahanian Decl *MDecl = ParseObjCMethodDecl(mLoc, methodType, IDecl,MethodImplKind, 60190ba78c64d0c24cfbc1bf88728db9775d44d7f9fFariborz Jahanian MethodDefinition); 6023536b443bc50d58a79f14fca9b6842541a434854Steve Naroff // Since this rule is used for both method declarations and definitions, 6032bd42fadafddc8acf744b57a970bdc96a077c617Steve Naroff // the caller is (optionally) responsible for consuming the ';'. 604f28b264437053fb0deacc9ba02b18a0966f7290aSteve Naroff return MDecl; 605294494e1cce92043562b4680c613df7fd028c02eSteve Naroff} 606294494e1cce92043562b4680c613df7fd028c02eSteve Naroff 607294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-selector: 608294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// identifier 609294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// one of 610294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// enum struct union if else while do for switch case default 611294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// break continue return goto asm sizeof typeof __alignof 612294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// unsigned long const short volatile signed restrict _Complex 613294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// in out inout bycopy byref oneway int char float double void _Bool 614294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 6152fc5c2428ecb450a3256c8316b93b8655cb76a0fChris LattnerIdentifierInfo *Parser::ParseObjCSelectorPiece(SourceLocation &SelectorLoc) { 616be74740cc246ce08d42804a684385a42eb814edbFariborz Jahanian 617ff38491c18b060526d754765b952f4a497a89416Chris Lattner switch (Tok.getKind()) { 618ff38491c18b060526d754765b952f4a497a89416Chris Lattner default: 619ff38491c18b060526d754765b952f4a497a89416Chris Lattner return 0; 620afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian case tok::ampamp: 621afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian case tok::ampequal: 622afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian case tok::amp: 623afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian case tok::pipe: 624afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian case tok::tilde: 625afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian case tok::exclaim: 626afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian case tok::exclaimequal: 627afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian case tok::pipepipe: 628afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian case tok::pipeequal: 629afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian case tok::caret: 630afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian case tok::caretequal: { 6313846ca29a8cc1d376a4b695194c29952dbbfb544Fariborz Jahanian std::string ThisTok(PP.getSpelling(Tok)); 632afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian if (isalpha(ThisTok[0])) { 633afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian IdentifierInfo *II = &PP.getIdentifierTable().get(ThisTok.data()); 634afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian Tok.setKind(tok::identifier); 635afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian SelectorLoc = ConsumeToken(); 636afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian return II; 637afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian } 638afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian return 0; 639afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian } 640afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian 641ff38491c18b060526d754765b952f4a497a89416Chris Lattner case tok::identifier: 642ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_asm: 643ff38491c18b060526d754765b952f4a497a89416Chris Lattner case tok::kw_auto: 6449298d9655aed28b2d9f6cc65c81401b209f03fdcChris Lattner case tok::kw_bool: 645ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_break: 646ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_case: 647ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_catch: 648ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_char: 649ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_class: 650ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_const: 651ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_const_cast: 652ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_continue: 653ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_default: 654ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_delete: 655ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_do: 656ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_double: 657ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_dynamic_cast: 658ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_else: 659ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_enum: 660ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_explicit: 661ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_export: 662ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_extern: 663ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_false: 664ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_float: 665ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_for: 666ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_friend: 667ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_goto: 668ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_if: 669ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_inline: 670ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_int: 671ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_long: 672ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_mutable: 673ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_namespace: 674ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_new: 675ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_operator: 676ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_private: 677ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_protected: 678ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_public: 679ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_register: 680ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_reinterpret_cast: 681ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_restrict: 682ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_return: 683ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_short: 684ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_signed: 685ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_sizeof: 686ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_static: 687ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_static_cast: 688ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_struct: 689ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_switch: 690ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_template: 691ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_this: 692ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_throw: 693ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_true: 694ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_try: 695ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_typedef: 696ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_typeid: 697ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_typename: 698ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_typeof: 699ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_union: 700ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_unsigned: 701ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_using: 702ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_virtual: 703ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_void: 704ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_volatile: 705ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_wchar_t: 706ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_while: 707ff38491c18b060526d754765b952f4a497a89416Chris Lattner case tok::kw__Bool: 708ff38491c18b060526d754765b952f4a497a89416Chris Lattner case tok::kw__Complex: 709ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw___alignof: 710ff38491c18b060526d754765b952f4a497a89416Chris Lattner IdentifierInfo *II = Tok.getIdentifierInfo(); 7114b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian SelectorLoc = ConsumeToken(); 712ff38491c18b060526d754765b952f4a497a89416Chris Lattner return II; 713d064951b0dcc95f8604d0d69ae82d9ecbd38c796Fariborz Jahanian } 714294494e1cce92043562b4680c613df7fd028c02eSteve Naroff} 715294494e1cce92043562b4680c613df7fd028c02eSteve Naroff 7160196cab54007ff072ec2642da8911c6b7e8d3fb5Fariborz Jahanian/// objc-for-collection-in: 'in' 7170196cab54007ff072ec2642da8911c6b7e8d3fb5Fariborz Jahanian/// 718335a2d4122e41343fe11a775889b8bec5b14be60Fariborz Jahanianbool Parser::isTokIdentifier_in() const { 7193ba5a0f90a03d5e13d02cbee9abd2a1ba01b18bcFariborz Jahanian // FIXME: May have to do additional look-ahead to only allow for 7203ba5a0f90a03d5e13d02cbee9abd2a1ba01b18bcFariborz Jahanian // valid tokens following an 'in'; such as an identifier, unary operators, 7213ba5a0f90a03d5e13d02cbee9abd2a1ba01b18bcFariborz Jahanian // '[' etc. 7221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return (getLang().ObjC2 && Tok.is(tok::identifier) && 7235ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner Tok.getIdentifierInfo() == ObjCTypeQuals[objc_in]); 7240196cab54007ff072ec2642da8911c6b7e8d3fb5Fariborz Jahanian} 7250196cab54007ff072ec2642da8911c6b7e8d3fb5Fariborz Jahanian 726a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ParseObjCTypeQualifierList - This routine parses the objective-c's type 727e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner/// qualifier list and builds their bitmask representation in the input 728e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner/// argument. 729294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 730294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-type-qualifiers: 731294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-type-qualifier 732294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-type-qualifiers objc-type-qualifier 733294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 734b77cab97f17f946744c920629ca17271308d8ebfDouglas Gregorvoid Parser::ParseObjCTypeQualifierList(ObjCDeclSpec &DS, 735b77cab97f17f946744c920629ca17271308d8ebfDouglas Gregor ObjCTypeNameContext Context) { 736e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner while (1) { 737d32b0225e29fcafb2b2b2a4b1c51dcb1518af9c6Douglas Gregor if (Tok.is(tok::code_completion)) { 738b77cab97f17f946744c920629ca17271308d8ebfDouglas Gregor Actions.CodeCompleteObjCPassingType(getCurScope(), DS, 739b77cab97f17f946744c920629ca17271308d8ebfDouglas Gregor Context == OTN_ParameterType); 740d32b0225e29fcafb2b2b2a4b1c51dcb1518af9c6Douglas Gregor ConsumeCodeCompletionToken(); 741d32b0225e29fcafb2b2b2a4b1c51dcb1518af9c6Douglas Gregor } 742d32b0225e29fcafb2b2b2a4b1c51dcb1518af9c6Douglas Gregor 743cb53b361bce341c8591333c6997f62e480acc0b4Chris Lattner if (Tok.isNot(tok::identifier)) 744e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner return; 7451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 746e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner const IdentifierInfo *II = Tok.getIdentifierInfo(); 747e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner for (unsigned i = 0; i != objc_NumQuals; ++i) { 748a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek if (II != ObjCTypeQuals[i]) 749e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner continue; 7501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 751a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCDeclSpec::ObjCDeclQualifier Qual; 752e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner switch (i) { 753e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner default: assert(0 && "Unknown decl qualifier"); 754a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek case objc_in: Qual = ObjCDeclSpec::DQ_In; break; 755a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek case objc_out: Qual = ObjCDeclSpec::DQ_Out; break; 756a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek case objc_inout: Qual = ObjCDeclSpec::DQ_Inout; break; 757a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek case objc_oneway: Qual = ObjCDeclSpec::DQ_Oneway; break; 758a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek case objc_bycopy: Qual = ObjCDeclSpec::DQ_Bycopy; break; 759a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek case objc_byref: Qual = ObjCDeclSpec::DQ_Byref; break; 760e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner } 761a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek DS.setObjCDeclQualifier(Qual); 762e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner ConsumeToken(); 763e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner II = 0; 764e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner break; 765e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner } 7661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 767e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner // If this wasn't a recognized qualifier, bail out. 768e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner if (II) return; 769e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner } 770e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner} 771e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner 772e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner/// objc-type-name: 773e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner/// '(' objc-type-qualifiers[opt] type-name ')' 774e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner/// '(' objc-type-qualifiers[opt] ')' 775e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner/// 776b77cab97f17f946744c920629ca17271308d8ebfDouglas GregorParsedType Parser::ParseObjCTypeName(ObjCDeclSpec &DS, 777b77cab97f17f946744c920629ca17271308d8ebfDouglas Gregor ObjCTypeNameContext Context) { 778df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner assert(Tok.is(tok::l_paren) && "expected ("); 7791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7804a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner SourceLocation LParenLoc = ConsumeParen(); 781e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner SourceLocation TypeStartLoc = Tok.getLocation(); 7821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 78319d74e1494fe399f0e2a94e9419c095f8214851bFariborz Jahanian // Parse type qualifiers, in, inout, etc. 784b77cab97f17f946744c920629ca17271308d8ebfDouglas Gregor ParseObjCTypeQualifierList(DS, Context); 7854fa7afd07421e7276d1717e4fdf43a5fdd65a622Steve Naroff 786b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType Ty; 787809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor if (isTypeSpecifierQualifier()) { 788f85e193739c953358c865005855253af4f68a497John McCall TypeResult TypeSpec = 789f85e193739c953358c865005855253af4f68a497John McCall ParseTypeName(0, Declarator::ObjCPrototypeContext, &DS); 790809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor if (!TypeSpec.isInvalid()) 791809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor Ty = TypeSpec.get(); 792809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor } 793f85e193739c953358c865005855253af4f68a497John McCall 7944a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner if (Tok.is(tok::r_paren)) 7954a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner ConsumeParen(); 7964a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner else if (Tok.getLocation() == TypeStartLoc) { 797e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner // If we didn't eat any tokens, then this isn't a type. 7981ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_type); 7994a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner SkipUntil(tok::r_paren); 8004a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner } else { 8014a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner // Otherwise, we found *something*, but didn't get a ')' in the right 8024a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner // place. Emit an error then return what we have as the type. 8034a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner MatchRHSPunctuation(tok::r_paren, LParenLoc); 804294494e1cce92043562b4680c613df7fd028c02eSteve Naroff } 805f28b264437053fb0deacc9ba02b18a0966f7290aSteve Naroff return Ty; 806294494e1cce92043562b4680c613df7fd028c02eSteve Naroff} 807294494e1cce92043562b4680c613df7fd028c02eSteve Naroff 808294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-method-decl: 809294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-selector 8104985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-keyword-selector objc-parmlist[opt] 811294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-type-name objc-selector 8124985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-type-name objc-keyword-selector objc-parmlist[opt] 813294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 814294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-keyword-selector: 8151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// objc-keyword-decl 816294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-keyword-selector objc-keyword-decl 817294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 818294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-keyword-decl: 8197ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// objc-selector ':' objc-type-name objc-keyword-attributes[opt] identifier 8207ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// objc-selector ':' objc-keyword-attributes[opt] identifier 8217ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// ':' objc-type-name objc-keyword-attributes[opt] identifier 8227ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// ':' objc-keyword-attributes[opt] identifier 823294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 8244985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-parmlist: 8254985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-parms objc-ellipsis[opt] 826294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 8274985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-parms: 8284985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-parms , parameter-declaration 829294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 8304985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-ellipsis: 831294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// , ... 832294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 8337ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// objc-keyword-attributes: [OBJC2] 8347ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// __attribute__((unused)) 8357ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// 836d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseObjCMethodDecl(SourceLocation mLoc, 8372ccccb3ff40c64927817a7e1ddf1da8c188ed224Douglas Gregor tok::TokenKind mType, 8382ccccb3ff40c64927817a7e1ddf1da8c188ed224Douglas Gregor Decl *IDecl, 83990ba78c64d0c24cfbc1bf88728db9775d44d7f9fFariborz Jahanian tok::ObjCKeywordKind MethodImplKind, 84090ba78c64d0c24cfbc1bf88728db9775d44d7f9fFariborz Jahanian bool MethodDefinition) { 84154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ParsingDeclRAIIObject PD(*this); 84254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 843e8f5a1710a7738deff40e10efcd05b1bd6af184fDouglas Gregor if (Tok.is(tok::code_completion)) { 84423c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCMethodDecl(getCurScope(), mType == tok::minus, 845b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall /*ReturnType=*/ ParsedType(), IDecl); 846dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 847e8f5a1710a7738deff40e10efcd05b1bd6af184fDouglas Gregor } 848e8f5a1710a7738deff40e10efcd05b1bd6af184fDouglas Gregor 849e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner // Parse the return type if present. 850b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ReturnType; 851a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCDeclSpec DSRet; 852df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::l_paren)) 853b77cab97f17f946744c920629ca17271308d8ebfDouglas Gregor ReturnType = ParseObjCTypeName(DSRet, OTN_ResultType); 8541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8559e0493576af77dba1c48858c03e31a2897d0681eTed Kremenek // If attributes exist before the method, parse them. 8560b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall ParsedAttributes methodAttrs(AttrFactory); 8577f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall if (getLang().ObjC2) 8580b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall MaybeParseGNUAttributes(methodAttrs); 8599e0493576af77dba1c48858c03e31a2897d0681eTed Kremenek 860e8f5a1710a7738deff40e10efcd05b1bd6af184fDouglas Gregor if (Tok.is(tok::code_completion)) { 86123c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCMethodDecl(getCurScope(), mType == tok::minus, 862e8f5a1710a7738deff40e10efcd05b1bd6af184fDouglas Gregor ReturnType, IDecl); 863dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 864e8f5a1710a7738deff40e10efcd05b1bd6af184fDouglas Gregor } 865e8f5a1710a7738deff40e10efcd05b1bd6af184fDouglas Gregor 8669e0493576af77dba1c48858c03e31a2897d0681eTed Kremenek // Now parse the selector. 867f85e193739c953358c865005855253af4f68a497John McCall SourceLocation SelectorStartLoc = Tok.getLocation(); 868bef1185418705e16012b3dd50cd7c260c8d6b79cSteve Naroff SourceLocation selLoc; 8692fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner IdentifierInfo *SelIdent = ParseObjCSelectorPiece(selLoc); 870e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner 87184c431088693e216193094d1dbf327a01173f57fSteve Naroff // An unnamed colon is valid. 87284c431088693e216193094d1dbf327a01173f57fSteve Naroff if (!SelIdent && Tok.isNot(tok::colon)) { // missing selector name. 8731ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_selector_for_method) 8741ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner << SourceRange(mLoc, Tok.getLocation()); 875e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner // Skip until we get a ; or {}. 876e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner SkipUntil(tok::r_brace); 877d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 878e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner } 8791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8804f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian llvm::SmallVector<DeclaratorChunk::ParamInfo, 8> CParamInfo; 881df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::colon)) { 882ff38491c18b060526d754765b952f4a497a89416Chris Lattner // If attributes exist after the method, parse them. 8837f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall if (getLang().ObjC2) 8840b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall MaybeParseGNUAttributes(methodAttrs); 8851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 886ff38491c18b060526d754765b952f4a497a89416Chris Lattner Selector Sel = PP.getSelectorTable().getNullarySelector(SelIdent); 887d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *Result 8887f53253223b29d77f1e9c5c0ce93a19932761b77Fariborz Jahanian = Actions.ActOnMethodDeclaration(getCurScope(), mLoc, Tok.getLocation(), 889926df6cfabf3eaa4afc990c097fa4619b76a9b57Douglas Gregor mType, IDecl, DSRet, ReturnType, 890926df6cfabf3eaa4afc990c097fa4619b76a9b57Douglas Gregor selLoc, Sel, 0, 8914f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian CParamInfo.data(), CParamInfo.size(), 8920b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall methodAttrs.getList(), MethodImplKind, 8930b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall false, MethodDefinition); 89454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall PD.complete(Result); 89554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall return Result; 896ff38491c18b060526d754765b952f4a497a89416Chris Lattner } 897f28b264437053fb0deacc9ba02b18a0966f7290aSteve Naroff 89868d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff llvm::SmallVector<IdentifierInfo *, 12> KeyIdents; 899f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall llvm::SmallVector<Sema::ObjCArgInfo, 12> ArgInfos; 9007f53253223b29d77f1e9c5c0ce93a19932761b77Fariborz Jahanian ParseScope PrototypeScope(this, 9017f53253223b29d77f1e9c5c0ce93a19932761b77Fariborz Jahanian Scope::FunctionPrototypeScope|Scope::DeclScope); 9020b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall 9030b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall AttributePool allParamAttrs(AttrFactory); 9047f53253223b29d77f1e9c5c0ce93a19932761b77Fariborz Jahanian 905ff38491c18b060526d754765b952f4a497a89416Chris Lattner while (1) { 9060b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall ParsedAttributes paramAttrs(AttrFactory); 907f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Sema::ObjCArgInfo ArgInfo; 9081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 909ff38491c18b060526d754765b952f4a497a89416Chris Lattner // Each iteration parses a single keyword argument. 910df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::colon)) { 911ff38491c18b060526d754765b952f4a497a89416Chris Lattner Diag(Tok, diag::err_expected_colon); 912ff38491c18b060526d754765b952f4a497a89416Chris Lattner break; 913ff38491c18b060526d754765b952f4a497a89416Chris Lattner } 914ff38491c18b060526d754765b952f4a497a89416Chris Lattner ConsumeToken(); // Eat the ':'. 9151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 916b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ArgInfo.Type = ParsedType(); 917e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner if (Tok.is(tok::l_paren)) // Parse the argument type if present. 918b77cab97f17f946744c920629ca17271308d8ebfDouglas Gregor ArgInfo.Type = ParseObjCTypeName(ArgInfo.DeclSpec, OTN_ParameterType); 919e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner 920ff38491c18b060526d754765b952f4a497a89416Chris Lattner // If attributes exist before the argument name, parse them. 921e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner ArgInfo.ArgAttrs = 0; 9227f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall if (getLang().ObjC2) { 9230b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall MaybeParseGNUAttributes(paramAttrs); 9240b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall ArgInfo.ArgAttrs = paramAttrs.getList(); 9257f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall } 9267ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff 92740ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor // Code completion for the next piece of the selector. 92840ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor if (Tok.is(tok::code_completion)) { 92940ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor ConsumeCodeCompletionToken(); 93040ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor KeyIdents.push_back(SelIdent); 93140ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor Actions.CodeCompleteObjCMethodDeclSelector(getCurScope(), 93240ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor mType == tok::minus, 93340ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor /*AtParameterName=*/true, 93440ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor ReturnType, 93540ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor KeyIdents.data(), 93640ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor KeyIdents.size()); 93740ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor KeyIdents.pop_back(); 93840ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor break; 93940ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor } 94040ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor 941df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 942ff38491c18b060526d754765b952f4a497a89416Chris Lattner Diag(Tok, diag::err_expected_ident); // missing argument name. 943ff38491c18b060526d754765b952f4a497a89416Chris Lattner break; 9444985aceceb9b9261b876b515d32726175c13a775Steve Naroff } 9451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 946e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner ArgInfo.Name = Tok.getIdentifierInfo(); 947e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner ArgInfo.NameLoc = Tok.getLocation(); 948ff38491c18b060526d754765b952f4a497a89416Chris Lattner ConsumeToken(); // Eat the identifier. 9491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 950e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner ArgInfos.push_back(ArgInfo); 951e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner KeyIdents.push_back(SelIdent); 952e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner 9530b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall // Make sure the attributes persist. 9540b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall allParamAttrs.takeAllFrom(paramAttrs.getPool()); 9550b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall 9561f5537aaac1e775aff1d523f2cc59a9a3bd6c946Douglas Gregor // Code completion for the next piece of the selector. 9571f5537aaac1e775aff1d523f2cc59a9a3bd6c946Douglas Gregor if (Tok.is(tok::code_completion)) { 9581f5537aaac1e775aff1d523f2cc59a9a3bd6c946Douglas Gregor ConsumeCodeCompletionToken(); 9591f5537aaac1e775aff1d523f2cc59a9a3bd6c946Douglas Gregor Actions.CodeCompleteObjCMethodDeclSelector(getCurScope(), 9601f5537aaac1e775aff1d523f2cc59a9a3bd6c946Douglas Gregor mType == tok::minus, 96140ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor /*AtParameterName=*/false, 9621f5537aaac1e775aff1d523f2cc59a9a3bd6c946Douglas Gregor ReturnType, 9631f5537aaac1e775aff1d523f2cc59a9a3bd6c946Douglas Gregor KeyIdents.data(), 9641f5537aaac1e775aff1d523f2cc59a9a3bd6c946Douglas Gregor KeyIdents.size()); 9651f5537aaac1e775aff1d523f2cc59a9a3bd6c946Douglas Gregor break; 9661f5537aaac1e775aff1d523f2cc59a9a3bd6c946Douglas Gregor } 9671f5537aaac1e775aff1d523f2cc59a9a3bd6c946Douglas Gregor 968ff38491c18b060526d754765b952f4a497a89416Chris Lattner // Check for another keyword selector. 9694b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian SourceLocation Loc; 9702fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner SelIdent = ParseObjCSelectorPiece(Loc); 971df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (!SelIdent && Tok.isNot(tok::colon)) 972ff38491c18b060526d754765b952f4a497a89416Chris Lattner break; 973ff38491c18b060526d754765b952f4a497a89416Chris Lattner // We have a selector or a colon, continue parsing. 974ff38491c18b060526d754765b952f4a497a89416Chris Lattner } 9751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 976335eafa5be51f6440672a74c73d588af72e96732Steve Naroff bool isVariadic = false; 9771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 978ff38491c18b060526d754765b952f4a497a89416Chris Lattner // Parse the (optional) parameter list. 979df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner while (Tok.is(tok::comma)) { 980ff38491c18b060526d754765b952f4a497a89416Chris Lattner ConsumeToken(); 981df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::ellipsis)) { 982335eafa5be51f6440672a74c73d588af72e96732Steve Naroff isVariadic = true; 9834985aceceb9b9261b876b515d32726175c13a775Steve Naroff ConsumeToken(); 984ff38491c18b060526d754765b952f4a497a89416Chris Lattner break; 9854985aceceb9b9261b876b515d32726175c13a775Steve Naroff } 9860b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall DeclSpec DS(AttrFactory); 987ff38491c18b060526d754765b952f4a497a89416Chris Lattner ParseDeclarationSpecifiers(DS); 9881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // Parse the declarator. 989ff38491c18b060526d754765b952f4a497a89416Chris Lattner Declarator ParmDecl(DS, Declarator::PrototypeContext); 990ff38491c18b060526d754765b952f4a497a89416Chris Lattner ParseDeclarator(ParmDecl); 9914f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian IdentifierInfo *ParmII = ParmDecl.getIdentifier(); 992d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *Param = Actions.ActOnParamDeclarator(getCurScope(), ParmDecl); 9934f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian CParamInfo.push_back(DeclaratorChunk::ParamInfo(ParmII, 9944f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian ParmDecl.getIdentifierLoc(), 9954f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian Param, 9964f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian 0)); 9974f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian 9984985aceceb9b9261b876b515d32726175c13a775Steve Naroff } 9991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10009c4bb2c08989265411925a04252fd4f93c26e3b1Cameron Esfahani // FIXME: Add support for optional parameter list... 1001e3a2ca7e30601cdd31c77a830f4cc487851e8096Fariborz Jahanian // If attributes exist after the method, parse them. 10027f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall if (getLang().ObjC2) 10030b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall MaybeParseGNUAttributes(methodAttrs); 10047f53253223b29d77f1e9c5c0ce93a19932761b77Fariborz Jahanian 10057f53253223b29d77f1e9c5c0ce93a19932761b77Fariborz Jahanian if (KeyIdents.size() == 0) { 10067f53253223b29d77f1e9c5c0ce93a19932761b77Fariborz Jahanian // Leave prototype scope. 10077f53253223b29d77f1e9c5c0ce93a19932761b77Fariborz Jahanian PrototypeScope.Exit(); 1008d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 10097f53253223b29d77f1e9c5c0ce93a19932761b77Fariborz Jahanian } 10107f53253223b29d77f1e9c5c0ce93a19932761b77Fariborz Jahanian 1011ff38491c18b060526d754765b952f4a497a89416Chris Lattner Selector Sel = PP.getSelectorTable().getSelector(KeyIdents.size(), 1012ff38491c18b060526d754765b952f4a497a89416Chris Lattner &KeyIdents[0]); 1013d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *Result 10147f53253223b29d77f1e9c5c0ce93a19932761b77Fariborz Jahanian = Actions.ActOnMethodDeclaration(getCurScope(), mLoc, Tok.getLocation(), 1015926df6cfabf3eaa4afc990c097fa4619b76a9b57Douglas Gregor mType, IDecl, DSRet, ReturnType, 1016926df6cfabf3eaa4afc990c097fa4619b76a9b57Douglas Gregor selLoc, Sel, &ArgInfos[0], 10174f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian CParamInfo.data(), CParamInfo.size(), 10180b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall methodAttrs.getList(), 101990ba78c64d0c24cfbc1bf88728db9775d44d7f9fFariborz Jahanian MethodImplKind, isVariadic, MethodDefinition); 10207f53253223b29d77f1e9c5c0ce93a19932761b77Fariborz Jahanian // Leave prototype scope. 10217f53253223b29d77f1e9c5c0ce93a19932761b77Fariborz Jahanian PrototypeScope.Exit(); 10227f53253223b29d77f1e9c5c0ce93a19932761b77Fariborz Jahanian 102354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall PD.complete(Result); 102454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall return Result; 1025294494e1cce92043562b4680c613df7fd028c02eSteve Naroff} 1026294494e1cce92043562b4680c613df7fd028c02eSteve Naroff 1027dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-refs: 1028dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// '<' identifier-list '>' 1029dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 10307caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattnerbool Parser:: 1031d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallParseObjCProtocolReferences(llvm::SmallVectorImpl<Decl *> &Protocols, 103271b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis llvm::SmallVectorImpl<SourceLocation> &ProtocolLocs, 103371b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis bool WarnOnDeclarations, 103471b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis SourceLocation &LAngleLoc, SourceLocation &EndLoc) { 1035e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner assert(Tok.is(tok::less) && "expected <"); 10361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 103771b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis LAngleLoc = ConsumeToken(); // the "<" 10381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1039e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner llvm::SmallVector<IdentifierLocPair, 8> ProtocolIdents; 10401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1041e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner while (1) { 104255385fe3e723cd675001e45f42d61adde6b7f075Douglas Gregor if (Tok.is(tok::code_completion)) { 104355385fe3e723cd675001e45f42d61adde6b7f075Douglas Gregor Actions.CodeCompleteObjCProtocolReferences(ProtocolIdents.data(), 104455385fe3e723cd675001e45f42d61adde6b7f075Douglas Gregor ProtocolIdents.size()); 1045dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 104655385fe3e723cd675001e45f42d61adde6b7f075Douglas Gregor } 104755385fe3e723cd675001e45f42d61adde6b7f075Douglas Gregor 1048e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner if (Tok.isNot(tok::identifier)) { 1049e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner Diag(Tok, diag::err_expected_ident); 1050e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner SkipUntil(tok::greater); 1051e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner return true; 1052e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner } 1053e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner ProtocolIdents.push_back(std::make_pair(Tok.getIdentifierInfo(), 1054e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner Tok.getLocation())); 105571b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis ProtocolLocs.push_back(Tok.getLocation()); 1056e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner ConsumeToken(); 10571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1058e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner if (Tok.isNot(tok::comma)) 1059e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner break; 1060e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner ConsumeToken(); 1061e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner } 10621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1063e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner // Consume the '>'. 1064e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner if (Tok.isNot(tok::greater)) { 1065e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner Diag(Tok, diag::err_expected_greater); 1066e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner return true; 1067e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner } 10681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1069e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner EndLoc = ConsumeAnyToken(); 10701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1071e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner // Convert the list of protocols identifiers into a list of protocol decls. 1072e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner Actions.FindProtocolDeclaration(WarnOnDeclarations, 1073e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner &ProtocolIdents[0], ProtocolIdents.size(), 1074e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner Protocols); 1075e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner return false; 1076e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner} 1077e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner 10789bd1d8d174a9d15ae343246c8322299248b9e92aDouglas Gregor/// \brief Parse the Objective-C protocol qualifiers that follow a typename 10799bd1d8d174a9d15ae343246c8322299248b9e92aDouglas Gregor/// in a decl-specifier-seq, starting at the '<'. 108046f936e055d763437accd1e5a1bc49e7e5dbc0a3Douglas Gregorbool Parser::ParseObjCProtocolQualifiers(DeclSpec &DS) { 10819bd1d8d174a9d15ae343246c8322299248b9e92aDouglas Gregor assert(Tok.is(tok::less) && "Protocol qualifiers start with '<'"); 10829bd1d8d174a9d15ae343246c8322299248b9e92aDouglas Gregor assert(getLang().ObjC1 && "Protocol qualifiers only exist in Objective-C"); 10839bd1d8d174a9d15ae343246c8322299248b9e92aDouglas Gregor SourceLocation LAngleLoc, EndProtoLoc; 10849bd1d8d174a9d15ae343246c8322299248b9e92aDouglas Gregor llvm::SmallVector<Decl *, 8> ProtocolDecl; 10859bd1d8d174a9d15ae343246c8322299248b9e92aDouglas Gregor llvm::SmallVector<SourceLocation, 8> ProtocolLocs; 108646f936e055d763437accd1e5a1bc49e7e5dbc0a3Douglas Gregor bool Result = ParseObjCProtocolReferences(ProtocolDecl, ProtocolLocs, false, 108746f936e055d763437accd1e5a1bc49e7e5dbc0a3Douglas Gregor LAngleLoc, EndProtoLoc); 10889bd1d8d174a9d15ae343246c8322299248b9e92aDouglas Gregor DS.setProtocolQualifiers(ProtocolDecl.data(), ProtocolDecl.size(), 10899bd1d8d174a9d15ae343246c8322299248b9e92aDouglas Gregor ProtocolLocs.data(), LAngleLoc); 10909bd1d8d174a9d15ae343246c8322299248b9e92aDouglas Gregor if (EndProtoLoc.isValid()) 10919bd1d8d174a9d15ae343246c8322299248b9e92aDouglas Gregor DS.SetRangeEnd(EndProtoLoc); 109246f936e055d763437accd1e5a1bc49e7e5dbc0a3Douglas Gregor return Result; 10939bd1d8d174a9d15ae343246c8322299248b9e92aDouglas Gregor} 10949bd1d8d174a9d15ae343246c8322299248b9e92aDouglas Gregor 10959bd1d8d174a9d15ae343246c8322299248b9e92aDouglas Gregor 1096dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-instance-variables: 1097dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// '{' objc-instance-variable-decl-list[opt] '}' 1098dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1099dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-instance-variable-decl-list: 1100dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-visibility-spec 1101dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-instance-variable-decl ';' 1102dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// ';' 1103dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-instance-variable-decl-list objc-visibility-spec 1104dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-instance-variable-decl-list objc-instance-variable-decl ';' 1105dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-instance-variable-decl-list ';' 1106dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1107dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-visibility-spec: 1108dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @private 1109dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @protected 1110dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @public 1111ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff/// @package [OBJC2] 1112dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1113dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-instance-variable-decl: 11141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// struct-declaration 1115dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1116d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallvoid Parser::ParseObjCClassInstanceVariables(Decl *interfaceDecl, 111783c481ade785a919ba21a33f9a8b1b21c1212fb3Fariborz Jahanian tok::ObjCKeywordKind visibility, 111860fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff SourceLocation atLoc) { 1119df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner assert(Tok.is(tok::l_brace) && "expected {"); 1120d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall llvm::SmallVector<Decl *, 32> AllIvarDecls; 1121e13594279a952537ac903325efff57e3edca79d9Chris Lattner 11221a0d31a3d7f14ddc6370ba912c778aece6c12cf0Douglas Gregor ParseScope ClassScope(this, Scope::DeclScope|Scope::ClassScope); 112372de6676bd30f9081ee4166bbe07b4c270258ce6Douglas Gregor 1124ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff SourceLocation LBraceLoc = ConsumeBrace(); // the "{" 11251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1126ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff // While we still have something to read, read the instance variables. 1127df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner while (Tok.isNot(tok::r_brace) && Tok.isNot(tok::eof)) { 1128ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff // Each iteration of this loop reads one objc-instance-variable-decl. 11291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1130ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff // Check for extraneous top-level semicolon. 1131df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::semi)) { 1132f13ca06e57ac094ed05ea08c26a499af1ba0ce88Douglas Gregor Diag(Tok, diag::ext_extra_ivar_semi) 1133849b243d4065f56742a4677d6dc8277609a151f8Douglas Gregor << FixItHint::CreateRemoval(Tok.getLocation()); 1134ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff ConsumeToken(); 1135ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff continue; 1136ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff } 11371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1138ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff // Set the default visibility to private. 1139df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::at)) { // parse objc-visibility-spec 1140ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff ConsumeToken(); // eat the @ sign 1141c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor 1142c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor if (Tok.is(tok::code_completion)) { 114323c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCAtVisibility(getCurScope()); 1144dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 1145c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor } 1146c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor 1147861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff switch (Tok.getObjCKeywordID()) { 1148ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff case tok::objc_private: 1149ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff case tok::objc_public: 1150ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff case tok::objc_protected: 1151ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff case tok::objc_package: 1152861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff visibility = Tok.getObjCKeywordID(); 1153ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff ConsumeToken(); 11541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump continue; 1155ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff default: 1156ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff Diag(Tok, diag::err_objc_illegal_visibility_spec); 1157ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff continue; 1158ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff } 1159ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff } 11601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1161c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor if (Tok.is(tok::code_completion)) { 116223c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteOrdinaryName(getCurScope(), 1163f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Sema::PCC_ObjCInstanceVariableList); 1164dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 1165c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor } 1166c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor 1167bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall struct ObjCIvarCallback : FieldCallback { 1168bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall Parser &P; 1169d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *IDecl; 1170bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall tok::ObjCKeywordKind visibility; 1171d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall llvm::SmallVectorImpl<Decl *> &AllIvarDecls; 1172bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall 1173d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall ObjCIvarCallback(Parser &P, Decl *IDecl, tok::ObjCKeywordKind V, 1174d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall llvm::SmallVectorImpl<Decl *> &AllIvarDecls) : 1175bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall P(P), IDecl(IDecl), visibility(V), AllIvarDecls(AllIvarDecls) { 1176bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall } 1177bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall 1178d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *invoke(FieldDeclarator &FD) { 1179bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall // Install the declarator into the interface decl. 1180d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *Field 118123c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor = P.Actions.ActOnIvar(P.getCurScope(), 1182bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall FD.D.getDeclSpec().getSourceRange().getBegin(), 1183bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall IDecl, FD.D, FD.BitfieldSize, visibility); 11840bd04596e4645ff145a046dfb3475f39674060d9Fariborz Jahanian if (Field) 11850bd04596e4645ff145a046dfb3475f39674060d9Fariborz Jahanian AllIvarDecls.push_back(Field); 1186bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall return Field; 1187bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall } 1188bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall } Callback(*this, interfaceDecl, visibility, AllIvarDecls); 1189d097be8f81fbf4ed96ac10bae18562dd8202666bFariborz Jahanian 1190e13594279a952537ac903325efff57e3edca79d9Chris Lattner // Parse all the comma separated declarators. 11910b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall DeclSpec DS(AttrFactory); 1192bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall ParseStructDeclaration(DS, Callback); 11931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1194df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::semi)) { 1195ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff ConsumeToken(); 1196ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff } else { 1197ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff Diag(Tok, diag::err_expected_semi_decl_list); 1198ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff // Skip to end of block or statement 1199ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff SkipUntil(tok::r_brace, true, true); 1200ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff } 1201ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff } 120260fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff SourceLocation RBraceLoc = MatchRHSPunctuation(tok::r_brace, LBraceLoc); 1203d097be8f81fbf4ed96ac10bae18562dd8202666bFariborz Jahanian Actions.ActOnLastBitfield(RBraceLoc, interfaceDecl, AllIvarDecls); 12048749be53f53384e7846502791ceda6c657228d07Steve Naroff // Call ActOnFields() even if we don't have any decls. This is useful 12058749be53f53384e7846502791ceda6c657228d07Steve Naroff // for code rewriting tools that need to be aware of the empty list. 120623c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.ActOnFields(getCurScope(), atLoc, interfaceDecl, 1207beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad AllIvarDecls.data(), AllIvarDecls.size(), 12081bfe1c2129771c06fb58ae5e8c079ae30e138309Daniel Dunbar LBraceLoc, RBraceLoc, 0); 1209ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff return; 12105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 1211dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff 1212dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-declaration: 1213dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-definition 1214dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-forward-reference 1215dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1216dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-definition: 12171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// @protocol identifier 12181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// objc-protocol-refs[opt] 12191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// objc-interface-decl-list 1220dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @end 1221dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1222dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-forward-reference: 1223dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @protocol identifier-list ';' 1224dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1225dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// "@protocol identifier ;" should be resolved as "@protocol 12263536b443bc50d58a79f14fca9b6842541a434854Steve Naroff/// identifier-list ;": objc-interface-decl-list may not start with a 1227dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// semicolon in the first alternative if objc-protocol-refs are omitted. 1228d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseObjCAtProtocolDeclaration(SourceLocation AtLoc, 12297f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall ParsedAttributes &attrs) { 1230861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff assert(Tok.isObjCAtKeyword(tok::objc_protocol) && 12317ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff "ParseObjCAtProtocolDeclaration(): Expected @protocol"); 12327ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff ConsumeToken(); // the "protocol" identifier 12331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1234083128f6b13dfa4fc615a838c49b516d901b1ac0Douglas Gregor if (Tok.is(tok::code_completion)) { 123523c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCProtocolDecl(getCurScope()); 1236dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 1237083128f6b13dfa4fc615a838c49b516d901b1ac0Douglas Gregor } 1238083128f6b13dfa4fc615a838c49b516d901b1ac0Douglas Gregor 1239df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 12407ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff Diag(Tok, diag::err_expected_ident); // missing protocol name. 1241d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 12427ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff } 12437ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff // Save the protocol name, then consume it. 12447ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff IdentifierInfo *protocolName = Tok.getIdentifierInfo(); 12457ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff SourceLocation nameLoc = ConsumeToken(); 12461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1247df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::semi)) { // forward declaration of one protocol. 12487caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner IdentifierLocPair ProtoInfo(protocolName, nameLoc); 12497ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff ConsumeToken(); 12501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return Actions.ActOnForwardProtocolDeclaration(AtLoc, &ProtoInfo, 1, 12517f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall attrs.getList()); 12527ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff } 12531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1254df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::comma)) { // list of forward declarations. 12557caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner llvm::SmallVector<IdentifierLocPair, 8> ProtocolRefs; 12567caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner ProtocolRefs.push_back(std::make_pair(protocolName, nameLoc)); 12577caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner 12587ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff // Parse the list of forward declarations. 12597ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff while (1) { 12607ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff ConsumeToken(); // the ',' 1261df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 12627ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff Diag(Tok, diag::err_expected_ident); 12637ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff SkipUntil(tok::semi); 1264d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 12657ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff } 12667caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner ProtocolRefs.push_back(IdentifierLocPair(Tok.getIdentifierInfo(), 12677caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner Tok.getLocation())); 12687ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff ConsumeToken(); // the identifier 12691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1270df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::comma)) 12717ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff break; 12727ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff } 12737ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff // Consume the ';'. 12747ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff if (ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@protocol")) 1275d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 12761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1277e440eb8158e71deb1e4ab11618ae3d680aac6da1Steve Naroff return Actions.ActOnForwardProtocolDeclaration(AtLoc, 12781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump &ProtocolRefs[0], 1279bc1c877fe28fb6a825f0b226a0a2da99e713ea03Fariborz Jahanian ProtocolRefs.size(), 12807f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall attrs.getList()); 12817caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner } 12821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12837ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff // Last, and definitely not least, parse a protocol declaration. 128471b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis SourceLocation LAngleLoc, EndProtoLoc; 12857caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner 1286d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall llvm::SmallVector<Decl *, 8> ProtocolRefs; 128771b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis llvm::SmallVector<SourceLocation, 8> ProtocolLocs; 12887caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner if (Tok.is(tok::less) && 128971b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis ParseObjCProtocolReferences(ProtocolRefs, ProtocolLocs, false, 129071b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis LAngleLoc, EndProtoLoc)) 1291d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 12921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1293d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ProtoType = 1294e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner Actions.ActOnStartProtocolInterface(AtLoc, protocolName, nameLoc, 1295beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad ProtocolRefs.data(), 1296beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad ProtocolRefs.size(), 129718df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor ProtocolLocs.data(), 12987f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall EndProtoLoc, attrs.getList()); 129925e077d59a8e8e43b65882b69610a3d5e2aaf53cFariborz Jahanian ParseObjCInterfaceDeclList(ProtoType, tok::objc_protocol); 1300bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner return ProtoType; 1301dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff} 1302dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff 1303dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-implementation: 1304dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-implementation-prologue 1305dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-category-implementation-prologue 1306dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1307dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-implementation-prologue: 1308dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @implementation identifier objc-superclass[opt] 1309dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-instance-variables[opt] 1310dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1311dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-category-implementation-prologue: 1312dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @implementation identifier ( identifier ) 1313d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseObjCAtImplementationDeclaration( 1314ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian SourceLocation atLoc) { 1315ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian assert(Tok.isObjCAtKeyword(tok::objc_implementation) && 1316ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian "ParseObjCAtImplementationDeclaration(): Expected @implementation"); 1317ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); // the "implementation" identifier 13181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13193b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor // Code completion after '@implementation'. 13203b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor if (Tok.is(tok::code_completion)) { 132123c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCImplementationDecl(getCurScope()); 1322dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 13233b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor } 13243b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor 1325df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 1326ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian Diag(Tok, diag::err_expected_ident); // missing class or category name. 1327d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 1328ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1329ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian // We have a class or category name - consume it. 1330ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian IdentifierInfo *nameId = Tok.getIdentifierInfo(); 1331ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian SourceLocation nameLoc = ConsumeToken(); // consume class or category name 13321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (Tok.is(tok::l_paren)) { 1334ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian // we have a category implementation. 1335dec0984fce504a39a7f085774fb67cfd9957be58Jeffrey Yasskin ConsumeParen(); 1336ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian SourceLocation categoryLoc, rparenLoc; 1337ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian IdentifierInfo *categoryId = 0; 13381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 133933ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor if (Tok.is(tok::code_completion)) { 134023c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCImplementationCategory(getCurScope(), nameId, nameLoc); 1341dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 134233ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor } 134333ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor 1344df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::identifier)) { 1345ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian categoryId = Tok.getIdentifierInfo(); 1346ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian categoryLoc = ConsumeToken(); 1347ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } else { 1348ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian Diag(Tok, diag::err_expected_ident); // missing category name. 1349d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 13501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 1351df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::r_paren)) { 1352ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian Diag(Tok, diag::err_expected_rparen); 1353ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian SkipUntil(tok::r_paren, false); // don't stop at ';' 1354d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 1355ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1356ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian rparenLoc = ConsumeParen(); 1357d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ImplCatType = Actions.ActOnStartCategoryImplementation( 13581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump atLoc, nameId, nameLoc, categoryId, 13598f3fde00ad4d4f943321e338b914ae4740711c84Fariborz Jahanian categoryLoc); 1360a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCImpDecl = ImplCatType; 136163e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian PendingObjCImpDecl.push_back(ObjCImpDecl); 1362d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 1363ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1364ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian // We have a class implementation 1365ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian SourceLocation superClassLoc; 1366ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian IdentifierInfo *superClassId = 0; 1367df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::colon)) { 1368ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian // We have a super class 1369ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); 1370df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 1371ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian Diag(Tok, diag::err_expected_ident); // missing super class name. 1372d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 1373ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1374ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian superClassId = Tok.getIdentifierInfo(); 1375ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian superClassLoc = ConsumeToken(); // Consume super class name 1376ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1377d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ImplClsType = Actions.ActOnStartClassImplementation( 1378cb53b361bce341c8591333c6997f62e480acc0b4Chris Lattner atLoc, nameId, nameLoc, 1379ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian superClassId, superClassLoc); 13801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 138160fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff if (Tok.is(tok::l_brace)) // we have ivars 138283c481ade785a919ba21a33f9a8b1b21c1212fb3Fariborz Jahanian ParseObjCClassInstanceVariables(ImplClsType/*FIXME*/, 138301f1bfc3284d5817517d35217885ea9ecb252817Fariborz Jahanian tok::objc_private, atLoc); 1384a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCImpDecl = ImplClsType; 138563e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian PendingObjCImpDecl.push_back(ObjCImpDecl); 138663e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian 1387d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 13885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 138960fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff 1390d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseObjCAtEndDeclaration(SourceRange atEnd) { 1391ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian assert(Tok.isObjCAtKeyword(tok::objc_end) && 1392ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian "ParseObjCAtEndDeclaration(): Expected @end"); 1393d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *Result = ObjCImpDecl; 1394ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); // the "end" identifier 1395a6e3ac514c924879699c6b0b1201028f0091044fFariborz Jahanian if (ObjCImpDecl) { 139623c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.ActOnAtEnd(getCurScope(), atEnd, ObjCImpDecl); 1397d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall ObjCImpDecl = 0; 139863e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian PendingObjCImpDecl.pop_back(); 1399a6e3ac514c924879699c6b0b1201028f0091044fFariborz Jahanian } 1400782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek else { 1401782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek // missing @implementation 140264089cece350472c04b420c497ae391443353325Fariborz Jahanian Diag(atEnd.getBegin(), diag::err_expected_implementation); 1403782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek } 1404a6e3ac514c924879699c6b0b1201028f0091044fFariborz Jahanian return Result; 14055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 1406e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian 14073fe104154dd2e8ffb351142d74f308938b5c99bfFariborz JahanianParser::DeclGroupPtrTy Parser::FinishPendingObjCActions() { 14083fe104154dd2e8ffb351142d74f308938b5c99bfFariborz Jahanian Actions.DiagnoseUseOfUnimplementedSelectors(); 140963e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian if (PendingObjCImpDecl.empty()) 1410d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return Actions.ConvertDeclToDeclGroup(0); 1411d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ImpDecl = PendingObjCImpDecl.pop_back_val(); 141223c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.ActOnAtEnd(getCurScope(), SourceRange(), ImpDecl); 141363e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian return Actions.ConvertDeclToDeclGroup(ImpDecl); 141463e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian} 141563e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian 1416e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian/// compatibility-alias-decl: 1417e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian/// @compatibility_alias alias-name class-name ';' 1418e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian/// 1419d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseObjCAtAliasDeclaration(SourceLocation atLoc) { 1420e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian assert(Tok.isObjCAtKeyword(tok::objc_compatibility_alias) && 1421e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian "ParseObjCAtAliasDeclaration(): Expected @compatibility_alias"); 1422e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian ConsumeToken(); // consume compatibility_alias 1423df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 1424e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian Diag(Tok, diag::err_expected_ident); 1425d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 1426e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian } 1427243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian IdentifierInfo *aliasId = Tok.getIdentifierInfo(); 1428243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian SourceLocation aliasLoc = ConsumeToken(); // consume alias-name 1429df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 1430e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian Diag(Tok, diag::err_expected_ident); 1431d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 1432e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian } 1433243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian IdentifierInfo *classId = Tok.getIdentifierInfo(); 1434243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian SourceLocation classLoc = ConsumeToken(); // consume class-name; 1435e6bf90aec0044342ffccd13201b8a3a31a985a4bDouglas Gregor ExpectAndConsume(tok::semi, diag::err_expected_semi_after, 1436e6bf90aec0044342ffccd13201b8a3a31a985a4bDouglas Gregor "@compatibility_alias"); 1437b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return Actions.ActOnCompatiblityAlias(atLoc, aliasId, aliasLoc, 1438b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner classId, classLoc); 14395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 14405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1441ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-synthesis: 1442ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// @synthesize property-ivar-list ';' 1443ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// 1444ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-ivar-list: 1445ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-ivar 1446ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-ivar-list ',' property-ivar 1447ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// 1448ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-ivar: 1449ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// identifier 1450ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// identifier '=' identifier 1451ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// 1452d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseObjCPropertySynthesize(SourceLocation atLoc) { 1453ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian assert(Tok.isObjCAtKeyword(tok::objc_synthesize) && 1454ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian "ParseObjCPropertyDynamic(): Expected '@synthesize'"); 1455dec0984fce504a39a7f085774fb67cfd9957be58Jeffrey Yasskin ConsumeToken(); // consume synthesize 14561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1457b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor while (true) { 1458322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor if (Tok.is(tok::code_completion)) { 145923c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCPropertyDefinition(getCurScope(), ObjCImpDecl); 1460dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 1461322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor } 1462322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor 1463b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor if (Tok.isNot(tok::identifier)) { 1464b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor Diag(Tok, diag::err_synthesized_property_name); 1465b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor SkipUntil(tok::semi); 1466d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 1467b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor } 1468b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor 1469f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian IdentifierInfo *propertyIvar = 0; 1470f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian IdentifierInfo *propertyId = Tok.getIdentifierInfo(); 1471f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian SourceLocation propertyLoc = ConsumeToken(); // consume property name 1472a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor SourceLocation propertyIvarLoc; 1473df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::equal)) { 1474ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian // property '=' ivar-name 1475ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); // consume '=' 1476322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor 1477322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor if (Tok.is(tok::code_completion)) { 147823c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCPropertySynthesizeIvar(getCurScope(), propertyId, 1479322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor ObjCImpDecl); 1480dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 1481322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor } 1482322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor 1483df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 1484ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian Diag(Tok, diag::err_expected_ident); 1485ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian break; 1486ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1487f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian propertyIvar = Tok.getIdentifierInfo(); 1488a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor propertyIvarLoc = ConsumeToken(); // consume ivar-name 1489ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 149023c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.ActOnPropertyImplDecl(getCurScope(), atLoc, propertyLoc, true, ObjCImpDecl, 1491a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor propertyId, propertyIvar, propertyIvarLoc); 1492df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::comma)) 1493ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian break; 1494ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); // consume ',' 1495ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1496e6bf90aec0044342ffccd13201b8a3a31a985a4bDouglas Gregor ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@synthesize"); 1497d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 1498ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian} 1499ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian 1500ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-dynamic: 1501ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// @dynamic property-list 1502ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// 1503ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-list: 1504ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// identifier 1505ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-list ',' identifier 1506ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// 1507d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseObjCPropertyDynamic(SourceLocation atLoc) { 1508ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian assert(Tok.isObjCAtKeyword(tok::objc_dynamic) && 1509ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian "ParseObjCPropertyDynamic(): Expected '@dynamic'"); 1510dec0984fce504a39a7f085774fb67cfd9957be58Jeffrey Yasskin ConsumeToken(); // consume dynamic 1511424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor while (true) { 1512424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor if (Tok.is(tok::code_completion)) { 151323c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCPropertyDefinition(getCurScope(), ObjCImpDecl); 1514dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 1515424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor } 1516424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor 1517424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor if (Tok.isNot(tok::identifier)) { 1518424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor Diag(Tok, diag::err_expected_ident); 1519424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor SkipUntil(tok::semi); 1520d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 1521424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor } 1522424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor 1523c35b9e4e2efad727538c848cf30d4b0eb1031dc9Fariborz Jahanian IdentifierInfo *propertyId = Tok.getIdentifierInfo(); 1524c35b9e4e2efad727538c848cf30d4b0eb1031dc9Fariborz Jahanian SourceLocation propertyLoc = ConsumeToken(); // consume property name 152523c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.ActOnPropertyImplDecl(getCurScope(), atLoc, propertyLoc, false, ObjCImpDecl, 1526a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor propertyId, 0, SourceLocation()); 1527c35b9e4e2efad727538c848cf30d4b0eb1031dc9Fariborz Jahanian 1528df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::comma)) 1529ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian break; 1530ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); // consume ',' 1531ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1532e6bf90aec0044342ffccd13201b8a3a31a985a4bDouglas Gregor ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@dynamic"); 1533d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 1534ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian} 15351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1536397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// objc-throw-statement: 1537397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// throw expression[opt]; 1538397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// 153960d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult Parser::ParseObjCThrowStmt(SourceLocation atLoc) { 154060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Res; 1541397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian ConsumeToken(); // consume throw 1542df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::semi)) { 154339f8f159c488a900e5958d5aab3e467af9ec8a2bFariborz Jahanian Res = ParseExpression(); 15440e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Res.isInvalid()) { 1545397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian SkipUntil(tok::semi); 154643bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 1547397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian } 1548397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian } 154902418c7f0cb8bb83f1a1a1fad9bf6104efa83e0eTed Kremenek // consume ';' 155002418c7f0cb8bb83f1a1a1fad9bf6104efa83e0eTed Kremenek ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@throw"); 15519ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return Actions.ActOnObjCAtThrowStmt(atLoc, Res.take(), getCurScope()); 1552397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian} 1553397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian 1554c385c90c68dfa376650e2facfbb444b2ec9bd110Fariborz Jahanian/// objc-synchronized-statement: 155578a677bbb5fa115fa0995b5783adeeefad67167eFariborz Jahanian/// @synchronized '(' expression ')' compound-statement 1556c385c90c68dfa376650e2facfbb444b2ec9bd110Fariborz Jahanian/// 155760d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 155843bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian RedlParser::ParseObjCSynchronizedStmt(SourceLocation atLoc) { 1559fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian ConsumeToken(); // consume synchronized 1560fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian if (Tok.isNot(tok::l_paren)) { 15611ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_lparen_after) << "@synchronized"; 156243bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 1563fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian } 1564fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian ConsumeParen(); // '(' 156560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Res(ParseExpression()); 15660e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Res.isInvalid()) { 1567fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian SkipUntil(tok::semi); 156843bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 1569fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian } 1570fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian if (Tok.isNot(tok::r_paren)) { 15711ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_lbrace); 157243bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 1573fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian } 1574fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian ConsumeParen(); // ')' 157578a677bbb5fa115fa0995b5783adeeefad67167eFariborz Jahanian if (Tok.isNot(tok::l_brace)) { 15761ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_lbrace); 157743bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 157878a677bbb5fa115fa0995b5783adeeefad67167eFariborz Jahanian } 15793ac438c383a4a9a73c76a05c76ec5d02f10a3c52Steve Naroff // Enter a scope to hold everything within the compound stmt. Compound 15803ac438c383a4a9a73c76a05c76ec5d02f10a3c52Steve Naroff // statements can always hold declarations. 15818935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor ParseScope BodyScope(this, Scope::DeclScope); 15823ac438c383a4a9a73c76a05c76ec5d02f10a3c52Steve Naroff 158360d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult SynchBody(ParseCompoundStatementBody()); 15840e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl 15858935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor BodyScope.Exit(); 15860e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (SynchBody.isInvalid()) 1587fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian SynchBody = Actions.ActOnNullStmt(Tok.getLocation()); 15889ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return Actions.ActOnObjCAtSynchronizedStmt(atLoc, Res.take(), SynchBody.take()); 1589c385c90c68dfa376650e2facfbb444b2ec9bd110Fariborz Jahanian} 1590c385c90c68dfa376650e2facfbb444b2ec9bd110Fariborz Jahanian 1591397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// objc-try-catch-statement: 1592397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// @try compound-statement objc-catch-list[opt] 1593397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// @try compound-statement objc-catch-list[opt] @finally compound-statement 1594397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// 1595397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// objc-catch-list: 1596397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// @catch ( parameter-declaration ) compound-statement 1597397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// objc-catch-list @catch ( catch-parameter-declaration ) compound-statement 1598397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// catch-parameter-declaration: 1599397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// parameter-declaration 1600397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// '...' [OBJC2] 1601397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// 160260d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult Parser::ParseObjCTryStmt(SourceLocation atLoc) { 1603397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian bool catch_or_finally_seen = false; 160443bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl 1605397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian ConsumeToken(); // consume try 1606df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::l_brace)) { 16071ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_lbrace); 160843bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 1609397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian } 16108f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor StmtVector CatchStmts(Actions); 161160d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult FinallyStmt; 16128935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor ParseScope TryScope(this, Scope::DeclScope); 161360d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult TryBody(ParseCompoundStatementBody()); 16148935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor TryScope.Exit(); 16150e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (TryBody.isInvalid()) 1616bd49a647afd9cc534fef13cadf652d4e9c396e2bFariborz Jahanian TryBody = Actions.ActOnNullStmt(Tok.getLocation()); 1617a55e52c0802cae3b7c366a05c461d3d15074c1a3Sebastian Redl 1618df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner while (Tok.is(tok::at)) { 16196b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner // At this point, we need to lookahead to determine if this @ is the start 16206b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner // of an @catch or @finally. We don't want to consume the @ token if this 16216b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner // is an @try or @encode or something else. 16226b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner Token AfterAt = GetLookAheadToken(1); 16236b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner if (!AfterAt.isObjCAtKeyword(tok::objc_catch) && 16246b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner !AfterAt.isObjCAtKeyword(tok::objc_finally)) 16256b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner break; 16260e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl 1627161a9c5afaafb4d527b7efba9675a8b2cbbe32e0Fariborz Jahanian SourceLocation AtCatchFinallyLoc = ConsumeToken(); 1628cb53b361bce341c8591333c6997f62e480acc0b4Chris Lattner if (Tok.isObjCAtKeyword(tok::objc_catch)) { 1629d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *FirstPart = 0; 16303b1191d7eaf2f4984564e01ab84b6713a9d80e70Fariborz Jahanian ConsumeToken(); // consume catch 1631df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::l_paren)) { 1632397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian ConsumeParen(); 1633e21dd6ffef4585fa43cd3586ed971217d65bf56cSteve Naroff ParseScope CatchScope(this, Scope::DeclScope|Scope::AtCatchScope); 1634df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::ellipsis)) { 16350b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall DeclSpec DS(AttrFactory); 1636397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian ParseDeclarationSpecifiers(DS); 163743bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl // For some odd reason, the name of the exception variable is 16381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // optional. As a result, we need to use "PrototypeContext", because 16397ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff // we must accept either 'declarator' or 'abstract-declarator' here. 16407ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff Declarator ParmDecl(DS, Declarator::PrototypeContext); 16417ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff ParseDeclarator(ParmDecl); 16427ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff 16434e6c0d19b7c072758922cf80525a81aeefc6e64bDouglas Gregor // Inform the actions module about the declarator, so it 16447ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff // gets added to the current scope. 164523c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor FirstPart = Actions.ActOnObjCExceptionDecl(getCurScope(), ParmDecl); 164664515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff } else 1647397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian ConsumeToken(); // consume '...' 16481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 164993a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff SourceLocation RParenLoc; 16501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 165193a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff if (Tok.is(tok::r_paren)) 165293a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff RParenLoc = ConsumeParen(); 165393a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff else // Skip over garbage, until we get to ')'. Eat the ')'. 165493a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff SkipUntil(tok::r_paren, true, false); 165593a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff 165660d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult CatchBody(true); 1657c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner if (Tok.is(tok::l_brace)) 1658c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner CatchBody = ParseCompoundStatementBody(); 1659c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner else 1660c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner Diag(Tok, diag::err_expected_lbrace); 16610e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (CatchBody.isInvalid()) 16623b1191d7eaf2f4984564e01ab84b6713a9d80e70Fariborz Jahanian CatchBody = Actions.ActOnNullStmt(Tok.getLocation()); 16638f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor 166460d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Catch = Actions.ActOnObjCAtCatchStmt(AtCatchFinallyLoc, 16658f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor RParenLoc, 16668f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor FirstPart, 16679ae2f076ca5ab1feb3ba95629099ec2319833701John McCall CatchBody.take()); 16688f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor if (!Catch.isInvalid()) 16698f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor CatchStmts.push_back(Catch.release()); 16708f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor 167164515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff } else { 16721ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(AtCatchFinallyLoc, diag::err_expected_lparen_after) 16731ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner << "@catch clause"; 167443bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 1675397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian } 1676397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian catch_or_finally_seen = true; 16776b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner } else { 16786b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner assert(Tok.isObjCAtKeyword(tok::objc_finally) && "Lookahead confused?"); 167964515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff ConsumeToken(); // consume finally 16808935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor ParseScope FinallyScope(this, Scope::DeclScope); 16810e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl 168260d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult FinallyBody(true); 1683c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner if (Tok.is(tok::l_brace)) 1684c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner FinallyBody = ParseCompoundStatementBody(); 1685c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner else 1686c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner Diag(Tok, diag::err_expected_lbrace); 16870e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (FinallyBody.isInvalid()) 1688161a9c5afaafb4d527b7efba9675a8b2cbbe32e0Fariborz Jahanian FinallyBody = Actions.ActOnNullStmt(Tok.getLocation()); 16890e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl FinallyStmt = Actions.ActOnObjCAtFinallyStmt(AtCatchFinallyLoc, 16909ae2f076ca5ab1feb3ba95629099ec2319833701John McCall FinallyBody.take()); 1691397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian catch_or_finally_seen = true; 1692397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian break; 1693397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian } 1694397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian } 1695bd49a647afd9cc534fef13cadf652d4e9c396e2bFariborz Jahanian if (!catch_or_finally_seen) { 1696397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian Diag(atLoc, diag::err_missing_catch_finally); 169743bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 1698bd49a647afd9cc534fef13cadf652d4e9c396e2bFariborz Jahanian } 16998f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor 17009ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return Actions.ActOnObjCAtTryStmt(atLoc, TryBody.take(), 17018f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor move_arg(CatchStmts), 17029ae2f076ca5ab1feb3ba95629099ec2319833701John McCall FinallyStmt.take()); 1703397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian} 1704ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian 1705f85e193739c953358c865005855253af4f68a497John McCall/// objc-autoreleasepool-statement: 1706f85e193739c953358c865005855253af4f68a497John McCall/// @autoreleasepool compound-statement 1707f85e193739c953358c865005855253af4f68a497John McCall/// 1708f85e193739c953358c865005855253af4f68a497John McCallStmtResult 1709f85e193739c953358c865005855253af4f68a497John McCallParser::ParseObjCAutoreleasePoolStmt(SourceLocation atLoc) { 1710f85e193739c953358c865005855253af4f68a497John McCall ConsumeToken(); // consume autoreleasepool 1711f85e193739c953358c865005855253af4f68a497John McCall if (Tok.isNot(tok::l_brace)) { 1712f85e193739c953358c865005855253af4f68a497John McCall Diag(Tok, diag::err_expected_lbrace); 1713f85e193739c953358c865005855253af4f68a497John McCall return StmtError(); 1714f85e193739c953358c865005855253af4f68a497John McCall } 1715f85e193739c953358c865005855253af4f68a497John McCall // Enter a scope to hold everything within the compound stmt. Compound 1716f85e193739c953358c865005855253af4f68a497John McCall // statements can always hold declarations. 1717f85e193739c953358c865005855253af4f68a497John McCall ParseScope BodyScope(this, Scope::DeclScope); 1718f85e193739c953358c865005855253af4f68a497John McCall 1719f85e193739c953358c865005855253af4f68a497John McCall StmtResult AutoreleasePoolBody(ParseCompoundStatementBody()); 1720f85e193739c953358c865005855253af4f68a497John McCall 1721f85e193739c953358c865005855253af4f68a497John McCall BodyScope.Exit(); 1722f85e193739c953358c865005855253af4f68a497John McCall if (AutoreleasePoolBody.isInvalid()) 1723f85e193739c953358c865005855253af4f68a497John McCall AutoreleasePoolBody = Actions.ActOnNullStmt(Tok.getLocation()); 1724f85e193739c953358c865005855253af4f68a497John McCall return Actions.ActOnObjCAutoreleasePoolStmt(atLoc, 1725f85e193739c953358c865005855253af4f68a497John McCall AutoreleasePoolBody.take()); 1726f85e193739c953358c865005855253af4f68a497John McCall} 1727f85e193739c953358c865005855253af4f68a497John McCall 17283536b443bc50d58a79f14fca9b6842541a434854Steve Naroff/// objc-method-def: objc-method-proto ';'[opt] '{' body '}' 1729ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// 1730d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseObjCMethodDefinition() { 1731d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *MDecl = ParseObjCMethodPrototype(ObjCImpDecl); 17321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1733f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall PrettyDeclStackTraceEntry CrashInfo(Actions, MDecl, Tok.getLocation(), 1734f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall "parsing Objective-C method"); 17351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1736ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian // parse optional ';' 1737209a8c2fa23636f6d065d618e7078e164903f5cdFariborz Jahanian if (Tok.is(tok::semi)) { 1738496e45ef3350fabc312c5a807d308c65c50af4dbTed Kremenek if (ObjCImpDecl) { 1739496e45ef3350fabc312c5a807d308c65c50af4dbTed Kremenek Diag(Tok, diag::warn_semicolon_before_method_body) 1740849b243d4065f56742a4677d6dc8277609a151f8Douglas Gregor << FixItHint::CreateRemoval(Tok.getLocation()); 1741496e45ef3350fabc312c5a807d308c65c50af4dbTed Kremenek } 1742ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); 1743209a8c2fa23636f6d065d618e7078e164903f5cdFariborz Jahanian } 1744ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian 1745409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // We should have an opening brace now. 1746df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::l_brace)) { 1747da323adbb99cee19a203ead852d5d9bfebb23fb7Steve Naroff Diag(Tok, diag::err_expected_method_body); 17481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1749409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // Skip over garbage, until we get to '{'. Don't eat the '{'. 1750409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff SkipUntil(tok::l_brace, true, true); 17511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1752409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // If we didn't find the '{', bail out. 1753409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff if (Tok.isNot(tok::l_brace)) 1754d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 1755ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1756409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff SourceLocation BraceLoc = Tok.getLocation(); 17571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1758409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // Enter a scope for the method body. 175915faee19fdb9017dd6d08a690427b18c3b062c2dChris Lattner ParseScope BodyScope(this, 176015faee19fdb9017dd6d08a690427b18c3b062c2dChris Lattner Scope::ObjCMethodScope|Scope::FnScope|Scope::DeclScope); 17611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1762409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // Tell the actions module that we have entered a method definition with the 1763394f3f483fa4e7b472630cfcd03f7840520958c5Steve Naroff // specified Declarator for the method. 176423c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.ActOnStartOfObjCMethodDef(getCurScope(), MDecl); 176561364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl 1766c9977d09a2de7f7d2245973413d4caf86c736640Douglas Gregor if (PP.isCodeCompletionEnabled()) { 1767c9977d09a2de7f7d2245973413d4caf86c736640Douglas Gregor if (trySkippingFunctionBodyForCodeCompletion()) { 1768c9977d09a2de7f7d2245973413d4caf86c736640Douglas Gregor BodyScope.Exit(); 1769b162054ba8f5b64fe87fbc4837933ab23eebd52bArgyrios Kyrtzidis return Actions.ActOnFinishFunctionBody(MDecl, 0); 1770c9977d09a2de7f7d2245973413d4caf86c736640Douglas Gregor } 1771c9977d09a2de7f7d2245973413d4caf86c736640Douglas Gregor } 17720fe5397b26695926a835fa99eceb7fc879b307afArgyrios Kyrtzidis 177360d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult FnBody(ParseCompoundStatementBody()); 177461364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl 1775409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // If the function body could not be parsed, make a bogus compoundstmt. 17760e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (FnBody.isInvalid()) 1777a60528cdac7deee3991c2b48af4df4f315e49e9dSebastian Redl FnBody = Actions.ActOnCompoundStmt(BraceLoc, BraceLoc, 1778a60528cdac7deee3991c2b48af4df4f315e49e9dSebastian Redl MultiStmtArg(Actions), false); 1779798d119415323ebcd029ffe1e0fb442a4ca8adbbSebastian Redl 1780409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // Leave the function body scope. 17818935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor BodyScope.Exit(); 1782c9977d09a2de7f7d2245973413d4caf86c736640Douglas Gregor 1783c9977d09a2de7f7d2245973413d4caf86c736640Douglas Gregor // TODO: Pass argument information. 1784c9977d09a2de7f7d2245973413d4caf86c736640Douglas Gregor Actions.ActOnFinishFunctionBody(MDecl, FnBody.take()); 178571c0a951d08dc7a2a057df8c15f22b36f6aa47c7Steve Naroff return MDecl; 17865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 17875508518a2702b00be3b15a26d772bde968972f54Anders Carlsson 178860d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult Parser::ParseObjCAtStatement(SourceLocation AtLoc) { 17899a0c85e640a08174569a303db22981612f05d385Douglas Gregor if (Tok.is(tok::code_completion)) { 179023c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCAtStatement(getCurScope()); 1791dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 17929a0c85e640a08174569a303db22981612f05d385Douglas Gregor return StmtError(); 17935d8031687d086701b4dadaab3e0de1def448da9dChris Lattner } 17945d8031687d086701b4dadaab3e0de1def448da9dChris Lattner 17955d8031687d086701b4dadaab3e0de1def448da9dChris Lattner if (Tok.isObjCAtKeyword(tok::objc_try)) 17966b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner return ParseObjCTryStmt(AtLoc); 17975d8031687d086701b4dadaab3e0de1def448da9dChris Lattner 17985d8031687d086701b4dadaab3e0de1def448da9dChris Lattner if (Tok.isObjCAtKeyword(tok::objc_throw)) 179964515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff return ParseObjCThrowStmt(AtLoc); 18005d8031687d086701b4dadaab3e0de1def448da9dChris Lattner 18015d8031687d086701b4dadaab3e0de1def448da9dChris Lattner if (Tok.isObjCAtKeyword(tok::objc_synchronized)) 180264515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff return ParseObjCSynchronizedStmt(AtLoc); 1803f85e193739c953358c865005855253af4f68a497John McCall 1804f85e193739c953358c865005855253af4f68a497John McCall if (Tok.isObjCAtKeyword(tok::objc_autoreleasepool)) 1805f85e193739c953358c865005855253af4f68a497John McCall return ParseObjCAutoreleasePoolStmt(AtLoc); 18065d8031687d086701b4dadaab3e0de1def448da9dChris Lattner 180760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Res(ParseExpressionWithLeadingAt(AtLoc)); 18080e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Res.isInvalid()) { 180964515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff // If the expression is invalid, skip ahead to the next semicolon. Not 181064515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff // doing this opens us up to the possibility of infinite loops if 181164515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff // ParseExpression does not consume any tokens. 181264515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff SkipUntil(tok::semi); 181343bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 181464515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff } 18155d8031687d086701b4dadaab3e0de1def448da9dChris Lattner 181664515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff // Otherwise, eat the semicolon. 18179ba23b4ceacd77cd264501690a7a9e94184ef71bDouglas Gregor ExpectAndConsumeSemi(diag::err_expected_semi_after_expr); 18189ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return Actions.ActOnExprStmt(Actions.MakeFullExpr(Res.take())); 181964515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff} 182064515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff 182160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult Parser::ParseObjCAtExpression(SourceLocation AtLoc) { 18225508518a2702b00be3b15a26d772bde968972f54Anders Carlsson switch (Tok.getKind()) { 18239a0c85e640a08174569a303db22981612f05d385Douglas Gregor case tok::code_completion: 182423c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCAtExpression(getCurScope()); 1825dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 18269a0c85e640a08174569a303db22981612f05d385Douglas Gregor return ExprError(); 18279a0c85e640a08174569a303db22981612f05d385Douglas Gregor 1828b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner case tok::string_literal: // primary-expression: string-literal 1829b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner case tok::wide_string_literal: 18301d922960e083906a586609ac6978678147250177Sebastian Redl return ParsePostfixExpressionSuffix(ParseObjCStringLiteral(AtLoc)); 1831b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner default: 18324fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner if (Tok.getIdentifierInfo() == 0) 18331d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(AtLoc, diag::err_unexpected_at)); 18342f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl 18354fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner switch (Tok.getIdentifierInfo()->getObjCKeywordID()) { 18364fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner case tok::objc_encode: 18371d922960e083906a586609ac6978678147250177Sebastian Redl return ParsePostfixExpressionSuffix(ParseObjCEncodeExpression(AtLoc)); 18384fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner case tok::objc_protocol: 18391d922960e083906a586609ac6978678147250177Sebastian Redl return ParsePostfixExpressionSuffix(ParseObjCProtocolExpression(AtLoc)); 18404fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner case tok::objc_selector: 18411d922960e083906a586609ac6978678147250177Sebastian Redl return ParsePostfixExpressionSuffix(ParseObjCSelectorExpression(AtLoc)); 18424fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner default: 18431d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(AtLoc, diag::err_unexpected_at)); 18444fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner } 18455508518a2702b00be3b15a26d772bde968972f54Anders Carlsson } 18465508518a2702b00be3b15a26d772bde968972f54Anders Carlsson} 18475508518a2702b00be3b15a26d772bde968972f54Anders Carlsson 18486aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// \brirg Parse the receiver of an Objective-C++ message send. 18496aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// 18506aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// This routine parses the receiver of a message send in 18516aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// Objective-C++ either as a type or as an expression. Note that this 18526aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// routine must not be called to parse a send to 'super', since it 18536aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// has no way to return such a result. 18546aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// 18556aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// \param IsExpr Whether the receiver was parsed as an expression. 18566aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// 18576aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// \param TypeOrExpr If the receiver was parsed as an expression (\c 18586aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// IsExpr is true), the parsed expression. If the receiver was parsed 18596aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// as a type (\c IsExpr is false), the parsed type. 18606aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// 18616aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// \returns True if an error occurred during parsing or semantic 18626aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// analysis, in which case the arguments do not have valid 18636aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// values. Otherwise, returns false for a successful parse. 18646aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// 18656aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// objc-receiver: [C++] 18666aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// 'super' [not parsed here] 18676aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// expression 18686aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// simple-type-specifier 18696aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// typename-specifier 18706aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregorbool Parser::ParseObjCXXMessageReceiver(bool &IsExpr, void *&TypeOrExpr) { 18710fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor InMessageExpressionRAIIObject InMessage(*this, true); 18720fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor 18736aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor if (Tok.is(tok::identifier) || Tok.is(tok::coloncolon) || 18746aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor Tok.is(tok::kw_typename) || Tok.is(tok::annot_cxxscope)) 18756aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor TryAnnotateTypeOrScopeToken(); 18766aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 18776aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor if (!isCXXSimpleTypeSpecifier()) { 18786aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // objc-receiver: 18796aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // expression 188060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Receiver = ParseExpression(); 18816aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor if (Receiver.isInvalid()) 18826aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor return true; 18836aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 18846aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor IsExpr = true; 18856aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor TypeOrExpr = Receiver.take(); 18866aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor return false; 18876aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor } 18886aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 18896aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // objc-receiver: 18906aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // typename-specifier 18916aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // simple-type-specifier 18926aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // expression (that starts with one of the above) 18930b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall DeclSpec DS(AttrFactory); 18946aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor ParseCXXSimpleTypeSpecifier(DS); 18956aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 18966aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor if (Tok.is(tok::l_paren)) { 18976aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // If we see an opening parentheses at this point, we are 18986aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // actually parsing an expression that starts with a 18996aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // function-style cast, e.g., 19006aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // 19016aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // postfix-expression: 19026aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // simple-type-specifier ( expression-list [opt] ) 19036aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // typename-specifier ( expression-list [opt] ) 19046aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // 19056aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // Parse the remainder of this case, then the (optional) 19066aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // postfix-expression suffix, followed by the (optional) 19076aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // right-hand side of the binary expression. We have an 19086aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // instance method. 190960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Receiver = ParseCXXTypeConstructExpression(DS); 19106aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor if (!Receiver.isInvalid()) 19119ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Receiver = ParsePostfixExpressionSuffix(Receiver.take()); 19126aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor if (!Receiver.isInvalid()) 19139ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Receiver = ParseRHSOfBinaryExpression(Receiver.take(), prec::Comma); 19146aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor if (Receiver.isInvalid()) 19156aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor return true; 19166aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 19176aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor IsExpr = true; 19186aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor TypeOrExpr = Receiver.take(); 19196aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor return false; 19206aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor } 19216aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 19226aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // We have a class message. Turn the simple-type-specifier or 19236aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // typename-specifier we parsed into a type and parse the 19246aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // remainder of the class message. 19256aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor Declarator DeclaratorInfo(DS, Declarator::TypeNameContext); 192623c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor TypeResult Type = Actions.ActOnTypeName(getCurScope(), DeclaratorInfo); 19276aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor if (Type.isInvalid()) 19286aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor return true; 19296aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 19306aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor IsExpr = false; 1931b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall TypeOrExpr = Type.get().getAsOpaquePtr(); 19326aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor return false; 19336aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor} 19346aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 19351b730e847ded503f2e615154035c083c4f94a067Douglas Gregor/// \brief Determine whether the parser is currently referring to a an 19361b730e847ded503f2e615154035c083c4f94a067Douglas Gregor/// Objective-C message send, using a simplified heuristic to avoid overhead. 19371b730e847ded503f2e615154035c083c4f94a067Douglas Gregor/// 19381b730e847ded503f2e615154035c083c4f94a067Douglas Gregor/// This routine will only return true for a subset of valid message-send 19391b730e847ded503f2e615154035c083c4f94a067Douglas Gregor/// expressions. 19401b730e847ded503f2e615154035c083c4f94a067Douglas Gregorbool Parser::isSimpleObjCMessageExpression() { 1941c59cb38810c63a806270385f79ea84e0203754eaChris Lattner assert(Tok.is(tok::l_square) && getLang().ObjC1 && 19421b730e847ded503f2e615154035c083c4f94a067Douglas Gregor "Incorrect start for isSimpleObjCMessageExpression"); 19431b730e847ded503f2e615154035c083c4f94a067Douglas Gregor return GetLookAheadToken(1).is(tok::identifier) && 19441b730e847ded503f2e615154035c083c4f94a067Douglas Gregor GetLookAheadToken(2).is(tok::identifier); 19451b730e847ded503f2e615154035c083c4f94a067Douglas Gregor} 19461b730e847ded503f2e615154035c083c4f94a067Douglas Gregor 19479497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregorbool Parser::isStartOfObjCClassMessageMissingOpenBracket() { 19489497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor if (!getLang().ObjC1 || !NextToken().is(tok::identifier) || 19499497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor InMessageExpression) 19509497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor return false; 19519497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor 19529497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor 19539497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor ParsedType Type; 19549497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor 19559497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor if (Tok.is(tok::annot_typename)) 19569497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor Type = getTypeAnnotation(Tok); 19579497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor else if (Tok.is(tok::identifier)) 19589497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor Type = Actions.getTypeName(*Tok.getIdentifierInfo(), Tok.getLocation(), 19599497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor getCurScope()); 19609497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor else 19619497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor return false; 19629497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor 19639497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor if (!Type.get().isNull() && Type.get()->isObjCObjectOrInterfaceType()) { 19649497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor const Token &AfterNext = GetLookAheadToken(2); 19659497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor if (AfterNext.is(tok::colon) || AfterNext.is(tok::r_square)) { 19669497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor if (Tok.is(tok::identifier)) 19679497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor TryAnnotateTypeOrScopeToken(); 19689497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor 19699497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor return Tok.is(tok::annot_typename); 19709497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor } 19719497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor } 19729497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor 19739497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor return false; 19749497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor} 19759497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor 19761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// objc-message-expr: 19770ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// '[' objc-receiver objc-message-args ']' 19780ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// 19792725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// objc-receiver: [C] 1980eb483eb3ee80300f15d6d13573d82493c2194461Chris Lattner/// 'super' 19810ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// expression 19820ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// class-name 19830ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// type-name 19846aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// 198560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult Parser::ParseObjCMessageExpression() { 1986699b66138ac307a32e238463e0eff513ff17d337Chris Lattner assert(Tok.is(tok::l_square) && "'[' expected"); 1987699b66138ac307a32e238463e0eff513ff17d337Chris Lattner SourceLocation LBracLoc = ConsumeBracket(); // consume '[' 1988699b66138ac307a32e238463e0eff513ff17d337Chris Lattner 19898e254cfe5a6ab4202c7fcc4b64bdd1ca0fe071acDouglas Gregor if (Tok.is(tok::code_completion)) { 199023c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCMessageReceiver(getCurScope()); 19918e254cfe5a6ab4202c7fcc4b64bdd1ca0fe071acDouglas Gregor ConsumeCodeCompletionToken(); 19928e254cfe5a6ab4202c7fcc4b64bdd1ca0fe071acDouglas Gregor SkipUntil(tok::r_square); 19938e254cfe5a6ab4202c7fcc4b64bdd1ca0fe071acDouglas Gregor return ExprError(); 19948e254cfe5a6ab4202c7fcc4b64bdd1ca0fe071acDouglas Gregor } 19958e254cfe5a6ab4202c7fcc4b64bdd1ca0fe071acDouglas Gregor 19960fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor InMessageExpressionRAIIObject InMessage(*this, true); 19970fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor 19986aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor if (getLang().CPlusPlus) { 19996aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // We completely separate the C and C++ cases because C++ requires 20006aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // more complicated (read: slower) parsing. 20016aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 20026aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // Handle send to super. 20036aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // FIXME: This doesn't benefit from the same typo-correction we 20046aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // get in Objective-C. 20056aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor if (Tok.is(tok::identifier) && Tok.getIdentifierInfo() == Ident_super && 200623c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor NextToken().isNot(tok::period) && getCurScope()->isInObjcMethodScope()) 2007b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall return ParseObjCMessageExpressionBody(LBracLoc, ConsumeToken(), 2008b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType(), 0); 20096aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 20106aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // Parse the receiver, which is either a type or an expression. 20116aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor bool IsExpr; 2012304b752a450c0fc5968c20ba25446d0bb7c6f68dNick Lewycky void *TypeOrExpr = NULL; 20136aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor if (ParseObjCXXMessageReceiver(IsExpr, TypeOrExpr)) { 20146aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor SkipUntil(tok::r_square); 20156aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor return ExprError(); 20166aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor } 20176aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 20186aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor if (IsExpr) 2019b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(), 2020b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType(), 20219ae2f076ca5ab1feb3ba95629099ec2319833701John McCall static_cast<Expr*>(TypeOrExpr)); 20226aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 20236aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(), 2024b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType::getFromOpaquePtr(TypeOrExpr), 2025b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall 0); 2026c59cb38810c63a806270385f79ea84e0203754eaChris Lattner } 2027c59cb38810c63a806270385f79ea84e0203754eaChris Lattner 2028c59cb38810c63a806270385f79ea84e0203754eaChris Lattner if (Tok.is(tok::identifier)) { 20291dbca6ea983231b4cab1a8f1edda8f6e13c21f12Douglas Gregor IdentifierInfo *Name = Tok.getIdentifierInfo(); 20301dbca6ea983231b4cab1a8f1edda8f6e13c21f12Douglas Gregor SourceLocation NameLoc = Tok.getLocation(); 2031b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ReceiverType; 203223c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor switch (Actions.getObjCMessageKind(getCurScope(), Name, NameLoc, 20331dbca6ea983231b4cab1a8f1edda8f6e13c21f12Douglas Gregor Name == Ident_super, 20341569f95831a8c99e9f664137bf8f40e47ee3d90fDouglas Gregor NextToken().is(tok::period), 20351569f95831a8c99e9f664137bf8f40e47ee3d90fDouglas Gregor ReceiverType)) { 2036f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall case Sema::ObjCSuperMessage: 2037b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall return ParseObjCMessageExpressionBody(LBracLoc, ConsumeToken(), 2038b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType(), 0); 20392725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor 2040f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall case Sema::ObjCClassMessage: 20411569f95831a8c99e9f664137bf8f40e47ee3d90fDouglas Gregor if (!ReceiverType) { 20422725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor SkipUntil(tok::r_square); 20432725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor return ExprError(); 20442725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor } 20452725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor 20461569f95831a8c99e9f664137bf8f40e47ee3d90fDouglas Gregor ConsumeToken(); // the type name 20471569f95831a8c99e9f664137bf8f40e47ee3d90fDouglas Gregor 20481569f95831a8c99e9f664137bf8f40e47ee3d90fDouglas Gregor return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(), 20499ae2f076ca5ab1feb3ba95629099ec2319833701John McCall ReceiverType, 0); 20501dbca6ea983231b4cab1a8f1edda8f6e13c21f12Douglas Gregor 2051f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall case Sema::ObjCInstanceMessage: 20522725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor // Fall through to parse an expression. 20531dbca6ea983231b4cab1a8f1edda8f6e13c21f12Douglas Gregor break; 2054d2869925b5f10e00b13fbf3f41bbb17e4c9adbe0Fariborz Jahanian } 2055699b66138ac307a32e238463e0eff513ff17d337Chris Lattner } 2056eb483eb3ee80300f15d6d13573d82493c2194461Chris Lattner 2057eb483eb3ee80300f15d6d13573d82493c2194461Chris Lattner // Otherwise, an arbitrary expression can be the receiver of a send. 205860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Res(ParseExpression()); 20590e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Res.isInvalid()) { 20605c749428a9938d5e2e9564b1c9b7a9252c30ee27Chris Lattner SkipUntil(tok::r_square); 20611d922960e083906a586609ac6978678147250177Sebastian Redl return move(Res); 2062699b66138ac307a32e238463e0eff513ff17d337Chris Lattner } 20631d922960e083906a586609ac6978678147250177Sebastian Redl 2064b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(), 2065b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType(), Res.take()); 2066699b66138ac307a32e238463e0eff513ff17d337Chris Lattner} 20671d922960e083906a586609ac6978678147250177Sebastian Redl 20682725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// \brief Parse the remainder of an Objective-C message following the 20692725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// '[' objc-receiver. 20702725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// 20712725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// This routine handles sends to super, class messages (sent to a 20722725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// class name), and instance messages (sent to an object), and the 20732725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// target is represented by \p SuperLoc, \p ReceiverType, or \p 20742725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// ReceiverExpr, respectively. Only one of these parameters may have 20752725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// a valid value. 20762725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// 20772725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// \param LBracLoc The location of the opening '['. 20782725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// 20792725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// \param SuperLoc If this is a send to 'super', the location of the 20802725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// 'super' keyword that indicates a send to the superclass. 20812725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// 20822725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// \param ReceiverType If this is a class message, the type of the 20832725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// class we are sending a message to. 20842725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// 20852725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// \param ReceiverExpr If this is an instance message, the expression 20862725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// used to compute the receiver object. 20871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 20880ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-message-args: 20890ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-selector 20900ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-keywordarg-list 20910ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// 20920ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-keywordarg-list: 20930ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-keywordarg 20940ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-keywordarg-list objc-keywordarg 20950ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// 20961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// objc-keywordarg: 20970ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// selector-name[opt] ':' objc-keywordexpr 20980ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// 20990ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-keywordexpr: 21000ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// nonempty-expr-list 21010ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// 21020ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// nonempty-expr-list: 21030ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// assignment-expression 21040ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// nonempty-expr-list , assignment-expression 21051d922960e083906a586609ac6978678147250177Sebastian Redl/// 210660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 2107699b66138ac307a32e238463e0eff513ff17d337Chris LattnerParser::ParseObjCMessageExpressionBody(SourceLocation LBracLoc, 21082725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor SourceLocation SuperLoc, 2109b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ReceiverType, 21101d922960e083906a586609ac6978678147250177Sebastian Redl ExprArg ReceiverExpr) { 21110fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor InMessageExpressionRAIIObject InMessage(*this, true); 21120fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor 2113c4df6d2c05c647a6a5770ba0c749782b6c023a3aSteve Naroff if (Tok.is(tok::code_completion)) { 21142725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor if (SuperLoc.isValid()) 211570c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor Actions.CodeCompleteObjCSuperMessage(getCurScope(), SuperLoc, 0, 0, 211670c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor false); 21172725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor else if (ReceiverType) 211870c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor Actions.CodeCompleteObjCClassMessage(getCurScope(), ReceiverType, 0, 0, 211970c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor false); 2120c4df6d2c05c647a6a5770ba0c749782b6c023a3aSteve Naroff else 21219ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Actions.CodeCompleteObjCInstanceMessage(getCurScope(), ReceiverExpr, 212270c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor 0, 0, false); 2123dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 2124c4df6d2c05c647a6a5770ba0c749782b6c023a3aSteve Naroff } 2125d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor 2126a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian // Parse objc-selector 21274b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian SourceLocation Loc; 21282fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner IdentifierInfo *selIdent = ParseObjCSelectorPiece(Loc); 212968d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff 2130ff975cfab9ada27df86038286d1678084aeb3428Anders Carlsson SourceLocation SelectorLoc = Loc; 21311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 213268d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff llvm::SmallVector<IdentifierInfo *, 12> KeyIdents; 2133a55e52c0802cae3b7c366a05c461d3d15074c1a3Sebastian Redl ExprVector KeyExprs(Actions); 213468d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff 2135df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::colon)) { 2136a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian while (1) { 2137a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian // Each iteration parses a single keyword argument. 213868d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff KeyIdents.push_back(selIdent); 213937387c932855c6d58d70bdd705cd3a9fdcd2a931Steve Naroff 2140df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::colon)) { 2141a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian Diag(Tok, diag::err_expected_colon); 21424fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // We must manually skip to a ']', otherwise the expression skipper will 21434fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // stop at the ']' when it skips to the ';'. We want it to skip beyond 21444fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // the enclosing expression. 21454fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner SkipUntil(tok::r_square); 21461d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(); 2147a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian } 21481d922960e083906a586609ac6978678147250177Sebastian Redl 214968d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff ConsumeToken(); // Eat the ':'. 21501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// Parse the expression after ':' 215170c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor 215270c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor if (Tok.is(tok::code_completion)) { 215370c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor if (SuperLoc.isValid()) 215470c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor Actions.CodeCompleteObjCSuperMessage(getCurScope(), SuperLoc, 215570c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor KeyIdents.data(), 215670c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor KeyIdents.size(), 215770c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor /*AtArgumentEpression=*/true); 215870c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor else if (ReceiverType) 215970c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor Actions.CodeCompleteObjCClassMessage(getCurScope(), ReceiverType, 216070c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor KeyIdents.data(), 216170c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor KeyIdents.size(), 216270c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor /*AtArgumentEpression=*/true); 216370c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor else 216470c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor Actions.CodeCompleteObjCInstanceMessage(getCurScope(), ReceiverExpr, 216570c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor KeyIdents.data(), 216670c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor KeyIdents.size(), 216770c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor /*AtArgumentEpression=*/true); 216870c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor 216970c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor ConsumeCodeCompletionToken(); 217070c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor SkipUntil(tok::r_square); 217170c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor return ExprError(); 217270c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor } 217370c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor 217460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Res(ParseAssignmentExpression()); 21750e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Res.isInvalid()) { 21764fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // We must manually skip to a ']', otherwise the expression skipper will 21774fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // stop at the ']' when it skips to the ';'. We want it to skip beyond 21784fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // the enclosing expression. 21794fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner SkipUntil(tok::r_square); 21801d922960e083906a586609ac6978678147250177Sebastian Redl return move(Res); 218137387c932855c6d58d70bdd705cd3a9fdcd2a931Steve Naroff } 21821d922960e083906a586609ac6978678147250177Sebastian Redl 218337387c932855c6d58d70bdd705cd3a9fdcd2a931Steve Naroff // We have a valid expression. 2184effa8d1c97b00a3f53e972b0e61d9aade5ea1c57Sebastian Redl KeyExprs.push_back(Res.release()); 21851d922960e083906a586609ac6978678147250177Sebastian Redl 2186d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor // Code completion after each argument. 2187d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor if (Tok.is(tok::code_completion)) { 21882725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor if (SuperLoc.isValid()) 218923c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCSuperMessage(getCurScope(), SuperLoc, 21902725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor KeyIdents.data(), 219170c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor KeyIdents.size(), 219270c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor /*AtArgumentEpression=*/false); 21932725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor else if (ReceiverType) 219423c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCClassMessage(getCurScope(), ReceiverType, 2195d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor KeyIdents.data(), 219670c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor KeyIdents.size(), 219770c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor /*AtArgumentEpression=*/false); 2198d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor else 21999ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Actions.CodeCompleteObjCInstanceMessage(getCurScope(), ReceiverExpr, 2200d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor KeyIdents.data(), 220170c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor KeyIdents.size(), 220270c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor /*AtArgumentEpression=*/false); 2203dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 220470c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor SkipUntil(tok::r_square); 220570c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor return ExprError(); 2206d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor } 2207d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor 220837387c932855c6d58d70bdd705cd3a9fdcd2a931Steve Naroff // Check for another keyword selector. 22092fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner selIdent = ParseObjCSelectorPiece(Loc); 2210df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (!selIdent && Tok.isNot(tok::colon)) 2211a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian break; 2212a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian // We have a selector or a colon, continue parsing. 2213a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian } 2214a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian // Parse the, optional, argument list, comma separated. 2215df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner while (Tok.is(tok::comma)) { 221649f109c786f99eb7468dac3976db083a65493444Steve Naroff ConsumeToken(); // Eat the ','. 22171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// Parse the expression after ',' 221860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Res(ParseAssignmentExpression()); 22190e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Res.isInvalid()) { 22204fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // We must manually skip to a ']', otherwise the expression skipper will 22214fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // stop at the ']' when it skips to the ';'. We want it to skip beyond 22224fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // the enclosing expression. 22234fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner SkipUntil(tok::r_square); 22241d922960e083906a586609ac6978678147250177Sebastian Redl return move(Res); 222549f109c786f99eb7468dac3976db083a65493444Steve Naroff } 22260e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl 222749f109c786f99eb7468dac3976db083a65493444Steve Naroff // We have a valid expression. 2228effa8d1c97b00a3f53e972b0e61d9aade5ea1c57Sebastian Redl KeyExprs.push_back(Res.release()); 2229a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian } 2230a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian } else if (!selIdent) { 2231a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian Diag(Tok, diag::err_expected_ident); // missing selector name. 22321d922960e083906a586609ac6978678147250177Sebastian Redl 22334fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // We must manually skip to a ']', otherwise the expression skipper will 22344fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // stop at the ']' when it skips to the ';'. We want it to skip beyond 22354fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // the enclosing expression. 22364fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner SkipUntil(tok::r_square); 22371d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(); 2238a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian } 2239809872eca7f6c024e2ab41ddffbbeeae807bf5dcFariborz Jahanian 2240df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::r_square)) { 2241809872eca7f6c024e2ab41ddffbbeeae807bf5dcFariborz Jahanian if (Tok.is(tok::identifier)) 2242809872eca7f6c024e2ab41ddffbbeeae807bf5dcFariborz Jahanian Diag(Tok, diag::err_expected_colon); 2243809872eca7f6c024e2ab41ddffbbeeae807bf5dcFariborz Jahanian else 2244809872eca7f6c024e2ab41ddffbbeeae807bf5dcFariborz Jahanian Diag(Tok, diag::err_expected_rsquare); 22454fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // We must manually skip to a ']', otherwise the expression skipper will 22464fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // stop at the ']' when it skips to the ';'. We want it to skip beyond 22474fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // the enclosing expression. 22484fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner SkipUntil(tok::r_square); 22491d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(); 2250a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian } 22511d922960e083906a586609ac6978678147250177Sebastian Redl 2252699b66138ac307a32e238463e0eff513ff17d337Chris Lattner SourceLocation RBracLoc = ConsumeBracket(); // consume ']' 22531d922960e083906a586609ac6978678147250177Sebastian Redl 225429238a0bf7cbf5b396efb451a0adb5fe4aa037caSteve Naroff unsigned nKeys = KeyIdents.size(); 2255ff38491c18b060526d754765b952f4a497a89416Chris Lattner if (nKeys == 0) 2256ff38491c18b060526d754765b952f4a497a89416Chris Lattner KeyIdents.push_back(selIdent); 2257ff38491c18b060526d754765b952f4a497a89416Chris Lattner Selector Sel = PP.getSelectorTable().getSelector(nKeys, &KeyIdents[0]); 22581d922960e083906a586609ac6978678147250177Sebastian Redl 22592725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor if (SuperLoc.isValid()) 226023c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor return Actions.ActOnSuperMessage(getCurScope(), SuperLoc, Sel, 22612725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor LBracLoc, SelectorLoc, RBracLoc, 2262f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall MultiExprArg(Actions, 2263f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall KeyExprs.take(), 2264f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall KeyExprs.size())); 22652725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor else if (ReceiverType) 226623c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor return Actions.ActOnClassMessage(getCurScope(), ReceiverType, Sel, 22672725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor LBracLoc, SelectorLoc, RBracLoc, 2268f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall MultiExprArg(Actions, 2269f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall KeyExprs.take(), 2270f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall KeyExprs.size())); 22719ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return Actions.ActOnInstanceMessage(getCurScope(), ReceiverExpr, Sel, 22722725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor LBracLoc, SelectorLoc, RBracLoc, 2273f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall MultiExprArg(Actions, 2274f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall KeyExprs.take(), 2275f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall KeyExprs.size())); 22760ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian} 22770ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian 227860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult Parser::ParseObjCStringLiteral(SourceLocation AtLoc) { 227960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Res(ParseStringLiteralExpression()); 22801d922960e083906a586609ac6978678147250177Sebastian Redl if (Res.isInvalid()) return move(Res); 22811d922960e083906a586609ac6978678147250177Sebastian Redl 2282b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner // @"foo" @"bar" is a valid concatenated string. Eat any subsequent string 2283b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner // expressions. At this point, we know that the only valid thing that starts 2284b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner // with '@' is an @"". 2285b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner llvm::SmallVector<SourceLocation, 4> AtLocs; 2286a55e52c0802cae3b7c366a05c461d3d15074c1a3Sebastian Redl ExprVector AtStrings(Actions); 2287b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner AtLocs.push_back(AtLoc); 2288effa8d1c97b00a3f53e972b0e61d9aade5ea1c57Sebastian Redl AtStrings.push_back(Res.release()); 22890e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl 2290b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner while (Tok.is(tok::at)) { 2291b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner AtLocs.push_back(ConsumeToken()); // eat the @. 2292b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner 229315faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl // Invalid unless there is a string literal. 229497cf6eb380016db868866faf27a086cd55a316d4Chris Lattner if (!isTokenStringLiteral()) 229597cf6eb380016db868866faf27a086cd55a316d4Chris Lattner return ExprError(Diag(Tok, diag::err_objc_concat_string)); 2296b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner 229760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Lit(ParseStringLiteralExpression()); 22980e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Lit.isInvalid()) 22991d922960e083906a586609ac6978678147250177Sebastian Redl return move(Lit); 23000e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl 2301effa8d1c97b00a3f53e972b0e61d9aade5ea1c57Sebastian Redl AtStrings.push_back(Lit.release()); 2302b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner } 23031d922960e083906a586609ac6978678147250177Sebastian Redl 23041d922960e083906a586609ac6978678147250177Sebastian Redl return Owned(Actions.ParseObjCStringLiteral(&AtLocs[0], AtStrings.take(), 23051d922960e083906a586609ac6978678147250177Sebastian Redl AtStrings.size())); 23065508518a2702b00be3b15a26d772bde968972f54Anders Carlsson} 2307f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson 2308f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson/// objc-encode-expression: 2309f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson/// @encode ( type-name ) 231060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 23111d922960e083906a586609ac6978678147250177Sebastian RedlParser::ParseObjCEncodeExpression(SourceLocation AtLoc) { 2312861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff assert(Tok.isObjCAtKeyword(tok::objc_encode) && "Not an @encode expression!"); 23131d922960e083906a586609ac6978678147250177Sebastian Redl 2314f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson SourceLocation EncLoc = ConsumeToken(); 23151d922960e083906a586609ac6978678147250177Sebastian Redl 23164fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner if (Tok.isNot(tok::l_paren)) 23171d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(Tok, diag::err_expected_lparen_after) << "@encode"); 23181d922960e083906a586609ac6978678147250177Sebastian Redl 2319f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson SourceLocation LParenLoc = ConsumeParen(); 23201d922960e083906a586609ac6978678147250177Sebastian Redl 2321809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor TypeResult Ty = ParseTypeName(); 23221d922960e083906a586609ac6978678147250177Sebastian Redl 23234988ae3fda10743c8ed8a98cdcb5a783362587b4Anders Carlsson SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); 23241d922960e083906a586609ac6978678147250177Sebastian Redl 2325809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor if (Ty.isInvalid()) 2326809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor return ExprError(); 2327809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor 23281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return Owned(Actions.ParseObjCEncodeExpression(AtLoc, EncLoc, LParenLoc, 2329809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor Ty.get(), RParenLoc)); 2330f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson} 233129b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson 233229b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson/// objc-protocol-expression 233329b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson/// @protocol ( protocol-name ) 233460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 23351d922960e083906a586609ac6978678147250177Sebastian RedlParser::ParseObjCProtocolExpression(SourceLocation AtLoc) { 233629b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson SourceLocation ProtoLoc = ConsumeToken(); 23371d922960e083906a586609ac6978678147250177Sebastian Redl 23384fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner if (Tok.isNot(tok::l_paren)) 23391d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(Tok, diag::err_expected_lparen_after) << "@protocol"); 23401d922960e083906a586609ac6978678147250177Sebastian Redl 234129b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson SourceLocation LParenLoc = ConsumeParen(); 23421d922960e083906a586609ac6978678147250177Sebastian Redl 23434fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner if (Tok.isNot(tok::identifier)) 23441d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(Tok, diag::err_expected_ident)); 23451d922960e083906a586609ac6978678147250177Sebastian Redl 2346390d50a725497e99247dc104a7d2c2a255d3af14Fariborz Jahanian IdentifierInfo *protocolId = Tok.getIdentifierInfo(); 234729b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson ConsumeToken(); 23481d922960e083906a586609ac6978678147250177Sebastian Redl 23494988ae3fda10743c8ed8a98cdcb5a783362587b4Anders Carlsson SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); 235029b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson 23511d922960e083906a586609ac6978678147250177Sebastian Redl return Owned(Actions.ParseObjCProtocolExpression(protocolId, AtLoc, ProtoLoc, 23521d922960e083906a586609ac6978678147250177Sebastian Redl LParenLoc, RParenLoc)); 235329b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson} 2354a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian 2355a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian/// objc-selector-expression 2356a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian/// @selector '(' objc-keyword-selector ')' 235760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult Parser::ParseObjCSelectorExpression(SourceLocation AtLoc) { 2358a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian SourceLocation SelectorLoc = ConsumeToken(); 23591d922960e083906a586609ac6978678147250177Sebastian Redl 23604fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner if (Tok.isNot(tok::l_paren)) 23611d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(Tok, diag::err_expected_lparen_after) << "@selector"); 23621d922960e083906a586609ac6978678147250177Sebastian Redl 2363b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian llvm::SmallVector<IdentifierInfo *, 12> KeyIdents; 2364a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian SourceLocation LParenLoc = ConsumeParen(); 2365a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian SourceLocation sLoc; 2366458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor 2367458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor if (Tok.is(tok::code_completion)) { 2368458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor Actions.CodeCompleteObjCSelector(getCurScope(), KeyIdents.data(), 2369458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor KeyIdents.size()); 2370458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor ConsumeCodeCompletionToken(); 2371458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor MatchRHSPunctuation(tok::r_paren, LParenLoc); 2372458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor return ExprError(); 2373458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor } 2374458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor 23752fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner IdentifierInfo *SelIdent = ParseObjCSelectorPiece(sLoc); 23765add7541726348b9d1c8e96ac5031b87c41acff0Chris Lattner if (!SelIdent && // missing selector name. 23775add7541726348b9d1c8e96ac5031b87c41acff0Chris Lattner Tok.isNot(tok::colon) && Tok.isNot(tok::coloncolon)) 23781d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(Tok, diag::err_expected_ident)); 23791d922960e083906a586609ac6978678147250177Sebastian Redl 2380b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian KeyIdents.push_back(SelIdent); 2381887407e71fd58de452361b77d72970e32b20ebe0Steve Naroff unsigned nColons = 0; 2382887407e71fd58de452361b77d72970e32b20ebe0Steve Naroff if (Tok.isNot(tok::r_paren)) { 2383a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian while (1) { 23845add7541726348b9d1c8e96ac5031b87c41acff0Chris Lattner if (Tok.is(tok::coloncolon)) { // Handle :: in C++. 23855add7541726348b9d1c8e96ac5031b87c41acff0Chris Lattner ++nColons; 23865add7541726348b9d1c8e96ac5031b87c41acff0Chris Lattner KeyIdents.push_back(0); 23875add7541726348b9d1c8e96ac5031b87c41acff0Chris Lattner } else if (Tok.isNot(tok::colon)) 23881d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(Tok, diag::err_expected_colon)); 23891d922960e083906a586609ac6978678147250177Sebastian Redl 23905add7541726348b9d1c8e96ac5031b87c41acff0Chris Lattner ++nColons; 23913b3e1a9e79703da067d23756e5624a4f487d6278Chris Lattner ConsumeToken(); // Eat the ':' or '::'. 2392a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian if (Tok.is(tok::r_paren)) 2393a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian break; 2394458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor 2395458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor if (Tok.is(tok::code_completion)) { 2396458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor Actions.CodeCompleteObjCSelector(getCurScope(), KeyIdents.data(), 2397458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor KeyIdents.size()); 2398458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor ConsumeCodeCompletionToken(); 2399458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor MatchRHSPunctuation(tok::r_paren, LParenLoc); 2400458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor return ExprError(); 2401458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor } 2402458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor 2403a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian // Check for another keyword selector. 2404a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian SourceLocation Loc; 24052fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner SelIdent = ParseObjCSelectorPiece(Loc); 2406b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian KeyIdents.push_back(SelIdent); 24073b3e1a9e79703da067d23756e5624a4f487d6278Chris Lattner if (!SelIdent && Tok.isNot(tok::colon) && Tok.isNot(tok::coloncolon)) 2408a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian break; 2409a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian } 2410887407e71fd58de452361b77d72970e32b20ebe0Steve Naroff } 2411a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); 2412887407e71fd58de452361b77d72970e32b20ebe0Steve Naroff Selector Sel = PP.getSelectorTable().getSelector(nColons, &KeyIdents[0]); 24131d922960e083906a586609ac6978678147250177Sebastian Redl return Owned(Actions.ParseObjCSelectorExpression(Sel, AtLoc, SelectorLoc, 24141d922960e083906a586609ac6978678147250177Sebastian Redl LParenLoc, RParenLoc)); 241558065b2d8038a4e9a91ea4813bd1774c0f6efacbGabor Greif } 2416