ParseObjc.cpp revision 304b752a450c0fc5968c20ba25446d0bb7c6f68d
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); 435ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner case tok::objc_interface: 445ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner return ParseObjCAtInterfaceDeclaration(AtLoc); 455ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner case tok::objc_protocol: 465ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner return ParseObjCAtProtocolDeclaration(AtLoc); 475ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner case tok::objc_implementation: 485ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner return ParseObjCAtImplementationDeclaration(AtLoc); 495ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner case tok::objc_end: 505ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner return ParseObjCAtEndDeclaration(AtLoc); 515ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner case tok::objc_compatibility_alias: 525ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner return ParseObjCAtAliasDeclaration(AtLoc); 535ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner case tok::objc_synthesize: 545ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner return ParseObjCPropertySynthesize(AtLoc); 555ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner case tok::objc_dynamic: 565ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner return ParseObjCPropertyDynamic(AtLoc); 575ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner default: 585ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner Diag(AtLoc, diag::err_unexpected_at); 595ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner SkipUntil(tok::semi); 60d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// objc-class-declaration: 665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// '@' 'class' identifier-list ';' 671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 68d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseObjCAtClassDeclaration(SourceLocation atLoc) { 695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ConsumeToken(); // the identifier "class" 705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::SmallVector<IdentifierInfo *, 8> ClassNames; 71c09cba67d0ad01e53e0fed07322e95dd281bcfd9Ted Kremenek llvm::SmallVector<SourceLocation, 8> ClassLocs; 72c09cba67d0ad01e53e0fed07322e95dd281bcfd9Ted Kremenek 731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer while (1) { 75df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Diag(Tok, diag::err_expected_ident); 775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SkipUntil(tok::semi); 78d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ClassNames.push_back(Tok.getIdentifierInfo()); 81c09cba67d0ad01e53e0fed07322e95dd281bcfd9Ted Kremenek ClassLocs.push_back(Tok.getLocation()); 825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ConsumeToken(); 831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 84df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::comma)) 855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer break; 861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ConsumeToken(); 885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Consume the ';'. 915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@class")) 92d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 94c09cba67d0ad01e53e0fed07322e95dd281bcfd9Ted Kremenek return Actions.ActOnForwardClassDeclaration(atLoc, ClassNames.data(), 95c09cba67d0ad01e53e0fed07322e95dd281bcfd9Ted Kremenek ClassLocs.data(), 96c09cba67d0ad01e53e0fed07322e95dd281bcfd9Ted Kremenek ClassNames.size()); 975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 99dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 100dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-interface: 101dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-interface-attributes[opt] objc-class-interface 102dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-category-interface 103dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 104dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-interface: 1051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// '@' 'interface' identifier objc-superclass[opt] 106dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-refs[opt] 1071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// objc-class-instance-variables[opt] 108dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-interface-decl-list 109dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @end 110dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 111dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-category-interface: 1121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// '@' 'interface' identifier '(' identifier[opt] ')' 113dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-refs[opt] 114dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-interface-decl-list 115dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @end 116dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 117dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-superclass: 118dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// ':' identifier 119dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 120dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-interface-attributes: 121dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// __attribute__((visibility("default"))) 122dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// __attribute__((visibility("hidden"))) 123dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// __attribute__((deprecated)) 124dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// __attribute__((unavailable)) 125dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// __attribute__((objc_exception)) - used by NSException on 64-bit 126dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 127d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseObjCAtInterfaceDeclaration( 128dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff SourceLocation atLoc, AttributeList *attrList) { 129861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff assert(Tok.isObjCAtKeyword(tok::objc_interface) && 130dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff "ParseObjCAtInterfaceDeclaration(): Expected @interface"); 131dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff ConsumeToken(); // the "interface" identifier 1321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1333b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor // Code completion after '@interface'. 1343b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor if (Tok.is(tok::code_completion)) { 13523c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCInterfaceDecl(getCurScope()); 136dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 1373b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor } 1383b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor 139df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 140dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff Diag(Tok, diag::err_expected_ident); // missing class or category name. 141d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 142dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff } 14363e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian 144dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff // We have a class or category name - consume it. 1457ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff IdentifierInfo *nameId = Tok.getIdentifierInfo(); 146dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff SourceLocation nameLoc = ConsumeToken(); 1475512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian if (Tok.is(tok::l_paren) && 1485512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian !isKnownToBeTypeSpecifier(GetLookAheadToken(1))) { // we have a category. 149dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff SourceLocation lparenLoc = ConsumeParen(); 150dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff SourceLocation categoryLoc, rparenLoc; 151dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff IdentifierInfo *categoryId = 0; 15233ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor if (Tok.is(tok::code_completion)) { 15323c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCInterfaceCategory(getCurScope(), nameId, nameLoc); 154dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 15533ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor } 15633ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor 157527fe23f8cbc6a4da1737a547a2517bc92fa88c8Steve Naroff // For ObjC2, the category name is optional (not an error). 158df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::identifier)) { 159dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff categoryId = Tok.getIdentifierInfo(); 160dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff categoryLoc = ConsumeToken(); 16105511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian } 16205511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian else if (!getLang().ObjC2) { 163527fe23f8cbc6a4da1737a547a2517bc92fa88c8Steve Naroff Diag(Tok, diag::err_expected_ident); // missing category name. 164d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 165dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff } 166df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::r_paren)) { 167dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff Diag(Tok, diag::err_expected_rparen); 168dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff SkipUntil(tok::r_paren, false); // don't stop at ';' 169d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 170dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff } 171dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff rparenLoc = ConsumeParen(); 1725512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian // Next, we need to check for any protocol references. 1735512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian SourceLocation LAngleLoc, EndProtoLoc; 174d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall llvm::SmallVector<Decl *, 8> ProtocolRefs; 1755512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian llvm::SmallVector<SourceLocation, 8> ProtocolLocs; 1765512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian if (Tok.is(tok::less) && 1775512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian ParseObjCProtocolReferences(ProtocolRefs, ProtocolLocs, true, 17871b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis LAngleLoc, EndProtoLoc)) 179d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 18005511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian 1815512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian if (attrList) // categories don't support attributes. 1825512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian Diag(Tok, diag::err_objc_no_attributes_on_category); 1835512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian 184d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *CategoryType = 1855512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian Actions.ActOnStartCategoryInterface(atLoc, 1865512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian nameId, nameLoc, 1875512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian categoryId, categoryLoc, 1885512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian ProtocolRefs.data(), 1895512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian ProtocolRefs.size(), 1905512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian ProtocolLocs.data(), 1915512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian EndProtoLoc); 1925512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian if (Tok.is(tok::l_brace)) 19383c481ade785a919ba21a33f9a8b1b21c1212fb3Fariborz Jahanian ParseObjCClassInstanceVariables(CategoryType, tok::objc_private, 19483c481ade785a919ba21a33f9a8b1b21c1212fb3Fariborz Jahanian atLoc); 19583c481ade785a919ba21a33f9a8b1b21c1212fb3Fariborz Jahanian 1965512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian ParseObjCInterfaceDeclList(CategoryType, tok::objc_not_keyword); 1975512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian return CategoryType; 198dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff } 199dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff // Parse a class interface. 200dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff IdentifierInfo *superClassId = 0; 201dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff SourceLocation superClassLoc; 2027ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff 203df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::colon)) { // a super class is specified. 204dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff ConsumeToken(); 2053b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor 2063b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor // Code completion of superclass names. 2073b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor if (Tok.is(tok::code_completion)) { 20823c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCSuperclass(getCurScope(), nameId, nameLoc); 209dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 2103b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor } 2113b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor 212df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 213dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff Diag(Tok, diag::err_expected_ident); // missing super class name. 214d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 215dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff } 216dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff superClassId = Tok.getIdentifierInfo(); 217dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff superClassLoc = ConsumeToken(); 218dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff } 219dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff // Next, we need to check for any protocol references. 220d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall llvm::SmallVector<Decl *, 8> ProtocolRefs; 22171b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis llvm::SmallVector<SourceLocation, 8> ProtocolLocs; 22271b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis SourceLocation LAngleLoc, EndProtoLoc; 22306036d3709955a53297b4cbe14e20db88f321470Chris Lattner if (Tok.is(tok::less) && 22471b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis ParseObjCProtocolReferences(ProtocolRefs, ProtocolLocs, true, 22571b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis LAngleLoc, EndProtoLoc)) 226d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 2271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 228d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ClsType = 2291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Actions.ActOnStartClassInterface(atLoc, nameId, nameLoc, 23006036d3709955a53297b4cbe14e20db88f321470Chris Lattner superClassId, superClassLoc, 231beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad ProtocolRefs.data(), ProtocolRefs.size(), 23218df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor ProtocolLocs.data(), 23306036d3709955a53297b4cbe14e20db88f321470Chris Lattner EndProtoLoc, attrList); 2341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 235df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::l_brace)) 23683c481ade785a919ba21a33f9a8b1b21c1212fb3Fariborz Jahanian ParseObjCClassInstanceVariables(ClsType, tok::objc_protected, atLoc); 237dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff 23825e077d59a8e8e43b65882b69610a3d5e2aaf53cFariborz Jahanian ParseObjCInterfaceDeclList(ClsType, tok::objc_interface); 2395512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian return ClsType; 240dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff} 241dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff 242d0014540005f2a5ab837365db6bd40f479406758John McCall/// The Objective-C property callback. This should be defined where 243d0014540005f2a5ab837365db6bd40f479406758John McCall/// it's used, but instead it's been lifted to here to support VS2005. 244d0014540005f2a5ab837365db6bd40f479406758John McCallstruct Parser::ObjCPropertyCallback : FieldCallback { 245d0014540005f2a5ab837365db6bd40f479406758John McCall Parser &P; 246d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *IDecl; 247d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall llvm::SmallVectorImpl<Decl *> &Props; 248d0014540005f2a5ab837365db6bd40f479406758John McCall ObjCDeclSpec &OCDS; 249d0014540005f2a5ab837365db6bd40f479406758John McCall SourceLocation AtLoc; 250d0014540005f2a5ab837365db6bd40f479406758John McCall tok::ObjCKeywordKind MethodImplKind; 251d0014540005f2a5ab837365db6bd40f479406758John McCall 252d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall ObjCPropertyCallback(Parser &P, Decl *IDecl, 253d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall llvm::SmallVectorImpl<Decl *> &Props, 254d0014540005f2a5ab837365db6bd40f479406758John McCall ObjCDeclSpec &OCDS, SourceLocation AtLoc, 255d0014540005f2a5ab837365db6bd40f479406758John McCall tok::ObjCKeywordKind MethodImplKind) : 256d0014540005f2a5ab837365db6bd40f479406758John McCall P(P), IDecl(IDecl), Props(Props), OCDS(OCDS), AtLoc(AtLoc), 257d0014540005f2a5ab837365db6bd40f479406758John McCall MethodImplKind(MethodImplKind) { 258d0014540005f2a5ab837365db6bd40f479406758John McCall } 259d0014540005f2a5ab837365db6bd40f479406758John McCall 260d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *invoke(FieldDeclarator &FD) { 261d0014540005f2a5ab837365db6bd40f479406758John McCall if (FD.D.getIdentifier() == 0) { 262d0014540005f2a5ab837365db6bd40f479406758John McCall P.Diag(AtLoc, diag::err_objc_property_requires_field_name) 263d0014540005f2a5ab837365db6bd40f479406758John McCall << FD.D.getSourceRange(); 264d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 265d0014540005f2a5ab837365db6bd40f479406758John McCall } 266d0014540005f2a5ab837365db6bd40f479406758John McCall if (FD.BitfieldSize) { 267d0014540005f2a5ab837365db6bd40f479406758John McCall P.Diag(AtLoc, diag::err_objc_property_bitfield) 268d0014540005f2a5ab837365db6bd40f479406758John McCall << FD.D.getSourceRange(); 269d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 270d0014540005f2a5ab837365db6bd40f479406758John McCall } 271d0014540005f2a5ab837365db6bd40f479406758John McCall 272d0014540005f2a5ab837365db6bd40f479406758John McCall // Install the property declarator into interfaceDecl. 273d0014540005f2a5ab837365db6bd40f479406758John McCall IdentifierInfo *SelName = 274d0014540005f2a5ab837365db6bd40f479406758John McCall OCDS.getGetterName() ? OCDS.getGetterName() : FD.D.getIdentifier(); 275d0014540005f2a5ab837365db6bd40f479406758John McCall 276d0014540005f2a5ab837365db6bd40f479406758John McCall Selector GetterSel = 277d0014540005f2a5ab837365db6bd40f479406758John McCall P.PP.getSelectorTable().getNullarySelector(SelName); 278d0014540005f2a5ab837365db6bd40f479406758John McCall IdentifierInfo *SetterName = OCDS.getSetterName(); 279d0014540005f2a5ab837365db6bd40f479406758John McCall Selector SetterSel; 280d0014540005f2a5ab837365db6bd40f479406758John McCall if (SetterName) 281d0014540005f2a5ab837365db6bd40f479406758John McCall SetterSel = P.PP.getSelectorTable().getSelector(1, &SetterName); 282d0014540005f2a5ab837365db6bd40f479406758John McCall else 283d0014540005f2a5ab837365db6bd40f479406758John McCall SetterSel = SelectorTable::constructSetterName(P.PP.getIdentifierTable(), 284d0014540005f2a5ab837365db6bd40f479406758John McCall P.PP.getSelectorTable(), 285d0014540005f2a5ab837365db6bd40f479406758John McCall FD.D.getIdentifier()); 286d0014540005f2a5ab837365db6bd40f479406758John McCall bool isOverridingProperty = false; 287d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *Property = 28823c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor P.Actions.ActOnProperty(P.getCurScope(), AtLoc, FD, OCDS, 289d0014540005f2a5ab837365db6bd40f479406758John McCall GetterSel, SetterSel, IDecl, 290d0014540005f2a5ab837365db6bd40f479406758John McCall &isOverridingProperty, 291d0014540005f2a5ab837365db6bd40f479406758John McCall MethodImplKind); 292d0014540005f2a5ab837365db6bd40f479406758John McCall if (!isOverridingProperty) 293d0014540005f2a5ab837365db6bd40f479406758John McCall Props.push_back(Property); 294d0014540005f2a5ab837365db6bd40f479406758John McCall 295d0014540005f2a5ab837365db6bd40f479406758John McCall return Property; 296d0014540005f2a5ab837365db6bd40f479406758John McCall } 297d0014540005f2a5ab837365db6bd40f479406758John McCall}; 298d0014540005f2a5ab837365db6bd40f479406758John McCall 299dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-interface-decl-list: 300dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// empty 301dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-interface-decl-list objc-property-decl [OBJC2] 302294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-interface-decl-list objc-method-requirement [OBJC2] 3033536b443bc50d58a79f14fca9b6842541a434854Steve Naroff/// objc-interface-decl-list objc-method-proto ';' 304dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-interface-decl-list declaration 305dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-interface-decl-list ';' 306dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 307294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-method-requirement: [OBJC2] 308294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// @required 309294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// @optional 310294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 311d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallvoid Parser::ParseObjCInterfaceDeclList(Decl *interfaceDecl, 312cb53b361bce341c8591333c6997f62e480acc0b4Chris Lattner tok::ObjCKeywordKind contextKey) { 313d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall llvm::SmallVector<Decl *, 32> allMethods; 314d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall llvm::SmallVector<Decl *, 16> allProperties; 315682bf92db408a6cbc3d37b5496a99b6ef85041ecChris Lattner llvm::SmallVector<DeclGroupPtrTy, 8> allTUVariables; 31600933591a2795d09dd1acff12a2d21bce7cb12c5Fariborz Jahanian tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword; 3171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 318782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek SourceRange AtEnd; 319bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner 320294494e1cce92043562b4680c613df7fd028c02eSteve Naroff while (1) { 321e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner // If this is a method prototype, parse it. 322df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::minus) || Tok.is(tok::plus)) { 323d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *methodPrototype = 324df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner ParseObjCMethodPrototype(interfaceDecl, MethodImplKind); 32525e077d59a8e8e43b65882b69610a3d5e2aaf53cFariborz Jahanian allMethods.push_back(methodPrototype); 3263536b443bc50d58a79f14fca9b6842541a434854Steve Naroff // Consume the ';' here, since ParseObjCMethodPrototype() is re-used for 3273536b443bc50d58a79f14fca9b6842541a434854Steve Naroff // method definitions. 328b6d74a158a9c002e3c0fcbda8ad8d0ccbb2e5088Chris Lattner ExpectAndConsume(tok::semi, diag::err_expected_semi_after_method_proto, 329b6d74a158a9c002e3c0fcbda8ad8d0ccbb2e5088Chris Lattner "", tok::semi); 330294494e1cce92043562b4680c613df7fd028c02eSteve Naroff continue; 331294494e1cce92043562b4680c613df7fd028c02eSteve Naroff } 33205511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian if (Tok.is(tok::l_paren)) { 33305511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian Diag(Tok, diag::err_expected_minus_or_plus); 334d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall ParseObjCMethodDecl(Tok.getLocation(), 335d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall tok::minus, 336d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall interfaceDecl, 337d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall MethodImplKind); 33805511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian continue; 33905511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian } 340e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner // Ignore excess semicolons. 341e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner if (Tok.is(tok::semi)) { 342294494e1cce92043562b4680c613df7fd028c02eSteve Naroff ConsumeToken(); 343e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner continue; 344e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner } 3451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 346bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // If we got to the end of the file, exit the loop. 347e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner if (Tok.is(tok::eof)) 348e3a2ca7e30601cdd31c77a830f4cc487851e8096Fariborz Jahanian break; 3491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 350b6ac2451bfed36206c5cec7217372c4299f67f2bDouglas Gregor // Code completion within an Objective-C interface. 351b6ac2451bfed36206c5cec7217372c4299f67f2bDouglas Gregor if (Tok.is(tok::code_completion)) { 35223c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteOrdinaryName(getCurScope(), 353f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall ObjCImpDecl? Sema::PCC_ObjCImplementation 354f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall : Sema::PCC_ObjCInterface); 355dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 356b6ac2451bfed36206c5cec7217372c4299f67f2bDouglas Gregor } 357b6ac2451bfed36206c5cec7217372c4299f67f2bDouglas Gregor 358e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner // If we don't have an @ directive, parse it as a function definition. 359e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner if (Tok.isNot(tok::at)) { 3601fd80116b49782c367ff5d5f50a8b76dd8a5d7f7Chris Lattner // The code below does not consume '}'s because it is afraid of eating the 3611fd80116b49782c367ff5d5f50a8b76dd8a5d7f7Chris Lattner // end of a namespace. Because of the way this code is structured, an 3621fd80116b49782c367ff5d5f50a8b76dd8a5d7f7Chris Lattner // erroneous r_brace would cause an infinite loop if not handled here. 3631fd80116b49782c367ff5d5f50a8b76dd8a5d7f7Chris Lattner if (Tok.is(tok::r_brace)) 3641fd80116b49782c367ff5d5f50a8b76dd8a5d7f7Chris Lattner break; 3651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3664985aceceb9b9261b876b515d32726175c13a775Steve Naroff // FIXME: as the name implies, this rule allows function definitions. 3674985aceceb9b9261b876b515d32726175c13a775Steve Naroff // We could pass a flag or check for functions during semantic analysis. 368bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt allTUVariables.push_back(ParseDeclarationOrFunctionDefinition(0)); 369e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner continue; 370e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner } 3711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 372e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner // Otherwise, we have an @ directive, eat the @. 373e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner SourceLocation AtLoc = ConsumeToken(); // the "@" 374c464ae8444edb6d07ea49b7a0eae1674c0fa1bb8Douglas Gregor if (Tok.is(tok::code_completion)) { 37523c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCAtDirective(getCurScope(), ObjCImpDecl, true); 376dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 377c464ae8444edb6d07ea49b7a0eae1674c0fa1bb8Douglas Gregor break; 378c464ae8444edb6d07ea49b7a0eae1674c0fa1bb8Douglas Gregor } 379c464ae8444edb6d07ea49b7a0eae1674c0fa1bb8Douglas Gregor 380a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner tok::ObjCKeywordKind DirectiveKind = Tok.getObjCKeywordID(); 3811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 382a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner if (DirectiveKind == tok::objc_end) { // @end -> terminate list 383782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek AtEnd.setBegin(AtLoc); 384782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek AtEnd.setEnd(Tok.getLocation()); 385e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner break; 386c3d43b783dfb1a1502aa8b31ab1985cf237b1f77Douglas Gregor } else if (DirectiveKind == tok::objc_not_keyword) { 387c3d43b783dfb1a1502aa8b31ab1985cf237b1f77Douglas Gregor Diag(Tok, diag::err_objc_unknown_at); 388c3d43b783dfb1a1502aa8b31ab1985cf237b1f77Douglas Gregor SkipUntil(tok::semi); 389c3d43b783dfb1a1502aa8b31ab1985cf237b1f77Douglas Gregor continue; 390bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner } 3911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 392bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // Eat the identifier. 393bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner ConsumeToken(); 394bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner 395a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner switch (DirectiveKind) { 396a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner default: 397bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // FIXME: If someone forgets an @end on a protocol, this loop will 398bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // continue to eat up tons of stuff and spew lots of nonsense errors. It 399bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // would probably be better to bail out if we saw an @class or @interface 400bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // or something like that. 401f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner Diag(AtLoc, diag::err_objc_illegal_interface_qual); 402bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // Skip until we see an '@' or '}' or ';'. 403a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner SkipUntil(tok::r_brace, tok::at); 404a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner break; 4051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 406a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner case tok::objc_required: 407a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner case tok::objc_optional: 408a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner // This is only valid on protocols. 409bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // FIXME: Should this check for ObjC2 being enabled? 410e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner if (contextKey != tok::objc_protocol) 411bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner Diag(AtLoc, diag::err_objc_directive_only_in_protocol); 412a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner else 413bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner MethodImplKind = DirectiveKind; 414a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner break; 4151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 416a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner case tok::objc_property: 417f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner if (!getLang().ObjC2) 418f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner Diag(AtLoc, diag::err_objc_propertoes_require_objc2); 419f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner 420e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner ObjCDeclSpec OCDS; 4211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // Parse property attribute list, if any. 4228ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner if (Tok.is(tok::l_paren)) 4234ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor ParseObjCPropertyAttribute(OCDS, interfaceDecl, 4244ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor allMethods.data(), allMethods.size()); 4251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 426d0014540005f2a5ab837365db6bd40f479406758John McCall ObjCPropertyCallback Callback(*this, interfaceDecl, allProperties, 427d0014540005f2a5ab837365db6bd40f479406758John McCall OCDS, AtLoc, MethodImplKind); 428bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall 429e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner // Parse all the comma separated declarators. 430e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner DeclSpec DS; 431bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall ParseStructDeclaration(DS, Callback); 4321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 433a1fed7e3beebf9bb1bc85123f283be3eb631c120Chris Lattner ExpectAndConsume(tok::semi, diag::err_expected_semi_decl_list, "", 434a1fed7e3beebf9bb1bc85123f283be3eb631c120Chris Lattner tok::at); 435a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner break; 436f28b264437053fb0deacc9ba02b18a0966f7290aSteve Naroff } 437294494e1cce92043562b4680c613df7fd028c02eSteve Naroff } 438bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner 439bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // We break out of the big loop in two cases: when we see @end or when we see 440bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // EOF. In the former case, eat the @end. In the later case, emit an error. 441c464ae8444edb6d07ea49b7a0eae1674c0fa1bb8Douglas Gregor if (Tok.is(tok::code_completion)) { 44223c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCAtDirective(getCurScope(), ObjCImpDecl, true); 443dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 444c464ae8444edb6d07ea49b7a0eae1674c0fa1bb8Douglas Gregor } else if (Tok.isObjCAtKeyword(tok::objc_end)) 445bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner ConsumeToken(); // the "end" identifier 446bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner else 447bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner Diag(Tok, diag::err_objc_missing_end); 4481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 449a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner // Insert collected methods declarations into the @interface object. 450bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // This passes in an invalid SourceLocation for AtEndLoc when EOF is hit. 45123c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.ActOnAtEnd(getCurScope(), AtEnd, interfaceDecl, 4521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump allMethods.data(), allMethods.size(), 453beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad allProperties.data(), allProperties.size(), 454beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad allTUVariables.data(), allTUVariables.size()); 455294494e1cce92043562b4680c613df7fd028c02eSteve Naroff} 456294494e1cce92043562b4680c613df7fd028c02eSteve Naroff 457d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// Parse property attribute declarations. 458d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// 459d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// property-attr-decl: '(' property-attrlist ')' 460d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// property-attrlist: 461d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// property-attribute 462d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// property-attrlist ',' property-attribute 463d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// property-attribute: 464d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// getter '=' identifier 465d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// setter '=' identifier ':' 466d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// readonly 467d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// readwrite 468d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// assign 469d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// retain 470d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// copy 471d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// nonatomic 472d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// 473d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallvoid Parser::ParseObjCPropertyAttribute(ObjCDeclSpec &DS, Decl *ClassDecl, 474d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl **Methods, 4754ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor unsigned NumMethods) { 4768ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner assert(Tok.getKind() == tok::l_paren); 477dd5b5f2bb73d037745940431b71eb98393d12d4fChris Lattner SourceLocation LHSLoc = ConsumeParen(); // consume '(' 4781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 479cd9f4b31c4fe5b77b5519cc17b4583fab912bad1Chris Lattner while (1) { 480ece8e71d12b6f4cb2dc501297afef126dab8ad74Steve Naroff if (Tok.is(tok::code_completion)) { 48123c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCPropertyFlags(getCurScope(), DS); 482dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 483ece8e71d12b6f4cb2dc501297afef126dab8ad74Steve Naroff } 484d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian const IdentifierInfo *II = Tok.getIdentifierInfo(); 4851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 486f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner // If this is not an identifier at all, bail out early. 487f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner if (II == 0) { 488f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner MatchRHSPunctuation(tok::r_paren, LHSLoc); 489f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner return; 490f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner } 4911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 492156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner SourceLocation AttrName = ConsumeToken(); // consume last attribute name 4931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 49492e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner if (II->isStr("readonly")) 495e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_readonly); 49692e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner else if (II->isStr("assign")) 497e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_assign); 49892e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner else if (II->isStr("readwrite")) 499e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_readwrite); 50092e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner else if (II->isStr("retain")) 501e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_retain); 50292e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner else if (II->isStr("copy")) 503e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_copy); 50492e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner else if (II->isStr("nonatomic")) 505e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_nonatomic); 50692e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner else if (II->isStr("getter") || II->isStr("setter")) { 507e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner // getter/setter require extra treatment. 508156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner if (ExpectAndConsume(tok::equal, diag::err_objc_expected_equal, "", 509156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner tok::r_paren)) 510dd5b5f2bb73d037745940431b71eb98393d12d4fChris Lattner return; 5111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5124ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor if (Tok.is(tok::code_completion)) { 5134ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor if (II->getNameStart()[0] == 's') 51423c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCPropertySetter(getCurScope(), ClassDecl, 5154ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor Methods, NumMethods); 5164ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor else 51723c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCPropertyGetter(getCurScope(), ClassDecl, 5184ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor Methods, NumMethods); 519dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 5204ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor } 5214ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor 5228ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner if (Tok.isNot(tok::identifier)) { 5231ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_ident); 5248ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner SkipUntil(tok::r_paren); 5258ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner return; 5268ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner } 5271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 528e013d685c6689ac7ae103ee88acf573422d1ed6aDaniel Dunbar if (II->getNameStart()[0] == 's') { 5298ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_setter); 5308ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner DS.setSetterName(Tok.getIdentifierInfo()); 531156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner ConsumeToken(); // consume method name 5321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 533e0097db2848c463a534c18c235c6d3e53f2f1b87Fariborz Jahanian if (ExpectAndConsume(tok::colon, 534e0097db2848c463a534c18c235c6d3e53f2f1b87Fariborz Jahanian diag::err_expected_colon_after_setter_name, "", 535156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner tok::r_paren)) 5368ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner return; 5378ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner } else { 5388ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_getter); 5398ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner DS.setGetterName(Tok.getIdentifierInfo()); 540156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner ConsumeToken(); // consume method name 5418ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner } 542e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner } else { 543a9500f05ba6c09bbd84d342236863833067cd816Chris Lattner Diag(AttrName, diag::err_objc_expected_property_attr) << II; 544cd9f4b31c4fe5b77b5519cc17b4583fab912bad1Chris Lattner SkipUntil(tok::r_paren); 545cd9f4b31c4fe5b77b5519cc17b4583fab912bad1Chris Lattner return; 546cd9f4b31c4fe5b77b5519cc17b4583fab912bad1Chris Lattner } 5471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 548156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner if (Tok.isNot(tok::comma)) 549156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner break; 5501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 551156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner ConsumeToken(); 552d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian } 5531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 554156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner MatchRHSPunctuation(tok::r_paren, LHSLoc); 555d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian} 556d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian 5573536b443bc50d58a79f14fca9b6842541a434854Steve Naroff/// objc-method-proto: 5581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// objc-instance-method objc-method-decl objc-method-attributes[opt] 5593536b443bc50d58a79f14fca9b6842541a434854Steve Naroff/// objc-class-method objc-method-decl objc-method-attributes[opt] 560294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 561294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-instance-method: '-' 562294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-class-method: '+' 563294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 5644985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-method-attributes: [OBJC2] 5654985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// __attribute__((deprecated)) 5664985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// 567d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseObjCMethodPrototype(Decl *IDecl, 568d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall tok::ObjCKeywordKind MethodImplKind) { 569df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner assert((Tok.is(tok::minus) || Tok.is(tok::plus)) && "expected +/-"); 570294494e1cce92043562b4680c613df7fd028c02eSteve Naroff 5711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump tok::TokenKind methodType = Tok.getKind(); 572bef1185418705e16012b3dd50cd7c260c8d6b79cSteve Naroff SourceLocation mLoc = ConsumeToken(); 573d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *MDecl = ParseObjCMethodDecl(mLoc, methodType, IDecl,MethodImplKind); 5743536b443bc50d58a79f14fca9b6842541a434854Steve Naroff // Since this rule is used for both method declarations and definitions, 5752bd42fadafddc8acf744b57a970bdc96a077c617Steve Naroff // the caller is (optionally) responsible for consuming the ';'. 576f28b264437053fb0deacc9ba02b18a0966f7290aSteve Naroff return MDecl; 577294494e1cce92043562b4680c613df7fd028c02eSteve Naroff} 578294494e1cce92043562b4680c613df7fd028c02eSteve Naroff 579294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-selector: 580294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// identifier 581294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// one of 582294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// enum struct union if else while do for switch case default 583294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// break continue return goto asm sizeof typeof __alignof 584294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// unsigned long const short volatile signed restrict _Complex 585294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// in out inout bycopy byref oneway int char float double void _Bool 586294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 5872fc5c2428ecb450a3256c8316b93b8655cb76a0fChris LattnerIdentifierInfo *Parser::ParseObjCSelectorPiece(SourceLocation &SelectorLoc) { 588be74740cc246ce08d42804a684385a42eb814edbFariborz Jahanian 589ff38491c18b060526d754765b952f4a497a89416Chris Lattner switch (Tok.getKind()) { 590ff38491c18b060526d754765b952f4a497a89416Chris Lattner default: 591ff38491c18b060526d754765b952f4a497a89416Chris Lattner return 0; 592afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian case tok::ampamp: 593afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian case tok::ampequal: 594afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian case tok::amp: 595afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian case tok::pipe: 596afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian case tok::tilde: 597afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian case tok::exclaim: 598afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian case tok::exclaimequal: 599afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian case tok::pipepipe: 600afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian case tok::pipeequal: 601afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian case tok::caret: 602afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian case tok::caretequal: { 6033846ca29a8cc1d376a4b695194c29952dbbfb544Fariborz Jahanian std::string ThisTok(PP.getSpelling(Tok)); 604afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian if (isalpha(ThisTok[0])) { 605afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian IdentifierInfo *II = &PP.getIdentifierTable().get(ThisTok.data()); 606afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian Tok.setKind(tok::identifier); 607afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian SelectorLoc = ConsumeToken(); 608afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian return II; 609afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian } 610afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian return 0; 611afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian } 612afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian 613ff38491c18b060526d754765b952f4a497a89416Chris Lattner case tok::identifier: 614ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_asm: 615ff38491c18b060526d754765b952f4a497a89416Chris Lattner case tok::kw_auto: 6169298d9655aed28b2d9f6cc65c81401b209f03fdcChris Lattner case tok::kw_bool: 617ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_break: 618ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_case: 619ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_catch: 620ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_char: 621ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_class: 622ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_const: 623ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_const_cast: 624ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_continue: 625ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_default: 626ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_delete: 627ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_do: 628ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_double: 629ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_dynamic_cast: 630ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_else: 631ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_enum: 632ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_explicit: 633ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_export: 634ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_extern: 635ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_false: 636ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_float: 637ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_for: 638ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_friend: 639ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_goto: 640ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_if: 641ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_inline: 642ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_int: 643ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_long: 644ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_mutable: 645ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_namespace: 646ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_new: 647ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_operator: 648ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_private: 649ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_protected: 650ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_public: 651ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_register: 652ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_reinterpret_cast: 653ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_restrict: 654ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_return: 655ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_short: 656ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_signed: 657ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_sizeof: 658ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_static: 659ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_static_cast: 660ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_struct: 661ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_switch: 662ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_template: 663ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_this: 664ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_throw: 665ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_true: 666ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_try: 667ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_typedef: 668ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_typeid: 669ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_typename: 670ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_typeof: 671ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_union: 672ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_unsigned: 673ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_using: 674ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_virtual: 675ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_void: 676ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_volatile: 677ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_wchar_t: 678ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_while: 679ff38491c18b060526d754765b952f4a497a89416Chris Lattner case tok::kw__Bool: 680ff38491c18b060526d754765b952f4a497a89416Chris Lattner case tok::kw__Complex: 681ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw___alignof: 682ff38491c18b060526d754765b952f4a497a89416Chris Lattner IdentifierInfo *II = Tok.getIdentifierInfo(); 6834b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian SelectorLoc = ConsumeToken(); 684ff38491c18b060526d754765b952f4a497a89416Chris Lattner return II; 685d064951b0dcc95f8604d0d69ae82d9ecbd38c796Fariborz Jahanian } 686294494e1cce92043562b4680c613df7fd028c02eSteve Naroff} 687294494e1cce92043562b4680c613df7fd028c02eSteve Naroff 6880196cab54007ff072ec2642da8911c6b7e8d3fb5Fariborz Jahanian/// objc-for-collection-in: 'in' 6890196cab54007ff072ec2642da8911c6b7e8d3fb5Fariborz Jahanian/// 690335a2d4122e41343fe11a775889b8bec5b14be60Fariborz Jahanianbool Parser::isTokIdentifier_in() const { 6913ba5a0f90a03d5e13d02cbee9abd2a1ba01b18bcFariborz Jahanian // FIXME: May have to do additional look-ahead to only allow for 6923ba5a0f90a03d5e13d02cbee9abd2a1ba01b18bcFariborz Jahanian // valid tokens following an 'in'; such as an identifier, unary operators, 6933ba5a0f90a03d5e13d02cbee9abd2a1ba01b18bcFariborz Jahanian // '[' etc. 6941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return (getLang().ObjC2 && Tok.is(tok::identifier) && 6955ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner Tok.getIdentifierInfo() == ObjCTypeQuals[objc_in]); 6960196cab54007ff072ec2642da8911c6b7e8d3fb5Fariborz Jahanian} 6970196cab54007ff072ec2642da8911c6b7e8d3fb5Fariborz Jahanian 698a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ParseObjCTypeQualifierList - This routine parses the objective-c's type 699e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner/// qualifier list and builds their bitmask representation in the input 700e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner/// argument. 701294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 702294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-type-qualifiers: 703294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-type-qualifier 704294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-type-qualifiers objc-type-qualifier 705294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 706d32b0225e29fcafb2b2b2a4b1c51dcb1518af9c6Douglas Gregorvoid Parser::ParseObjCTypeQualifierList(ObjCDeclSpec &DS, bool IsParameter) { 707e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner while (1) { 708d32b0225e29fcafb2b2b2a4b1c51dcb1518af9c6Douglas Gregor if (Tok.is(tok::code_completion)) { 709d32b0225e29fcafb2b2b2a4b1c51dcb1518af9c6Douglas Gregor Actions.CodeCompleteObjCPassingType(getCurScope(), DS); 710d32b0225e29fcafb2b2b2a4b1c51dcb1518af9c6Douglas Gregor ConsumeCodeCompletionToken(); 711d32b0225e29fcafb2b2b2a4b1c51dcb1518af9c6Douglas Gregor } 712d32b0225e29fcafb2b2b2a4b1c51dcb1518af9c6Douglas Gregor 713cb53b361bce341c8591333c6997f62e480acc0b4Chris Lattner if (Tok.isNot(tok::identifier)) 714e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner return; 7151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 716e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner const IdentifierInfo *II = Tok.getIdentifierInfo(); 717e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner for (unsigned i = 0; i != objc_NumQuals; ++i) { 718a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek if (II != ObjCTypeQuals[i]) 719e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner continue; 7201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 721a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCDeclSpec::ObjCDeclQualifier Qual; 722e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner switch (i) { 723e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner default: assert(0 && "Unknown decl qualifier"); 724a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek case objc_in: Qual = ObjCDeclSpec::DQ_In; break; 725a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek case objc_out: Qual = ObjCDeclSpec::DQ_Out; break; 726a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek case objc_inout: Qual = ObjCDeclSpec::DQ_Inout; break; 727a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek case objc_oneway: Qual = ObjCDeclSpec::DQ_Oneway; break; 728a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek case objc_bycopy: Qual = ObjCDeclSpec::DQ_Bycopy; break; 729a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek case objc_byref: Qual = ObjCDeclSpec::DQ_Byref; break; 730e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner } 731a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek DS.setObjCDeclQualifier(Qual); 732e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner ConsumeToken(); 733e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner II = 0; 734e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner break; 735e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner } 7361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 737e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner // If this wasn't a recognized qualifier, bail out. 738e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner if (II) return; 739e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner } 740e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner} 741e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner 742e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner/// objc-type-name: 743e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner/// '(' objc-type-qualifiers[opt] type-name ')' 744e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner/// '(' objc-type-qualifiers[opt] ')' 745e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner/// 746b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCallParsedType Parser::ParseObjCTypeName(ObjCDeclSpec &DS, bool IsParameter) { 747df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner assert(Tok.is(tok::l_paren) && "expected ("); 7481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7494a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner SourceLocation LParenLoc = ConsumeParen(); 750e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner SourceLocation TypeStartLoc = Tok.getLocation(); 7511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 75219d74e1494fe399f0e2a94e9419c095f8214851bFariborz Jahanian // Parse type qualifiers, in, inout, etc. 753d32b0225e29fcafb2b2b2a4b1c51dcb1518af9c6Douglas Gregor ParseObjCTypeQualifierList(DS, IsParameter); 7544fa7afd07421e7276d1717e4fdf43a5fdd65a622Steve Naroff 755b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType Ty; 756809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor if (isTypeSpecifierQualifier()) { 757809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor TypeResult TypeSpec = ParseTypeName(); 758809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor if (!TypeSpec.isInvalid()) 759809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor Ty = TypeSpec.get(); 760809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor } 7611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7624a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner if (Tok.is(tok::r_paren)) 7634a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner ConsumeParen(); 7644a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner else if (Tok.getLocation() == TypeStartLoc) { 765e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner // If we didn't eat any tokens, then this isn't a type. 7661ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_type); 7674a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner SkipUntil(tok::r_paren); 7684a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner } else { 7694a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner // Otherwise, we found *something*, but didn't get a ')' in the right 7704a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner // place. Emit an error then return what we have as the type. 7714a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner MatchRHSPunctuation(tok::r_paren, LParenLoc); 772294494e1cce92043562b4680c613df7fd028c02eSteve Naroff } 773f28b264437053fb0deacc9ba02b18a0966f7290aSteve Naroff return Ty; 774294494e1cce92043562b4680c613df7fd028c02eSteve Naroff} 775294494e1cce92043562b4680c613df7fd028c02eSteve Naroff 776294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-method-decl: 777294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-selector 7784985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-keyword-selector objc-parmlist[opt] 779294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-type-name objc-selector 7804985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-type-name objc-keyword-selector objc-parmlist[opt] 781294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 782294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-keyword-selector: 7831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// objc-keyword-decl 784294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-keyword-selector objc-keyword-decl 785294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 786294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-keyword-decl: 7877ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// objc-selector ':' objc-type-name objc-keyword-attributes[opt] identifier 7887ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// objc-selector ':' objc-keyword-attributes[opt] identifier 7897ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// ':' objc-type-name objc-keyword-attributes[opt] identifier 7907ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// ':' objc-keyword-attributes[opt] identifier 791294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 7924985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-parmlist: 7934985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-parms objc-ellipsis[opt] 794294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 7954985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-parms: 7964985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-parms , parameter-declaration 797294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 7984985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-ellipsis: 799294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// , ... 800294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 8017ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// objc-keyword-attributes: [OBJC2] 8027ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// __attribute__((unused)) 8037ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// 804d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseObjCMethodDecl(SourceLocation mLoc, 8052ccccb3ff40c64927817a7e1ddf1da8c188ed224Douglas Gregor tok::TokenKind mType, 8062ccccb3ff40c64927817a7e1ddf1da8c188ed224Douglas Gregor Decl *IDecl, 8072ccccb3ff40c64927817a7e1ddf1da8c188ed224Douglas Gregor tok::ObjCKeywordKind MethodImplKind) { 80854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ParsingDeclRAIIObject PD(*this); 80954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 810e8f5a1710a7738deff40e10efcd05b1bd6af184fDouglas Gregor if (Tok.is(tok::code_completion)) { 81123c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCMethodDecl(getCurScope(), mType == tok::minus, 812b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall /*ReturnType=*/ ParsedType(), IDecl); 813dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 814e8f5a1710a7738deff40e10efcd05b1bd6af184fDouglas Gregor } 815e8f5a1710a7738deff40e10efcd05b1bd6af184fDouglas Gregor 816e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner // Parse the return type if present. 817b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ReturnType; 818a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCDeclSpec DSRet; 819df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::l_paren)) 820d32b0225e29fcafb2b2b2a4b1c51dcb1518af9c6Douglas Gregor ReturnType = ParseObjCTypeName(DSRet, false); 8211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8229e0493576af77dba1c48858c03e31a2897d0681eTed Kremenek // If attributes exist before the method, parse them. 8239e0493576af77dba1c48858c03e31a2897d0681eTed Kremenek llvm::OwningPtr<AttributeList> MethodAttrs; 8249e0493576af77dba1c48858c03e31a2897d0681eTed Kremenek if (getLang().ObjC2 && Tok.is(tok::kw___attribute)) 8259e0493576af77dba1c48858c03e31a2897d0681eTed Kremenek MethodAttrs.reset(ParseGNUAttributes()); 8269e0493576af77dba1c48858c03e31a2897d0681eTed Kremenek 827e8f5a1710a7738deff40e10efcd05b1bd6af184fDouglas Gregor if (Tok.is(tok::code_completion)) { 82823c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCMethodDecl(getCurScope(), mType == tok::minus, 829e8f5a1710a7738deff40e10efcd05b1bd6af184fDouglas Gregor ReturnType, IDecl); 830dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 831e8f5a1710a7738deff40e10efcd05b1bd6af184fDouglas Gregor } 832e8f5a1710a7738deff40e10efcd05b1bd6af184fDouglas Gregor 8339e0493576af77dba1c48858c03e31a2897d0681eTed Kremenek // Now parse the selector. 834bef1185418705e16012b3dd50cd7c260c8d6b79cSteve Naroff SourceLocation selLoc; 8352fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner IdentifierInfo *SelIdent = ParseObjCSelectorPiece(selLoc); 836e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner 83784c431088693e216193094d1dbf327a01173f57fSteve Naroff // An unnamed colon is valid. 83884c431088693e216193094d1dbf327a01173f57fSteve Naroff if (!SelIdent && Tok.isNot(tok::colon)) { // missing selector name. 8391ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_selector_for_method) 8401ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner << SourceRange(mLoc, Tok.getLocation()); 841e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner // Skip until we get a ; or {}. 842e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner SkipUntil(tok::r_brace); 843d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 844e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner } 8451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8464f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian llvm::SmallVector<DeclaratorChunk::ParamInfo, 8> CParamInfo; 847df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::colon)) { 848ff38491c18b060526d754765b952f4a497a89416Chris Lattner // If attributes exist after the method, parse them. 8491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (getLang().ObjC2 && Tok.is(tok::kw___attribute)) 8509e0493576af77dba1c48858c03e31a2897d0681eTed Kremenek MethodAttrs.reset(addAttributeLists(MethodAttrs.take(), 8519e0493576af77dba1c48858c03e31a2897d0681eTed Kremenek ParseGNUAttributes())); 8521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 853ff38491c18b060526d754765b952f4a497a89416Chris Lattner Selector Sel = PP.getSelectorTable().getNullarySelector(SelIdent); 854d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *Result 85554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall = Actions.ActOnMethodDeclaration(mLoc, Tok.getLocation(), 8561f7b6f88f18d7f6b10265acec5d41c4ed1897487Fariborz Jahanian mType, IDecl, DSRet, ReturnType, Sel, 8574f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian 0, 8584f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian CParamInfo.data(), CParamInfo.size(), 8594f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian MethodAttrs.get(), 8601c6a3cc88177c67498fccdf14cfdf09959214e41Ted Kremenek MethodImplKind); 86154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall PD.complete(Result); 86254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall return Result; 863ff38491c18b060526d754765b952f4a497a89416Chris Lattner } 864f28b264437053fb0deacc9ba02b18a0966f7290aSteve Naroff 86568d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff llvm::SmallVector<IdentifierInfo *, 12> KeyIdents; 866f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall llvm::SmallVector<Sema::ObjCArgInfo, 12> ArgInfos; 8671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 868ff38491c18b060526d754765b952f4a497a89416Chris Lattner while (1) { 869f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Sema::ObjCArgInfo ArgInfo; 8701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 871ff38491c18b060526d754765b952f4a497a89416Chris Lattner // Each iteration parses a single keyword argument. 872df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::colon)) { 873ff38491c18b060526d754765b952f4a497a89416Chris Lattner Diag(Tok, diag::err_expected_colon); 874ff38491c18b060526d754765b952f4a497a89416Chris Lattner break; 875ff38491c18b060526d754765b952f4a497a89416Chris Lattner } 876ff38491c18b060526d754765b952f4a497a89416Chris Lattner ConsumeToken(); // Eat the ':'. 8771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 878b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ArgInfo.Type = ParsedType(); 879e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner if (Tok.is(tok::l_paren)) // Parse the argument type if present. 880d32b0225e29fcafb2b2b2a4b1c51dcb1518af9c6Douglas Gregor ArgInfo.Type = ParseObjCTypeName(ArgInfo.DeclSpec, true); 881e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner 882ff38491c18b060526d754765b952f4a497a89416Chris Lattner // If attributes exist before the argument name, parse them. 883e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner ArgInfo.ArgAttrs = 0; 884df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (getLang().ObjC2 && Tok.is(tok::kw___attribute)) 885bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt ArgInfo.ArgAttrs = ParseGNUAttributes(); 8867ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff 88740ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor // Code completion for the next piece of the selector. 88840ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor if (Tok.is(tok::code_completion)) { 88940ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor ConsumeCodeCompletionToken(); 89040ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor KeyIdents.push_back(SelIdent); 89140ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor Actions.CodeCompleteObjCMethodDeclSelector(getCurScope(), 89240ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor mType == tok::minus, 89340ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor /*AtParameterName=*/true, 89440ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor ReturnType, 89540ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor KeyIdents.data(), 89640ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor KeyIdents.size()); 89740ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor KeyIdents.pop_back(); 89840ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor break; 89940ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor } 90040ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor 901df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 902ff38491c18b060526d754765b952f4a497a89416Chris Lattner Diag(Tok, diag::err_expected_ident); // missing argument name. 903ff38491c18b060526d754765b952f4a497a89416Chris Lattner break; 9044985aceceb9b9261b876b515d32726175c13a775Steve Naroff } 9051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 906e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner ArgInfo.Name = Tok.getIdentifierInfo(); 907e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner ArgInfo.NameLoc = Tok.getLocation(); 908ff38491c18b060526d754765b952f4a497a89416Chris Lattner ConsumeToken(); // Eat the identifier. 9091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 910e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner ArgInfos.push_back(ArgInfo); 911e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner KeyIdents.push_back(SelIdent); 912e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner 9131f5537aaac1e775aff1d523f2cc59a9a3bd6c946Douglas Gregor // Code completion for the next piece of the selector. 9141f5537aaac1e775aff1d523f2cc59a9a3bd6c946Douglas Gregor if (Tok.is(tok::code_completion)) { 9151f5537aaac1e775aff1d523f2cc59a9a3bd6c946Douglas Gregor ConsumeCodeCompletionToken(); 9161f5537aaac1e775aff1d523f2cc59a9a3bd6c946Douglas Gregor Actions.CodeCompleteObjCMethodDeclSelector(getCurScope(), 9171f5537aaac1e775aff1d523f2cc59a9a3bd6c946Douglas Gregor mType == tok::minus, 91840ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor /*AtParameterName=*/false, 9191f5537aaac1e775aff1d523f2cc59a9a3bd6c946Douglas Gregor ReturnType, 9201f5537aaac1e775aff1d523f2cc59a9a3bd6c946Douglas Gregor KeyIdents.data(), 9211f5537aaac1e775aff1d523f2cc59a9a3bd6c946Douglas Gregor KeyIdents.size()); 9221f5537aaac1e775aff1d523f2cc59a9a3bd6c946Douglas Gregor break; 9231f5537aaac1e775aff1d523f2cc59a9a3bd6c946Douglas Gregor } 9241f5537aaac1e775aff1d523f2cc59a9a3bd6c946Douglas Gregor 925ff38491c18b060526d754765b952f4a497a89416Chris Lattner // Check for another keyword selector. 9264b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian SourceLocation Loc; 9272fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner SelIdent = ParseObjCSelectorPiece(Loc); 928df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (!SelIdent && Tok.isNot(tok::colon)) 929ff38491c18b060526d754765b952f4a497a89416Chris Lattner break; 930ff38491c18b060526d754765b952f4a497a89416Chris Lattner // We have a selector or a colon, continue parsing. 931ff38491c18b060526d754765b952f4a497a89416Chris Lattner } 9321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 933335eafa5be51f6440672a74c73d588af72e96732Steve Naroff bool isVariadic = false; 9341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 935ff38491c18b060526d754765b952f4a497a89416Chris Lattner // Parse the (optional) parameter list. 936df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner while (Tok.is(tok::comma)) { 937ff38491c18b060526d754765b952f4a497a89416Chris Lattner ConsumeToken(); 938df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::ellipsis)) { 939335eafa5be51f6440672a74c73d588af72e96732Steve Naroff isVariadic = true; 9404985aceceb9b9261b876b515d32726175c13a775Steve Naroff ConsumeToken(); 941ff38491c18b060526d754765b952f4a497a89416Chris Lattner break; 9424985aceceb9b9261b876b515d32726175c13a775Steve Naroff } 943ff38491c18b060526d754765b952f4a497a89416Chris Lattner DeclSpec DS; 944ff38491c18b060526d754765b952f4a497a89416Chris Lattner ParseDeclarationSpecifiers(DS); 9451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // Parse the declarator. 946ff38491c18b060526d754765b952f4a497a89416Chris Lattner Declarator ParmDecl(DS, Declarator::PrototypeContext); 947ff38491c18b060526d754765b952f4a497a89416Chris Lattner ParseDeclarator(ParmDecl); 9484f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian IdentifierInfo *ParmII = ParmDecl.getIdentifier(); 949d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *Param = Actions.ActOnParamDeclarator(getCurScope(), ParmDecl); 9504f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian CParamInfo.push_back(DeclaratorChunk::ParamInfo(ParmII, 9514f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian ParmDecl.getIdentifierLoc(), 9524f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian Param, 9534f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian 0)); 9544f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian 9554985aceceb9b9261b876b515d32726175c13a775Steve Naroff } 9561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 957ff38491c18b060526d754765b952f4a497a89416Chris Lattner // FIXME: Add support for optional parmameter list... 958e3a2ca7e30601cdd31c77a830f4cc487851e8096Fariborz Jahanian // If attributes exist after the method, parse them. 9591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (getLang().ObjC2 && Tok.is(tok::kw___attribute)) 9609e0493576af77dba1c48858c03e31a2897d0681eTed Kremenek MethodAttrs.reset(addAttributeLists(MethodAttrs.take(), 9619e0493576af77dba1c48858c03e31a2897d0681eTed Kremenek ParseGNUAttributes())); 9621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9633688fc679389d67b6755e62406998f9ea84d886aFariborz Jahanian if (KeyIdents.size() == 0) 964d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 965ff38491c18b060526d754765b952f4a497a89416Chris Lattner Selector Sel = PP.getSelectorTable().getSelector(KeyIdents.size(), 966ff38491c18b060526d754765b952f4a497a89416Chris Lattner &KeyIdents[0]); 967d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *Result 96854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall = Actions.ActOnMethodDeclaration(mLoc, Tok.getLocation(), 9693688fc679389d67b6755e62406998f9ea84d886aFariborz Jahanian mType, IDecl, DSRet, ReturnType, Sel, 9704f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian &ArgInfos[0], 9714f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian CParamInfo.data(), CParamInfo.size(), 9721e37765c9257ef1d051f54a674eaa964bdba9693Ted Kremenek MethodAttrs.get(), 973335eafa5be51f6440672a74c73d588af72e96732Steve Naroff MethodImplKind, isVariadic); 97454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall PD.complete(Result); 9751e37765c9257ef1d051f54a674eaa964bdba9693Ted Kremenek 9761e37765c9257ef1d051f54a674eaa964bdba9693Ted Kremenek // Delete referenced AttributeList objects. 977f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall for (llvm::SmallVectorImpl<Sema::ObjCArgInfo>::iterator 9781e37765c9257ef1d051f54a674eaa964bdba9693Ted Kremenek I = ArgInfos.begin(), E = ArgInfos.end(); I != E; ++I) 9791e37765c9257ef1d051f54a674eaa964bdba9693Ted Kremenek delete I->ArgAttrs; 9801e37765c9257ef1d051f54a674eaa964bdba9693Ted Kremenek 98154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall return Result; 982294494e1cce92043562b4680c613df7fd028c02eSteve Naroff} 983294494e1cce92043562b4680c613df7fd028c02eSteve Naroff 984dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-refs: 985dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// '<' identifier-list '>' 986dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 9877caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattnerbool Parser:: 988d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallParseObjCProtocolReferences(llvm::SmallVectorImpl<Decl *> &Protocols, 98971b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis llvm::SmallVectorImpl<SourceLocation> &ProtocolLocs, 99071b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis bool WarnOnDeclarations, 99171b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis SourceLocation &LAngleLoc, SourceLocation &EndLoc) { 992e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner assert(Tok.is(tok::less) && "expected <"); 9931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 99471b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis LAngleLoc = ConsumeToken(); // the "<" 9951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 996e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner llvm::SmallVector<IdentifierLocPair, 8> ProtocolIdents; 9971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 998e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner while (1) { 99955385fe3e723cd675001e45f42d61adde6b7f075Douglas Gregor if (Tok.is(tok::code_completion)) { 100055385fe3e723cd675001e45f42d61adde6b7f075Douglas Gregor Actions.CodeCompleteObjCProtocolReferences(ProtocolIdents.data(), 100155385fe3e723cd675001e45f42d61adde6b7f075Douglas Gregor ProtocolIdents.size()); 1002dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 100355385fe3e723cd675001e45f42d61adde6b7f075Douglas Gregor } 100455385fe3e723cd675001e45f42d61adde6b7f075Douglas Gregor 1005e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner if (Tok.isNot(tok::identifier)) { 1006e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner Diag(Tok, diag::err_expected_ident); 1007e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner SkipUntil(tok::greater); 1008e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner return true; 1009e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner } 1010e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner ProtocolIdents.push_back(std::make_pair(Tok.getIdentifierInfo(), 1011e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner Tok.getLocation())); 101271b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis ProtocolLocs.push_back(Tok.getLocation()); 1013e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner ConsumeToken(); 10141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1015e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner if (Tok.isNot(tok::comma)) 1016e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner break; 1017e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner ConsumeToken(); 1018e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner } 10191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1020e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner // Consume the '>'. 1021e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner if (Tok.isNot(tok::greater)) { 1022e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner Diag(Tok, diag::err_expected_greater); 1023e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner return true; 1024e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner } 10251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1026e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner EndLoc = ConsumeAnyToken(); 10271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1028e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner // Convert the list of protocols identifiers into a list of protocol decls. 1029e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner Actions.FindProtocolDeclaration(WarnOnDeclarations, 1030e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner &ProtocolIdents[0], ProtocolIdents.size(), 1031e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner Protocols); 1032e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner return false; 1033e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner} 1034e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner 1035dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-instance-variables: 1036dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// '{' objc-instance-variable-decl-list[opt] '}' 1037dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1038dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-instance-variable-decl-list: 1039dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-visibility-spec 1040dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-instance-variable-decl ';' 1041dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// ';' 1042dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-instance-variable-decl-list objc-visibility-spec 1043dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-instance-variable-decl-list objc-instance-variable-decl ';' 1044dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-instance-variable-decl-list ';' 1045dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1046dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-visibility-spec: 1047dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @private 1048dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @protected 1049dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @public 1050ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff/// @package [OBJC2] 1051dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1052dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-instance-variable-decl: 10531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// struct-declaration 1054dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1055d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallvoid Parser::ParseObjCClassInstanceVariables(Decl *interfaceDecl, 105683c481ade785a919ba21a33f9a8b1b21c1212fb3Fariborz Jahanian tok::ObjCKeywordKind visibility, 105760fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff SourceLocation atLoc) { 1058df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner assert(Tok.is(tok::l_brace) && "expected {"); 1059d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall llvm::SmallVector<Decl *, 32> AllIvarDecls; 1060e13594279a952537ac903325efff57e3edca79d9Chris Lattner 10611a0d31a3d7f14ddc6370ba912c778aece6c12cf0Douglas Gregor ParseScope ClassScope(this, Scope::DeclScope|Scope::ClassScope); 106272de6676bd30f9081ee4166bbe07b4c270258ce6Douglas Gregor 1063ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff SourceLocation LBraceLoc = ConsumeBrace(); // the "{" 10641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1065ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff // While we still have something to read, read the instance variables. 1066df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner while (Tok.isNot(tok::r_brace) && Tok.isNot(tok::eof)) { 1067ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff // Each iteration of this loop reads one objc-instance-variable-decl. 10681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1069ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff // Check for extraneous top-level semicolon. 1070df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::semi)) { 1071f13ca06e57ac094ed05ea08c26a499af1ba0ce88Douglas Gregor Diag(Tok, diag::ext_extra_ivar_semi) 1072849b243d4065f56742a4677d6dc8277609a151f8Douglas Gregor << FixItHint::CreateRemoval(Tok.getLocation()); 1073ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff ConsumeToken(); 1074ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff continue; 1075ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff } 10761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1077ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff // Set the default visibility to private. 1078df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::at)) { // parse objc-visibility-spec 1079ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff ConsumeToken(); // eat the @ sign 1080c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor 1081c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor if (Tok.is(tok::code_completion)) { 108223c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCAtVisibility(getCurScope()); 1083dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 1084c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor } 1085c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor 1086861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff switch (Tok.getObjCKeywordID()) { 1087ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff case tok::objc_private: 1088ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff case tok::objc_public: 1089ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff case tok::objc_protected: 1090ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff case tok::objc_package: 1091861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff visibility = Tok.getObjCKeywordID(); 1092ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff ConsumeToken(); 10931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump continue; 1094ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff default: 1095ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff Diag(Tok, diag::err_objc_illegal_visibility_spec); 1096ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff continue; 1097ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff } 1098ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff } 10991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1100c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor if (Tok.is(tok::code_completion)) { 110123c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteOrdinaryName(getCurScope(), 1102f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Sema::PCC_ObjCInstanceVariableList); 1103dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 1104c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor } 1105c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor 1106bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall struct ObjCIvarCallback : FieldCallback { 1107bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall Parser &P; 1108d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *IDecl; 1109bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall tok::ObjCKeywordKind visibility; 1110d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall llvm::SmallVectorImpl<Decl *> &AllIvarDecls; 1111bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall 1112d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall ObjCIvarCallback(Parser &P, Decl *IDecl, tok::ObjCKeywordKind V, 1113d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall llvm::SmallVectorImpl<Decl *> &AllIvarDecls) : 1114bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall P(P), IDecl(IDecl), visibility(V), AllIvarDecls(AllIvarDecls) { 1115bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall } 1116bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall 1117d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *invoke(FieldDeclarator &FD) { 1118bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall // Install the declarator into the interface decl. 1119d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *Field 112023c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor = P.Actions.ActOnIvar(P.getCurScope(), 1121bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall FD.D.getDeclSpec().getSourceRange().getBegin(), 1122bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall IDecl, FD.D, FD.BitfieldSize, visibility); 11230bd04596e4645ff145a046dfb3475f39674060d9Fariborz Jahanian if (Field) 11240bd04596e4645ff145a046dfb3475f39674060d9Fariborz Jahanian AllIvarDecls.push_back(Field); 1125bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall return Field; 1126bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall } 1127bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall } Callback(*this, interfaceDecl, visibility, AllIvarDecls); 1128d097be8f81fbf4ed96ac10bae18562dd8202666bFariborz Jahanian 1129e13594279a952537ac903325efff57e3edca79d9Chris Lattner // Parse all the comma separated declarators. 1130e13594279a952537ac903325efff57e3edca79d9Chris Lattner DeclSpec DS; 1131bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall ParseStructDeclaration(DS, Callback); 11321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1133df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::semi)) { 1134ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff ConsumeToken(); 1135ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff } else { 1136ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff Diag(Tok, diag::err_expected_semi_decl_list); 1137ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff // Skip to end of block or statement 1138ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff SkipUntil(tok::r_brace, true, true); 1139ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff } 1140ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff } 114160fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff SourceLocation RBraceLoc = MatchRHSPunctuation(tok::r_brace, LBraceLoc); 1142d097be8f81fbf4ed96ac10bae18562dd8202666bFariborz Jahanian Actions.ActOnLastBitfield(RBraceLoc, interfaceDecl, AllIvarDecls); 11438749be53f53384e7846502791ceda6c657228d07Steve Naroff // Call ActOnFields() even if we don't have any decls. This is useful 11448749be53f53384e7846502791ceda6c657228d07Steve Naroff // for code rewriting tools that need to be aware of the empty list. 114523c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.ActOnFields(getCurScope(), atLoc, interfaceDecl, 1146beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad AllIvarDecls.data(), AllIvarDecls.size(), 11471bfe1c2129771c06fb58ae5e8c079ae30e138309Daniel Dunbar LBraceLoc, RBraceLoc, 0); 1148ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff return; 11495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 1150dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff 1151dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-declaration: 1152dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-definition 1153dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-forward-reference 1154dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1155dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-definition: 11561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// @protocol identifier 11571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// objc-protocol-refs[opt] 11581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// objc-interface-decl-list 1159dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @end 1160dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1161dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-forward-reference: 1162dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @protocol identifier-list ';' 1163dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1164dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// "@protocol identifier ;" should be resolved as "@protocol 11653536b443bc50d58a79f14fca9b6842541a434854Steve Naroff/// identifier-list ;": objc-interface-decl-list may not start with a 1166dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// semicolon in the first alternative if objc-protocol-refs are omitted. 1167d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseObjCAtProtocolDeclaration(SourceLocation AtLoc, 1168b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner AttributeList *attrList) { 1169861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff assert(Tok.isObjCAtKeyword(tok::objc_protocol) && 11707ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff "ParseObjCAtProtocolDeclaration(): Expected @protocol"); 11717ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff ConsumeToken(); // the "protocol" identifier 11721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1173083128f6b13dfa4fc615a838c49b516d901b1ac0Douglas Gregor if (Tok.is(tok::code_completion)) { 117423c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCProtocolDecl(getCurScope()); 1175dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 1176083128f6b13dfa4fc615a838c49b516d901b1ac0Douglas Gregor } 1177083128f6b13dfa4fc615a838c49b516d901b1ac0Douglas Gregor 1178df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 11797ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff Diag(Tok, diag::err_expected_ident); // missing protocol name. 1180d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 11817ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff } 11827ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff // Save the protocol name, then consume it. 11837ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff IdentifierInfo *protocolName = Tok.getIdentifierInfo(); 11847ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff SourceLocation nameLoc = ConsumeToken(); 11851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1186df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::semi)) { // forward declaration of one protocol. 11877caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner IdentifierLocPair ProtoInfo(protocolName, nameLoc); 11887ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff ConsumeToken(); 11891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return Actions.ActOnForwardProtocolDeclaration(AtLoc, &ProtoInfo, 1, 1190bc1c877fe28fb6a825f0b226a0a2da99e713ea03Fariborz Jahanian attrList); 11917ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff } 11921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1193df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::comma)) { // list of forward declarations. 11947caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner llvm::SmallVector<IdentifierLocPair, 8> ProtocolRefs; 11957caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner ProtocolRefs.push_back(std::make_pair(protocolName, nameLoc)); 11967caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner 11977ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff // Parse the list of forward declarations. 11987ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff while (1) { 11997ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff ConsumeToken(); // the ',' 1200df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 12017ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff Diag(Tok, diag::err_expected_ident); 12027ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff SkipUntil(tok::semi); 1203d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 12047ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff } 12057caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner ProtocolRefs.push_back(IdentifierLocPair(Tok.getIdentifierInfo(), 12067caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner Tok.getLocation())); 12077ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff ConsumeToken(); // the identifier 12081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1209df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::comma)) 12107ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff break; 12117ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff } 12127ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff // Consume the ';'. 12137ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff if (ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@protocol")) 1214d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 12151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1216e440eb8158e71deb1e4ab11618ae3d680aac6da1Steve Naroff return Actions.ActOnForwardProtocolDeclaration(AtLoc, 12171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump &ProtocolRefs[0], 1218bc1c877fe28fb6a825f0b226a0a2da99e713ea03Fariborz Jahanian ProtocolRefs.size(), 1219bc1c877fe28fb6a825f0b226a0a2da99e713ea03Fariborz Jahanian attrList); 12207caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner } 12211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12227ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff // Last, and definitely not least, parse a protocol declaration. 122371b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis SourceLocation LAngleLoc, EndProtoLoc; 12247caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner 1225d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall llvm::SmallVector<Decl *, 8> ProtocolRefs; 122671b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis llvm::SmallVector<SourceLocation, 8> ProtocolLocs; 12277caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner if (Tok.is(tok::less) && 122871b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis ParseObjCProtocolReferences(ProtocolRefs, ProtocolLocs, false, 122971b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis LAngleLoc, EndProtoLoc)) 1230d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 12311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1232d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ProtoType = 1233e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner Actions.ActOnStartProtocolInterface(AtLoc, protocolName, nameLoc, 1234beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad ProtocolRefs.data(), 1235beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad ProtocolRefs.size(), 123618df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor ProtocolLocs.data(), 1237246e70f69cb8aeb67225c54690f1c6b25abd5a86Daniel Dunbar EndProtoLoc, attrList); 123825e077d59a8e8e43b65882b69610a3d5e2aaf53cFariborz Jahanian ParseObjCInterfaceDeclList(ProtoType, tok::objc_protocol); 1239bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner return ProtoType; 1240dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff} 1241dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff 1242dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-implementation: 1243dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-implementation-prologue 1244dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-category-implementation-prologue 1245dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1246dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-implementation-prologue: 1247dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @implementation identifier objc-superclass[opt] 1248dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-instance-variables[opt] 1249dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1250dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-category-implementation-prologue: 1251dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @implementation identifier ( identifier ) 1252d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseObjCAtImplementationDeclaration( 1253ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian SourceLocation atLoc) { 1254ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian assert(Tok.isObjCAtKeyword(tok::objc_implementation) && 1255ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian "ParseObjCAtImplementationDeclaration(): Expected @implementation"); 1256ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); // the "implementation" identifier 12571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12583b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor // Code completion after '@implementation'. 12593b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor if (Tok.is(tok::code_completion)) { 126023c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCImplementationDecl(getCurScope()); 1261dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 12623b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor } 12633b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor 1264df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 1265ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian Diag(Tok, diag::err_expected_ident); // missing class or category name. 1266d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 1267ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1268ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian // We have a class or category name - consume it. 1269ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian IdentifierInfo *nameId = Tok.getIdentifierInfo(); 1270ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian SourceLocation nameLoc = ConsumeToken(); // consume class or category name 12711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (Tok.is(tok::l_paren)) { 1273ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian // we have a category implementation. 1274ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian SourceLocation lparenLoc = ConsumeParen(); 1275ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian SourceLocation categoryLoc, rparenLoc; 1276ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian IdentifierInfo *categoryId = 0; 12771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 127833ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor if (Tok.is(tok::code_completion)) { 127923c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCImplementationCategory(getCurScope(), nameId, nameLoc); 1280dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 128133ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor } 128233ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor 1283df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::identifier)) { 1284ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian categoryId = Tok.getIdentifierInfo(); 1285ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian categoryLoc = ConsumeToken(); 1286ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } else { 1287ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian Diag(Tok, diag::err_expected_ident); // missing category name. 1288d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 12891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 1290df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::r_paren)) { 1291ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian Diag(Tok, diag::err_expected_rparen); 1292ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian SkipUntil(tok::r_paren, false); // don't stop at ';' 1293d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 1294ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1295ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian rparenLoc = ConsumeParen(); 1296d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ImplCatType = Actions.ActOnStartCategoryImplementation( 12971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump atLoc, nameId, nameLoc, categoryId, 12988f3fde00ad4d4f943321e338b914ae4740711c84Fariborz Jahanian categoryLoc); 1299a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCImpDecl = ImplCatType; 130063e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian PendingObjCImpDecl.push_back(ObjCImpDecl); 1301d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 1302ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1303ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian // We have a class implementation 1304ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian SourceLocation superClassLoc; 1305ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian IdentifierInfo *superClassId = 0; 1306df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::colon)) { 1307ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian // We have a super class 1308ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); 1309df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 1310ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian Diag(Tok, diag::err_expected_ident); // missing super class name. 1311d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 1312ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1313ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian superClassId = Tok.getIdentifierInfo(); 1314ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian superClassLoc = ConsumeToken(); // Consume super class name 1315ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1316d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ImplClsType = Actions.ActOnStartClassImplementation( 1317cb53b361bce341c8591333c6997f62e480acc0b4Chris Lattner atLoc, nameId, nameLoc, 1318ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian superClassId, superClassLoc); 13191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 132060fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff if (Tok.is(tok::l_brace)) // we have ivars 132183c481ade785a919ba21a33f9a8b1b21c1212fb3Fariborz Jahanian ParseObjCClassInstanceVariables(ImplClsType/*FIXME*/, 132201f1bfc3284d5817517d35217885ea9ecb252817Fariborz Jahanian tok::objc_private, atLoc); 1323a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCImpDecl = ImplClsType; 132463e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian PendingObjCImpDecl.push_back(ObjCImpDecl); 132563e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian 1326d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 13275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 132860fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff 1329d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseObjCAtEndDeclaration(SourceRange atEnd) { 1330ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian assert(Tok.isObjCAtKeyword(tok::objc_end) && 1331ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian "ParseObjCAtEndDeclaration(): Expected @end"); 1332d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *Result = ObjCImpDecl; 1333ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); // the "end" identifier 1334a6e3ac514c924879699c6b0b1201028f0091044fFariborz Jahanian if (ObjCImpDecl) { 133523c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.ActOnAtEnd(getCurScope(), atEnd, ObjCImpDecl); 1336d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall ObjCImpDecl = 0; 133763e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian PendingObjCImpDecl.pop_back(); 1338a6e3ac514c924879699c6b0b1201028f0091044fFariborz Jahanian } 1339782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek else { 1340782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek // missing @implementation 1341782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek Diag(atEnd.getBegin(), diag::warn_expected_implementation); 1342782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek } 1343a6e3ac514c924879699c6b0b1201028f0091044fFariborz Jahanian return Result; 13445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 1345e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian 13463fe104154dd2e8ffb351142d74f308938b5c99bfFariborz JahanianParser::DeclGroupPtrTy Parser::FinishPendingObjCActions() { 13473fe104154dd2e8ffb351142d74f308938b5c99bfFariborz Jahanian Actions.DiagnoseUseOfUnimplementedSelectors(); 134863e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian if (PendingObjCImpDecl.empty()) 1349d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return Actions.ConvertDeclToDeclGroup(0); 1350d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ImpDecl = PendingObjCImpDecl.pop_back_val(); 135123c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.ActOnAtEnd(getCurScope(), SourceRange(), ImpDecl); 135263e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian return Actions.ConvertDeclToDeclGroup(ImpDecl); 135363e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian} 135463e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian 1355e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian/// compatibility-alias-decl: 1356e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian/// @compatibility_alias alias-name class-name ';' 1357e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian/// 1358d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseObjCAtAliasDeclaration(SourceLocation atLoc) { 1359e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian assert(Tok.isObjCAtKeyword(tok::objc_compatibility_alias) && 1360e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian "ParseObjCAtAliasDeclaration(): Expected @compatibility_alias"); 1361e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian ConsumeToken(); // consume compatibility_alias 1362df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 1363e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian Diag(Tok, diag::err_expected_ident); 1364d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 1365e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian } 1366243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian IdentifierInfo *aliasId = Tok.getIdentifierInfo(); 1367243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian SourceLocation aliasLoc = ConsumeToken(); // consume alias-name 1368df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 1369e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian Diag(Tok, diag::err_expected_ident); 1370d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 1371e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian } 1372243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian IdentifierInfo *classId = Tok.getIdentifierInfo(); 1373243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian SourceLocation classLoc = ConsumeToken(); // consume class-name; 1374243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian if (Tok.isNot(tok::semi)) { 13751ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_semi_after) << "@compatibility_alias"; 1376d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 1377243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian } 1378b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return Actions.ActOnCompatiblityAlias(atLoc, aliasId, aliasLoc, 1379b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner classId, classLoc); 13805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 13815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1382ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-synthesis: 1383ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// @synthesize property-ivar-list ';' 1384ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// 1385ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-ivar-list: 1386ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-ivar 1387ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-ivar-list ',' property-ivar 1388ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// 1389ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-ivar: 1390ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// identifier 1391ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// identifier '=' identifier 1392ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// 1393d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseObjCPropertySynthesize(SourceLocation atLoc) { 1394ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian assert(Tok.isObjCAtKeyword(tok::objc_synthesize) && 1395ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian "ParseObjCPropertyDynamic(): Expected '@synthesize'"); 1396f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian SourceLocation loc = ConsumeToken(); // consume synthesize 13971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1398b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor while (true) { 1399322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor if (Tok.is(tok::code_completion)) { 140023c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCPropertyDefinition(getCurScope(), ObjCImpDecl); 1401dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 1402322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor } 1403322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor 1404b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor if (Tok.isNot(tok::identifier)) { 1405b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor Diag(Tok, diag::err_synthesized_property_name); 1406b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor SkipUntil(tok::semi); 1407d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 1408b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor } 1409b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor 1410f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian IdentifierInfo *propertyIvar = 0; 1411f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian IdentifierInfo *propertyId = Tok.getIdentifierInfo(); 1412f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian SourceLocation propertyLoc = ConsumeToken(); // consume property name 1413df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::equal)) { 1414ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian // property '=' ivar-name 1415ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); // consume '=' 1416322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor 1417322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor if (Tok.is(tok::code_completion)) { 141823c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCPropertySynthesizeIvar(getCurScope(), propertyId, 1419322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor ObjCImpDecl); 1420dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 1421322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor } 1422322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor 1423df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 1424ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian Diag(Tok, diag::err_expected_ident); 1425ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian break; 1426ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1427f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian propertyIvar = Tok.getIdentifierInfo(); 1428ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); // consume ivar-name 1429ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 143023c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.ActOnPropertyImplDecl(getCurScope(), atLoc, propertyLoc, true, ObjCImpDecl, 1431f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian propertyId, propertyIvar); 1432df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::comma)) 1433ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian break; 1434ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); // consume ',' 1435ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1436b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor if (Tok.isNot(tok::semi)) { 14371ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_semi_after) << "@synthesize"; 1438b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor SkipUntil(tok::semi); 1439b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor } 1440d3fdcb5a1bf6bd5e54e18579c054ea3c292a0e28Fariborz Jahanian else 1441d3fdcb5a1bf6bd5e54e18579c054ea3c292a0e28Fariborz Jahanian ConsumeToken(); // consume ';' 1442d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 1443ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian} 1444ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian 1445ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-dynamic: 1446ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// @dynamic property-list 1447ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// 1448ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-list: 1449ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// identifier 1450ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-list ',' identifier 1451ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// 1452d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseObjCPropertyDynamic(SourceLocation atLoc) { 1453ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian assert(Tok.isObjCAtKeyword(tok::objc_dynamic) && 1454ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian "ParseObjCPropertyDynamic(): Expected '@dynamic'"); 1455ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian SourceLocation loc = ConsumeToken(); // consume dynamic 1456424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor while (true) { 1457424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor if (Tok.is(tok::code_completion)) { 145823c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCPropertyDefinition(getCurScope(), ObjCImpDecl); 1459dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 1460424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor } 1461424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor 1462424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor if (Tok.isNot(tok::identifier)) { 1463424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor Diag(Tok, diag::err_expected_ident); 1464424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor SkipUntil(tok::semi); 1465d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 1466424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor } 1467424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor 1468c35b9e4e2efad727538c848cf30d4b0eb1031dc9Fariborz Jahanian IdentifierInfo *propertyId = Tok.getIdentifierInfo(); 1469c35b9e4e2efad727538c848cf30d4b0eb1031dc9Fariborz Jahanian SourceLocation propertyLoc = ConsumeToken(); // consume property name 147023c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.ActOnPropertyImplDecl(getCurScope(), atLoc, propertyLoc, false, ObjCImpDecl, 1471c35b9e4e2efad727538c848cf30d4b0eb1031dc9Fariborz Jahanian propertyId, 0); 1472c35b9e4e2efad727538c848cf30d4b0eb1031dc9Fariborz Jahanian 1473df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::comma)) 1474ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian break; 1475ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); // consume ',' 1476ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 147794b24db37e80a75c4088e592d4150fb12b00bfb3Fariborz Jahanian if (Tok.isNot(tok::semi)) { 14781ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_semi_after) << "@dynamic"; 147994b24db37e80a75c4088e592d4150fb12b00bfb3Fariborz Jahanian SkipUntil(tok::semi); 148094b24db37e80a75c4088e592d4150fb12b00bfb3Fariborz Jahanian } 148194b24db37e80a75c4088e592d4150fb12b00bfb3Fariborz Jahanian else 148294b24db37e80a75c4088e592d4150fb12b00bfb3Fariborz Jahanian ConsumeToken(); // consume ';' 1483d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 1484ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian} 14851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1486397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// objc-throw-statement: 1487397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// throw expression[opt]; 1488397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// 148960d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult Parser::ParseObjCThrowStmt(SourceLocation atLoc) { 149060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Res; 1491397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian ConsumeToken(); // consume throw 1492df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::semi)) { 149339f8f159c488a900e5958d5aab3e467af9ec8a2bFariborz Jahanian Res = ParseExpression(); 14940e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Res.isInvalid()) { 1495397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian SkipUntil(tok::semi); 149643bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 1497397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian } 1498397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian } 149902418c7f0cb8bb83f1a1a1fad9bf6104efa83e0eTed Kremenek // consume ';' 150002418c7f0cb8bb83f1a1a1fad9bf6104efa83e0eTed Kremenek ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@throw"); 15019ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return Actions.ActOnObjCAtThrowStmt(atLoc, Res.take(), getCurScope()); 1502397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian} 1503397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian 1504c385c90c68dfa376650e2facfbb444b2ec9bd110Fariborz Jahanian/// objc-synchronized-statement: 150578a677bbb5fa115fa0995b5783adeeefad67167eFariborz Jahanian/// @synchronized '(' expression ')' compound-statement 1506c385c90c68dfa376650e2facfbb444b2ec9bd110Fariborz Jahanian/// 150760d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 150843bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian RedlParser::ParseObjCSynchronizedStmt(SourceLocation atLoc) { 1509fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian ConsumeToken(); // consume synchronized 1510fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian if (Tok.isNot(tok::l_paren)) { 15111ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_lparen_after) << "@synchronized"; 151243bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 1513fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian } 1514fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian ConsumeParen(); // '(' 151560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Res(ParseExpression()); 15160e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Res.isInvalid()) { 1517fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian SkipUntil(tok::semi); 151843bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 1519fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian } 1520fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian if (Tok.isNot(tok::r_paren)) { 15211ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_lbrace); 152243bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 1523fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian } 1524fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian ConsumeParen(); // ')' 152578a677bbb5fa115fa0995b5783adeeefad67167eFariborz Jahanian if (Tok.isNot(tok::l_brace)) { 15261ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_lbrace); 152743bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 152878a677bbb5fa115fa0995b5783adeeefad67167eFariborz Jahanian } 15293ac438c383a4a9a73c76a05c76ec5d02f10a3c52Steve Naroff // Enter a scope to hold everything within the compound stmt. Compound 15303ac438c383a4a9a73c76a05c76ec5d02f10a3c52Steve Naroff // statements can always hold declarations. 15318935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor ParseScope BodyScope(this, Scope::DeclScope); 15323ac438c383a4a9a73c76a05c76ec5d02f10a3c52Steve Naroff 153360d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult SynchBody(ParseCompoundStatementBody()); 15340e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl 15358935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor BodyScope.Exit(); 15360e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (SynchBody.isInvalid()) 1537fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian SynchBody = Actions.ActOnNullStmt(Tok.getLocation()); 15389ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return Actions.ActOnObjCAtSynchronizedStmt(atLoc, Res.take(), SynchBody.take()); 1539c385c90c68dfa376650e2facfbb444b2ec9bd110Fariborz Jahanian} 1540c385c90c68dfa376650e2facfbb444b2ec9bd110Fariborz Jahanian 1541397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// objc-try-catch-statement: 1542397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// @try compound-statement objc-catch-list[opt] 1543397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// @try compound-statement objc-catch-list[opt] @finally compound-statement 1544397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// 1545397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// objc-catch-list: 1546397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// @catch ( parameter-declaration ) compound-statement 1547397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// objc-catch-list @catch ( catch-parameter-declaration ) compound-statement 1548397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// catch-parameter-declaration: 1549397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// parameter-declaration 1550397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// '...' [OBJC2] 1551397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// 155260d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult Parser::ParseObjCTryStmt(SourceLocation atLoc) { 1553397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian bool catch_or_finally_seen = false; 155443bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl 1555397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian ConsumeToken(); // consume try 1556df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::l_brace)) { 15571ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_lbrace); 155843bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 1559397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian } 15608f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor StmtVector CatchStmts(Actions); 156160d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult FinallyStmt; 15628935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor ParseScope TryScope(this, Scope::DeclScope); 156360d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult TryBody(ParseCompoundStatementBody()); 15648935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor TryScope.Exit(); 15650e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (TryBody.isInvalid()) 1566bd49a647afd9cc534fef13cadf652d4e9c396e2bFariborz Jahanian TryBody = Actions.ActOnNullStmt(Tok.getLocation()); 1567a55e52c0802cae3b7c366a05c461d3d15074c1a3Sebastian Redl 1568df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner while (Tok.is(tok::at)) { 15696b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner // At this point, we need to lookahead to determine if this @ is the start 15706b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner // of an @catch or @finally. We don't want to consume the @ token if this 15716b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner // is an @try or @encode or something else. 15726b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner Token AfterAt = GetLookAheadToken(1); 15736b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner if (!AfterAt.isObjCAtKeyword(tok::objc_catch) && 15746b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner !AfterAt.isObjCAtKeyword(tok::objc_finally)) 15756b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner break; 15760e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl 1577161a9c5afaafb4d527b7efba9675a8b2cbbe32e0Fariborz Jahanian SourceLocation AtCatchFinallyLoc = ConsumeToken(); 1578cb53b361bce341c8591333c6997f62e480acc0b4Chris Lattner if (Tok.isObjCAtKeyword(tok::objc_catch)) { 1579d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *FirstPart = 0; 15803b1191d7eaf2f4984564e01ab84b6713a9d80e70Fariborz Jahanian ConsumeToken(); // consume catch 1581df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::l_paren)) { 1582397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian ConsumeParen(); 1583e21dd6ffef4585fa43cd3586ed971217d65bf56cSteve Naroff ParseScope CatchScope(this, Scope::DeclScope|Scope::AtCatchScope); 1584df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::ellipsis)) { 1585397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian DeclSpec DS; 1586397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian ParseDeclarationSpecifiers(DS); 158743bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl // For some odd reason, the name of the exception variable is 15881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // optional. As a result, we need to use "PrototypeContext", because 15897ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff // we must accept either 'declarator' or 'abstract-declarator' here. 15907ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff Declarator ParmDecl(DS, Declarator::PrototypeContext); 15917ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff ParseDeclarator(ParmDecl); 15927ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff 15934e6c0d19b7c072758922cf80525a81aeefc6e64bDouglas Gregor // Inform the actions module about the declarator, so it 15947ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff // gets added to the current scope. 159523c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor FirstPart = Actions.ActOnObjCExceptionDecl(getCurScope(), ParmDecl); 159664515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff } else 1597397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian ConsumeToken(); // consume '...' 15981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 159993a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff SourceLocation RParenLoc; 16001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 160193a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff if (Tok.is(tok::r_paren)) 160293a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff RParenLoc = ConsumeParen(); 160393a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff else // Skip over garbage, until we get to ')'. Eat the ')'. 160493a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff SkipUntil(tok::r_paren, true, false); 160593a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff 160660d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult CatchBody(true); 1607c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner if (Tok.is(tok::l_brace)) 1608c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner CatchBody = ParseCompoundStatementBody(); 1609c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner else 1610c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner Diag(Tok, diag::err_expected_lbrace); 16110e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (CatchBody.isInvalid()) 16123b1191d7eaf2f4984564e01ab84b6713a9d80e70Fariborz Jahanian CatchBody = Actions.ActOnNullStmt(Tok.getLocation()); 16138f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor 161460d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Catch = Actions.ActOnObjCAtCatchStmt(AtCatchFinallyLoc, 16158f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor RParenLoc, 16168f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor FirstPart, 16179ae2f076ca5ab1feb3ba95629099ec2319833701John McCall CatchBody.take()); 16188f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor if (!Catch.isInvalid()) 16198f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor CatchStmts.push_back(Catch.release()); 16208f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor 162164515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff } else { 16221ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(AtCatchFinallyLoc, diag::err_expected_lparen_after) 16231ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner << "@catch clause"; 162443bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 1625397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian } 1626397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian catch_or_finally_seen = true; 16276b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner } else { 16286b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner assert(Tok.isObjCAtKeyword(tok::objc_finally) && "Lookahead confused?"); 162964515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff ConsumeToken(); // consume finally 16308935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor ParseScope FinallyScope(this, Scope::DeclScope); 16310e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl 163260d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult FinallyBody(true); 1633c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner if (Tok.is(tok::l_brace)) 1634c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner FinallyBody = ParseCompoundStatementBody(); 1635c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner else 1636c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner Diag(Tok, diag::err_expected_lbrace); 16370e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (FinallyBody.isInvalid()) 1638161a9c5afaafb4d527b7efba9675a8b2cbbe32e0Fariborz Jahanian FinallyBody = Actions.ActOnNullStmt(Tok.getLocation()); 16390e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl FinallyStmt = Actions.ActOnObjCAtFinallyStmt(AtCatchFinallyLoc, 16409ae2f076ca5ab1feb3ba95629099ec2319833701John McCall FinallyBody.take()); 1641397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian catch_or_finally_seen = true; 1642397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian break; 1643397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian } 1644397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian } 1645bd49a647afd9cc534fef13cadf652d4e9c396e2bFariborz Jahanian if (!catch_or_finally_seen) { 1646397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian Diag(atLoc, diag::err_missing_catch_finally); 164743bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 1648bd49a647afd9cc534fef13cadf652d4e9c396e2bFariborz Jahanian } 16498f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor 16509ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return Actions.ActOnObjCAtTryStmt(atLoc, TryBody.take(), 16518f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor move_arg(CatchStmts), 16529ae2f076ca5ab1feb3ba95629099ec2319833701John McCall FinallyStmt.take()); 1653397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian} 1654ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian 16553536b443bc50d58a79f14fca9b6842541a434854Steve Naroff/// objc-method-def: objc-method-proto ';'[opt] '{' body '}' 1656ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// 1657d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseObjCMethodDefinition() { 1658d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *MDecl = ParseObjCMethodPrototype(ObjCImpDecl); 16591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1660f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall PrettyDeclStackTraceEntry CrashInfo(Actions, MDecl, Tok.getLocation(), 1661f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall "parsing Objective-C method"); 16621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1663ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian // parse optional ';' 1664209a8c2fa23636f6d065d618e7078e164903f5cdFariborz Jahanian if (Tok.is(tok::semi)) { 1665496e45ef3350fabc312c5a807d308c65c50af4dbTed Kremenek if (ObjCImpDecl) { 1666496e45ef3350fabc312c5a807d308c65c50af4dbTed Kremenek Diag(Tok, diag::warn_semicolon_before_method_body) 1667849b243d4065f56742a4677d6dc8277609a151f8Douglas Gregor << FixItHint::CreateRemoval(Tok.getLocation()); 1668496e45ef3350fabc312c5a807d308c65c50af4dbTed Kremenek } 1669ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); 1670209a8c2fa23636f6d065d618e7078e164903f5cdFariborz Jahanian } 1671ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian 1672409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // We should have an opening brace now. 1673df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::l_brace)) { 1674da323adbb99cee19a203ead852d5d9bfebb23fb7Steve Naroff Diag(Tok, diag::err_expected_method_body); 16751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1676409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // Skip over garbage, until we get to '{'. Don't eat the '{'. 1677409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff SkipUntil(tok::l_brace, true, true); 16781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1679409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // If we didn't find the '{', bail out. 1680409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff if (Tok.isNot(tok::l_brace)) 1681d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 1682ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1683409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff SourceLocation BraceLoc = Tok.getLocation(); 16841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1685409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // Enter a scope for the method body. 168615faee19fdb9017dd6d08a690427b18c3b062c2dChris Lattner ParseScope BodyScope(this, 168715faee19fdb9017dd6d08a690427b18c3b062c2dChris Lattner Scope::ObjCMethodScope|Scope::FnScope|Scope::DeclScope); 16881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1689409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // Tell the actions module that we have entered a method definition with the 1690394f3f483fa4e7b472630cfcd03f7840520958c5Steve Naroff // specified Declarator for the method. 169123c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.ActOnStartOfObjCMethodDef(getCurScope(), MDecl); 169261364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl 169360d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult FnBody(ParseCompoundStatementBody()); 169461364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl 1695409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // If the function body could not be parsed, make a bogus compoundstmt. 16960e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (FnBody.isInvalid()) 1697a60528cdac7deee3991c2b48af4df4f315e49e9dSebastian Redl FnBody = Actions.ActOnCompoundStmt(BraceLoc, BraceLoc, 1698a60528cdac7deee3991c2b48af4df4f315e49e9dSebastian Redl MultiStmtArg(Actions), false); 1699798d119415323ebcd029ffe1e0fb442a4ca8adbbSebastian Redl 170032ce8376efb7e0d70e5f7e8fcf685130293f412bSteve Naroff // TODO: Pass argument information. 17019ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Actions.ActOnFinishFunctionBody(MDecl, FnBody.take()); 17021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1703409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // Leave the function body scope. 17048935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor BodyScope.Exit(); 1705798d119415323ebcd029ffe1e0fb442a4ca8adbbSebastian Redl 170671c0a951d08dc7a2a057df8c15f22b36f6aa47c7Steve Naroff return MDecl; 17075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 17085508518a2702b00be3b15a26d772bde968972f54Anders Carlsson 170960d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult Parser::ParseObjCAtStatement(SourceLocation AtLoc) { 17109a0c85e640a08174569a303db22981612f05d385Douglas Gregor if (Tok.is(tok::code_completion)) { 171123c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCAtStatement(getCurScope()); 1712dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 17139a0c85e640a08174569a303db22981612f05d385Douglas Gregor return StmtError(); 17145d8031687d086701b4dadaab3e0de1def448da9dChris Lattner } 17155d8031687d086701b4dadaab3e0de1def448da9dChris Lattner 17165d8031687d086701b4dadaab3e0de1def448da9dChris Lattner if (Tok.isObjCAtKeyword(tok::objc_try)) 17176b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner return ParseObjCTryStmt(AtLoc); 17185d8031687d086701b4dadaab3e0de1def448da9dChris Lattner 17195d8031687d086701b4dadaab3e0de1def448da9dChris Lattner if (Tok.isObjCAtKeyword(tok::objc_throw)) 172064515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff return ParseObjCThrowStmt(AtLoc); 17215d8031687d086701b4dadaab3e0de1def448da9dChris Lattner 17225d8031687d086701b4dadaab3e0de1def448da9dChris Lattner if (Tok.isObjCAtKeyword(tok::objc_synchronized)) 172364515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff return ParseObjCSynchronizedStmt(AtLoc); 17245d8031687d086701b4dadaab3e0de1def448da9dChris Lattner 172560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Res(ParseExpressionWithLeadingAt(AtLoc)); 17260e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Res.isInvalid()) { 172764515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff // If the expression is invalid, skip ahead to the next semicolon. Not 172864515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff // doing this opens us up to the possibility of infinite loops if 172964515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff // ParseExpression does not consume any tokens. 173064515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff SkipUntil(tok::semi); 173143bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 173264515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff } 17335d8031687d086701b4dadaab3e0de1def448da9dChris Lattner 173464515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff // Otherwise, eat the semicolon. 17359ba23b4ceacd77cd264501690a7a9e94184ef71bDouglas Gregor ExpectAndConsumeSemi(diag::err_expected_semi_after_expr); 17369ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return Actions.ActOnExprStmt(Actions.MakeFullExpr(Res.take())); 173764515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff} 173864515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff 173960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult Parser::ParseObjCAtExpression(SourceLocation AtLoc) { 17405508518a2702b00be3b15a26d772bde968972f54Anders Carlsson switch (Tok.getKind()) { 17419a0c85e640a08174569a303db22981612f05d385Douglas Gregor case tok::code_completion: 174223c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCAtExpression(getCurScope()); 1743dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 17449a0c85e640a08174569a303db22981612f05d385Douglas Gregor return ExprError(); 17459a0c85e640a08174569a303db22981612f05d385Douglas Gregor 1746b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner case tok::string_literal: // primary-expression: string-literal 1747b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner case tok::wide_string_literal: 17481d922960e083906a586609ac6978678147250177Sebastian Redl return ParsePostfixExpressionSuffix(ParseObjCStringLiteral(AtLoc)); 1749b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner default: 17504fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner if (Tok.getIdentifierInfo() == 0) 17511d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(AtLoc, diag::err_unexpected_at)); 17522f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl 17534fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner switch (Tok.getIdentifierInfo()->getObjCKeywordID()) { 17544fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner case tok::objc_encode: 17551d922960e083906a586609ac6978678147250177Sebastian Redl return ParsePostfixExpressionSuffix(ParseObjCEncodeExpression(AtLoc)); 17564fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner case tok::objc_protocol: 17571d922960e083906a586609ac6978678147250177Sebastian Redl return ParsePostfixExpressionSuffix(ParseObjCProtocolExpression(AtLoc)); 17584fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner case tok::objc_selector: 17591d922960e083906a586609ac6978678147250177Sebastian Redl return ParsePostfixExpressionSuffix(ParseObjCSelectorExpression(AtLoc)); 17604fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner default: 17611d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(AtLoc, diag::err_unexpected_at)); 17624fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner } 17635508518a2702b00be3b15a26d772bde968972f54Anders Carlsson } 17645508518a2702b00be3b15a26d772bde968972f54Anders Carlsson} 17655508518a2702b00be3b15a26d772bde968972f54Anders Carlsson 17666aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// \brirg Parse the receiver of an Objective-C++ message send. 17676aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// 17686aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// This routine parses the receiver of a message send in 17696aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// Objective-C++ either as a type or as an expression. Note that this 17706aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// routine must not be called to parse a send to 'super', since it 17716aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// has no way to return such a result. 17726aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// 17736aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// \param IsExpr Whether the receiver was parsed as an expression. 17746aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// 17756aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// \param TypeOrExpr If the receiver was parsed as an expression (\c 17766aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// IsExpr is true), the parsed expression. If the receiver was parsed 17776aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// as a type (\c IsExpr is false), the parsed type. 17786aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// 17796aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// \returns True if an error occurred during parsing or semantic 17806aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// analysis, in which case the arguments do not have valid 17816aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// values. Otherwise, returns false for a successful parse. 17826aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// 17836aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// objc-receiver: [C++] 17846aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// 'super' [not parsed here] 17856aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// expression 17866aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// simple-type-specifier 17876aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// typename-specifier 17886aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregorbool Parser::ParseObjCXXMessageReceiver(bool &IsExpr, void *&TypeOrExpr) { 17890fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor InMessageExpressionRAIIObject InMessage(*this, true); 17900fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor 17916aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor if (Tok.is(tok::identifier) || Tok.is(tok::coloncolon) || 17926aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor Tok.is(tok::kw_typename) || Tok.is(tok::annot_cxxscope)) 17936aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor TryAnnotateTypeOrScopeToken(); 17946aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 17956aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor if (!isCXXSimpleTypeSpecifier()) { 17966aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // objc-receiver: 17976aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // expression 179860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Receiver = ParseExpression(); 17996aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor if (Receiver.isInvalid()) 18006aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor return true; 18016aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 18026aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor IsExpr = true; 18036aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor TypeOrExpr = Receiver.take(); 18046aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor return false; 18056aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor } 18066aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 18076aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // objc-receiver: 18086aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // typename-specifier 18096aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // simple-type-specifier 18106aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // expression (that starts with one of the above) 18116aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor DeclSpec DS; 18126aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor ParseCXXSimpleTypeSpecifier(DS); 18136aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 18146aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor if (Tok.is(tok::l_paren)) { 18156aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // If we see an opening parentheses at this point, we are 18166aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // actually parsing an expression that starts with a 18176aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // function-style cast, e.g., 18186aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // 18196aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // postfix-expression: 18206aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // simple-type-specifier ( expression-list [opt] ) 18216aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // typename-specifier ( expression-list [opt] ) 18226aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // 18236aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // Parse the remainder of this case, then the (optional) 18246aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // postfix-expression suffix, followed by the (optional) 18256aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // right-hand side of the binary expression. We have an 18266aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // instance method. 182760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Receiver = ParseCXXTypeConstructExpression(DS); 18286aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor if (!Receiver.isInvalid()) 18299ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Receiver = ParsePostfixExpressionSuffix(Receiver.take()); 18306aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor if (!Receiver.isInvalid()) 18319ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Receiver = ParseRHSOfBinaryExpression(Receiver.take(), prec::Comma); 18326aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor if (Receiver.isInvalid()) 18336aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor return true; 18346aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 18356aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor IsExpr = true; 18366aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor TypeOrExpr = Receiver.take(); 18376aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor return false; 18386aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor } 18396aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 18406aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // We have a class message. Turn the simple-type-specifier or 18416aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // typename-specifier we parsed into a type and parse the 18426aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // remainder of the class message. 18436aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor Declarator DeclaratorInfo(DS, Declarator::TypeNameContext); 184423c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor TypeResult Type = Actions.ActOnTypeName(getCurScope(), DeclaratorInfo); 18456aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor if (Type.isInvalid()) 18466aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor return true; 18476aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 18486aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor IsExpr = false; 1849b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall TypeOrExpr = Type.get().getAsOpaquePtr(); 18506aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor return false; 18516aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor} 18526aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 18531b730e847ded503f2e615154035c083c4f94a067Douglas Gregor/// \brief Determine whether the parser is currently referring to a an 18541b730e847ded503f2e615154035c083c4f94a067Douglas Gregor/// Objective-C message send, using a simplified heuristic to avoid overhead. 18551b730e847ded503f2e615154035c083c4f94a067Douglas Gregor/// 18561b730e847ded503f2e615154035c083c4f94a067Douglas Gregor/// This routine will only return true for a subset of valid message-send 18571b730e847ded503f2e615154035c083c4f94a067Douglas Gregor/// expressions. 18581b730e847ded503f2e615154035c083c4f94a067Douglas Gregorbool Parser::isSimpleObjCMessageExpression() { 1859c59cb38810c63a806270385f79ea84e0203754eaChris Lattner assert(Tok.is(tok::l_square) && getLang().ObjC1 && 18601b730e847ded503f2e615154035c083c4f94a067Douglas Gregor "Incorrect start for isSimpleObjCMessageExpression"); 18611b730e847ded503f2e615154035c083c4f94a067Douglas Gregor return GetLookAheadToken(1).is(tok::identifier) && 18621b730e847ded503f2e615154035c083c4f94a067Douglas Gregor GetLookAheadToken(2).is(tok::identifier); 18631b730e847ded503f2e615154035c083c4f94a067Douglas Gregor} 18641b730e847ded503f2e615154035c083c4f94a067Douglas Gregor 18651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// objc-message-expr: 18660ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// '[' objc-receiver objc-message-args ']' 18670ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// 18682725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// objc-receiver: [C] 1869eb483eb3ee80300f15d6d13573d82493c2194461Chris Lattner/// 'super' 18700ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// expression 18710ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// class-name 18720ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// type-name 18736aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// 187460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult Parser::ParseObjCMessageExpression() { 1875699b66138ac307a32e238463e0eff513ff17d337Chris Lattner assert(Tok.is(tok::l_square) && "'[' expected"); 1876699b66138ac307a32e238463e0eff513ff17d337Chris Lattner SourceLocation LBracLoc = ConsumeBracket(); // consume '[' 1877699b66138ac307a32e238463e0eff513ff17d337Chris Lattner 18788e254cfe5a6ab4202c7fcc4b64bdd1ca0fe071acDouglas Gregor if (Tok.is(tok::code_completion)) { 187923c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCMessageReceiver(getCurScope()); 18808e254cfe5a6ab4202c7fcc4b64bdd1ca0fe071acDouglas Gregor ConsumeCodeCompletionToken(); 18818e254cfe5a6ab4202c7fcc4b64bdd1ca0fe071acDouglas Gregor SkipUntil(tok::r_square); 18828e254cfe5a6ab4202c7fcc4b64bdd1ca0fe071acDouglas Gregor return ExprError(); 18838e254cfe5a6ab4202c7fcc4b64bdd1ca0fe071acDouglas Gregor } 18848e254cfe5a6ab4202c7fcc4b64bdd1ca0fe071acDouglas Gregor 18850fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor InMessageExpressionRAIIObject InMessage(*this, true); 18860fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor 18876aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor if (getLang().CPlusPlus) { 18886aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // We completely separate the C and C++ cases because C++ requires 18896aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // more complicated (read: slower) parsing. 18906aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 18916aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // Handle send to super. 18926aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // FIXME: This doesn't benefit from the same typo-correction we 18936aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // get in Objective-C. 18946aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor if (Tok.is(tok::identifier) && Tok.getIdentifierInfo() == Ident_super && 189523c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor NextToken().isNot(tok::period) && getCurScope()->isInObjcMethodScope()) 1896b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall return ParseObjCMessageExpressionBody(LBracLoc, ConsumeToken(), 1897b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType(), 0); 18986aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 18996aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // Parse the receiver, which is either a type or an expression. 19006aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor bool IsExpr; 1901304b752a450c0fc5968c20ba25446d0bb7c6f68dNick Lewycky void *TypeOrExpr = NULL; 19026aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor if (ParseObjCXXMessageReceiver(IsExpr, TypeOrExpr)) { 19036aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor SkipUntil(tok::r_square); 19046aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor return ExprError(); 19056aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor } 19066aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 19076aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor if (IsExpr) 1908b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(), 1909b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType(), 19109ae2f076ca5ab1feb3ba95629099ec2319833701John McCall static_cast<Expr*>(TypeOrExpr)); 19116aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 19126aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(), 1913b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType::getFromOpaquePtr(TypeOrExpr), 1914b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall 0); 1915c59cb38810c63a806270385f79ea84e0203754eaChris Lattner } 1916c59cb38810c63a806270385f79ea84e0203754eaChris Lattner 1917c59cb38810c63a806270385f79ea84e0203754eaChris Lattner if (Tok.is(tok::identifier)) { 19181dbca6ea983231b4cab1a8f1edda8f6e13c21f12Douglas Gregor IdentifierInfo *Name = Tok.getIdentifierInfo(); 19191dbca6ea983231b4cab1a8f1edda8f6e13c21f12Douglas Gregor SourceLocation NameLoc = Tok.getLocation(); 1920b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ReceiverType; 192123c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor switch (Actions.getObjCMessageKind(getCurScope(), Name, NameLoc, 19221dbca6ea983231b4cab1a8f1edda8f6e13c21f12Douglas Gregor Name == Ident_super, 19231569f95831a8c99e9f664137bf8f40e47ee3d90fDouglas Gregor NextToken().is(tok::period), 19241569f95831a8c99e9f664137bf8f40e47ee3d90fDouglas Gregor ReceiverType)) { 1925f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall case Sema::ObjCSuperMessage: 1926b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall return ParseObjCMessageExpressionBody(LBracLoc, ConsumeToken(), 1927b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType(), 0); 19282725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor 1929f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall case Sema::ObjCClassMessage: 19301569f95831a8c99e9f664137bf8f40e47ee3d90fDouglas Gregor if (!ReceiverType) { 19312725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor SkipUntil(tok::r_square); 19322725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor return ExprError(); 19332725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor } 19342725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor 19351569f95831a8c99e9f664137bf8f40e47ee3d90fDouglas Gregor ConsumeToken(); // the type name 19361569f95831a8c99e9f664137bf8f40e47ee3d90fDouglas Gregor 19371569f95831a8c99e9f664137bf8f40e47ee3d90fDouglas Gregor return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(), 19389ae2f076ca5ab1feb3ba95629099ec2319833701John McCall ReceiverType, 0); 19391dbca6ea983231b4cab1a8f1edda8f6e13c21f12Douglas Gregor 1940f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall case Sema::ObjCInstanceMessage: 19412725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor // Fall through to parse an expression. 19421dbca6ea983231b4cab1a8f1edda8f6e13c21f12Douglas Gregor break; 1943d2869925b5f10e00b13fbf3f41bbb17e4c9adbe0Fariborz Jahanian } 1944699b66138ac307a32e238463e0eff513ff17d337Chris Lattner } 1945eb483eb3ee80300f15d6d13573d82493c2194461Chris Lattner 1946eb483eb3ee80300f15d6d13573d82493c2194461Chris Lattner // Otherwise, an arbitrary expression can be the receiver of a send. 194760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Res(ParseExpression()); 19480e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Res.isInvalid()) { 19495c749428a9938d5e2e9564b1c9b7a9252c30ee27Chris Lattner SkipUntil(tok::r_square); 19501d922960e083906a586609ac6978678147250177Sebastian Redl return move(Res); 1951699b66138ac307a32e238463e0eff513ff17d337Chris Lattner } 19521d922960e083906a586609ac6978678147250177Sebastian Redl 1953b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(), 1954b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType(), Res.take()); 1955699b66138ac307a32e238463e0eff513ff17d337Chris Lattner} 19561d922960e083906a586609ac6978678147250177Sebastian Redl 19572725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// \brief Parse the remainder of an Objective-C message following the 19582725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// '[' objc-receiver. 19592725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// 19602725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// This routine handles sends to super, class messages (sent to a 19612725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// class name), and instance messages (sent to an object), and the 19622725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// target is represented by \p SuperLoc, \p ReceiverType, or \p 19632725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// ReceiverExpr, respectively. Only one of these parameters may have 19642725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// a valid value. 19652725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// 19662725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// \param LBracLoc The location of the opening '['. 19672725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// 19682725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// \param SuperLoc If this is a send to 'super', the location of the 19692725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// 'super' keyword that indicates a send to the superclass. 19702725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// 19712725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// \param ReceiverType If this is a class message, the type of the 19722725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// class we are sending a message to. 19732725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// 19742725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// \param ReceiverExpr If this is an instance message, the expression 19752725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// used to compute the receiver object. 19761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 19770ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-message-args: 19780ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-selector 19790ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-keywordarg-list 19800ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// 19810ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-keywordarg-list: 19820ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-keywordarg 19830ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-keywordarg-list objc-keywordarg 19840ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// 19851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// objc-keywordarg: 19860ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// selector-name[opt] ':' objc-keywordexpr 19870ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// 19880ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-keywordexpr: 19890ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// nonempty-expr-list 19900ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// 19910ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// nonempty-expr-list: 19920ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// assignment-expression 19930ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// nonempty-expr-list , assignment-expression 19941d922960e083906a586609ac6978678147250177Sebastian Redl/// 199560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 1996699b66138ac307a32e238463e0eff513ff17d337Chris LattnerParser::ParseObjCMessageExpressionBody(SourceLocation LBracLoc, 19972725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor SourceLocation SuperLoc, 1998b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ReceiverType, 19991d922960e083906a586609ac6978678147250177Sebastian Redl ExprArg ReceiverExpr) { 20000fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor InMessageExpressionRAIIObject InMessage(*this, true); 20010fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor 2002c4df6d2c05c647a6a5770ba0c749782b6c023a3aSteve Naroff if (Tok.is(tok::code_completion)) { 20032725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor if (SuperLoc.isValid()) 200423c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCSuperMessage(getCurScope(), SuperLoc, 0, 0); 20052725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor else if (ReceiverType) 200623c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCClassMessage(getCurScope(), ReceiverType, 0, 0); 2007c4df6d2c05c647a6a5770ba0c749782b6c023a3aSteve Naroff else 20089ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Actions.CodeCompleteObjCInstanceMessage(getCurScope(), ReceiverExpr, 2009d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor 0, 0); 2010dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 2011c4df6d2c05c647a6a5770ba0c749782b6c023a3aSteve Naroff } 2012d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor 2013a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian // Parse objc-selector 20144b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian SourceLocation Loc; 20152fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner IdentifierInfo *selIdent = ParseObjCSelectorPiece(Loc); 201668d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff 2017ff975cfab9ada27df86038286d1678084aeb3428Anders Carlsson SourceLocation SelectorLoc = Loc; 20181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 201968d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff llvm::SmallVector<IdentifierInfo *, 12> KeyIdents; 2020a55e52c0802cae3b7c366a05c461d3d15074c1a3Sebastian Redl ExprVector KeyExprs(Actions); 202168d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff 2022df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::colon)) { 2023a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian while (1) { 2024a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian // Each iteration parses a single keyword argument. 202568d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff KeyIdents.push_back(selIdent); 202637387c932855c6d58d70bdd705cd3a9fdcd2a931Steve Naroff 2027df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::colon)) { 2028a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian Diag(Tok, diag::err_expected_colon); 20294fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // We must manually skip to a ']', otherwise the expression skipper will 20304fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // stop at the ']' when it skips to the ';'. We want it to skip beyond 20314fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // the enclosing expression. 20324fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner SkipUntil(tok::r_square); 20331d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(); 2034a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian } 20351d922960e083906a586609ac6978678147250177Sebastian Redl 203668d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff ConsumeToken(); // Eat the ':'. 20371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// Parse the expression after ':' 203860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Res(ParseAssignmentExpression()); 20390e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Res.isInvalid()) { 20404fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // We must manually skip to a ']', otherwise the expression skipper will 20414fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // stop at the ']' when it skips to the ';'. We want it to skip beyond 20424fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // the enclosing expression. 20434fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner SkipUntil(tok::r_square); 20441d922960e083906a586609ac6978678147250177Sebastian Redl return move(Res); 204537387c932855c6d58d70bdd705cd3a9fdcd2a931Steve Naroff } 20461d922960e083906a586609ac6978678147250177Sebastian Redl 204737387c932855c6d58d70bdd705cd3a9fdcd2a931Steve Naroff // We have a valid expression. 2048effa8d1c97b00a3f53e972b0e61d9aade5ea1c57Sebastian Redl KeyExprs.push_back(Res.release()); 20491d922960e083906a586609ac6978678147250177Sebastian Redl 2050d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor // Code completion after each argument. 2051d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor if (Tok.is(tok::code_completion)) { 20522725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor if (SuperLoc.isValid()) 205323c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCSuperMessage(getCurScope(), SuperLoc, 20542725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor KeyIdents.data(), 20552725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor KeyIdents.size()); 20562725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor else if (ReceiverType) 205723c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCClassMessage(getCurScope(), ReceiverType, 2058d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor KeyIdents.data(), 2059d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor KeyIdents.size()); 2060d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor else 20619ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Actions.CodeCompleteObjCInstanceMessage(getCurScope(), ReceiverExpr, 2062d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor KeyIdents.data(), 2063d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor KeyIdents.size()); 2064dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 2065d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor } 2066d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor 206737387c932855c6d58d70bdd705cd3a9fdcd2a931Steve Naroff // Check for another keyword selector. 20682fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner selIdent = ParseObjCSelectorPiece(Loc); 2069df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (!selIdent && Tok.isNot(tok::colon)) 2070a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian break; 2071a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian // We have a selector or a colon, continue parsing. 2072a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian } 2073a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian // Parse the, optional, argument list, comma separated. 2074df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner while (Tok.is(tok::comma)) { 207549f109c786f99eb7468dac3976db083a65493444Steve Naroff ConsumeToken(); // Eat the ','. 20761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// Parse the expression after ',' 207760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Res(ParseAssignmentExpression()); 20780e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Res.isInvalid()) { 20794fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // We must manually skip to a ']', otherwise the expression skipper will 20804fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // stop at the ']' when it skips to the ';'. We want it to skip beyond 20814fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // the enclosing expression. 20824fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner SkipUntil(tok::r_square); 20831d922960e083906a586609ac6978678147250177Sebastian Redl return move(Res); 208449f109c786f99eb7468dac3976db083a65493444Steve Naroff } 20850e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl 208649f109c786f99eb7468dac3976db083a65493444Steve Naroff // We have a valid expression. 2087effa8d1c97b00a3f53e972b0e61d9aade5ea1c57Sebastian Redl KeyExprs.push_back(Res.release()); 2088a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian } 2089a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian } else if (!selIdent) { 2090a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian Diag(Tok, diag::err_expected_ident); // missing selector name. 20911d922960e083906a586609ac6978678147250177Sebastian Redl 20924fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // We must manually skip to a ']', otherwise the expression skipper will 20934fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // stop at the ']' when it skips to the ';'. We want it to skip beyond 20944fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // the enclosing expression. 20954fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner SkipUntil(tok::r_square); 20961d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(); 2097a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian } 2098809872eca7f6c024e2ab41ddffbbeeae807bf5dcFariborz Jahanian 2099df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::r_square)) { 2100809872eca7f6c024e2ab41ddffbbeeae807bf5dcFariborz Jahanian if (Tok.is(tok::identifier)) 2101809872eca7f6c024e2ab41ddffbbeeae807bf5dcFariborz Jahanian Diag(Tok, diag::err_expected_colon); 2102809872eca7f6c024e2ab41ddffbbeeae807bf5dcFariborz Jahanian else 2103809872eca7f6c024e2ab41ddffbbeeae807bf5dcFariborz Jahanian Diag(Tok, diag::err_expected_rsquare); 21044fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // We must manually skip to a ']', otherwise the expression skipper will 21054fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // stop at the ']' when it skips to the ';'. We want it to skip beyond 21064fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // the enclosing expression. 21074fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner SkipUntil(tok::r_square); 21081d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(); 2109a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian } 21101d922960e083906a586609ac6978678147250177Sebastian Redl 2111699b66138ac307a32e238463e0eff513ff17d337Chris Lattner SourceLocation RBracLoc = ConsumeBracket(); // consume ']' 21121d922960e083906a586609ac6978678147250177Sebastian Redl 211329238a0bf7cbf5b396efb451a0adb5fe4aa037caSteve Naroff unsigned nKeys = KeyIdents.size(); 2114ff38491c18b060526d754765b952f4a497a89416Chris Lattner if (nKeys == 0) 2115ff38491c18b060526d754765b952f4a497a89416Chris Lattner KeyIdents.push_back(selIdent); 2116ff38491c18b060526d754765b952f4a497a89416Chris Lattner Selector Sel = PP.getSelectorTable().getSelector(nKeys, &KeyIdents[0]); 21171d922960e083906a586609ac6978678147250177Sebastian Redl 21182725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor if (SuperLoc.isValid()) 211923c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor return Actions.ActOnSuperMessage(getCurScope(), SuperLoc, Sel, 21202725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor LBracLoc, SelectorLoc, RBracLoc, 2121f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall MultiExprArg(Actions, 2122f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall KeyExprs.take(), 2123f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall KeyExprs.size())); 21242725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor else if (ReceiverType) 212523c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor return Actions.ActOnClassMessage(getCurScope(), ReceiverType, Sel, 21262725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor LBracLoc, SelectorLoc, RBracLoc, 2127f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall MultiExprArg(Actions, 2128f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall KeyExprs.take(), 2129f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall KeyExprs.size())); 21309ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return Actions.ActOnInstanceMessage(getCurScope(), ReceiverExpr, Sel, 21312725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor LBracLoc, SelectorLoc, RBracLoc, 2132f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall MultiExprArg(Actions, 2133f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall KeyExprs.take(), 2134f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall KeyExprs.size())); 21350ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian} 21360ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian 213760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult Parser::ParseObjCStringLiteral(SourceLocation AtLoc) { 213860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Res(ParseStringLiteralExpression()); 21391d922960e083906a586609ac6978678147250177Sebastian Redl if (Res.isInvalid()) return move(Res); 21401d922960e083906a586609ac6978678147250177Sebastian Redl 2141b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner // @"foo" @"bar" is a valid concatenated string. Eat any subsequent string 2142b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner // expressions. At this point, we know that the only valid thing that starts 2143b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner // with '@' is an @"". 2144b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner llvm::SmallVector<SourceLocation, 4> AtLocs; 2145a55e52c0802cae3b7c366a05c461d3d15074c1a3Sebastian Redl ExprVector AtStrings(Actions); 2146b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner AtLocs.push_back(AtLoc); 2147effa8d1c97b00a3f53e972b0e61d9aade5ea1c57Sebastian Redl AtStrings.push_back(Res.release()); 21480e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl 2149b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner while (Tok.is(tok::at)) { 2150b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner AtLocs.push_back(ConsumeToken()); // eat the @. 2151b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner 215215faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl // Invalid unless there is a string literal. 215397cf6eb380016db868866faf27a086cd55a316d4Chris Lattner if (!isTokenStringLiteral()) 215497cf6eb380016db868866faf27a086cd55a316d4Chris Lattner return ExprError(Diag(Tok, diag::err_objc_concat_string)); 2155b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner 215660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Lit(ParseStringLiteralExpression()); 21570e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Lit.isInvalid()) 21581d922960e083906a586609ac6978678147250177Sebastian Redl return move(Lit); 21590e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl 2160effa8d1c97b00a3f53e972b0e61d9aade5ea1c57Sebastian Redl AtStrings.push_back(Lit.release()); 2161b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner } 21621d922960e083906a586609ac6978678147250177Sebastian Redl 21631d922960e083906a586609ac6978678147250177Sebastian Redl return Owned(Actions.ParseObjCStringLiteral(&AtLocs[0], AtStrings.take(), 21641d922960e083906a586609ac6978678147250177Sebastian Redl AtStrings.size())); 21655508518a2702b00be3b15a26d772bde968972f54Anders Carlsson} 2166f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson 2167f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson/// objc-encode-expression: 2168f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson/// @encode ( type-name ) 216960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 21701d922960e083906a586609ac6978678147250177Sebastian RedlParser::ParseObjCEncodeExpression(SourceLocation AtLoc) { 2171861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff assert(Tok.isObjCAtKeyword(tok::objc_encode) && "Not an @encode expression!"); 21721d922960e083906a586609ac6978678147250177Sebastian Redl 2173f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson SourceLocation EncLoc = ConsumeToken(); 21741d922960e083906a586609ac6978678147250177Sebastian Redl 21754fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner if (Tok.isNot(tok::l_paren)) 21761d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(Tok, diag::err_expected_lparen_after) << "@encode"); 21771d922960e083906a586609ac6978678147250177Sebastian Redl 2178f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson SourceLocation LParenLoc = ConsumeParen(); 21791d922960e083906a586609ac6978678147250177Sebastian Redl 2180809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor TypeResult Ty = ParseTypeName(); 21811d922960e083906a586609ac6978678147250177Sebastian Redl 21824988ae3fda10743c8ed8a98cdcb5a783362587b4Anders Carlsson SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); 21831d922960e083906a586609ac6978678147250177Sebastian Redl 2184809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor if (Ty.isInvalid()) 2185809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor return ExprError(); 2186809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor 21871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return Owned(Actions.ParseObjCEncodeExpression(AtLoc, EncLoc, LParenLoc, 2188809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor Ty.get(), RParenLoc)); 2189f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson} 219029b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson 219129b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson/// objc-protocol-expression 219229b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson/// @protocol ( protocol-name ) 219360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 21941d922960e083906a586609ac6978678147250177Sebastian RedlParser::ParseObjCProtocolExpression(SourceLocation AtLoc) { 219529b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson SourceLocation ProtoLoc = ConsumeToken(); 21961d922960e083906a586609ac6978678147250177Sebastian Redl 21974fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner if (Tok.isNot(tok::l_paren)) 21981d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(Tok, diag::err_expected_lparen_after) << "@protocol"); 21991d922960e083906a586609ac6978678147250177Sebastian Redl 220029b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson SourceLocation LParenLoc = ConsumeParen(); 22011d922960e083906a586609ac6978678147250177Sebastian Redl 22024fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner if (Tok.isNot(tok::identifier)) 22031d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(Tok, diag::err_expected_ident)); 22041d922960e083906a586609ac6978678147250177Sebastian Redl 2205390d50a725497e99247dc104a7d2c2a255d3af14Fariborz Jahanian IdentifierInfo *protocolId = Tok.getIdentifierInfo(); 220629b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson ConsumeToken(); 22071d922960e083906a586609ac6978678147250177Sebastian Redl 22084988ae3fda10743c8ed8a98cdcb5a783362587b4Anders Carlsson SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); 220929b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson 22101d922960e083906a586609ac6978678147250177Sebastian Redl return Owned(Actions.ParseObjCProtocolExpression(protocolId, AtLoc, ProtoLoc, 22111d922960e083906a586609ac6978678147250177Sebastian Redl LParenLoc, RParenLoc)); 221229b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson} 2213a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian 2214a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian/// objc-selector-expression 2215a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian/// @selector '(' objc-keyword-selector ')' 221660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult Parser::ParseObjCSelectorExpression(SourceLocation AtLoc) { 2217a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian SourceLocation SelectorLoc = ConsumeToken(); 22181d922960e083906a586609ac6978678147250177Sebastian Redl 22194fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner if (Tok.isNot(tok::l_paren)) 22201d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(Tok, diag::err_expected_lparen_after) << "@selector"); 22211d922960e083906a586609ac6978678147250177Sebastian Redl 2222b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian llvm::SmallVector<IdentifierInfo *, 12> KeyIdents; 2223a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian SourceLocation LParenLoc = ConsumeParen(); 2224a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian SourceLocation sLoc; 2225458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor 2226458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor if (Tok.is(tok::code_completion)) { 2227458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor Actions.CodeCompleteObjCSelector(getCurScope(), KeyIdents.data(), 2228458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor KeyIdents.size()); 2229458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor ConsumeCodeCompletionToken(); 2230458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor MatchRHSPunctuation(tok::r_paren, LParenLoc); 2231458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor return ExprError(); 2232458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor } 2233458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor 22342fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner IdentifierInfo *SelIdent = ParseObjCSelectorPiece(sLoc); 22355add7541726348b9d1c8e96ac5031b87c41acff0Chris Lattner if (!SelIdent && // missing selector name. 22365add7541726348b9d1c8e96ac5031b87c41acff0Chris Lattner Tok.isNot(tok::colon) && Tok.isNot(tok::coloncolon)) 22371d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(Tok, diag::err_expected_ident)); 22381d922960e083906a586609ac6978678147250177Sebastian Redl 2239b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian KeyIdents.push_back(SelIdent); 2240887407e71fd58de452361b77d72970e32b20ebe0Steve Naroff unsigned nColons = 0; 2241887407e71fd58de452361b77d72970e32b20ebe0Steve Naroff if (Tok.isNot(tok::r_paren)) { 2242a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian while (1) { 22435add7541726348b9d1c8e96ac5031b87c41acff0Chris Lattner if (Tok.is(tok::coloncolon)) { // Handle :: in C++. 22445add7541726348b9d1c8e96ac5031b87c41acff0Chris Lattner ++nColons; 22455add7541726348b9d1c8e96ac5031b87c41acff0Chris Lattner KeyIdents.push_back(0); 22465add7541726348b9d1c8e96ac5031b87c41acff0Chris Lattner } else if (Tok.isNot(tok::colon)) 22471d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(Tok, diag::err_expected_colon)); 22481d922960e083906a586609ac6978678147250177Sebastian Redl 22495add7541726348b9d1c8e96ac5031b87c41acff0Chris Lattner ++nColons; 2250a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian ConsumeToken(); // Eat the ':'. 2251a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian if (Tok.is(tok::r_paren)) 2252a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian break; 2253458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor 2254458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor if (Tok.is(tok::code_completion)) { 2255458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor Actions.CodeCompleteObjCSelector(getCurScope(), KeyIdents.data(), 2256458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor KeyIdents.size()); 2257458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor ConsumeCodeCompletionToken(); 2258458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor MatchRHSPunctuation(tok::r_paren, LParenLoc); 2259458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor return ExprError(); 2260458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor } 2261458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor 2262a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian // Check for another keyword selector. 2263a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian SourceLocation Loc; 22642fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner SelIdent = ParseObjCSelectorPiece(Loc); 2265b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian KeyIdents.push_back(SelIdent); 2266a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian if (!SelIdent && Tok.isNot(tok::colon)) 2267a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian break; 2268a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian } 2269887407e71fd58de452361b77d72970e32b20ebe0Steve Naroff } 2270a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); 2271887407e71fd58de452361b77d72970e32b20ebe0Steve Naroff Selector Sel = PP.getSelectorTable().getSelector(nColons, &KeyIdents[0]); 22721d922960e083906a586609ac6978678147250177Sebastian Redl return Owned(Actions.ParseObjCSelectorExpression(Sel, AtLoc, SelectorLoc, 22731d922960e083906a586609ac6978678147250177Sebastian Redl LParenLoc, RParenLoc)); 227458065b2d8038a4e9a91ea4813bd1774c0f6efacbGabor Greif } 2275