ParseObjc.cpp revision 60d7b3a319d84d688752be3870615ac0f111fb16
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" 1619510856727e0e14a3696b2a72c35163bff2a71fJohn McCall#include "clang/Sema/DeclSpec.h" 1719510856727e0e14a3696b2a72c35163bff2a71fJohn McCall#include "clang/Sema/Scope.h" 185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "llvm/ADT/SmallVector.h" 195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing namespace clang; 205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 22891dca671a80c865c6def7259f170ba785e4faaaChris Lattner/// ParseObjCAtDirectives - Handle parts of the external-declaration production: 235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// external-declaration: [C99 6.9] 245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// [OBJC] objc-class-definition 2591fa0b7759b575045142abd6ee48c076297ad77bSteve Naroff/// [OBJC] objc-class-declaration 2691fa0b7759b575045142abd6ee48c076297ad77bSteve Naroff/// [OBJC] objc-alias-declaration 2791fa0b7759b575045142abd6ee48c076297ad77bSteve Naroff/// [OBJC] objc-protocol-definition 2891fa0b7759b575045142abd6ee48c076297ad77bSteve Naroff/// [OBJC] objc-method-definition 2991fa0b7759b575045142abd6ee48c076297ad77bSteve Naroff/// [OBJC] '@' 'end' 30d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseObjCAtDirectives() { 315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation AtLoc = ConsumeToken(); // the "@" 321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 33c464ae8444edb6d07ea49b7a0eae1674c0fa1bb8Douglas Gregor if (Tok.is(tok::code_completion)) { 3423c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCAtDirective(getCurScope(), ObjCImpDecl, false); 35dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 36c464ae8444edb6d07ea49b7a0eae1674c0fa1bb8Douglas Gregor } 37c464ae8444edb6d07ea49b7a0eae1674c0fa1bb8Douglas Gregor 38861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff switch (Tok.getObjCKeywordID()) { 395ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner case tok::objc_class: 405ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner return ParseObjCAtClassDeclaration(AtLoc); 415ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner case tok::objc_interface: 425ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner return ParseObjCAtInterfaceDeclaration(AtLoc); 435ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner case tok::objc_protocol: 445ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner return ParseObjCAtProtocolDeclaration(AtLoc); 455ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner case tok::objc_implementation: 465ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner return ParseObjCAtImplementationDeclaration(AtLoc); 475ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner case tok::objc_end: 485ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner return ParseObjCAtEndDeclaration(AtLoc); 495ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner case tok::objc_compatibility_alias: 505ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner return ParseObjCAtAliasDeclaration(AtLoc); 515ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner case tok::objc_synthesize: 525ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner return ParseObjCPropertySynthesize(AtLoc); 535ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner case tok::objc_dynamic: 545ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner return ParseObjCPropertyDynamic(AtLoc); 555ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner default: 565ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner Diag(AtLoc, diag::err_unexpected_at); 575ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner SkipUntil(tok::semi); 58d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// objc-class-declaration: 645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// '@' 'class' identifier-list ';' 651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 66d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseObjCAtClassDeclaration(SourceLocation atLoc) { 675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ConsumeToken(); // the identifier "class" 685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::SmallVector<IdentifierInfo *, 8> ClassNames; 69c09cba67d0ad01e53e0fed07322e95dd281bcfd9Ted Kremenek llvm::SmallVector<SourceLocation, 8> ClassLocs; 70c09cba67d0ad01e53e0fed07322e95dd281bcfd9Ted Kremenek 711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer while (1) { 73df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Diag(Tok, diag::err_expected_ident); 755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SkipUntil(tok::semi); 76d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ClassNames.push_back(Tok.getIdentifierInfo()); 79c09cba67d0ad01e53e0fed07322e95dd281bcfd9Ted Kremenek ClassLocs.push_back(Tok.getLocation()); 805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ConsumeToken(); 811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 82df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::comma)) 835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer break; 841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ConsumeToken(); 865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Consume the ';'. 895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@class")) 90d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 92c09cba67d0ad01e53e0fed07322e95dd281bcfd9Ted Kremenek return Actions.ActOnForwardClassDeclaration(atLoc, ClassNames.data(), 93c09cba67d0ad01e53e0fed07322e95dd281bcfd9Ted Kremenek ClassLocs.data(), 94c09cba67d0ad01e53e0fed07322e95dd281bcfd9Ted Kremenek ClassNames.size()); 955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 97dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 98dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-interface: 99dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-interface-attributes[opt] objc-class-interface 100dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-category-interface 101dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 102dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-interface: 1031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// '@' 'interface' identifier objc-superclass[opt] 104dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-refs[opt] 1051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// objc-class-instance-variables[opt] 106dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-interface-decl-list 107dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @end 108dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 109dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-category-interface: 1101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// '@' 'interface' identifier '(' identifier[opt] ')' 111dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-refs[opt] 112dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-interface-decl-list 113dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @end 114dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 115dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-superclass: 116dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// ':' identifier 117dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 118dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-interface-attributes: 119dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// __attribute__((visibility("default"))) 120dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// __attribute__((visibility("hidden"))) 121dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// __attribute__((deprecated)) 122dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// __attribute__((unavailable)) 123dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// __attribute__((objc_exception)) - used by NSException on 64-bit 124dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 125d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseObjCAtInterfaceDeclaration( 126dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff SourceLocation atLoc, AttributeList *attrList) { 127861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff assert(Tok.isObjCAtKeyword(tok::objc_interface) && 128dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff "ParseObjCAtInterfaceDeclaration(): Expected @interface"); 129dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff ConsumeToken(); // the "interface" identifier 1301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1313b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor // Code completion after '@interface'. 1323b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor if (Tok.is(tok::code_completion)) { 13323c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCInterfaceDecl(getCurScope()); 134dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 1353b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor } 1363b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor 137df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 138dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff Diag(Tok, diag::err_expected_ident); // missing class or category name. 139d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 140dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff } 14163e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian 142dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff // We have a class or category name - consume it. 1437ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff IdentifierInfo *nameId = Tok.getIdentifierInfo(); 144dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff SourceLocation nameLoc = ConsumeToken(); 1455512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian if (Tok.is(tok::l_paren) && 1465512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian !isKnownToBeTypeSpecifier(GetLookAheadToken(1))) { // we have a category. 147dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff SourceLocation lparenLoc = ConsumeParen(); 148dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff SourceLocation categoryLoc, rparenLoc; 149dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff IdentifierInfo *categoryId = 0; 15033ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor if (Tok.is(tok::code_completion)) { 15123c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCInterfaceCategory(getCurScope(), nameId, nameLoc); 152dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 15333ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor } 15433ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor 155527fe23f8cbc6a4da1737a547a2517bc92fa88c8Steve Naroff // For ObjC2, the category name is optional (not an error). 156df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::identifier)) { 157dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff categoryId = Tok.getIdentifierInfo(); 158dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff categoryLoc = ConsumeToken(); 15905511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian } 16005511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian else if (!getLang().ObjC2) { 161527fe23f8cbc6a4da1737a547a2517bc92fa88c8Steve Naroff Diag(Tok, diag::err_expected_ident); // missing category name. 162d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 163dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff } 164df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::r_paren)) { 165dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff Diag(Tok, diag::err_expected_rparen); 166dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff SkipUntil(tok::r_paren, false); // don't stop at ';' 167d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 168dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff } 169dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff rparenLoc = ConsumeParen(); 1705512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian // Next, we need to check for any protocol references. 1715512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian SourceLocation LAngleLoc, EndProtoLoc; 172d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall llvm::SmallVector<Decl *, 8> ProtocolRefs; 1735512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian llvm::SmallVector<SourceLocation, 8> ProtocolLocs; 1745512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian if (Tok.is(tok::less) && 1755512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian ParseObjCProtocolReferences(ProtocolRefs, ProtocolLocs, true, 17671b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis LAngleLoc, EndProtoLoc)) 177d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 17805511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian 1795512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian if (attrList) // categories don't support attributes. 1805512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian Diag(Tok, diag::err_objc_no_attributes_on_category); 1815512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian 182d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *CategoryType = 1835512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian Actions.ActOnStartCategoryInterface(atLoc, 1845512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian nameId, nameLoc, 1855512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian categoryId, categoryLoc, 1865512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian ProtocolRefs.data(), 1875512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian ProtocolRefs.size(), 1885512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian ProtocolLocs.data(), 1895512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian EndProtoLoc); 1905512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian if (Tok.is(tok::l_brace)) 19183c481ade785a919ba21a33f9a8b1b21c1212fb3Fariborz Jahanian ParseObjCClassInstanceVariables(CategoryType, tok::objc_private, 19283c481ade785a919ba21a33f9a8b1b21c1212fb3Fariborz Jahanian atLoc); 19383c481ade785a919ba21a33f9a8b1b21c1212fb3Fariborz Jahanian 1945512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian ParseObjCInterfaceDeclList(CategoryType, tok::objc_not_keyword); 1955512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian return CategoryType; 196dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff } 197dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff // Parse a class interface. 198dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff IdentifierInfo *superClassId = 0; 199dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff SourceLocation superClassLoc; 2007ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff 201df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::colon)) { // a super class is specified. 202dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff ConsumeToken(); 2033b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor 2043b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor // Code completion of superclass names. 2053b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor if (Tok.is(tok::code_completion)) { 20623c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCSuperclass(getCurScope(), nameId, nameLoc); 207dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 2083b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor } 2093b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor 210df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 211dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff Diag(Tok, diag::err_expected_ident); // missing super class name. 212d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 213dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff } 214dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff superClassId = Tok.getIdentifierInfo(); 215dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff superClassLoc = ConsumeToken(); 216dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff } 217dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff // Next, we need to check for any protocol references. 218d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall llvm::SmallVector<Decl *, 8> ProtocolRefs; 21971b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis llvm::SmallVector<SourceLocation, 8> ProtocolLocs; 22071b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis SourceLocation LAngleLoc, EndProtoLoc; 22106036d3709955a53297b4cbe14e20db88f321470Chris Lattner if (Tok.is(tok::less) && 22271b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis ParseObjCProtocolReferences(ProtocolRefs, ProtocolLocs, true, 22371b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis LAngleLoc, EndProtoLoc)) 224d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 2251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 226d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ClsType = 2271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Actions.ActOnStartClassInterface(atLoc, nameId, nameLoc, 22806036d3709955a53297b4cbe14e20db88f321470Chris Lattner superClassId, superClassLoc, 229beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad ProtocolRefs.data(), ProtocolRefs.size(), 23018df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor ProtocolLocs.data(), 23106036d3709955a53297b4cbe14e20db88f321470Chris Lattner EndProtoLoc, attrList); 2321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 233df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::l_brace)) 23483c481ade785a919ba21a33f9a8b1b21c1212fb3Fariborz Jahanian ParseObjCClassInstanceVariables(ClsType, tok::objc_protected, atLoc); 235dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff 23625e077d59a8e8e43b65882b69610a3d5e2aaf53cFariborz Jahanian ParseObjCInterfaceDeclList(ClsType, tok::objc_interface); 2375512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian return ClsType; 238dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff} 239dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff 240d0014540005f2a5ab837365db6bd40f479406758John McCall/// The Objective-C property callback. This should be defined where 241d0014540005f2a5ab837365db6bd40f479406758John McCall/// it's used, but instead it's been lifted to here to support VS2005. 242d0014540005f2a5ab837365db6bd40f479406758John McCallstruct Parser::ObjCPropertyCallback : FieldCallback { 243d0014540005f2a5ab837365db6bd40f479406758John McCall Parser &P; 244d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *IDecl; 245d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall llvm::SmallVectorImpl<Decl *> &Props; 246d0014540005f2a5ab837365db6bd40f479406758John McCall ObjCDeclSpec &OCDS; 247d0014540005f2a5ab837365db6bd40f479406758John McCall SourceLocation AtLoc; 248d0014540005f2a5ab837365db6bd40f479406758John McCall tok::ObjCKeywordKind MethodImplKind; 249d0014540005f2a5ab837365db6bd40f479406758John McCall 250d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall ObjCPropertyCallback(Parser &P, Decl *IDecl, 251d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall llvm::SmallVectorImpl<Decl *> &Props, 252d0014540005f2a5ab837365db6bd40f479406758John McCall ObjCDeclSpec &OCDS, SourceLocation AtLoc, 253d0014540005f2a5ab837365db6bd40f479406758John McCall tok::ObjCKeywordKind MethodImplKind) : 254d0014540005f2a5ab837365db6bd40f479406758John McCall P(P), IDecl(IDecl), Props(Props), OCDS(OCDS), AtLoc(AtLoc), 255d0014540005f2a5ab837365db6bd40f479406758John McCall MethodImplKind(MethodImplKind) { 256d0014540005f2a5ab837365db6bd40f479406758John McCall } 257d0014540005f2a5ab837365db6bd40f479406758John McCall 258d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *invoke(FieldDeclarator &FD) { 259d0014540005f2a5ab837365db6bd40f479406758John McCall if (FD.D.getIdentifier() == 0) { 260d0014540005f2a5ab837365db6bd40f479406758John McCall P.Diag(AtLoc, diag::err_objc_property_requires_field_name) 261d0014540005f2a5ab837365db6bd40f479406758John McCall << FD.D.getSourceRange(); 262d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 263d0014540005f2a5ab837365db6bd40f479406758John McCall } 264d0014540005f2a5ab837365db6bd40f479406758John McCall if (FD.BitfieldSize) { 265d0014540005f2a5ab837365db6bd40f479406758John McCall P.Diag(AtLoc, diag::err_objc_property_bitfield) 266d0014540005f2a5ab837365db6bd40f479406758John McCall << FD.D.getSourceRange(); 267d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 268d0014540005f2a5ab837365db6bd40f479406758John McCall } 269d0014540005f2a5ab837365db6bd40f479406758John McCall 270d0014540005f2a5ab837365db6bd40f479406758John McCall // Install the property declarator into interfaceDecl. 271d0014540005f2a5ab837365db6bd40f479406758John McCall IdentifierInfo *SelName = 272d0014540005f2a5ab837365db6bd40f479406758John McCall OCDS.getGetterName() ? OCDS.getGetterName() : FD.D.getIdentifier(); 273d0014540005f2a5ab837365db6bd40f479406758John McCall 274d0014540005f2a5ab837365db6bd40f479406758John McCall Selector GetterSel = 275d0014540005f2a5ab837365db6bd40f479406758John McCall P.PP.getSelectorTable().getNullarySelector(SelName); 276d0014540005f2a5ab837365db6bd40f479406758John McCall IdentifierInfo *SetterName = OCDS.getSetterName(); 277d0014540005f2a5ab837365db6bd40f479406758John McCall Selector SetterSel; 278d0014540005f2a5ab837365db6bd40f479406758John McCall if (SetterName) 279d0014540005f2a5ab837365db6bd40f479406758John McCall SetterSel = P.PP.getSelectorTable().getSelector(1, &SetterName); 280d0014540005f2a5ab837365db6bd40f479406758John McCall else 281d0014540005f2a5ab837365db6bd40f479406758John McCall SetterSel = SelectorTable::constructSetterName(P.PP.getIdentifierTable(), 282d0014540005f2a5ab837365db6bd40f479406758John McCall P.PP.getSelectorTable(), 283d0014540005f2a5ab837365db6bd40f479406758John McCall FD.D.getIdentifier()); 284d0014540005f2a5ab837365db6bd40f479406758John McCall bool isOverridingProperty = false; 285d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *Property = 28623c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor P.Actions.ActOnProperty(P.getCurScope(), AtLoc, FD, OCDS, 287d0014540005f2a5ab837365db6bd40f479406758John McCall GetterSel, SetterSel, IDecl, 288d0014540005f2a5ab837365db6bd40f479406758John McCall &isOverridingProperty, 289d0014540005f2a5ab837365db6bd40f479406758John McCall MethodImplKind); 290d0014540005f2a5ab837365db6bd40f479406758John McCall if (!isOverridingProperty) 291d0014540005f2a5ab837365db6bd40f479406758John McCall Props.push_back(Property); 292d0014540005f2a5ab837365db6bd40f479406758John McCall 293d0014540005f2a5ab837365db6bd40f479406758John McCall return Property; 294d0014540005f2a5ab837365db6bd40f479406758John McCall } 295d0014540005f2a5ab837365db6bd40f479406758John McCall}; 296d0014540005f2a5ab837365db6bd40f479406758John McCall 297dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-interface-decl-list: 298dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// empty 299dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-interface-decl-list objc-property-decl [OBJC2] 300294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-interface-decl-list objc-method-requirement [OBJC2] 3013536b443bc50d58a79f14fca9b6842541a434854Steve Naroff/// objc-interface-decl-list objc-method-proto ';' 302dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-interface-decl-list declaration 303dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-interface-decl-list ';' 304dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 305294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-method-requirement: [OBJC2] 306294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// @required 307294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// @optional 308294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 309d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallvoid Parser::ParseObjCInterfaceDeclList(Decl *interfaceDecl, 310cb53b361bce341c8591333c6997f62e480acc0b4Chris Lattner tok::ObjCKeywordKind contextKey) { 311d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall llvm::SmallVector<Decl *, 32> allMethods; 312d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall llvm::SmallVector<Decl *, 16> allProperties; 313682bf92db408a6cbc3d37b5496a99b6ef85041ecChris Lattner llvm::SmallVector<DeclGroupPtrTy, 8> allTUVariables; 31400933591a2795d09dd1acff12a2d21bce7cb12c5Fariborz Jahanian tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword; 3151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 316782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek SourceRange AtEnd; 317bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner 318294494e1cce92043562b4680c613df7fd028c02eSteve Naroff while (1) { 319e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner // If this is a method prototype, parse it. 320df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::minus) || Tok.is(tok::plus)) { 321d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *methodPrototype = 322df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner ParseObjCMethodPrototype(interfaceDecl, MethodImplKind); 32325e077d59a8e8e43b65882b69610a3d5e2aaf53cFariborz Jahanian allMethods.push_back(methodPrototype); 3243536b443bc50d58a79f14fca9b6842541a434854Steve Naroff // Consume the ';' here, since ParseObjCMethodPrototype() is re-used for 3253536b443bc50d58a79f14fca9b6842541a434854Steve Naroff // method definitions. 326b6d74a158a9c002e3c0fcbda8ad8d0ccbb2e5088Chris Lattner ExpectAndConsume(tok::semi, diag::err_expected_semi_after_method_proto, 327b6d74a158a9c002e3c0fcbda8ad8d0ccbb2e5088Chris Lattner "", tok::semi); 328294494e1cce92043562b4680c613df7fd028c02eSteve Naroff continue; 329294494e1cce92043562b4680c613df7fd028c02eSteve Naroff } 33005511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian if (Tok.is(tok::l_paren)) { 33105511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian Diag(Tok, diag::err_expected_minus_or_plus); 332d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall ParseObjCMethodDecl(Tok.getLocation(), 333d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall tok::minus, 334d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall interfaceDecl, 335d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall MethodImplKind); 33605511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian continue; 33705511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian } 338e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner // Ignore excess semicolons. 339e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner if (Tok.is(tok::semi)) { 340294494e1cce92043562b4680c613df7fd028c02eSteve Naroff ConsumeToken(); 341e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner continue; 342e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner } 3431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 344bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // If we got to the end of the file, exit the loop. 345e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner if (Tok.is(tok::eof)) 346e3a2ca7e30601cdd31c77a830f4cc487851e8096Fariborz Jahanian break; 3471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 348b6ac2451bfed36206c5cec7217372c4299f67f2bDouglas Gregor // Code completion within an Objective-C interface. 349b6ac2451bfed36206c5cec7217372c4299f67f2bDouglas Gregor if (Tok.is(tok::code_completion)) { 35023c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteOrdinaryName(getCurScope(), 351e6b1bb6e7fe906d164637ca33503b8fafdbc99e5Douglas Gregor ObjCImpDecl? Action::PCC_ObjCImplementation 352e6b1bb6e7fe906d164637ca33503b8fafdbc99e5Douglas Gregor : Action::PCC_ObjCInterface); 353dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 354b6ac2451bfed36206c5cec7217372c4299f67f2bDouglas Gregor } 355b6ac2451bfed36206c5cec7217372c4299f67f2bDouglas Gregor 356e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner // If we don't have an @ directive, parse it as a function definition. 357e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner if (Tok.isNot(tok::at)) { 3581fd80116b49782c367ff5d5f50a8b76dd8a5d7f7Chris Lattner // The code below does not consume '}'s because it is afraid of eating the 3591fd80116b49782c367ff5d5f50a8b76dd8a5d7f7Chris Lattner // end of a namespace. Because of the way this code is structured, an 3601fd80116b49782c367ff5d5f50a8b76dd8a5d7f7Chris Lattner // erroneous r_brace would cause an infinite loop if not handled here. 3611fd80116b49782c367ff5d5f50a8b76dd8a5d7f7Chris Lattner if (Tok.is(tok::r_brace)) 3621fd80116b49782c367ff5d5f50a8b76dd8a5d7f7Chris Lattner break; 3631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3644985aceceb9b9261b876b515d32726175c13a775Steve Naroff // FIXME: as the name implies, this rule allows function definitions. 3654985aceceb9b9261b876b515d32726175c13a775Steve Naroff // We could pass a flag or check for functions during semantic analysis. 366bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt allTUVariables.push_back(ParseDeclarationOrFunctionDefinition(0)); 367e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner continue; 368e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner } 3691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 370e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner // Otherwise, we have an @ directive, eat the @. 371e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner SourceLocation AtLoc = ConsumeToken(); // the "@" 372c464ae8444edb6d07ea49b7a0eae1674c0fa1bb8Douglas Gregor if (Tok.is(tok::code_completion)) { 37323c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCAtDirective(getCurScope(), ObjCImpDecl, true); 374dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 375c464ae8444edb6d07ea49b7a0eae1674c0fa1bb8Douglas Gregor break; 376c464ae8444edb6d07ea49b7a0eae1674c0fa1bb8Douglas Gregor } 377c464ae8444edb6d07ea49b7a0eae1674c0fa1bb8Douglas Gregor 378a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner tok::ObjCKeywordKind DirectiveKind = Tok.getObjCKeywordID(); 3791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 380a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner if (DirectiveKind == tok::objc_end) { // @end -> terminate list 381782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek AtEnd.setBegin(AtLoc); 382782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek AtEnd.setEnd(Tok.getLocation()); 383e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner break; 384c3d43b783dfb1a1502aa8b31ab1985cf237b1f77Douglas Gregor } else if (DirectiveKind == tok::objc_not_keyword) { 385c3d43b783dfb1a1502aa8b31ab1985cf237b1f77Douglas Gregor Diag(Tok, diag::err_objc_unknown_at); 386c3d43b783dfb1a1502aa8b31ab1985cf237b1f77Douglas Gregor SkipUntil(tok::semi); 387c3d43b783dfb1a1502aa8b31ab1985cf237b1f77Douglas Gregor continue; 388bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner } 3891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 390bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // Eat the identifier. 391bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner ConsumeToken(); 392bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner 393a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner switch (DirectiveKind) { 394a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner default: 395bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // FIXME: If someone forgets an @end on a protocol, this loop will 396bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // continue to eat up tons of stuff and spew lots of nonsense errors. It 397bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // would probably be better to bail out if we saw an @class or @interface 398bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // or something like that. 399f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner Diag(AtLoc, diag::err_objc_illegal_interface_qual); 400bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // Skip until we see an '@' or '}' or ';'. 401a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner SkipUntil(tok::r_brace, tok::at); 402a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner break; 4031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 404a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner case tok::objc_required: 405a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner case tok::objc_optional: 406a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner // This is only valid on protocols. 407bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // FIXME: Should this check for ObjC2 being enabled? 408e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner if (contextKey != tok::objc_protocol) 409bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner Diag(AtLoc, diag::err_objc_directive_only_in_protocol); 410a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner else 411bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner MethodImplKind = DirectiveKind; 412a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner break; 4131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 414a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner case tok::objc_property: 415f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner if (!getLang().ObjC2) 416f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner Diag(AtLoc, diag::err_objc_propertoes_require_objc2); 417f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner 418e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner ObjCDeclSpec OCDS; 4191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // Parse property attribute list, if any. 4208ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner if (Tok.is(tok::l_paren)) 4214ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor ParseObjCPropertyAttribute(OCDS, interfaceDecl, 4224ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor allMethods.data(), allMethods.size()); 4231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 424d0014540005f2a5ab837365db6bd40f479406758John McCall ObjCPropertyCallback Callback(*this, interfaceDecl, allProperties, 425d0014540005f2a5ab837365db6bd40f479406758John McCall OCDS, AtLoc, MethodImplKind); 426bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall 427e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner // Parse all the comma separated declarators. 428e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner DeclSpec DS; 429bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall ParseStructDeclaration(DS, Callback); 4301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 431a1fed7e3beebf9bb1bc85123f283be3eb631c120Chris Lattner ExpectAndConsume(tok::semi, diag::err_expected_semi_decl_list, "", 432a1fed7e3beebf9bb1bc85123f283be3eb631c120Chris Lattner tok::at); 433a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner break; 434f28b264437053fb0deacc9ba02b18a0966f7290aSteve Naroff } 435294494e1cce92043562b4680c613df7fd028c02eSteve Naroff } 436bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner 437bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // We break out of the big loop in two cases: when we see @end or when we see 438bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // EOF. In the former case, eat the @end. In the later case, emit an error. 439c464ae8444edb6d07ea49b7a0eae1674c0fa1bb8Douglas Gregor if (Tok.is(tok::code_completion)) { 44023c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCAtDirective(getCurScope(), ObjCImpDecl, true); 441dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 442c464ae8444edb6d07ea49b7a0eae1674c0fa1bb8Douglas Gregor } else if (Tok.isObjCAtKeyword(tok::objc_end)) 443bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner ConsumeToken(); // the "end" identifier 444bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner else 445bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner Diag(Tok, diag::err_objc_missing_end); 4461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 447a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner // Insert collected methods declarations into the @interface object. 448bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // This passes in an invalid SourceLocation for AtEndLoc when EOF is hit. 44923c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.ActOnAtEnd(getCurScope(), AtEnd, interfaceDecl, 4501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump allMethods.data(), allMethods.size(), 451beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad allProperties.data(), allProperties.size(), 452beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad allTUVariables.data(), allTUVariables.size()); 453294494e1cce92043562b4680c613df7fd028c02eSteve Naroff} 454294494e1cce92043562b4680c613df7fd028c02eSteve Naroff 455d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// Parse property attribute declarations. 456d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// 457d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// property-attr-decl: '(' property-attrlist ')' 458d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// property-attrlist: 459d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// property-attribute 460d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// property-attrlist ',' property-attribute 461d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// property-attribute: 462d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// getter '=' identifier 463d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// setter '=' identifier ':' 464d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// readonly 465d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// readwrite 466d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// assign 467d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// retain 468d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// copy 469d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// nonatomic 470d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// 471d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallvoid Parser::ParseObjCPropertyAttribute(ObjCDeclSpec &DS, Decl *ClassDecl, 472d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl **Methods, 4734ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor unsigned NumMethods) { 4748ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner assert(Tok.getKind() == tok::l_paren); 475dd5b5f2bb73d037745940431b71eb98393d12d4fChris Lattner SourceLocation LHSLoc = ConsumeParen(); // consume '(' 4761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 477cd9f4b31c4fe5b77b5519cc17b4583fab912bad1Chris Lattner while (1) { 478ece8e71d12b6f4cb2dc501297afef126dab8ad74Steve Naroff if (Tok.is(tok::code_completion)) { 47923c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCPropertyFlags(getCurScope(), DS); 480dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 481ece8e71d12b6f4cb2dc501297afef126dab8ad74Steve Naroff } 482d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian const IdentifierInfo *II = Tok.getIdentifierInfo(); 4831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 484f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner // If this is not an identifier at all, bail out early. 485f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner if (II == 0) { 486f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner MatchRHSPunctuation(tok::r_paren, LHSLoc); 487f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner return; 488f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner } 4891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 490156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner SourceLocation AttrName = ConsumeToken(); // consume last attribute name 4911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 49292e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner if (II->isStr("readonly")) 493e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_readonly); 49492e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner else if (II->isStr("assign")) 495e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_assign); 49692e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner else if (II->isStr("readwrite")) 497e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_readwrite); 49892e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner else if (II->isStr("retain")) 499e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_retain); 50092e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner else if (II->isStr("copy")) 501e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_copy); 50292e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner else if (II->isStr("nonatomic")) 503e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_nonatomic); 50492e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner else if (II->isStr("getter") || II->isStr("setter")) { 505e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner // getter/setter require extra treatment. 506156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner if (ExpectAndConsume(tok::equal, diag::err_objc_expected_equal, "", 507156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner tok::r_paren)) 508dd5b5f2bb73d037745940431b71eb98393d12d4fChris Lattner return; 5091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5104ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor if (Tok.is(tok::code_completion)) { 5114ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor if (II->getNameStart()[0] == 's') 51223c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCPropertySetter(getCurScope(), ClassDecl, 5134ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor Methods, NumMethods); 5144ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor else 51523c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCPropertyGetter(getCurScope(), ClassDecl, 5164ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor Methods, NumMethods); 517dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 5184ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor } 5194ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor 5208ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner if (Tok.isNot(tok::identifier)) { 5211ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_ident); 5228ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner SkipUntil(tok::r_paren); 5238ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner return; 5248ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner } 5251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 526e013d685c6689ac7ae103ee88acf573422d1ed6aDaniel Dunbar if (II->getNameStart()[0] == 's') { 5278ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_setter); 5288ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner DS.setSetterName(Tok.getIdentifierInfo()); 529156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner ConsumeToken(); // consume method name 5301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 531e0097db2848c463a534c18c235c6d3e53f2f1b87Fariborz Jahanian if (ExpectAndConsume(tok::colon, 532e0097db2848c463a534c18c235c6d3e53f2f1b87Fariborz Jahanian diag::err_expected_colon_after_setter_name, "", 533156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner tok::r_paren)) 5348ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner return; 5358ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner } else { 5368ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_getter); 5378ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner DS.setGetterName(Tok.getIdentifierInfo()); 538156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner ConsumeToken(); // consume method name 5398ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner } 540e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner } else { 541a9500f05ba6c09bbd84d342236863833067cd816Chris Lattner Diag(AttrName, diag::err_objc_expected_property_attr) << II; 542cd9f4b31c4fe5b77b5519cc17b4583fab912bad1Chris Lattner SkipUntil(tok::r_paren); 543cd9f4b31c4fe5b77b5519cc17b4583fab912bad1Chris Lattner return; 544cd9f4b31c4fe5b77b5519cc17b4583fab912bad1Chris Lattner } 5451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 546156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner if (Tok.isNot(tok::comma)) 547156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner break; 5481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 549156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner ConsumeToken(); 550d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian } 5511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 552156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner MatchRHSPunctuation(tok::r_paren, LHSLoc); 553d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian} 554d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian 5553536b443bc50d58a79f14fca9b6842541a434854Steve Naroff/// objc-method-proto: 5561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// objc-instance-method objc-method-decl objc-method-attributes[opt] 5573536b443bc50d58a79f14fca9b6842541a434854Steve Naroff/// objc-class-method objc-method-decl objc-method-attributes[opt] 558294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 559294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-instance-method: '-' 560294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-class-method: '+' 561294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 5624985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-method-attributes: [OBJC2] 5634985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// __attribute__((deprecated)) 5644985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// 565d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseObjCMethodPrototype(Decl *IDecl, 566d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall tok::ObjCKeywordKind MethodImplKind) { 567df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner assert((Tok.is(tok::minus) || Tok.is(tok::plus)) && "expected +/-"); 568294494e1cce92043562b4680c613df7fd028c02eSteve Naroff 5691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump tok::TokenKind methodType = Tok.getKind(); 570bef1185418705e16012b3dd50cd7c260c8d6b79cSteve Naroff SourceLocation mLoc = ConsumeToken(); 5711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 572d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *MDecl = ParseObjCMethodDecl(mLoc, methodType, IDecl,MethodImplKind); 5733536b443bc50d58a79f14fca9b6842541a434854Steve Naroff // Since this rule is used for both method declarations and definitions, 5742bd42fadafddc8acf744b57a970bdc96a077c617Steve Naroff // the caller is (optionally) responsible for consuming the ';'. 575f28b264437053fb0deacc9ba02b18a0966f7290aSteve Naroff return MDecl; 576294494e1cce92043562b4680c613df7fd028c02eSteve Naroff} 577294494e1cce92043562b4680c613df7fd028c02eSteve Naroff 578294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-selector: 579294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// identifier 580294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// one of 581294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// enum struct union if else while do for switch case default 582294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// break continue return goto asm sizeof typeof __alignof 583294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// unsigned long const short volatile signed restrict _Complex 584294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// in out inout bycopy byref oneway int char float double void _Bool 585294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 5862fc5c2428ecb450a3256c8316b93b8655cb76a0fChris LattnerIdentifierInfo *Parser::ParseObjCSelectorPiece(SourceLocation &SelectorLoc) { 587ff38491c18b060526d754765b952f4a497a89416Chris Lattner switch (Tok.getKind()) { 588ff38491c18b060526d754765b952f4a497a89416Chris Lattner default: 589ff38491c18b060526d754765b952f4a497a89416Chris Lattner return 0; 590ff38491c18b060526d754765b952f4a497a89416Chris Lattner case tok::identifier: 591ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_asm: 592ff38491c18b060526d754765b952f4a497a89416Chris Lattner case tok::kw_auto: 5939298d9655aed28b2d9f6cc65c81401b209f03fdcChris Lattner case tok::kw_bool: 594ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_break: 595ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_case: 596ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_catch: 597ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_char: 598ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_class: 599ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_const: 600ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_const_cast: 601ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_continue: 602ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_default: 603ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_delete: 604ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_do: 605ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_double: 606ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_dynamic_cast: 607ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_else: 608ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_enum: 609ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_explicit: 610ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_export: 611ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_extern: 612ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_false: 613ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_float: 614ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_for: 615ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_friend: 616ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_goto: 617ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_if: 618ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_inline: 619ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_int: 620ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_long: 621ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_mutable: 622ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_namespace: 623ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_new: 624ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_operator: 625ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_private: 626ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_protected: 627ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_public: 628ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_register: 629ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_reinterpret_cast: 630ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_restrict: 631ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_return: 632ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_short: 633ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_signed: 634ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_sizeof: 635ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_static: 636ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_static_cast: 637ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_struct: 638ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_switch: 639ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_template: 640ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_this: 641ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_throw: 642ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_true: 643ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_try: 644ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_typedef: 645ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_typeid: 646ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_typename: 647ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_typeof: 648ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_union: 649ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_unsigned: 650ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_using: 651ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_virtual: 652ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_void: 653ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_volatile: 654ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_wchar_t: 655ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_while: 656ff38491c18b060526d754765b952f4a497a89416Chris Lattner case tok::kw__Bool: 657ff38491c18b060526d754765b952f4a497a89416Chris Lattner case tok::kw__Complex: 658ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw___alignof: 659ff38491c18b060526d754765b952f4a497a89416Chris Lattner IdentifierInfo *II = Tok.getIdentifierInfo(); 6604b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian SelectorLoc = ConsumeToken(); 661ff38491c18b060526d754765b952f4a497a89416Chris Lattner return II; 662d064951b0dcc95f8604d0d69ae82d9ecbd38c796Fariborz Jahanian } 663294494e1cce92043562b4680c613df7fd028c02eSteve Naroff} 664294494e1cce92043562b4680c613df7fd028c02eSteve Naroff 6650196cab54007ff072ec2642da8911c6b7e8d3fb5Fariborz Jahanian/// objc-for-collection-in: 'in' 6660196cab54007ff072ec2642da8911c6b7e8d3fb5Fariborz Jahanian/// 667335a2d4122e41343fe11a775889b8bec5b14be60Fariborz Jahanianbool Parser::isTokIdentifier_in() const { 6683ba5a0f90a03d5e13d02cbee9abd2a1ba01b18bcFariborz Jahanian // FIXME: May have to do additional look-ahead to only allow for 6693ba5a0f90a03d5e13d02cbee9abd2a1ba01b18bcFariborz Jahanian // valid tokens following an 'in'; such as an identifier, unary operators, 6703ba5a0f90a03d5e13d02cbee9abd2a1ba01b18bcFariborz Jahanian // '[' etc. 6711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return (getLang().ObjC2 && Tok.is(tok::identifier) && 6725ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner Tok.getIdentifierInfo() == ObjCTypeQuals[objc_in]); 6730196cab54007ff072ec2642da8911c6b7e8d3fb5Fariborz Jahanian} 6740196cab54007ff072ec2642da8911c6b7e8d3fb5Fariborz Jahanian 675a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ParseObjCTypeQualifierList - This routine parses the objective-c's type 676e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner/// qualifier list and builds their bitmask representation in the input 677e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner/// argument. 678294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 679294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-type-qualifiers: 680294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-type-qualifier 681294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-type-qualifiers objc-type-qualifier 682294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 683d32b0225e29fcafb2b2b2a4b1c51dcb1518af9c6Douglas Gregorvoid Parser::ParseObjCTypeQualifierList(ObjCDeclSpec &DS, bool IsParameter) { 684e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner while (1) { 685d32b0225e29fcafb2b2b2a4b1c51dcb1518af9c6Douglas Gregor if (Tok.is(tok::code_completion)) { 686d32b0225e29fcafb2b2b2a4b1c51dcb1518af9c6Douglas Gregor Actions.CodeCompleteObjCPassingType(getCurScope(), DS); 687d32b0225e29fcafb2b2b2a4b1c51dcb1518af9c6Douglas Gregor ConsumeCodeCompletionToken(); 688d32b0225e29fcafb2b2b2a4b1c51dcb1518af9c6Douglas Gregor } 689d32b0225e29fcafb2b2b2a4b1c51dcb1518af9c6Douglas Gregor 690cb53b361bce341c8591333c6997f62e480acc0b4Chris Lattner if (Tok.isNot(tok::identifier)) 691e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner return; 6921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 693e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner const IdentifierInfo *II = Tok.getIdentifierInfo(); 694e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner for (unsigned i = 0; i != objc_NumQuals; ++i) { 695a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek if (II != ObjCTypeQuals[i]) 696e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner continue; 6971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 698a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCDeclSpec::ObjCDeclQualifier Qual; 699e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner switch (i) { 700e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner default: assert(0 && "Unknown decl qualifier"); 701a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek case objc_in: Qual = ObjCDeclSpec::DQ_In; break; 702a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek case objc_out: Qual = ObjCDeclSpec::DQ_Out; break; 703a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek case objc_inout: Qual = ObjCDeclSpec::DQ_Inout; break; 704a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek case objc_oneway: Qual = ObjCDeclSpec::DQ_Oneway; break; 705a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek case objc_bycopy: Qual = ObjCDeclSpec::DQ_Bycopy; break; 706a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek case objc_byref: Qual = ObjCDeclSpec::DQ_Byref; break; 707e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner } 708a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek DS.setObjCDeclQualifier(Qual); 709e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner ConsumeToken(); 710e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner II = 0; 711e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner break; 712e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner } 7131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 714e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner // If this wasn't a recognized qualifier, bail out. 715e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner if (II) return; 716e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner } 717e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner} 718e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner 719e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner/// objc-type-name: 720e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner/// '(' objc-type-qualifiers[opt] type-name ')' 721e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner/// '(' objc-type-qualifiers[opt] ')' 722e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner/// 723b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCallParsedType Parser::ParseObjCTypeName(ObjCDeclSpec &DS, bool IsParameter) { 724df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner assert(Tok.is(tok::l_paren) && "expected ("); 7251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7264a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner SourceLocation LParenLoc = ConsumeParen(); 727e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner SourceLocation TypeStartLoc = Tok.getLocation(); 7281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 72919d74e1494fe399f0e2a94e9419c095f8214851bFariborz Jahanian // Parse type qualifiers, in, inout, etc. 730d32b0225e29fcafb2b2b2a4b1c51dcb1518af9c6Douglas Gregor ParseObjCTypeQualifierList(DS, IsParameter); 7314fa7afd07421e7276d1717e4fdf43a5fdd65a622Steve Naroff 732b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType Ty; 733809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor if (isTypeSpecifierQualifier()) { 734809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor TypeResult TypeSpec = ParseTypeName(); 735809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor if (!TypeSpec.isInvalid()) 736809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor Ty = TypeSpec.get(); 737809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor } 7381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7394a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner if (Tok.is(tok::r_paren)) 7404a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner ConsumeParen(); 7414a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner else if (Tok.getLocation() == TypeStartLoc) { 742e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner // If we didn't eat any tokens, then this isn't a type. 7431ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_type); 7444a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner SkipUntil(tok::r_paren); 7454a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner } else { 7464a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner // Otherwise, we found *something*, but didn't get a ')' in the right 7474a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner // place. Emit an error then return what we have as the type. 7484a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner MatchRHSPunctuation(tok::r_paren, LParenLoc); 749294494e1cce92043562b4680c613df7fd028c02eSteve Naroff } 750f28b264437053fb0deacc9ba02b18a0966f7290aSteve Naroff return Ty; 751294494e1cce92043562b4680c613df7fd028c02eSteve Naroff} 752294494e1cce92043562b4680c613df7fd028c02eSteve Naroff 753294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-method-decl: 754294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-selector 7554985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-keyword-selector objc-parmlist[opt] 756294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-type-name objc-selector 7574985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-type-name objc-keyword-selector objc-parmlist[opt] 758294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 759294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-keyword-selector: 7601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// objc-keyword-decl 761294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-keyword-selector objc-keyword-decl 762294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 763294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-keyword-decl: 7647ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// objc-selector ':' objc-type-name objc-keyword-attributes[opt] identifier 7657ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// objc-selector ':' objc-keyword-attributes[opt] identifier 7667ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// ':' objc-type-name objc-keyword-attributes[opt] identifier 7677ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// ':' objc-keyword-attributes[opt] identifier 768294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 7694985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-parmlist: 7704985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-parms objc-ellipsis[opt] 771294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 7724985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-parms: 7734985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-parms , parameter-declaration 774294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 7754985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-ellipsis: 776294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// , ... 777294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 7787ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// objc-keyword-attributes: [OBJC2] 7797ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// __attribute__((unused)) 7807ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// 781d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseObjCMethodDecl(SourceLocation mLoc, 7822ccccb3ff40c64927817a7e1ddf1da8c188ed224Douglas Gregor tok::TokenKind mType, 7832ccccb3ff40c64927817a7e1ddf1da8c188ed224Douglas Gregor Decl *IDecl, 7842ccccb3ff40c64927817a7e1ddf1da8c188ed224Douglas Gregor tok::ObjCKeywordKind MethodImplKind) { 78554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ParsingDeclRAIIObject PD(*this); 78654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 787e8f5a1710a7738deff40e10efcd05b1bd6af184fDouglas Gregor if (Tok.is(tok::code_completion)) { 78823c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCMethodDecl(getCurScope(), mType == tok::minus, 789b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall /*ReturnType=*/ ParsedType(), IDecl); 790dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 791e8f5a1710a7738deff40e10efcd05b1bd6af184fDouglas Gregor } 792e8f5a1710a7738deff40e10efcd05b1bd6af184fDouglas Gregor 793e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner // Parse the return type if present. 794b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ReturnType; 795a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCDeclSpec DSRet; 796df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::l_paren)) 797d32b0225e29fcafb2b2b2a4b1c51dcb1518af9c6Douglas Gregor ReturnType = ParseObjCTypeName(DSRet, false); 7981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7999e0493576af77dba1c48858c03e31a2897d0681eTed Kremenek // If attributes exist before the method, parse them. 8009e0493576af77dba1c48858c03e31a2897d0681eTed Kremenek llvm::OwningPtr<AttributeList> MethodAttrs; 8019e0493576af77dba1c48858c03e31a2897d0681eTed Kremenek if (getLang().ObjC2 && Tok.is(tok::kw___attribute)) 8029e0493576af77dba1c48858c03e31a2897d0681eTed Kremenek MethodAttrs.reset(ParseGNUAttributes()); 8039e0493576af77dba1c48858c03e31a2897d0681eTed Kremenek 804e8f5a1710a7738deff40e10efcd05b1bd6af184fDouglas Gregor if (Tok.is(tok::code_completion)) { 80523c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCMethodDecl(getCurScope(), mType == tok::minus, 806e8f5a1710a7738deff40e10efcd05b1bd6af184fDouglas Gregor ReturnType, IDecl); 807dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 808e8f5a1710a7738deff40e10efcd05b1bd6af184fDouglas Gregor } 809e8f5a1710a7738deff40e10efcd05b1bd6af184fDouglas Gregor 8109e0493576af77dba1c48858c03e31a2897d0681eTed Kremenek // Now parse the selector. 811bef1185418705e16012b3dd50cd7c260c8d6b79cSteve Naroff SourceLocation selLoc; 8122fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner IdentifierInfo *SelIdent = ParseObjCSelectorPiece(selLoc); 813e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner 81484c431088693e216193094d1dbf327a01173f57fSteve Naroff // An unnamed colon is valid. 81584c431088693e216193094d1dbf327a01173f57fSteve Naroff if (!SelIdent && Tok.isNot(tok::colon)) { // missing selector name. 8161ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_selector_for_method) 8171ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner << SourceRange(mLoc, Tok.getLocation()); 818e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner // Skip until we get a ; or {}. 819e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner SkipUntil(tok::r_brace); 820d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 821e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner } 8221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8234f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian llvm::SmallVector<DeclaratorChunk::ParamInfo, 8> CParamInfo; 824df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::colon)) { 825ff38491c18b060526d754765b952f4a497a89416Chris Lattner // If attributes exist after the method, parse them. 8261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (getLang().ObjC2 && Tok.is(tok::kw___attribute)) 8279e0493576af77dba1c48858c03e31a2897d0681eTed Kremenek MethodAttrs.reset(addAttributeLists(MethodAttrs.take(), 8289e0493576af77dba1c48858c03e31a2897d0681eTed Kremenek ParseGNUAttributes())); 8291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 830ff38491c18b060526d754765b952f4a497a89416Chris Lattner Selector Sel = PP.getSelectorTable().getNullarySelector(SelIdent); 831d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *Result 83254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall = Actions.ActOnMethodDeclaration(mLoc, Tok.getLocation(), 8331f7b6f88f18d7f6b10265acec5d41c4ed1897487Fariborz Jahanian mType, IDecl, DSRet, ReturnType, Sel, 8344f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian 0, 8354f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian CParamInfo.data(), CParamInfo.size(), 8364f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian MethodAttrs.get(), 8371c6a3cc88177c67498fccdf14cfdf09959214e41Ted Kremenek MethodImplKind); 83854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall PD.complete(Result); 83954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall return Result; 840ff38491c18b060526d754765b952f4a497a89416Chris Lattner } 841f28b264437053fb0deacc9ba02b18a0966f7290aSteve Naroff 84268d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff llvm::SmallVector<IdentifierInfo *, 12> KeyIdents; 843e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner llvm::SmallVector<Action::ObjCArgInfo, 12> ArgInfos; 8441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 845ff38491c18b060526d754765b952f4a497a89416Chris Lattner while (1) { 846e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner Action::ObjCArgInfo ArgInfo; 8471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 848ff38491c18b060526d754765b952f4a497a89416Chris Lattner // Each iteration parses a single keyword argument. 849df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::colon)) { 850ff38491c18b060526d754765b952f4a497a89416Chris Lattner Diag(Tok, diag::err_expected_colon); 851ff38491c18b060526d754765b952f4a497a89416Chris Lattner break; 852ff38491c18b060526d754765b952f4a497a89416Chris Lattner } 853ff38491c18b060526d754765b952f4a497a89416Chris Lattner ConsumeToken(); // Eat the ':'. 8541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 855b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ArgInfo.Type = ParsedType(); 856e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner if (Tok.is(tok::l_paren)) // Parse the argument type if present. 857d32b0225e29fcafb2b2b2a4b1c51dcb1518af9c6Douglas Gregor ArgInfo.Type = ParseObjCTypeName(ArgInfo.DeclSpec, true); 858e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner 859ff38491c18b060526d754765b952f4a497a89416Chris Lattner // If attributes exist before the argument name, parse them. 860e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner ArgInfo.ArgAttrs = 0; 861df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (getLang().ObjC2 && Tok.is(tok::kw___attribute)) 862bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt ArgInfo.ArgAttrs = ParseGNUAttributes(); 8637ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff 86440ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor // Code completion for the next piece of the selector. 86540ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor if (Tok.is(tok::code_completion)) { 86640ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor ConsumeCodeCompletionToken(); 86740ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor KeyIdents.push_back(SelIdent); 86840ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor Actions.CodeCompleteObjCMethodDeclSelector(getCurScope(), 86940ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor mType == tok::minus, 87040ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor /*AtParameterName=*/true, 87140ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor ReturnType, 87240ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor KeyIdents.data(), 87340ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor KeyIdents.size()); 87440ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor KeyIdents.pop_back(); 87540ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor break; 87640ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor } 87740ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor 878df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 879ff38491c18b060526d754765b952f4a497a89416Chris Lattner Diag(Tok, diag::err_expected_ident); // missing argument name. 880ff38491c18b060526d754765b952f4a497a89416Chris Lattner break; 8814985aceceb9b9261b876b515d32726175c13a775Steve Naroff } 8821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 883e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner ArgInfo.Name = Tok.getIdentifierInfo(); 884e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner ArgInfo.NameLoc = Tok.getLocation(); 885ff38491c18b060526d754765b952f4a497a89416Chris Lattner ConsumeToken(); // Eat the identifier. 8861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 887e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner ArgInfos.push_back(ArgInfo); 888e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner KeyIdents.push_back(SelIdent); 889e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner 8901f5537aaac1e775aff1d523f2cc59a9a3bd6c946Douglas Gregor // Code completion for the next piece of the selector. 8911f5537aaac1e775aff1d523f2cc59a9a3bd6c946Douglas Gregor if (Tok.is(tok::code_completion)) { 8921f5537aaac1e775aff1d523f2cc59a9a3bd6c946Douglas Gregor ConsumeCodeCompletionToken(); 8931f5537aaac1e775aff1d523f2cc59a9a3bd6c946Douglas Gregor Actions.CodeCompleteObjCMethodDeclSelector(getCurScope(), 8941f5537aaac1e775aff1d523f2cc59a9a3bd6c946Douglas Gregor mType == tok::minus, 89540ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor /*AtParameterName=*/false, 8961f5537aaac1e775aff1d523f2cc59a9a3bd6c946Douglas Gregor ReturnType, 8971f5537aaac1e775aff1d523f2cc59a9a3bd6c946Douglas Gregor KeyIdents.data(), 8981f5537aaac1e775aff1d523f2cc59a9a3bd6c946Douglas Gregor KeyIdents.size()); 8991f5537aaac1e775aff1d523f2cc59a9a3bd6c946Douglas Gregor break; 9001f5537aaac1e775aff1d523f2cc59a9a3bd6c946Douglas Gregor } 9011f5537aaac1e775aff1d523f2cc59a9a3bd6c946Douglas Gregor 902ff38491c18b060526d754765b952f4a497a89416Chris Lattner // Check for another keyword selector. 9034b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian SourceLocation Loc; 9042fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner SelIdent = ParseObjCSelectorPiece(Loc); 905df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (!SelIdent && Tok.isNot(tok::colon)) 906ff38491c18b060526d754765b952f4a497a89416Chris Lattner break; 907ff38491c18b060526d754765b952f4a497a89416Chris Lattner // We have a selector or a colon, continue parsing. 908ff38491c18b060526d754765b952f4a497a89416Chris Lattner } 9091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 910335eafa5be51f6440672a74c73d588af72e96732Steve Naroff bool isVariadic = false; 9111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 912ff38491c18b060526d754765b952f4a497a89416Chris Lattner // Parse the (optional) parameter list. 913df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner while (Tok.is(tok::comma)) { 914ff38491c18b060526d754765b952f4a497a89416Chris Lattner ConsumeToken(); 915df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::ellipsis)) { 916335eafa5be51f6440672a74c73d588af72e96732Steve Naroff isVariadic = true; 9174985aceceb9b9261b876b515d32726175c13a775Steve Naroff ConsumeToken(); 918ff38491c18b060526d754765b952f4a497a89416Chris Lattner break; 9194985aceceb9b9261b876b515d32726175c13a775Steve Naroff } 920ff38491c18b060526d754765b952f4a497a89416Chris Lattner DeclSpec DS; 921ff38491c18b060526d754765b952f4a497a89416Chris Lattner ParseDeclarationSpecifiers(DS); 9221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // Parse the declarator. 923ff38491c18b060526d754765b952f4a497a89416Chris Lattner Declarator ParmDecl(DS, Declarator::PrototypeContext); 924ff38491c18b060526d754765b952f4a497a89416Chris Lattner ParseDeclarator(ParmDecl); 9254f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian IdentifierInfo *ParmII = ParmDecl.getIdentifier(); 926d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *Param = Actions.ActOnParamDeclarator(getCurScope(), ParmDecl); 9274f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian CParamInfo.push_back(DeclaratorChunk::ParamInfo(ParmII, 9284f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian ParmDecl.getIdentifierLoc(), 9294f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian Param, 9304f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian 0)); 9314f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian 9324985aceceb9b9261b876b515d32726175c13a775Steve Naroff } 9331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 934ff38491c18b060526d754765b952f4a497a89416Chris Lattner // FIXME: Add support for optional parmameter list... 935e3a2ca7e30601cdd31c77a830f4cc487851e8096Fariborz Jahanian // If attributes exist after the method, parse them. 9361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (getLang().ObjC2 && Tok.is(tok::kw___attribute)) 9379e0493576af77dba1c48858c03e31a2897d0681eTed Kremenek MethodAttrs.reset(addAttributeLists(MethodAttrs.take(), 9389e0493576af77dba1c48858c03e31a2897d0681eTed Kremenek ParseGNUAttributes())); 9391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9403688fc679389d67b6755e62406998f9ea84d886aFariborz Jahanian if (KeyIdents.size() == 0) 941d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 942ff38491c18b060526d754765b952f4a497a89416Chris Lattner Selector Sel = PP.getSelectorTable().getSelector(KeyIdents.size(), 943ff38491c18b060526d754765b952f4a497a89416Chris Lattner &KeyIdents[0]); 944d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *Result 94554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall = Actions.ActOnMethodDeclaration(mLoc, Tok.getLocation(), 9463688fc679389d67b6755e62406998f9ea84d886aFariborz Jahanian mType, IDecl, DSRet, ReturnType, Sel, 9474f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian &ArgInfos[0], 9484f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian CParamInfo.data(), CParamInfo.size(), 9491e37765c9257ef1d051f54a674eaa964bdba9693Ted Kremenek MethodAttrs.get(), 950335eafa5be51f6440672a74c73d588af72e96732Steve Naroff MethodImplKind, isVariadic); 95154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall PD.complete(Result); 9521e37765c9257ef1d051f54a674eaa964bdba9693Ted Kremenek 9531e37765c9257ef1d051f54a674eaa964bdba9693Ted Kremenek // Delete referenced AttributeList objects. 9541e37765c9257ef1d051f54a674eaa964bdba9693Ted Kremenek for (llvm::SmallVectorImpl<Action::ObjCArgInfo>::iterator 9551e37765c9257ef1d051f54a674eaa964bdba9693Ted Kremenek I = ArgInfos.begin(), E = ArgInfos.end(); I != E; ++I) 9561e37765c9257ef1d051f54a674eaa964bdba9693Ted Kremenek delete I->ArgAttrs; 9571e37765c9257ef1d051f54a674eaa964bdba9693Ted Kremenek 95854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall return Result; 959294494e1cce92043562b4680c613df7fd028c02eSteve Naroff} 960294494e1cce92043562b4680c613df7fd028c02eSteve Naroff 961dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-refs: 962dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// '<' identifier-list '>' 963dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 9647caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattnerbool Parser:: 965d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallParseObjCProtocolReferences(llvm::SmallVectorImpl<Decl *> &Protocols, 96671b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis llvm::SmallVectorImpl<SourceLocation> &ProtocolLocs, 96771b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis bool WarnOnDeclarations, 96871b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis SourceLocation &LAngleLoc, SourceLocation &EndLoc) { 969e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner assert(Tok.is(tok::less) && "expected <"); 9701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 97171b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis LAngleLoc = ConsumeToken(); // the "<" 9721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 973e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner llvm::SmallVector<IdentifierLocPair, 8> ProtocolIdents; 9741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 975e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner while (1) { 97655385fe3e723cd675001e45f42d61adde6b7f075Douglas Gregor if (Tok.is(tok::code_completion)) { 97755385fe3e723cd675001e45f42d61adde6b7f075Douglas Gregor Actions.CodeCompleteObjCProtocolReferences(ProtocolIdents.data(), 97855385fe3e723cd675001e45f42d61adde6b7f075Douglas Gregor ProtocolIdents.size()); 979dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 98055385fe3e723cd675001e45f42d61adde6b7f075Douglas Gregor } 98155385fe3e723cd675001e45f42d61adde6b7f075Douglas Gregor 982e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner if (Tok.isNot(tok::identifier)) { 983e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner Diag(Tok, diag::err_expected_ident); 984e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner SkipUntil(tok::greater); 985e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner return true; 986e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner } 987e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner ProtocolIdents.push_back(std::make_pair(Tok.getIdentifierInfo(), 988e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner Tok.getLocation())); 98971b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis ProtocolLocs.push_back(Tok.getLocation()); 990e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner ConsumeToken(); 9911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 992e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner if (Tok.isNot(tok::comma)) 993e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner break; 994e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner ConsumeToken(); 995e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner } 9961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 997e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner // Consume the '>'. 998e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner if (Tok.isNot(tok::greater)) { 999e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner Diag(Tok, diag::err_expected_greater); 1000e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner return true; 1001e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner } 10021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1003e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner EndLoc = ConsumeAnyToken(); 10041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1005e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner // Convert the list of protocols identifiers into a list of protocol decls. 1006e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner Actions.FindProtocolDeclaration(WarnOnDeclarations, 1007e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner &ProtocolIdents[0], ProtocolIdents.size(), 1008e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner Protocols); 1009e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner return false; 1010e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner} 1011e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner 1012dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-instance-variables: 1013dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// '{' objc-instance-variable-decl-list[opt] '}' 1014dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1015dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-instance-variable-decl-list: 1016dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-visibility-spec 1017dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-instance-variable-decl ';' 1018dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// ';' 1019dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-instance-variable-decl-list objc-visibility-spec 1020dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-instance-variable-decl-list objc-instance-variable-decl ';' 1021dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-instance-variable-decl-list ';' 1022dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1023dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-visibility-spec: 1024dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @private 1025dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @protected 1026dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @public 1027ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff/// @package [OBJC2] 1028dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1029dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-instance-variable-decl: 10301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// struct-declaration 1031dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1032d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallvoid Parser::ParseObjCClassInstanceVariables(Decl *interfaceDecl, 103383c481ade785a919ba21a33f9a8b1b21c1212fb3Fariborz Jahanian tok::ObjCKeywordKind visibility, 103460fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff SourceLocation atLoc) { 1035df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner assert(Tok.is(tok::l_brace) && "expected {"); 1036d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall llvm::SmallVector<Decl *, 32> AllIvarDecls; 1037e13594279a952537ac903325efff57e3edca79d9Chris Lattner 10381a0d31a3d7f14ddc6370ba912c778aece6c12cf0Douglas Gregor ParseScope ClassScope(this, Scope::DeclScope|Scope::ClassScope); 103972de6676bd30f9081ee4166bbe07b4c270258ce6Douglas Gregor 1040ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff SourceLocation LBraceLoc = ConsumeBrace(); // the "{" 10411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1042ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff // While we still have something to read, read the instance variables. 1043df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner while (Tok.isNot(tok::r_brace) && Tok.isNot(tok::eof)) { 1044ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff // Each iteration of this loop reads one objc-instance-variable-decl. 10451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1046ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff // Check for extraneous top-level semicolon. 1047df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::semi)) { 1048f13ca06e57ac094ed05ea08c26a499af1ba0ce88Douglas Gregor Diag(Tok, diag::ext_extra_ivar_semi) 1049849b243d4065f56742a4677d6dc8277609a151f8Douglas Gregor << FixItHint::CreateRemoval(Tok.getLocation()); 1050ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff ConsumeToken(); 1051ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff continue; 1052ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff } 10531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1054ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff // Set the default visibility to private. 1055df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::at)) { // parse objc-visibility-spec 1056ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff ConsumeToken(); // eat the @ sign 1057c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor 1058c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor if (Tok.is(tok::code_completion)) { 105923c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCAtVisibility(getCurScope()); 1060dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 1061c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor } 1062c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor 1063861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff switch (Tok.getObjCKeywordID()) { 1064ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff case tok::objc_private: 1065ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff case tok::objc_public: 1066ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff case tok::objc_protected: 1067ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff case tok::objc_package: 1068861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff visibility = Tok.getObjCKeywordID(); 1069ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff ConsumeToken(); 10701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump continue; 1071ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff default: 1072ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff Diag(Tok, diag::err_objc_illegal_visibility_spec); 1073ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff continue; 1074ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff } 1075ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff } 10761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1077c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor if (Tok.is(tok::code_completion)) { 107823c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteOrdinaryName(getCurScope(), 1079e6b1bb6e7fe906d164637ca33503b8fafdbc99e5Douglas Gregor Action::PCC_ObjCInstanceVariableList); 1080dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 1081c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor } 1082c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor 1083bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall struct ObjCIvarCallback : FieldCallback { 1084bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall Parser &P; 1085d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *IDecl; 1086bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall tok::ObjCKeywordKind visibility; 1087d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall llvm::SmallVectorImpl<Decl *> &AllIvarDecls; 1088bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall 1089d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall ObjCIvarCallback(Parser &P, Decl *IDecl, tok::ObjCKeywordKind V, 1090d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall llvm::SmallVectorImpl<Decl *> &AllIvarDecls) : 1091bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall P(P), IDecl(IDecl), visibility(V), AllIvarDecls(AllIvarDecls) { 1092bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall } 1093bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall 1094d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *invoke(FieldDeclarator &FD) { 1095bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall // Install the declarator into the interface decl. 1096d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *Field 109723c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor = P.Actions.ActOnIvar(P.getCurScope(), 1098bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall FD.D.getDeclSpec().getSourceRange().getBegin(), 1099bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall IDecl, FD.D, FD.BitfieldSize, visibility); 11000bd04596e4645ff145a046dfb3475f39674060d9Fariborz Jahanian if (Field) 11010bd04596e4645ff145a046dfb3475f39674060d9Fariborz Jahanian AllIvarDecls.push_back(Field); 1102bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall return Field; 1103bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall } 1104bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall } Callback(*this, interfaceDecl, visibility, AllIvarDecls); 1105d097be8f81fbf4ed96ac10bae18562dd8202666bFariborz Jahanian 1106e13594279a952537ac903325efff57e3edca79d9Chris Lattner // Parse all the comma separated declarators. 1107e13594279a952537ac903325efff57e3edca79d9Chris Lattner DeclSpec DS; 1108bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall ParseStructDeclaration(DS, Callback); 11091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1110df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::semi)) { 1111ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff ConsumeToken(); 1112ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff } else { 1113ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff Diag(Tok, diag::err_expected_semi_decl_list); 1114ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff // Skip to end of block or statement 1115ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff SkipUntil(tok::r_brace, true, true); 1116ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff } 1117ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff } 111860fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff SourceLocation RBraceLoc = MatchRHSPunctuation(tok::r_brace, LBraceLoc); 1119d097be8f81fbf4ed96ac10bae18562dd8202666bFariborz Jahanian Actions.ActOnLastBitfield(RBraceLoc, interfaceDecl, AllIvarDecls); 11208749be53f53384e7846502791ceda6c657228d07Steve Naroff // Call ActOnFields() even if we don't have any decls. This is useful 11218749be53f53384e7846502791ceda6c657228d07Steve Naroff // for code rewriting tools that need to be aware of the empty list. 112223c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.ActOnFields(getCurScope(), atLoc, interfaceDecl, 1123beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad AllIvarDecls.data(), AllIvarDecls.size(), 11241bfe1c2129771c06fb58ae5e8c079ae30e138309Daniel Dunbar LBraceLoc, RBraceLoc, 0); 1125ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff return; 11265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 1127dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff 1128dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-declaration: 1129dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-definition 1130dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-forward-reference 1131dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1132dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-definition: 11331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// @protocol identifier 11341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// objc-protocol-refs[opt] 11351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// objc-interface-decl-list 1136dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @end 1137dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1138dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-forward-reference: 1139dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @protocol identifier-list ';' 1140dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1141dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// "@protocol identifier ;" should be resolved as "@protocol 11423536b443bc50d58a79f14fca9b6842541a434854Steve Naroff/// identifier-list ;": objc-interface-decl-list may not start with a 1143dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// semicolon in the first alternative if objc-protocol-refs are omitted. 1144d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseObjCAtProtocolDeclaration(SourceLocation AtLoc, 1145b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner AttributeList *attrList) { 1146861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff assert(Tok.isObjCAtKeyword(tok::objc_protocol) && 11477ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff "ParseObjCAtProtocolDeclaration(): Expected @protocol"); 11487ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff ConsumeToken(); // the "protocol" identifier 11491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1150083128f6b13dfa4fc615a838c49b516d901b1ac0Douglas Gregor if (Tok.is(tok::code_completion)) { 115123c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCProtocolDecl(getCurScope()); 1152dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 1153083128f6b13dfa4fc615a838c49b516d901b1ac0Douglas Gregor } 1154083128f6b13dfa4fc615a838c49b516d901b1ac0Douglas Gregor 1155df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 11567ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff Diag(Tok, diag::err_expected_ident); // missing protocol name. 1157d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 11587ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff } 11597ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff // Save the protocol name, then consume it. 11607ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff IdentifierInfo *protocolName = Tok.getIdentifierInfo(); 11617ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff SourceLocation nameLoc = ConsumeToken(); 11621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1163df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::semi)) { // forward declaration of one protocol. 11647caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner IdentifierLocPair ProtoInfo(protocolName, nameLoc); 11657ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff ConsumeToken(); 11661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return Actions.ActOnForwardProtocolDeclaration(AtLoc, &ProtoInfo, 1, 1167bc1c877fe28fb6a825f0b226a0a2da99e713ea03Fariborz Jahanian attrList); 11687ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff } 11691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1170df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::comma)) { // list of forward declarations. 11717caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner llvm::SmallVector<IdentifierLocPair, 8> ProtocolRefs; 11727caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner ProtocolRefs.push_back(std::make_pair(protocolName, nameLoc)); 11737caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner 11747ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff // Parse the list of forward declarations. 11757ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff while (1) { 11767ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff ConsumeToken(); // the ',' 1177df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 11787ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff Diag(Tok, diag::err_expected_ident); 11797ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff SkipUntil(tok::semi); 1180d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 11817ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff } 11827caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner ProtocolRefs.push_back(IdentifierLocPair(Tok.getIdentifierInfo(), 11837caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner Tok.getLocation())); 11847ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff ConsumeToken(); // the identifier 11851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1186df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::comma)) 11877ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff break; 11887ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff } 11897ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff // Consume the ';'. 11907ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff if (ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@protocol")) 1191d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 11921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1193e440eb8158e71deb1e4ab11618ae3d680aac6da1Steve Naroff return Actions.ActOnForwardProtocolDeclaration(AtLoc, 11941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump &ProtocolRefs[0], 1195bc1c877fe28fb6a825f0b226a0a2da99e713ea03Fariborz Jahanian ProtocolRefs.size(), 1196bc1c877fe28fb6a825f0b226a0a2da99e713ea03Fariborz Jahanian attrList); 11977caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner } 11981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11997ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff // Last, and definitely not least, parse a protocol declaration. 120071b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis SourceLocation LAngleLoc, EndProtoLoc; 12017caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner 1202d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall llvm::SmallVector<Decl *, 8> ProtocolRefs; 120371b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis llvm::SmallVector<SourceLocation, 8> ProtocolLocs; 12047caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner if (Tok.is(tok::less) && 120571b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis ParseObjCProtocolReferences(ProtocolRefs, ProtocolLocs, false, 120671b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis LAngleLoc, EndProtoLoc)) 1207d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 12081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1209d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ProtoType = 1210e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner Actions.ActOnStartProtocolInterface(AtLoc, protocolName, nameLoc, 1211beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad ProtocolRefs.data(), 1212beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad ProtocolRefs.size(), 121318df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor ProtocolLocs.data(), 1214246e70f69cb8aeb67225c54690f1c6b25abd5a86Daniel Dunbar EndProtoLoc, attrList); 121525e077d59a8e8e43b65882b69610a3d5e2aaf53cFariborz Jahanian ParseObjCInterfaceDeclList(ProtoType, tok::objc_protocol); 1216bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner return ProtoType; 1217dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff} 1218dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff 1219dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-implementation: 1220dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-implementation-prologue 1221dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-category-implementation-prologue 1222dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1223dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-implementation-prologue: 1224dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @implementation identifier objc-superclass[opt] 1225dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-instance-variables[opt] 1226dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1227dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-category-implementation-prologue: 1228dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @implementation identifier ( identifier ) 1229d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseObjCAtImplementationDeclaration( 1230ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian SourceLocation atLoc) { 1231ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian assert(Tok.isObjCAtKeyword(tok::objc_implementation) && 1232ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian "ParseObjCAtImplementationDeclaration(): Expected @implementation"); 1233ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); // the "implementation" identifier 12341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12353b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor // Code completion after '@implementation'. 12363b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor if (Tok.is(tok::code_completion)) { 123723c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCImplementationDecl(getCurScope()); 1238dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 12393b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor } 12403b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor 1241df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 1242ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian Diag(Tok, diag::err_expected_ident); // missing class or category name. 1243d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 1244ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1245ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian // We have a class or category name - consume it. 1246ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian IdentifierInfo *nameId = Tok.getIdentifierInfo(); 1247ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian SourceLocation nameLoc = ConsumeToken(); // consume class or category name 12481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (Tok.is(tok::l_paren)) { 1250ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian // we have a category implementation. 1251ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian SourceLocation lparenLoc = ConsumeParen(); 1252ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian SourceLocation categoryLoc, rparenLoc; 1253ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian IdentifierInfo *categoryId = 0; 12541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 125533ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor if (Tok.is(tok::code_completion)) { 125623c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCImplementationCategory(getCurScope(), nameId, nameLoc); 1257dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 125833ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor } 125933ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor 1260df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::identifier)) { 1261ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian categoryId = Tok.getIdentifierInfo(); 1262ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian categoryLoc = ConsumeToken(); 1263ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } else { 1264ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian Diag(Tok, diag::err_expected_ident); // missing category name. 1265d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 12661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 1267df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::r_paren)) { 1268ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian Diag(Tok, diag::err_expected_rparen); 1269ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian SkipUntil(tok::r_paren, false); // don't stop at ';' 1270d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 1271ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1272ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian rparenLoc = ConsumeParen(); 1273d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ImplCatType = Actions.ActOnStartCategoryImplementation( 12741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump atLoc, nameId, nameLoc, categoryId, 12758f3fde00ad4d4f943321e338b914ae4740711c84Fariborz Jahanian categoryLoc); 1276a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCImpDecl = ImplCatType; 127763e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian PendingObjCImpDecl.push_back(ObjCImpDecl); 1278d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 1279ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1280ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian // We have a class implementation 1281ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian SourceLocation superClassLoc; 1282ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian IdentifierInfo *superClassId = 0; 1283df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::colon)) { 1284ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian // We have a super class 1285ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); 1286df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 1287ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian Diag(Tok, diag::err_expected_ident); // missing super class name. 1288d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 1289ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1290ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian superClassId = Tok.getIdentifierInfo(); 1291ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian superClassLoc = ConsumeToken(); // Consume super class name 1292ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1293d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ImplClsType = Actions.ActOnStartClassImplementation( 1294cb53b361bce341c8591333c6997f62e480acc0b4Chris Lattner atLoc, nameId, nameLoc, 1295ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian superClassId, superClassLoc); 12961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 129760fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff if (Tok.is(tok::l_brace)) // we have ivars 129883c481ade785a919ba21a33f9a8b1b21c1212fb3Fariborz Jahanian ParseObjCClassInstanceVariables(ImplClsType/*FIXME*/, 129901f1bfc3284d5817517d35217885ea9ecb252817Fariborz Jahanian tok::objc_private, atLoc); 1300a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCImpDecl = ImplClsType; 130163e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian PendingObjCImpDecl.push_back(ObjCImpDecl); 130263e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian 1303d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 13045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 130560fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff 1306d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseObjCAtEndDeclaration(SourceRange atEnd) { 1307ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian assert(Tok.isObjCAtKeyword(tok::objc_end) && 1308ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian "ParseObjCAtEndDeclaration(): Expected @end"); 1309d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *Result = ObjCImpDecl; 1310ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); // the "end" identifier 1311a6e3ac514c924879699c6b0b1201028f0091044fFariborz Jahanian if (ObjCImpDecl) { 131223c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.ActOnAtEnd(getCurScope(), atEnd, ObjCImpDecl); 1313d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall ObjCImpDecl = 0; 131463e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian PendingObjCImpDecl.pop_back(); 1315a6e3ac514c924879699c6b0b1201028f0091044fFariborz Jahanian } 1316782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek else { 1317782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek // missing @implementation 1318782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek Diag(atEnd.getBegin(), diag::warn_expected_implementation); 1319782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek } 1320a6e3ac514c924879699c6b0b1201028f0091044fFariborz Jahanian return Result; 13215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 1322e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian 13233fe104154dd2e8ffb351142d74f308938b5c99bfFariborz JahanianParser::DeclGroupPtrTy Parser::FinishPendingObjCActions() { 13243fe104154dd2e8ffb351142d74f308938b5c99bfFariborz Jahanian Actions.DiagnoseUseOfUnimplementedSelectors(); 132563e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian if (PendingObjCImpDecl.empty()) 1326d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return Actions.ConvertDeclToDeclGroup(0); 1327d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ImpDecl = PendingObjCImpDecl.pop_back_val(); 132823c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.ActOnAtEnd(getCurScope(), SourceRange(), ImpDecl); 132963e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian return Actions.ConvertDeclToDeclGroup(ImpDecl); 133063e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian} 133163e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian 1332e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian/// compatibility-alias-decl: 1333e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian/// @compatibility_alias alias-name class-name ';' 1334e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian/// 1335d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseObjCAtAliasDeclaration(SourceLocation atLoc) { 1336e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian assert(Tok.isObjCAtKeyword(tok::objc_compatibility_alias) && 1337e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian "ParseObjCAtAliasDeclaration(): Expected @compatibility_alias"); 1338e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian ConsumeToken(); // consume compatibility_alias 1339df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 1340e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian Diag(Tok, diag::err_expected_ident); 1341d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 1342e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian } 1343243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian IdentifierInfo *aliasId = Tok.getIdentifierInfo(); 1344243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian SourceLocation aliasLoc = ConsumeToken(); // consume alias-name 1345df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 1346e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian Diag(Tok, diag::err_expected_ident); 1347d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 1348e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian } 1349243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian IdentifierInfo *classId = Tok.getIdentifierInfo(); 1350243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian SourceLocation classLoc = ConsumeToken(); // consume class-name; 1351243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian if (Tok.isNot(tok::semi)) { 13521ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_semi_after) << "@compatibility_alias"; 1353d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 1354243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian } 1355b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return Actions.ActOnCompatiblityAlias(atLoc, aliasId, aliasLoc, 1356b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner classId, classLoc); 13575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 13585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1359ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-synthesis: 1360ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// @synthesize property-ivar-list ';' 1361ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// 1362ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-ivar-list: 1363ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-ivar 1364ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-ivar-list ',' property-ivar 1365ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// 1366ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-ivar: 1367ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// identifier 1368ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// identifier '=' identifier 1369ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// 1370d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseObjCPropertySynthesize(SourceLocation atLoc) { 1371ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian assert(Tok.isObjCAtKeyword(tok::objc_synthesize) && 1372ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian "ParseObjCPropertyDynamic(): Expected '@synthesize'"); 1373f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian SourceLocation loc = ConsumeToken(); // consume synthesize 13741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1375b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor while (true) { 1376322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor if (Tok.is(tok::code_completion)) { 137723c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCPropertyDefinition(getCurScope(), ObjCImpDecl); 1378dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 1379322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor } 1380322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor 1381b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor if (Tok.isNot(tok::identifier)) { 1382b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor Diag(Tok, diag::err_synthesized_property_name); 1383b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor SkipUntil(tok::semi); 1384d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 1385b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor } 1386b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor 1387f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian IdentifierInfo *propertyIvar = 0; 1388f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian IdentifierInfo *propertyId = Tok.getIdentifierInfo(); 1389f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian SourceLocation propertyLoc = ConsumeToken(); // consume property name 1390df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::equal)) { 1391ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian // property '=' ivar-name 1392ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); // consume '=' 1393322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor 1394322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor if (Tok.is(tok::code_completion)) { 139523c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCPropertySynthesizeIvar(getCurScope(), propertyId, 1396322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor ObjCImpDecl); 1397dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 1398322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor } 1399322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor 1400df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 1401ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian Diag(Tok, diag::err_expected_ident); 1402ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian break; 1403ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1404f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian propertyIvar = Tok.getIdentifierInfo(); 1405ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); // consume ivar-name 1406ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 140723c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.ActOnPropertyImplDecl(getCurScope(), atLoc, propertyLoc, true, ObjCImpDecl, 1408f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian propertyId, propertyIvar); 1409df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::comma)) 1410ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian break; 1411ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); // consume ',' 1412ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1413b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor if (Tok.isNot(tok::semi)) { 14141ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_semi_after) << "@synthesize"; 1415b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor SkipUntil(tok::semi); 1416b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor } 1417d3fdcb5a1bf6bd5e54e18579c054ea3c292a0e28Fariborz Jahanian else 1418d3fdcb5a1bf6bd5e54e18579c054ea3c292a0e28Fariborz Jahanian ConsumeToken(); // consume ';' 1419d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 1420ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian} 1421ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian 1422ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-dynamic: 1423ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// @dynamic property-list 1424ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// 1425ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-list: 1426ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// identifier 1427ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-list ',' identifier 1428ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// 1429d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseObjCPropertyDynamic(SourceLocation atLoc) { 1430ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian assert(Tok.isObjCAtKeyword(tok::objc_dynamic) && 1431ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian "ParseObjCPropertyDynamic(): Expected '@dynamic'"); 1432ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian SourceLocation loc = ConsumeToken(); // consume dynamic 1433424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor while (true) { 1434424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor if (Tok.is(tok::code_completion)) { 143523c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCPropertyDefinition(getCurScope(), ObjCImpDecl); 1436dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 1437424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor } 1438424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor 1439424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor if (Tok.isNot(tok::identifier)) { 1440424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor Diag(Tok, diag::err_expected_ident); 1441424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor SkipUntil(tok::semi); 1442d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 1443424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor } 1444424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor 1445c35b9e4e2efad727538c848cf30d4b0eb1031dc9Fariborz Jahanian IdentifierInfo *propertyId = Tok.getIdentifierInfo(); 1446c35b9e4e2efad727538c848cf30d4b0eb1031dc9Fariborz Jahanian SourceLocation propertyLoc = ConsumeToken(); // consume property name 144723c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.ActOnPropertyImplDecl(getCurScope(), atLoc, propertyLoc, false, ObjCImpDecl, 1448c35b9e4e2efad727538c848cf30d4b0eb1031dc9Fariborz Jahanian propertyId, 0); 1449c35b9e4e2efad727538c848cf30d4b0eb1031dc9Fariborz Jahanian 1450df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::comma)) 1451ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian break; 1452ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); // consume ',' 1453ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 145494b24db37e80a75c4088e592d4150fb12b00bfb3Fariborz Jahanian if (Tok.isNot(tok::semi)) { 14551ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_semi_after) << "@dynamic"; 145694b24db37e80a75c4088e592d4150fb12b00bfb3Fariborz Jahanian SkipUntil(tok::semi); 145794b24db37e80a75c4088e592d4150fb12b00bfb3Fariborz Jahanian } 145894b24db37e80a75c4088e592d4150fb12b00bfb3Fariborz Jahanian else 145994b24db37e80a75c4088e592d4150fb12b00bfb3Fariborz Jahanian ConsumeToken(); // consume ';' 1460d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 1461ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian} 14621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1463397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// objc-throw-statement: 1464397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// throw expression[opt]; 1465397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// 146660d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult Parser::ParseObjCThrowStmt(SourceLocation atLoc) { 146760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Res; 1468397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian ConsumeToken(); // consume throw 1469df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::semi)) { 147039f8f159c488a900e5958d5aab3e467af9ec8a2bFariborz Jahanian Res = ParseExpression(); 14710e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Res.isInvalid()) { 1472397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian SkipUntil(tok::semi); 147343bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 1474397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian } 1475397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian } 147602418c7f0cb8bb83f1a1a1fad9bf6104efa83e0eTed Kremenek // consume ';' 147702418c7f0cb8bb83f1a1a1fad9bf6104efa83e0eTed Kremenek ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@throw"); 14789ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return Actions.ActOnObjCAtThrowStmt(atLoc, Res.take(), getCurScope()); 1479397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian} 1480397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian 1481c385c90c68dfa376650e2facfbb444b2ec9bd110Fariborz Jahanian/// objc-synchronized-statement: 148278a677bbb5fa115fa0995b5783adeeefad67167eFariborz Jahanian/// @synchronized '(' expression ')' compound-statement 1483c385c90c68dfa376650e2facfbb444b2ec9bd110Fariborz Jahanian/// 148460d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 148543bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian RedlParser::ParseObjCSynchronizedStmt(SourceLocation atLoc) { 1486fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian ConsumeToken(); // consume synchronized 1487fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian if (Tok.isNot(tok::l_paren)) { 14881ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_lparen_after) << "@synchronized"; 148943bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 1490fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian } 1491fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian ConsumeParen(); // '(' 149260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Res(ParseExpression()); 14930e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Res.isInvalid()) { 1494fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian SkipUntil(tok::semi); 149543bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 1496fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian } 1497fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian if (Tok.isNot(tok::r_paren)) { 14981ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_lbrace); 149943bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 1500fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian } 1501fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian ConsumeParen(); // ')' 150278a677bbb5fa115fa0995b5783adeeefad67167eFariborz Jahanian if (Tok.isNot(tok::l_brace)) { 15031ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_lbrace); 150443bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 150578a677bbb5fa115fa0995b5783adeeefad67167eFariborz Jahanian } 15063ac438c383a4a9a73c76a05c76ec5d02f10a3c52Steve Naroff // Enter a scope to hold everything within the compound stmt. Compound 15073ac438c383a4a9a73c76a05c76ec5d02f10a3c52Steve Naroff // statements can always hold declarations. 15088935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor ParseScope BodyScope(this, Scope::DeclScope); 15093ac438c383a4a9a73c76a05c76ec5d02f10a3c52Steve Naroff 151060d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult SynchBody(ParseCompoundStatementBody()); 15110e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl 15128935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor BodyScope.Exit(); 15130e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (SynchBody.isInvalid()) 1514fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian SynchBody = Actions.ActOnNullStmt(Tok.getLocation()); 15159ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return Actions.ActOnObjCAtSynchronizedStmt(atLoc, Res.take(), SynchBody.take()); 1516c385c90c68dfa376650e2facfbb444b2ec9bd110Fariborz Jahanian} 1517c385c90c68dfa376650e2facfbb444b2ec9bd110Fariborz Jahanian 1518397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// objc-try-catch-statement: 1519397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// @try compound-statement objc-catch-list[opt] 1520397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// @try compound-statement objc-catch-list[opt] @finally compound-statement 1521397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// 1522397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// objc-catch-list: 1523397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// @catch ( parameter-declaration ) compound-statement 1524397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// objc-catch-list @catch ( catch-parameter-declaration ) compound-statement 1525397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// catch-parameter-declaration: 1526397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// parameter-declaration 1527397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// '...' [OBJC2] 1528397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// 152960d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult Parser::ParseObjCTryStmt(SourceLocation atLoc) { 1530397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian bool catch_or_finally_seen = false; 153143bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl 1532397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian ConsumeToken(); // consume try 1533df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::l_brace)) { 15341ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_lbrace); 153543bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 1536397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian } 15378f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor StmtVector CatchStmts(Actions); 153860d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult FinallyStmt; 15398935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor ParseScope TryScope(this, Scope::DeclScope); 154060d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult TryBody(ParseCompoundStatementBody()); 15418935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor TryScope.Exit(); 15420e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (TryBody.isInvalid()) 1543bd49a647afd9cc534fef13cadf652d4e9c396e2bFariborz Jahanian TryBody = Actions.ActOnNullStmt(Tok.getLocation()); 1544a55e52c0802cae3b7c366a05c461d3d15074c1a3Sebastian Redl 1545df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner while (Tok.is(tok::at)) { 15466b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner // At this point, we need to lookahead to determine if this @ is the start 15476b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner // of an @catch or @finally. We don't want to consume the @ token if this 15486b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner // is an @try or @encode or something else. 15496b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner Token AfterAt = GetLookAheadToken(1); 15506b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner if (!AfterAt.isObjCAtKeyword(tok::objc_catch) && 15516b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner !AfterAt.isObjCAtKeyword(tok::objc_finally)) 15526b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner break; 15530e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl 1554161a9c5afaafb4d527b7efba9675a8b2cbbe32e0Fariborz Jahanian SourceLocation AtCatchFinallyLoc = ConsumeToken(); 1555cb53b361bce341c8591333c6997f62e480acc0b4Chris Lattner if (Tok.isObjCAtKeyword(tok::objc_catch)) { 1556d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *FirstPart = 0; 15573b1191d7eaf2f4984564e01ab84b6713a9d80e70Fariborz Jahanian ConsumeToken(); // consume catch 1558df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::l_paren)) { 1559397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian ConsumeParen(); 1560e21dd6ffef4585fa43cd3586ed971217d65bf56cSteve Naroff ParseScope CatchScope(this, Scope::DeclScope|Scope::AtCatchScope); 1561df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::ellipsis)) { 1562397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian DeclSpec DS; 1563397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian ParseDeclarationSpecifiers(DS); 156443bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl // For some odd reason, the name of the exception variable is 15651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // optional. As a result, we need to use "PrototypeContext", because 15667ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff // we must accept either 'declarator' or 'abstract-declarator' here. 15677ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff Declarator ParmDecl(DS, Declarator::PrototypeContext); 15687ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff ParseDeclarator(ParmDecl); 15697ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff 15704e6c0d19b7c072758922cf80525a81aeefc6e64bDouglas Gregor // Inform the actions module about the declarator, so it 15717ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff // gets added to the current scope. 157223c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor FirstPart = Actions.ActOnObjCExceptionDecl(getCurScope(), ParmDecl); 157364515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff } else 1574397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian ConsumeToken(); // consume '...' 15751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 157693a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff SourceLocation RParenLoc; 15771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 157893a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff if (Tok.is(tok::r_paren)) 157993a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff RParenLoc = ConsumeParen(); 158093a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff else // Skip over garbage, until we get to ')'. Eat the ')'. 158193a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff SkipUntil(tok::r_paren, true, false); 158293a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff 158360d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult CatchBody(true); 1584c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner if (Tok.is(tok::l_brace)) 1585c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner CatchBody = ParseCompoundStatementBody(); 1586c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner else 1587c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner Diag(Tok, diag::err_expected_lbrace); 15880e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (CatchBody.isInvalid()) 15893b1191d7eaf2f4984564e01ab84b6713a9d80e70Fariborz Jahanian CatchBody = Actions.ActOnNullStmt(Tok.getLocation()); 15908f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor 159160d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Catch = Actions.ActOnObjCAtCatchStmt(AtCatchFinallyLoc, 15928f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor RParenLoc, 15938f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor FirstPart, 15949ae2f076ca5ab1feb3ba95629099ec2319833701John McCall CatchBody.take()); 15958f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor if (!Catch.isInvalid()) 15968f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor CatchStmts.push_back(Catch.release()); 15978f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor 159864515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff } else { 15991ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(AtCatchFinallyLoc, diag::err_expected_lparen_after) 16001ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner << "@catch clause"; 160143bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 1602397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian } 1603397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian catch_or_finally_seen = true; 16046b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner } else { 16056b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner assert(Tok.isObjCAtKeyword(tok::objc_finally) && "Lookahead confused?"); 160664515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff ConsumeToken(); // consume finally 16078935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor ParseScope FinallyScope(this, Scope::DeclScope); 16080e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl 160960d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult FinallyBody(true); 1610c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner if (Tok.is(tok::l_brace)) 1611c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner FinallyBody = ParseCompoundStatementBody(); 1612c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner else 1613c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner Diag(Tok, diag::err_expected_lbrace); 16140e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (FinallyBody.isInvalid()) 1615161a9c5afaafb4d527b7efba9675a8b2cbbe32e0Fariborz Jahanian FinallyBody = Actions.ActOnNullStmt(Tok.getLocation()); 16160e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl FinallyStmt = Actions.ActOnObjCAtFinallyStmt(AtCatchFinallyLoc, 16179ae2f076ca5ab1feb3ba95629099ec2319833701John McCall FinallyBody.take()); 1618397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian catch_or_finally_seen = true; 1619397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian break; 1620397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian } 1621397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian } 1622bd49a647afd9cc534fef13cadf652d4e9c396e2bFariborz Jahanian if (!catch_or_finally_seen) { 1623397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian Diag(atLoc, diag::err_missing_catch_finally); 162443bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 1625bd49a647afd9cc534fef13cadf652d4e9c396e2bFariborz Jahanian } 16268f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor 16279ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return Actions.ActOnObjCAtTryStmt(atLoc, TryBody.take(), 16288f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor move_arg(CatchStmts), 16299ae2f076ca5ab1feb3ba95629099ec2319833701John McCall FinallyStmt.take()); 1630397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian} 1631ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian 16323536b443bc50d58a79f14fca9b6842541a434854Steve Naroff/// objc-method-def: objc-method-proto ';'[opt] '{' body '}' 1633ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// 1634d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseObjCMethodDefinition() { 1635d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *MDecl = ParseObjCMethodPrototype(ObjCImpDecl); 16361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 163749f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner PrettyStackTraceActionsDecl CrashInfo(MDecl, Tok.getLocation(), Actions, 163849f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner PP.getSourceManager(), 163949f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner "parsing Objective-C method"); 16401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1641ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian // parse optional ';' 1642209a8c2fa23636f6d065d618e7078e164903f5cdFariborz Jahanian if (Tok.is(tok::semi)) { 1643496e45ef3350fabc312c5a807d308c65c50af4dbTed Kremenek if (ObjCImpDecl) { 1644496e45ef3350fabc312c5a807d308c65c50af4dbTed Kremenek Diag(Tok, diag::warn_semicolon_before_method_body) 1645849b243d4065f56742a4677d6dc8277609a151f8Douglas Gregor << FixItHint::CreateRemoval(Tok.getLocation()); 1646496e45ef3350fabc312c5a807d308c65c50af4dbTed Kremenek } 1647ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); 1648209a8c2fa23636f6d065d618e7078e164903f5cdFariborz Jahanian } 1649ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian 1650409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // We should have an opening brace now. 1651df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::l_brace)) { 1652da323adbb99cee19a203ead852d5d9bfebb23fb7Steve Naroff Diag(Tok, diag::err_expected_method_body); 16531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1654409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // Skip over garbage, until we get to '{'. Don't eat the '{'. 1655409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff SkipUntil(tok::l_brace, true, true); 16561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1657409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // If we didn't find the '{', bail out. 1658409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff if (Tok.isNot(tok::l_brace)) 1659d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 1660ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1661409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff SourceLocation BraceLoc = Tok.getLocation(); 16621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1663409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // Enter a scope for the method body. 166415faee19fdb9017dd6d08a690427b18c3b062c2dChris Lattner ParseScope BodyScope(this, 166515faee19fdb9017dd6d08a690427b18c3b062c2dChris Lattner Scope::ObjCMethodScope|Scope::FnScope|Scope::DeclScope); 16661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1667409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // Tell the actions module that we have entered a method definition with the 1668394f3f483fa4e7b472630cfcd03f7840520958c5Steve Naroff // specified Declarator for the method. 166923c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.ActOnStartOfObjCMethodDef(getCurScope(), MDecl); 167061364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl 167160d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult FnBody(ParseCompoundStatementBody()); 167261364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl 1673409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // If the function body could not be parsed, make a bogus compoundstmt. 16740e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (FnBody.isInvalid()) 1675a60528cdac7deee3991c2b48af4df4f315e49e9dSebastian Redl FnBody = Actions.ActOnCompoundStmt(BraceLoc, BraceLoc, 1676a60528cdac7deee3991c2b48af4df4f315e49e9dSebastian Redl MultiStmtArg(Actions), false); 1677798d119415323ebcd029ffe1e0fb442a4ca8adbbSebastian Redl 167832ce8376efb7e0d70e5f7e8fcf685130293f412bSteve Naroff // TODO: Pass argument information. 16799ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Actions.ActOnFinishFunctionBody(MDecl, FnBody.take()); 16801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1681409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // Leave the function body scope. 16828935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor BodyScope.Exit(); 1683798d119415323ebcd029ffe1e0fb442a4ca8adbbSebastian Redl 168471c0a951d08dc7a2a057df8c15f22b36f6aa47c7Steve Naroff return MDecl; 16855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 16865508518a2702b00be3b15a26d772bde968972f54Anders Carlsson 168760d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult Parser::ParseObjCAtStatement(SourceLocation AtLoc) { 16889a0c85e640a08174569a303db22981612f05d385Douglas Gregor if (Tok.is(tok::code_completion)) { 168923c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCAtStatement(getCurScope()); 1690dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 16919a0c85e640a08174569a303db22981612f05d385Douglas Gregor return StmtError(); 16925d8031687d086701b4dadaab3e0de1def448da9dChris Lattner } 16935d8031687d086701b4dadaab3e0de1def448da9dChris Lattner 16945d8031687d086701b4dadaab3e0de1def448da9dChris Lattner if (Tok.isObjCAtKeyword(tok::objc_try)) 16956b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner return ParseObjCTryStmt(AtLoc); 16965d8031687d086701b4dadaab3e0de1def448da9dChris Lattner 16975d8031687d086701b4dadaab3e0de1def448da9dChris Lattner if (Tok.isObjCAtKeyword(tok::objc_throw)) 169864515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff return ParseObjCThrowStmt(AtLoc); 16995d8031687d086701b4dadaab3e0de1def448da9dChris Lattner 17005d8031687d086701b4dadaab3e0de1def448da9dChris Lattner if (Tok.isObjCAtKeyword(tok::objc_synchronized)) 170164515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff return ParseObjCSynchronizedStmt(AtLoc); 17025d8031687d086701b4dadaab3e0de1def448da9dChris Lattner 170360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Res(ParseExpressionWithLeadingAt(AtLoc)); 17040e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Res.isInvalid()) { 170564515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff // If the expression is invalid, skip ahead to the next semicolon. Not 170664515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff // doing this opens us up to the possibility of infinite loops if 170764515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff // ParseExpression does not consume any tokens. 170864515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff SkipUntil(tok::semi); 170943bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 171064515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff } 17115d8031687d086701b4dadaab3e0de1def448da9dChris Lattner 171264515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff // Otherwise, eat the semicolon. 171364515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff ExpectAndConsume(tok::semi, diag::err_expected_semi_after_expr); 17149ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return Actions.ActOnExprStmt(Actions.MakeFullExpr(Res.take())); 171564515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff} 171664515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff 171760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult Parser::ParseObjCAtExpression(SourceLocation AtLoc) { 17185508518a2702b00be3b15a26d772bde968972f54Anders Carlsson switch (Tok.getKind()) { 17199a0c85e640a08174569a303db22981612f05d385Douglas Gregor case tok::code_completion: 172023c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCAtExpression(getCurScope()); 1721dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 17229a0c85e640a08174569a303db22981612f05d385Douglas Gregor return ExprError(); 17239a0c85e640a08174569a303db22981612f05d385Douglas Gregor 1724b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner case tok::string_literal: // primary-expression: string-literal 1725b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner case tok::wide_string_literal: 17261d922960e083906a586609ac6978678147250177Sebastian Redl return ParsePostfixExpressionSuffix(ParseObjCStringLiteral(AtLoc)); 1727b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner default: 17284fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner if (Tok.getIdentifierInfo() == 0) 17291d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(AtLoc, diag::err_unexpected_at)); 17302f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl 17314fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner switch (Tok.getIdentifierInfo()->getObjCKeywordID()) { 17324fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner case tok::objc_encode: 17331d922960e083906a586609ac6978678147250177Sebastian Redl return ParsePostfixExpressionSuffix(ParseObjCEncodeExpression(AtLoc)); 17344fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner case tok::objc_protocol: 17351d922960e083906a586609ac6978678147250177Sebastian Redl return ParsePostfixExpressionSuffix(ParseObjCProtocolExpression(AtLoc)); 17364fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner case tok::objc_selector: 17371d922960e083906a586609ac6978678147250177Sebastian Redl return ParsePostfixExpressionSuffix(ParseObjCSelectorExpression(AtLoc)); 17384fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner default: 17391d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(AtLoc, diag::err_unexpected_at)); 17404fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner } 17415508518a2702b00be3b15a26d772bde968972f54Anders Carlsson } 17425508518a2702b00be3b15a26d772bde968972f54Anders Carlsson} 17435508518a2702b00be3b15a26d772bde968972f54Anders Carlsson 17446aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// \brirg Parse the receiver of an Objective-C++ message send. 17456aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// 17466aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// This routine parses the receiver of a message send in 17476aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// Objective-C++ either as a type or as an expression. Note that this 17486aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// routine must not be called to parse a send to 'super', since it 17496aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// has no way to return such a result. 17506aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// 17516aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// \param IsExpr Whether the receiver was parsed as an expression. 17526aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// 17536aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// \param TypeOrExpr If the receiver was parsed as an expression (\c 17546aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// IsExpr is true), the parsed expression. If the receiver was parsed 17556aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// as a type (\c IsExpr is false), the parsed type. 17566aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// 17576aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// \returns True if an error occurred during parsing or semantic 17586aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// analysis, in which case the arguments do not have valid 17596aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// values. Otherwise, returns false for a successful parse. 17606aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// 17616aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// objc-receiver: [C++] 17626aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// 'super' [not parsed here] 17636aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// expression 17646aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// simple-type-specifier 17656aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// typename-specifier 17666aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregorbool Parser::ParseObjCXXMessageReceiver(bool &IsExpr, void *&TypeOrExpr) { 17676aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor if (Tok.is(tok::identifier) || Tok.is(tok::coloncolon) || 17686aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor Tok.is(tok::kw_typename) || Tok.is(tok::annot_cxxscope)) 17696aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor TryAnnotateTypeOrScopeToken(); 17706aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 17716aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor if (!isCXXSimpleTypeSpecifier()) { 17726aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // objc-receiver: 17736aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // expression 177460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Receiver = ParseExpression(); 17756aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor if (Receiver.isInvalid()) 17766aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor return true; 17776aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 17786aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor IsExpr = true; 17796aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor TypeOrExpr = Receiver.take(); 17806aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor return false; 17816aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor } 17826aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 17836aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // objc-receiver: 17846aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // typename-specifier 17856aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // simple-type-specifier 17866aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // expression (that starts with one of the above) 17876aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor DeclSpec DS; 17886aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor ParseCXXSimpleTypeSpecifier(DS); 17896aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 17906aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor if (Tok.is(tok::l_paren)) { 17916aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // If we see an opening parentheses at this point, we are 17926aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // actually parsing an expression that starts with a 17936aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // function-style cast, e.g., 17946aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // 17956aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // postfix-expression: 17966aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // simple-type-specifier ( expression-list [opt] ) 17976aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // typename-specifier ( expression-list [opt] ) 17986aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // 17996aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // Parse the remainder of this case, then the (optional) 18006aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // postfix-expression suffix, followed by the (optional) 18016aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // right-hand side of the binary expression. We have an 18026aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // instance method. 180360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Receiver = ParseCXXTypeConstructExpression(DS); 18046aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor if (!Receiver.isInvalid()) 18059ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Receiver = ParsePostfixExpressionSuffix(Receiver.take()); 18066aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor if (!Receiver.isInvalid()) 18079ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Receiver = ParseRHSOfBinaryExpression(Receiver.take(), prec::Comma); 18086aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor if (Receiver.isInvalid()) 18096aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor return true; 18106aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 18116aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor IsExpr = true; 18126aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor TypeOrExpr = Receiver.take(); 18136aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor return false; 18146aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor } 18156aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 18166aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // We have a class message. Turn the simple-type-specifier or 18176aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // typename-specifier we parsed into a type and parse the 18186aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // remainder of the class message. 18196aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor Declarator DeclaratorInfo(DS, Declarator::TypeNameContext); 182023c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor TypeResult Type = Actions.ActOnTypeName(getCurScope(), DeclaratorInfo); 18216aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor if (Type.isInvalid()) 18226aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor return true; 18236aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 18246aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor IsExpr = false; 1825b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall TypeOrExpr = Type.get().getAsOpaquePtr(); 18266aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor return false; 18276aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor} 18286aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 18291b730e847ded503f2e615154035c083c4f94a067Douglas Gregor/// \brief Determine whether the parser is currently referring to a an 18301b730e847ded503f2e615154035c083c4f94a067Douglas Gregor/// Objective-C message send, using a simplified heuristic to avoid overhead. 18311b730e847ded503f2e615154035c083c4f94a067Douglas Gregor/// 18321b730e847ded503f2e615154035c083c4f94a067Douglas Gregor/// This routine will only return true for a subset of valid message-send 18331b730e847ded503f2e615154035c083c4f94a067Douglas Gregor/// expressions. 18341b730e847ded503f2e615154035c083c4f94a067Douglas Gregorbool Parser::isSimpleObjCMessageExpression() { 1835c59cb38810c63a806270385f79ea84e0203754eaChris Lattner assert(Tok.is(tok::l_square) && getLang().ObjC1 && 18361b730e847ded503f2e615154035c083c4f94a067Douglas Gregor "Incorrect start for isSimpleObjCMessageExpression"); 18371b730e847ded503f2e615154035c083c4f94a067Douglas Gregor return GetLookAheadToken(1).is(tok::identifier) && 18381b730e847ded503f2e615154035c083c4f94a067Douglas Gregor GetLookAheadToken(2).is(tok::identifier); 18391b730e847ded503f2e615154035c083c4f94a067Douglas Gregor} 18401b730e847ded503f2e615154035c083c4f94a067Douglas Gregor 18411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// objc-message-expr: 18420ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// '[' objc-receiver objc-message-args ']' 18430ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// 18442725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// objc-receiver: [C] 1845eb483eb3ee80300f15d6d13573d82493c2194461Chris Lattner/// 'super' 18460ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// expression 18470ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// class-name 18480ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// type-name 18496aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// 185060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult Parser::ParseObjCMessageExpression() { 1851699b66138ac307a32e238463e0eff513ff17d337Chris Lattner assert(Tok.is(tok::l_square) && "'[' expected"); 1852699b66138ac307a32e238463e0eff513ff17d337Chris Lattner SourceLocation LBracLoc = ConsumeBracket(); // consume '[' 1853699b66138ac307a32e238463e0eff513ff17d337Chris Lattner 18548e254cfe5a6ab4202c7fcc4b64bdd1ca0fe071acDouglas Gregor if (Tok.is(tok::code_completion)) { 185523c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCMessageReceiver(getCurScope()); 18568e254cfe5a6ab4202c7fcc4b64bdd1ca0fe071acDouglas Gregor ConsumeCodeCompletionToken(); 18578e254cfe5a6ab4202c7fcc4b64bdd1ca0fe071acDouglas Gregor SkipUntil(tok::r_square); 18588e254cfe5a6ab4202c7fcc4b64bdd1ca0fe071acDouglas Gregor return ExprError(); 18598e254cfe5a6ab4202c7fcc4b64bdd1ca0fe071acDouglas Gregor } 18608e254cfe5a6ab4202c7fcc4b64bdd1ca0fe071acDouglas Gregor 18616aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor if (getLang().CPlusPlus) { 18626aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // We completely separate the C and C++ cases because C++ requires 18636aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // more complicated (read: slower) parsing. 18646aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 18656aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // Handle send to super. 18666aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // FIXME: This doesn't benefit from the same typo-correction we 18676aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // get in Objective-C. 18686aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor if (Tok.is(tok::identifier) && Tok.getIdentifierInfo() == Ident_super && 186923c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor NextToken().isNot(tok::period) && getCurScope()->isInObjcMethodScope()) 1870b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall return ParseObjCMessageExpressionBody(LBracLoc, ConsumeToken(), 1871b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType(), 0); 18726aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 18736aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // Parse the receiver, which is either a type or an expression. 18746aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor bool IsExpr; 18756aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor void *TypeOrExpr; 18766aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor if (ParseObjCXXMessageReceiver(IsExpr, TypeOrExpr)) { 18776aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor SkipUntil(tok::r_square); 18786aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor return ExprError(); 18796aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor } 18806aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 18816aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor if (IsExpr) 1882b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(), 1883b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType(), 18849ae2f076ca5ab1feb3ba95629099ec2319833701John McCall static_cast<Expr*>(TypeOrExpr)); 18856aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 18866aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(), 1887b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType::getFromOpaquePtr(TypeOrExpr), 1888b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall 0); 1889c59cb38810c63a806270385f79ea84e0203754eaChris Lattner } 1890c59cb38810c63a806270385f79ea84e0203754eaChris Lattner 1891c59cb38810c63a806270385f79ea84e0203754eaChris Lattner if (Tok.is(tok::identifier)) { 18921dbca6ea983231b4cab1a8f1edda8f6e13c21f12Douglas Gregor IdentifierInfo *Name = Tok.getIdentifierInfo(); 18931dbca6ea983231b4cab1a8f1edda8f6e13c21f12Douglas Gregor SourceLocation NameLoc = Tok.getLocation(); 1894b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ReceiverType; 189523c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor switch (Actions.getObjCMessageKind(getCurScope(), Name, NameLoc, 18961dbca6ea983231b4cab1a8f1edda8f6e13c21f12Douglas Gregor Name == Ident_super, 18971569f95831a8c99e9f664137bf8f40e47ee3d90fDouglas Gregor NextToken().is(tok::period), 18981569f95831a8c99e9f664137bf8f40e47ee3d90fDouglas Gregor ReceiverType)) { 18991dbca6ea983231b4cab1a8f1edda8f6e13c21f12Douglas Gregor case Action::ObjCSuperMessage: 1900b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall return ParseObjCMessageExpressionBody(LBracLoc, ConsumeToken(), 1901b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType(), 0); 19022725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor 19031569f95831a8c99e9f664137bf8f40e47ee3d90fDouglas Gregor case Action::ObjCClassMessage: 19041569f95831a8c99e9f664137bf8f40e47ee3d90fDouglas Gregor if (!ReceiverType) { 19052725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor SkipUntil(tok::r_square); 19062725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor return ExprError(); 19072725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor } 19082725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor 19091569f95831a8c99e9f664137bf8f40e47ee3d90fDouglas Gregor ConsumeToken(); // the type name 19101569f95831a8c99e9f664137bf8f40e47ee3d90fDouglas Gregor 19111569f95831a8c99e9f664137bf8f40e47ee3d90fDouglas Gregor return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(), 19129ae2f076ca5ab1feb3ba95629099ec2319833701John McCall ReceiverType, 0); 19131dbca6ea983231b4cab1a8f1edda8f6e13c21f12Douglas Gregor 19141dbca6ea983231b4cab1a8f1edda8f6e13c21f12Douglas Gregor case Action::ObjCInstanceMessage: 19152725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor // Fall through to parse an expression. 19161dbca6ea983231b4cab1a8f1edda8f6e13c21f12Douglas Gregor break; 1917d2869925b5f10e00b13fbf3f41bbb17e4c9adbe0Fariborz Jahanian } 1918699b66138ac307a32e238463e0eff513ff17d337Chris Lattner } 1919eb483eb3ee80300f15d6d13573d82493c2194461Chris Lattner 1920eb483eb3ee80300f15d6d13573d82493c2194461Chris Lattner // Otherwise, an arbitrary expression can be the receiver of a send. 192160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Res(ParseExpression()); 19220e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Res.isInvalid()) { 19235c749428a9938d5e2e9564b1c9b7a9252c30ee27Chris Lattner SkipUntil(tok::r_square); 19241d922960e083906a586609ac6978678147250177Sebastian Redl return move(Res); 1925699b66138ac307a32e238463e0eff513ff17d337Chris Lattner } 19261d922960e083906a586609ac6978678147250177Sebastian Redl 1927b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(), 1928b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType(), Res.take()); 1929699b66138ac307a32e238463e0eff513ff17d337Chris Lattner} 19301d922960e083906a586609ac6978678147250177Sebastian Redl 19312725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// \brief Parse the remainder of an Objective-C message following the 19322725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// '[' objc-receiver. 19332725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// 19342725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// This routine handles sends to super, class messages (sent to a 19352725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// class name), and instance messages (sent to an object), and the 19362725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// target is represented by \p SuperLoc, \p ReceiverType, or \p 19372725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// ReceiverExpr, respectively. Only one of these parameters may have 19382725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// a valid value. 19392725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// 19402725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// \param LBracLoc The location of the opening '['. 19412725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// 19422725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// \param SuperLoc If this is a send to 'super', the location of the 19432725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// 'super' keyword that indicates a send to the superclass. 19442725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// 19452725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// \param ReceiverType If this is a class message, the type of the 19462725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// class we are sending a message to. 19472725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// 19482725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// \param ReceiverExpr If this is an instance message, the expression 19492725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// used to compute the receiver object. 19501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 19510ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-message-args: 19520ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-selector 19530ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-keywordarg-list 19540ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// 19550ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-keywordarg-list: 19560ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-keywordarg 19570ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-keywordarg-list objc-keywordarg 19580ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// 19591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// objc-keywordarg: 19600ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// selector-name[opt] ':' objc-keywordexpr 19610ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// 19620ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-keywordexpr: 19630ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// nonempty-expr-list 19640ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// 19650ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// nonempty-expr-list: 19660ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// assignment-expression 19670ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// nonempty-expr-list , assignment-expression 19681d922960e083906a586609ac6978678147250177Sebastian Redl/// 196960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 1970699b66138ac307a32e238463e0eff513ff17d337Chris LattnerParser::ParseObjCMessageExpressionBody(SourceLocation LBracLoc, 19712725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor SourceLocation SuperLoc, 1972b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ReceiverType, 19731d922960e083906a586609ac6978678147250177Sebastian Redl ExprArg ReceiverExpr) { 1974c4df6d2c05c647a6a5770ba0c749782b6c023a3aSteve Naroff if (Tok.is(tok::code_completion)) { 19752725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor if (SuperLoc.isValid()) 197623c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCSuperMessage(getCurScope(), SuperLoc, 0, 0); 19772725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor else if (ReceiverType) 197823c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCClassMessage(getCurScope(), ReceiverType, 0, 0); 1979c4df6d2c05c647a6a5770ba0c749782b6c023a3aSteve Naroff else 19809ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Actions.CodeCompleteObjCInstanceMessage(getCurScope(), ReceiverExpr, 1981d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor 0, 0); 1982dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 1983c4df6d2c05c647a6a5770ba0c749782b6c023a3aSteve Naroff } 1984d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor 1985a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian // Parse objc-selector 19864b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian SourceLocation Loc; 19872fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner IdentifierInfo *selIdent = ParseObjCSelectorPiece(Loc); 198868d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff 1989ff975cfab9ada27df86038286d1678084aeb3428Anders Carlsson SourceLocation SelectorLoc = Loc; 19901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 199168d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff llvm::SmallVector<IdentifierInfo *, 12> KeyIdents; 1992a55e52c0802cae3b7c366a05c461d3d15074c1a3Sebastian Redl ExprVector KeyExprs(Actions); 199368d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff 1994df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::colon)) { 1995a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian while (1) { 1996a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian // Each iteration parses a single keyword argument. 199768d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff KeyIdents.push_back(selIdent); 199837387c932855c6d58d70bdd705cd3a9fdcd2a931Steve Naroff 1999df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::colon)) { 2000a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian Diag(Tok, diag::err_expected_colon); 20014fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // We must manually skip to a ']', otherwise the expression skipper will 20024fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // stop at the ']' when it skips to the ';'. We want it to skip beyond 20034fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // the enclosing expression. 20044fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner SkipUntil(tok::r_square); 20051d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(); 2006a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian } 20071d922960e083906a586609ac6978678147250177Sebastian Redl 200868d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff ConsumeToken(); // Eat the ':'. 20091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// Parse the expression after ':' 201060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Res(ParseAssignmentExpression()); 20110e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Res.isInvalid()) { 20124fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // We must manually skip to a ']', otherwise the expression skipper will 20134fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // stop at the ']' when it skips to the ';'. We want it to skip beyond 20144fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // the enclosing expression. 20154fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner SkipUntil(tok::r_square); 20161d922960e083906a586609ac6978678147250177Sebastian Redl return move(Res); 201737387c932855c6d58d70bdd705cd3a9fdcd2a931Steve Naroff } 20181d922960e083906a586609ac6978678147250177Sebastian Redl 201937387c932855c6d58d70bdd705cd3a9fdcd2a931Steve Naroff // We have a valid expression. 2020effa8d1c97b00a3f53e972b0e61d9aade5ea1c57Sebastian Redl KeyExprs.push_back(Res.release()); 20211d922960e083906a586609ac6978678147250177Sebastian Redl 2022d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor // Code completion after each argument. 2023d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor if (Tok.is(tok::code_completion)) { 20242725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor if (SuperLoc.isValid()) 202523c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCSuperMessage(getCurScope(), SuperLoc, 20262725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor KeyIdents.data(), 20272725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor KeyIdents.size()); 20282725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor else if (ReceiverType) 202923c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCClassMessage(getCurScope(), ReceiverType, 2030d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor KeyIdents.data(), 2031d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor KeyIdents.size()); 2032d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor else 20339ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Actions.CodeCompleteObjCInstanceMessage(getCurScope(), ReceiverExpr, 2034d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor KeyIdents.data(), 2035d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor KeyIdents.size()); 2036dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 2037d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor } 2038d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor 203937387c932855c6d58d70bdd705cd3a9fdcd2a931Steve Naroff // Check for another keyword selector. 20402fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner selIdent = ParseObjCSelectorPiece(Loc); 2041df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (!selIdent && Tok.isNot(tok::colon)) 2042a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian break; 2043a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian // We have a selector or a colon, continue parsing. 2044a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian } 2045a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian // Parse the, optional, argument list, comma separated. 2046df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner while (Tok.is(tok::comma)) { 204749f109c786f99eb7468dac3976db083a65493444Steve Naroff ConsumeToken(); // Eat the ','. 20481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// Parse the expression after ',' 204960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Res(ParseAssignmentExpression()); 20500e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Res.isInvalid()) { 20514fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // We must manually skip to a ']', otherwise the expression skipper will 20524fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // stop at the ']' when it skips to the ';'. We want it to skip beyond 20534fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // the enclosing expression. 20544fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner SkipUntil(tok::r_square); 20551d922960e083906a586609ac6978678147250177Sebastian Redl return move(Res); 205649f109c786f99eb7468dac3976db083a65493444Steve Naroff } 20570e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl 205849f109c786f99eb7468dac3976db083a65493444Steve Naroff // We have a valid expression. 2059effa8d1c97b00a3f53e972b0e61d9aade5ea1c57Sebastian Redl KeyExprs.push_back(Res.release()); 2060a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian } 2061a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian } else if (!selIdent) { 2062a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian Diag(Tok, diag::err_expected_ident); // missing selector name. 20631d922960e083906a586609ac6978678147250177Sebastian Redl 20644fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // We must manually skip to a ']', otherwise the expression skipper will 20654fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // stop at the ']' when it skips to the ';'. We want it to skip beyond 20664fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // the enclosing expression. 20674fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner SkipUntil(tok::r_square); 20681d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(); 2069a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian } 2070809872eca7f6c024e2ab41ddffbbeeae807bf5dcFariborz Jahanian 2071df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::r_square)) { 2072809872eca7f6c024e2ab41ddffbbeeae807bf5dcFariborz Jahanian if (Tok.is(tok::identifier)) 2073809872eca7f6c024e2ab41ddffbbeeae807bf5dcFariborz Jahanian Diag(Tok, diag::err_expected_colon); 2074809872eca7f6c024e2ab41ddffbbeeae807bf5dcFariborz Jahanian else 2075809872eca7f6c024e2ab41ddffbbeeae807bf5dcFariborz Jahanian Diag(Tok, diag::err_expected_rsquare); 20764fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // We must manually skip to a ']', otherwise the expression skipper will 20774fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // stop at the ']' when it skips to the ';'. We want it to skip beyond 20784fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // the enclosing expression. 20794fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner SkipUntil(tok::r_square); 20801d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(); 2081a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian } 20821d922960e083906a586609ac6978678147250177Sebastian Redl 2083699b66138ac307a32e238463e0eff513ff17d337Chris Lattner SourceLocation RBracLoc = ConsumeBracket(); // consume ']' 20841d922960e083906a586609ac6978678147250177Sebastian Redl 208529238a0bf7cbf5b396efb451a0adb5fe4aa037caSteve Naroff unsigned nKeys = KeyIdents.size(); 2086ff38491c18b060526d754765b952f4a497a89416Chris Lattner if (nKeys == 0) 2087ff38491c18b060526d754765b952f4a497a89416Chris Lattner KeyIdents.push_back(selIdent); 2088ff38491c18b060526d754765b952f4a497a89416Chris Lattner Selector Sel = PP.getSelectorTable().getSelector(nKeys, &KeyIdents[0]); 20891d922960e083906a586609ac6978678147250177Sebastian Redl 20902725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor if (SuperLoc.isValid()) 209123c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor return Actions.ActOnSuperMessage(getCurScope(), SuperLoc, Sel, 20922725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor LBracLoc, SelectorLoc, RBracLoc, 20932725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor Action::MultiExprArg(Actions, 20942725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor KeyExprs.take(), 20952725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor KeyExprs.size())); 20962725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor else if (ReceiverType) 209723c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor return Actions.ActOnClassMessage(getCurScope(), ReceiverType, Sel, 20982725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor LBracLoc, SelectorLoc, RBracLoc, 20992725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor Action::MultiExprArg(Actions, 21002725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor KeyExprs.take(), 21012725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor KeyExprs.size())); 21029ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return Actions.ActOnInstanceMessage(getCurScope(), ReceiverExpr, Sel, 21032725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor LBracLoc, SelectorLoc, RBracLoc, 21042725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor Action::MultiExprArg(Actions, 21052725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor KeyExprs.take(), 21062725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor KeyExprs.size())); 21070ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian} 21080ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian 210960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult Parser::ParseObjCStringLiteral(SourceLocation AtLoc) { 211060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Res(ParseStringLiteralExpression()); 21111d922960e083906a586609ac6978678147250177Sebastian Redl if (Res.isInvalid()) return move(Res); 21121d922960e083906a586609ac6978678147250177Sebastian Redl 2113b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner // @"foo" @"bar" is a valid concatenated string. Eat any subsequent string 2114b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner // expressions. At this point, we know that the only valid thing that starts 2115b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner // with '@' is an @"". 2116b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner llvm::SmallVector<SourceLocation, 4> AtLocs; 2117a55e52c0802cae3b7c366a05c461d3d15074c1a3Sebastian Redl ExprVector AtStrings(Actions); 2118b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner AtLocs.push_back(AtLoc); 2119effa8d1c97b00a3f53e972b0e61d9aade5ea1c57Sebastian Redl AtStrings.push_back(Res.release()); 21200e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl 2121b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner while (Tok.is(tok::at)) { 2122b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner AtLocs.push_back(ConsumeToken()); // eat the @. 2123b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner 212415faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl // Invalid unless there is a string literal. 212597cf6eb380016db868866faf27a086cd55a316d4Chris Lattner if (!isTokenStringLiteral()) 212697cf6eb380016db868866faf27a086cd55a316d4Chris Lattner return ExprError(Diag(Tok, diag::err_objc_concat_string)); 2127b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner 212860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Lit(ParseStringLiteralExpression()); 21290e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Lit.isInvalid()) 21301d922960e083906a586609ac6978678147250177Sebastian Redl return move(Lit); 21310e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl 2132effa8d1c97b00a3f53e972b0e61d9aade5ea1c57Sebastian Redl AtStrings.push_back(Lit.release()); 2133b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner } 21341d922960e083906a586609ac6978678147250177Sebastian Redl 21351d922960e083906a586609ac6978678147250177Sebastian Redl return Owned(Actions.ParseObjCStringLiteral(&AtLocs[0], AtStrings.take(), 21361d922960e083906a586609ac6978678147250177Sebastian Redl AtStrings.size())); 21375508518a2702b00be3b15a26d772bde968972f54Anders Carlsson} 2138f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson 2139f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson/// objc-encode-expression: 2140f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson/// @encode ( type-name ) 214160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 21421d922960e083906a586609ac6978678147250177Sebastian RedlParser::ParseObjCEncodeExpression(SourceLocation AtLoc) { 2143861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff assert(Tok.isObjCAtKeyword(tok::objc_encode) && "Not an @encode expression!"); 21441d922960e083906a586609ac6978678147250177Sebastian Redl 2145f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson SourceLocation EncLoc = ConsumeToken(); 21461d922960e083906a586609ac6978678147250177Sebastian Redl 21474fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner if (Tok.isNot(tok::l_paren)) 21481d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(Tok, diag::err_expected_lparen_after) << "@encode"); 21491d922960e083906a586609ac6978678147250177Sebastian Redl 2150f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson SourceLocation LParenLoc = ConsumeParen(); 21511d922960e083906a586609ac6978678147250177Sebastian Redl 2152809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor TypeResult Ty = ParseTypeName(); 21531d922960e083906a586609ac6978678147250177Sebastian Redl 21544988ae3fda10743c8ed8a98cdcb5a783362587b4Anders Carlsson SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); 21551d922960e083906a586609ac6978678147250177Sebastian Redl 2156809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor if (Ty.isInvalid()) 2157809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor return ExprError(); 2158809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor 21591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return Owned(Actions.ParseObjCEncodeExpression(AtLoc, EncLoc, LParenLoc, 2160809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor Ty.get(), RParenLoc)); 2161f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson} 216229b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson 216329b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson/// objc-protocol-expression 216429b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson/// @protocol ( protocol-name ) 216560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 21661d922960e083906a586609ac6978678147250177Sebastian RedlParser::ParseObjCProtocolExpression(SourceLocation AtLoc) { 216729b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson SourceLocation ProtoLoc = ConsumeToken(); 21681d922960e083906a586609ac6978678147250177Sebastian Redl 21694fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner if (Tok.isNot(tok::l_paren)) 21701d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(Tok, diag::err_expected_lparen_after) << "@protocol"); 21711d922960e083906a586609ac6978678147250177Sebastian Redl 217229b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson SourceLocation LParenLoc = ConsumeParen(); 21731d922960e083906a586609ac6978678147250177Sebastian Redl 21744fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner if (Tok.isNot(tok::identifier)) 21751d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(Tok, diag::err_expected_ident)); 21761d922960e083906a586609ac6978678147250177Sebastian Redl 2177390d50a725497e99247dc104a7d2c2a255d3af14Fariborz Jahanian IdentifierInfo *protocolId = Tok.getIdentifierInfo(); 217829b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson ConsumeToken(); 21791d922960e083906a586609ac6978678147250177Sebastian Redl 21804988ae3fda10743c8ed8a98cdcb5a783362587b4Anders Carlsson SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); 218129b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson 21821d922960e083906a586609ac6978678147250177Sebastian Redl return Owned(Actions.ParseObjCProtocolExpression(protocolId, AtLoc, ProtoLoc, 21831d922960e083906a586609ac6978678147250177Sebastian Redl LParenLoc, RParenLoc)); 218429b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson} 2185a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian 2186a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian/// objc-selector-expression 2187a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian/// @selector '(' objc-keyword-selector ')' 218860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult Parser::ParseObjCSelectorExpression(SourceLocation AtLoc) { 2189a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian SourceLocation SelectorLoc = ConsumeToken(); 21901d922960e083906a586609ac6978678147250177Sebastian Redl 21914fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner if (Tok.isNot(tok::l_paren)) 21921d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(Tok, diag::err_expected_lparen_after) << "@selector"); 21931d922960e083906a586609ac6978678147250177Sebastian Redl 2194b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian llvm::SmallVector<IdentifierInfo *, 12> KeyIdents; 2195a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian SourceLocation LParenLoc = ConsumeParen(); 2196a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian SourceLocation sLoc; 21972fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner IdentifierInfo *SelIdent = ParseObjCSelectorPiece(sLoc); 21981d922960e083906a586609ac6978678147250177Sebastian Redl if (!SelIdent && Tok.isNot(tok::colon)) // missing selector name. 21991d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(Tok, diag::err_expected_ident)); 22001d922960e083906a586609ac6978678147250177Sebastian Redl 2201b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian KeyIdents.push_back(SelIdent); 2202887407e71fd58de452361b77d72970e32b20ebe0Steve Naroff unsigned nColons = 0; 2203887407e71fd58de452361b77d72970e32b20ebe0Steve Naroff if (Tok.isNot(tok::r_paren)) { 2204a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian while (1) { 22054fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner if (Tok.isNot(tok::colon)) 22061d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(Tok, diag::err_expected_colon)); 22071d922960e083906a586609ac6978678147250177Sebastian Redl 2208cb53b361bce341c8591333c6997f62e480acc0b4Chris Lattner nColons++; 2209a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian ConsumeToken(); // Eat the ':'. 2210a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian if (Tok.is(tok::r_paren)) 2211a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian break; 2212a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian // Check for another keyword selector. 2213a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian SourceLocation Loc; 22142fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner SelIdent = ParseObjCSelectorPiece(Loc); 2215b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian KeyIdents.push_back(SelIdent); 2216a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian if (!SelIdent && Tok.isNot(tok::colon)) 2217a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian break; 2218a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian } 2219887407e71fd58de452361b77d72970e32b20ebe0Steve Naroff } 2220a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); 2221887407e71fd58de452361b77d72970e32b20ebe0Steve Naroff Selector Sel = PP.getSelectorTable().getSelector(nColons, &KeyIdents[0]); 22221d922960e083906a586609ac6978678147250177Sebastian Redl return Owned(Actions.ParseObjCSelectorExpression(Sel, AtLoc, SelectorLoc, 22231d922960e083906a586609ac6978678147250177Sebastian Redl LParenLoc, RParenLoc)); 222458065b2d8038a4e9a91ea4813bd1774c0f6efacbGabor Greif } 2225