ParseObjc.cpp revision 2ccccb3ff40c64927817a7e1ddf1da8c188ed224
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/// 683a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekvoid Parser::ParseObjCTypeQualifierList(ObjCDeclSpec &DS) { 684e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner while (1) { 685cb53b361bce341c8591333c6997f62e480acc0b4Chris Lattner if (Tok.isNot(tok::identifier)) 686e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner return; 6871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 688e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner const IdentifierInfo *II = Tok.getIdentifierInfo(); 689e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner for (unsigned i = 0; i != objc_NumQuals; ++i) { 690a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek if (II != ObjCTypeQuals[i]) 691e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner continue; 6921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 693a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCDeclSpec::ObjCDeclQualifier Qual; 694e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner switch (i) { 695e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner default: assert(0 && "Unknown decl qualifier"); 696a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek case objc_in: Qual = ObjCDeclSpec::DQ_In; break; 697a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek case objc_out: Qual = ObjCDeclSpec::DQ_Out; break; 698a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek case objc_inout: Qual = ObjCDeclSpec::DQ_Inout; break; 699a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek case objc_oneway: Qual = ObjCDeclSpec::DQ_Oneway; break; 700a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek case objc_bycopy: Qual = ObjCDeclSpec::DQ_Bycopy; break; 701a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek case objc_byref: Qual = ObjCDeclSpec::DQ_Byref; break; 702e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner } 703a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek DS.setObjCDeclQualifier(Qual); 704e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner ConsumeToken(); 705e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner II = 0; 706e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner break; 707e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner } 7081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 709e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner // If this wasn't a recognized qualifier, bail out. 710e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner if (II) return; 711e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner } 712e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner} 713e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner 714e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner/// objc-type-name: 715e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner/// '(' objc-type-qualifiers[opt] type-name ')' 716e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner/// '(' objc-type-qualifiers[opt] ')' 717e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner/// 718a526c5c67e5a0473c340903ee542ce570119665fTed KremenekParser::TypeTy *Parser::ParseObjCTypeName(ObjCDeclSpec &DS) { 719df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner assert(Tok.is(tok::l_paren) && "expected ("); 7201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7214a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner SourceLocation LParenLoc = ConsumeParen(); 722e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner SourceLocation TypeStartLoc = Tok.getLocation(); 7231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 72419d74e1494fe399f0e2a94e9419c095f8214851bFariborz Jahanian // Parse type qualifiers, in, inout, etc. 725a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ParseObjCTypeQualifierList(DS); 7264fa7afd07421e7276d1717e4fdf43a5fdd65a622Steve Naroff 7274a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner TypeTy *Ty = 0; 728809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor if (isTypeSpecifierQualifier()) { 729809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor TypeResult TypeSpec = ParseTypeName(); 730809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor if (!TypeSpec.isInvalid()) 731809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor Ty = TypeSpec.get(); 732809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor } 7331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7344a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner if (Tok.is(tok::r_paren)) 7354a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner ConsumeParen(); 7364a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner else if (Tok.getLocation() == TypeStartLoc) { 737e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner // If we didn't eat any tokens, then this isn't a type. 7381ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_type); 7394a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner SkipUntil(tok::r_paren); 7404a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner } else { 7414a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner // Otherwise, we found *something*, but didn't get a ')' in the right 7424a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner // place. Emit an error then return what we have as the type. 7434a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner MatchRHSPunctuation(tok::r_paren, LParenLoc); 744294494e1cce92043562b4680c613df7fd028c02eSteve Naroff } 745f28b264437053fb0deacc9ba02b18a0966f7290aSteve Naroff return Ty; 746294494e1cce92043562b4680c613df7fd028c02eSteve Naroff} 747294494e1cce92043562b4680c613df7fd028c02eSteve Naroff 748294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-method-decl: 749294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-selector 7504985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-keyword-selector objc-parmlist[opt] 751294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-type-name objc-selector 7524985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-type-name objc-keyword-selector objc-parmlist[opt] 753294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 754294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-keyword-selector: 7551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// objc-keyword-decl 756294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-keyword-selector objc-keyword-decl 757294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 758294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-keyword-decl: 7597ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// objc-selector ':' objc-type-name objc-keyword-attributes[opt] identifier 7607ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// objc-selector ':' objc-keyword-attributes[opt] identifier 7617ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// ':' objc-type-name objc-keyword-attributes[opt] identifier 7627ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// ':' objc-keyword-attributes[opt] identifier 763294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 7644985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-parmlist: 7654985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-parms objc-ellipsis[opt] 766294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 7674985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-parms: 7684985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-parms , parameter-declaration 769294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 7704985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-ellipsis: 771294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// , ... 772294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 7737ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// objc-keyword-attributes: [OBJC2] 7747ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// __attribute__((unused)) 7757ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// 776d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseObjCMethodDecl(SourceLocation mLoc, 7772ccccb3ff40c64927817a7e1ddf1da8c188ed224Douglas Gregor tok::TokenKind mType, 7782ccccb3ff40c64927817a7e1ddf1da8c188ed224Douglas Gregor Decl *IDecl, 7792ccccb3ff40c64927817a7e1ddf1da8c188ed224Douglas Gregor tok::ObjCKeywordKind MethodImplKind) { 78054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ParsingDeclRAIIObject PD(*this); 78154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 782e8f5a1710a7738deff40e10efcd05b1bd6af184fDouglas Gregor if (Tok.is(tok::code_completion)) { 78323c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCMethodDecl(getCurScope(), mType == tok::minus, 784e8f5a1710a7738deff40e10efcd05b1bd6af184fDouglas Gregor /*ReturnType=*/0, IDecl); 785dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 786e8f5a1710a7738deff40e10efcd05b1bd6af184fDouglas Gregor } 787e8f5a1710a7738deff40e10efcd05b1bd6af184fDouglas Gregor 788e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner // Parse the return type if present. 789ff38491c18b060526d754765b952f4a497a89416Chris Lattner TypeTy *ReturnType = 0; 790a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCDeclSpec DSRet; 791df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::l_paren)) 792f1de0ca05e2df6f23bd559028693a12d1ebdaaf6Fariborz Jahanian ReturnType = ParseObjCTypeName(DSRet); 7931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7949e0493576af77dba1c48858c03e31a2897d0681eTed Kremenek // If attributes exist before the method, parse them. 7959e0493576af77dba1c48858c03e31a2897d0681eTed Kremenek llvm::OwningPtr<AttributeList> MethodAttrs; 7969e0493576af77dba1c48858c03e31a2897d0681eTed Kremenek if (getLang().ObjC2 && Tok.is(tok::kw___attribute)) 7979e0493576af77dba1c48858c03e31a2897d0681eTed Kremenek MethodAttrs.reset(ParseGNUAttributes()); 7989e0493576af77dba1c48858c03e31a2897d0681eTed Kremenek 799e8f5a1710a7738deff40e10efcd05b1bd6af184fDouglas Gregor if (Tok.is(tok::code_completion)) { 80023c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCMethodDecl(getCurScope(), mType == tok::minus, 801e8f5a1710a7738deff40e10efcd05b1bd6af184fDouglas Gregor ReturnType, IDecl); 802dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 803e8f5a1710a7738deff40e10efcd05b1bd6af184fDouglas Gregor } 804e8f5a1710a7738deff40e10efcd05b1bd6af184fDouglas Gregor 8059e0493576af77dba1c48858c03e31a2897d0681eTed Kremenek // Now parse the selector. 806bef1185418705e16012b3dd50cd7c260c8d6b79cSteve Naroff SourceLocation selLoc; 8072fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner IdentifierInfo *SelIdent = ParseObjCSelectorPiece(selLoc); 808e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner 80984c431088693e216193094d1dbf327a01173f57fSteve Naroff // An unnamed colon is valid. 81084c431088693e216193094d1dbf327a01173f57fSteve Naroff if (!SelIdent && Tok.isNot(tok::colon)) { // missing selector name. 8111ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_selector_for_method) 8121ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner << SourceRange(mLoc, Tok.getLocation()); 813e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner // Skip until we get a ; or {}. 814e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner SkipUntil(tok::r_brace); 815d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 816e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner } 8171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8184f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian llvm::SmallVector<DeclaratorChunk::ParamInfo, 8> CParamInfo; 819df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::colon)) { 820ff38491c18b060526d754765b952f4a497a89416Chris Lattner // If attributes exist after the method, parse them. 8211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (getLang().ObjC2 && Tok.is(tok::kw___attribute)) 8229e0493576af77dba1c48858c03e31a2897d0681eTed Kremenek MethodAttrs.reset(addAttributeLists(MethodAttrs.take(), 8239e0493576af77dba1c48858c03e31a2897d0681eTed Kremenek ParseGNUAttributes())); 8241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 825ff38491c18b060526d754765b952f4a497a89416Chris Lattner Selector Sel = PP.getSelectorTable().getNullarySelector(SelIdent); 826d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *Result 82754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall = Actions.ActOnMethodDeclaration(mLoc, Tok.getLocation(), 8281f7b6f88f18d7f6b10265acec5d41c4ed1897487Fariborz Jahanian mType, IDecl, DSRet, ReturnType, Sel, 8294f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian 0, 8304f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian CParamInfo.data(), CParamInfo.size(), 8314f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian MethodAttrs.get(), 8321c6a3cc88177c67498fccdf14cfdf09959214e41Ted Kremenek MethodImplKind); 83354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall PD.complete(Result); 83454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall return Result; 835ff38491c18b060526d754765b952f4a497a89416Chris Lattner } 836f28b264437053fb0deacc9ba02b18a0966f7290aSteve Naroff 83768d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff llvm::SmallVector<IdentifierInfo *, 12> KeyIdents; 838e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner llvm::SmallVector<Action::ObjCArgInfo, 12> ArgInfos; 8391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 840ff38491c18b060526d754765b952f4a497a89416Chris Lattner while (1) { 841e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner Action::ObjCArgInfo ArgInfo; 8421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 843ff38491c18b060526d754765b952f4a497a89416Chris Lattner // Each iteration parses a single keyword argument. 844df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::colon)) { 845ff38491c18b060526d754765b952f4a497a89416Chris Lattner Diag(Tok, diag::err_expected_colon); 846ff38491c18b060526d754765b952f4a497a89416Chris Lattner break; 847ff38491c18b060526d754765b952f4a497a89416Chris Lattner } 848ff38491c18b060526d754765b952f4a497a89416Chris Lattner ConsumeToken(); // Eat the ':'. 8491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 850e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner ArgInfo.Type = 0; 851e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner if (Tok.is(tok::l_paren)) // Parse the argument type if present. 852e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner ArgInfo.Type = ParseObjCTypeName(ArgInfo.DeclSpec); 853e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner 854ff38491c18b060526d754765b952f4a497a89416Chris Lattner // If attributes exist before the argument name, parse them. 855e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner ArgInfo.ArgAttrs = 0; 856df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (getLang().ObjC2 && Tok.is(tok::kw___attribute)) 857bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt ArgInfo.ArgAttrs = ParseGNUAttributes(); 8587ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff 85940ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor // Code completion for the next piece of the selector. 86040ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor if (Tok.is(tok::code_completion)) { 86140ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor ConsumeCodeCompletionToken(); 86240ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor KeyIdents.push_back(SelIdent); 86340ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor Actions.CodeCompleteObjCMethodDeclSelector(getCurScope(), 86440ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor mType == tok::minus, 86540ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor /*AtParameterName=*/true, 86640ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor ReturnType, 86740ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor KeyIdents.data(), 86840ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor KeyIdents.size()); 86940ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor KeyIdents.pop_back(); 87040ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor break; 87140ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor } 87240ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor 873df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 874ff38491c18b060526d754765b952f4a497a89416Chris Lattner Diag(Tok, diag::err_expected_ident); // missing argument name. 875ff38491c18b060526d754765b952f4a497a89416Chris Lattner break; 8764985aceceb9b9261b876b515d32726175c13a775Steve Naroff } 8771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 878e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner ArgInfo.Name = Tok.getIdentifierInfo(); 879e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner ArgInfo.NameLoc = Tok.getLocation(); 880ff38491c18b060526d754765b952f4a497a89416Chris Lattner ConsumeToken(); // Eat the identifier. 8811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 882e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner ArgInfos.push_back(ArgInfo); 883e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner KeyIdents.push_back(SelIdent); 884e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner 8851f5537aaac1e775aff1d523f2cc59a9a3bd6c946Douglas Gregor // Code completion for the next piece of the selector. 8861f5537aaac1e775aff1d523f2cc59a9a3bd6c946Douglas Gregor if (Tok.is(tok::code_completion)) { 8871f5537aaac1e775aff1d523f2cc59a9a3bd6c946Douglas Gregor ConsumeCodeCompletionToken(); 8881f5537aaac1e775aff1d523f2cc59a9a3bd6c946Douglas Gregor Actions.CodeCompleteObjCMethodDeclSelector(getCurScope(), 8891f5537aaac1e775aff1d523f2cc59a9a3bd6c946Douglas Gregor mType == tok::minus, 89040ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor /*AtParameterName=*/false, 8911f5537aaac1e775aff1d523f2cc59a9a3bd6c946Douglas Gregor ReturnType, 8921f5537aaac1e775aff1d523f2cc59a9a3bd6c946Douglas Gregor KeyIdents.data(), 8931f5537aaac1e775aff1d523f2cc59a9a3bd6c946Douglas Gregor KeyIdents.size()); 8941f5537aaac1e775aff1d523f2cc59a9a3bd6c946Douglas Gregor break; 8951f5537aaac1e775aff1d523f2cc59a9a3bd6c946Douglas Gregor } 8961f5537aaac1e775aff1d523f2cc59a9a3bd6c946Douglas Gregor 897ff38491c18b060526d754765b952f4a497a89416Chris Lattner // Check for another keyword selector. 8984b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian SourceLocation Loc; 8992fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner SelIdent = ParseObjCSelectorPiece(Loc); 900df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (!SelIdent && Tok.isNot(tok::colon)) 901ff38491c18b060526d754765b952f4a497a89416Chris Lattner break; 902ff38491c18b060526d754765b952f4a497a89416Chris Lattner // We have a selector or a colon, continue parsing. 903ff38491c18b060526d754765b952f4a497a89416Chris Lattner } 9041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 905335eafa5be51f6440672a74c73d588af72e96732Steve Naroff bool isVariadic = false; 9061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 907ff38491c18b060526d754765b952f4a497a89416Chris Lattner // Parse the (optional) parameter list. 908df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner while (Tok.is(tok::comma)) { 909ff38491c18b060526d754765b952f4a497a89416Chris Lattner ConsumeToken(); 910df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::ellipsis)) { 911335eafa5be51f6440672a74c73d588af72e96732Steve Naroff isVariadic = true; 9124985aceceb9b9261b876b515d32726175c13a775Steve Naroff ConsumeToken(); 913ff38491c18b060526d754765b952f4a497a89416Chris Lattner break; 9144985aceceb9b9261b876b515d32726175c13a775Steve Naroff } 915ff38491c18b060526d754765b952f4a497a89416Chris Lattner DeclSpec DS; 916ff38491c18b060526d754765b952f4a497a89416Chris Lattner ParseDeclarationSpecifiers(DS); 9171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // Parse the declarator. 918ff38491c18b060526d754765b952f4a497a89416Chris Lattner Declarator ParmDecl(DS, Declarator::PrototypeContext); 919ff38491c18b060526d754765b952f4a497a89416Chris Lattner ParseDeclarator(ParmDecl); 9204f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian IdentifierInfo *ParmII = ParmDecl.getIdentifier(); 921d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *Param = Actions.ActOnParamDeclarator(getCurScope(), ParmDecl); 9224f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian CParamInfo.push_back(DeclaratorChunk::ParamInfo(ParmII, 9234f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian ParmDecl.getIdentifierLoc(), 9244f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian Param, 9254f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian 0)); 9264f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian 9274985aceceb9b9261b876b515d32726175c13a775Steve Naroff } 9281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 929ff38491c18b060526d754765b952f4a497a89416Chris Lattner // FIXME: Add support for optional parmameter list... 930e3a2ca7e30601cdd31c77a830f4cc487851e8096Fariborz Jahanian // If attributes exist after the method, parse them. 9311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (getLang().ObjC2 && Tok.is(tok::kw___attribute)) 9329e0493576af77dba1c48858c03e31a2897d0681eTed Kremenek MethodAttrs.reset(addAttributeLists(MethodAttrs.take(), 9339e0493576af77dba1c48858c03e31a2897d0681eTed Kremenek ParseGNUAttributes())); 9341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9353688fc679389d67b6755e62406998f9ea84d886aFariborz Jahanian if (KeyIdents.size() == 0) 936d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 937ff38491c18b060526d754765b952f4a497a89416Chris Lattner Selector Sel = PP.getSelectorTable().getSelector(KeyIdents.size(), 938ff38491c18b060526d754765b952f4a497a89416Chris Lattner &KeyIdents[0]); 939d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *Result 94054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall = Actions.ActOnMethodDeclaration(mLoc, Tok.getLocation(), 9413688fc679389d67b6755e62406998f9ea84d886aFariborz Jahanian mType, IDecl, DSRet, ReturnType, Sel, 9424f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian &ArgInfos[0], 9434f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian CParamInfo.data(), CParamInfo.size(), 9441e37765c9257ef1d051f54a674eaa964bdba9693Ted Kremenek MethodAttrs.get(), 945335eafa5be51f6440672a74c73d588af72e96732Steve Naroff MethodImplKind, isVariadic); 94654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall PD.complete(Result); 9471e37765c9257ef1d051f54a674eaa964bdba9693Ted Kremenek 9481e37765c9257ef1d051f54a674eaa964bdba9693Ted Kremenek // Delete referenced AttributeList objects. 9491e37765c9257ef1d051f54a674eaa964bdba9693Ted Kremenek for (llvm::SmallVectorImpl<Action::ObjCArgInfo>::iterator 9501e37765c9257ef1d051f54a674eaa964bdba9693Ted Kremenek I = ArgInfos.begin(), E = ArgInfos.end(); I != E; ++I) 9511e37765c9257ef1d051f54a674eaa964bdba9693Ted Kremenek delete I->ArgAttrs; 9521e37765c9257ef1d051f54a674eaa964bdba9693Ted Kremenek 95354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall return Result; 954294494e1cce92043562b4680c613df7fd028c02eSteve Naroff} 955294494e1cce92043562b4680c613df7fd028c02eSteve Naroff 956dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-refs: 957dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// '<' identifier-list '>' 958dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 9597caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattnerbool Parser:: 960d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallParseObjCProtocolReferences(llvm::SmallVectorImpl<Decl *> &Protocols, 96171b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis llvm::SmallVectorImpl<SourceLocation> &ProtocolLocs, 96271b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis bool WarnOnDeclarations, 96371b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis SourceLocation &LAngleLoc, SourceLocation &EndLoc) { 964e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner assert(Tok.is(tok::less) && "expected <"); 9651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 96671b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis LAngleLoc = ConsumeToken(); // the "<" 9671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 968e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner llvm::SmallVector<IdentifierLocPair, 8> ProtocolIdents; 9691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 970e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner while (1) { 97155385fe3e723cd675001e45f42d61adde6b7f075Douglas Gregor if (Tok.is(tok::code_completion)) { 97255385fe3e723cd675001e45f42d61adde6b7f075Douglas Gregor Actions.CodeCompleteObjCProtocolReferences(ProtocolIdents.data(), 97355385fe3e723cd675001e45f42d61adde6b7f075Douglas Gregor ProtocolIdents.size()); 974dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 97555385fe3e723cd675001e45f42d61adde6b7f075Douglas Gregor } 97655385fe3e723cd675001e45f42d61adde6b7f075Douglas Gregor 977e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner if (Tok.isNot(tok::identifier)) { 978e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner Diag(Tok, diag::err_expected_ident); 979e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner SkipUntil(tok::greater); 980e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner return true; 981e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner } 982e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner ProtocolIdents.push_back(std::make_pair(Tok.getIdentifierInfo(), 983e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner Tok.getLocation())); 98471b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis ProtocolLocs.push_back(Tok.getLocation()); 985e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner ConsumeToken(); 9861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 987e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner if (Tok.isNot(tok::comma)) 988e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner break; 989e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner ConsumeToken(); 990e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner } 9911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 992e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner // Consume the '>'. 993e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner if (Tok.isNot(tok::greater)) { 994e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner Diag(Tok, diag::err_expected_greater); 995e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner return true; 996e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner } 9971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 998e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner EndLoc = ConsumeAnyToken(); 9991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1000e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner // Convert the list of protocols identifiers into a list of protocol decls. 1001e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner Actions.FindProtocolDeclaration(WarnOnDeclarations, 1002e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner &ProtocolIdents[0], ProtocolIdents.size(), 1003e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner Protocols); 1004e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner return false; 1005e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner} 1006e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner 1007dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-instance-variables: 1008dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// '{' objc-instance-variable-decl-list[opt] '}' 1009dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1010dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-instance-variable-decl-list: 1011dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-visibility-spec 1012dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-instance-variable-decl ';' 1013dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// ';' 1014dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-instance-variable-decl-list objc-visibility-spec 1015dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-instance-variable-decl-list objc-instance-variable-decl ';' 1016dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-instance-variable-decl-list ';' 1017dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1018dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-visibility-spec: 1019dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @private 1020dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @protected 1021dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @public 1022ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff/// @package [OBJC2] 1023dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1024dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-instance-variable-decl: 10251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// struct-declaration 1026dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1027d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallvoid Parser::ParseObjCClassInstanceVariables(Decl *interfaceDecl, 102883c481ade785a919ba21a33f9a8b1b21c1212fb3Fariborz Jahanian tok::ObjCKeywordKind visibility, 102960fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff SourceLocation atLoc) { 1030df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner assert(Tok.is(tok::l_brace) && "expected {"); 1031d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall llvm::SmallVector<Decl *, 32> AllIvarDecls; 1032e13594279a952537ac903325efff57e3edca79d9Chris Lattner 10331a0d31a3d7f14ddc6370ba912c778aece6c12cf0Douglas Gregor ParseScope ClassScope(this, Scope::DeclScope|Scope::ClassScope); 103472de6676bd30f9081ee4166bbe07b4c270258ce6Douglas Gregor 1035ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff SourceLocation LBraceLoc = ConsumeBrace(); // the "{" 10361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1037ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff // While we still have something to read, read the instance variables. 1038df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner while (Tok.isNot(tok::r_brace) && Tok.isNot(tok::eof)) { 1039ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff // Each iteration of this loop reads one objc-instance-variable-decl. 10401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1041ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff // Check for extraneous top-level semicolon. 1042df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::semi)) { 1043f13ca06e57ac094ed05ea08c26a499af1ba0ce88Douglas Gregor Diag(Tok, diag::ext_extra_ivar_semi) 1044849b243d4065f56742a4677d6dc8277609a151f8Douglas Gregor << FixItHint::CreateRemoval(Tok.getLocation()); 1045ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff ConsumeToken(); 1046ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff continue; 1047ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff } 10481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1049ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff // Set the default visibility to private. 1050df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::at)) { // parse objc-visibility-spec 1051ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff ConsumeToken(); // eat the @ sign 1052c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor 1053c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor if (Tok.is(tok::code_completion)) { 105423c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCAtVisibility(getCurScope()); 1055dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 1056c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor } 1057c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor 1058861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff switch (Tok.getObjCKeywordID()) { 1059ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff case tok::objc_private: 1060ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff case tok::objc_public: 1061ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff case tok::objc_protected: 1062ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff case tok::objc_package: 1063861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff visibility = Tok.getObjCKeywordID(); 1064ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff ConsumeToken(); 10651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump continue; 1066ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff default: 1067ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff Diag(Tok, diag::err_objc_illegal_visibility_spec); 1068ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff continue; 1069ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff } 1070ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff } 10711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1072c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor if (Tok.is(tok::code_completion)) { 107323c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteOrdinaryName(getCurScope(), 1074e6b1bb6e7fe906d164637ca33503b8fafdbc99e5Douglas Gregor Action::PCC_ObjCInstanceVariableList); 1075dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 1076c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor } 1077c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor 1078bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall struct ObjCIvarCallback : FieldCallback { 1079bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall Parser &P; 1080d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *IDecl; 1081bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall tok::ObjCKeywordKind visibility; 1082d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall llvm::SmallVectorImpl<Decl *> &AllIvarDecls; 1083bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall 1084d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall ObjCIvarCallback(Parser &P, Decl *IDecl, tok::ObjCKeywordKind V, 1085d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall llvm::SmallVectorImpl<Decl *> &AllIvarDecls) : 1086bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall P(P), IDecl(IDecl), visibility(V), AllIvarDecls(AllIvarDecls) { 1087bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall } 1088bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall 1089d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *invoke(FieldDeclarator &FD) { 1090bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall // Install the declarator into the interface decl. 1091d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *Field 109223c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor = P.Actions.ActOnIvar(P.getCurScope(), 1093bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall FD.D.getDeclSpec().getSourceRange().getBegin(), 1094bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall IDecl, FD.D, FD.BitfieldSize, visibility); 10950bd04596e4645ff145a046dfb3475f39674060d9Fariborz Jahanian if (Field) 10960bd04596e4645ff145a046dfb3475f39674060d9Fariborz Jahanian AllIvarDecls.push_back(Field); 1097bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall return Field; 1098bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall } 1099bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall } Callback(*this, interfaceDecl, visibility, AllIvarDecls); 1100bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall 1101e13594279a952537ac903325efff57e3edca79d9Chris Lattner // Parse all the comma separated declarators. 1102e13594279a952537ac903325efff57e3edca79d9Chris Lattner DeclSpec DS; 1103bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall ParseStructDeclaration(DS, Callback); 11041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1105df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::semi)) { 1106ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff ConsumeToken(); 1107ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff } else { 1108ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff Diag(Tok, diag::err_expected_semi_decl_list); 1109ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff // Skip to end of block or statement 1110ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff SkipUntil(tok::r_brace, true, true); 1111ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff } 1112ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff } 111360fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff SourceLocation RBraceLoc = MatchRHSPunctuation(tok::r_brace, LBraceLoc); 11148749be53f53384e7846502791ceda6c657228d07Steve Naroff // Call ActOnFields() even if we don't have any decls. This is useful 11158749be53f53384e7846502791ceda6c657228d07Steve Naroff // for code rewriting tools that need to be aware of the empty list. 111623c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.ActOnFields(getCurScope(), atLoc, interfaceDecl, 1117beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad AllIvarDecls.data(), AllIvarDecls.size(), 11181bfe1c2129771c06fb58ae5e8c079ae30e138309Daniel Dunbar LBraceLoc, RBraceLoc, 0); 1119ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff return; 11205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 1121dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff 1122dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-declaration: 1123dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-definition 1124dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-forward-reference 1125dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1126dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-definition: 11271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// @protocol identifier 11281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// objc-protocol-refs[opt] 11291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// objc-interface-decl-list 1130dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @end 1131dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1132dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-forward-reference: 1133dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @protocol identifier-list ';' 1134dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1135dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// "@protocol identifier ;" should be resolved as "@protocol 11363536b443bc50d58a79f14fca9b6842541a434854Steve Naroff/// identifier-list ;": objc-interface-decl-list may not start with a 1137dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// semicolon in the first alternative if objc-protocol-refs are omitted. 1138d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseObjCAtProtocolDeclaration(SourceLocation AtLoc, 1139b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner AttributeList *attrList) { 1140861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff assert(Tok.isObjCAtKeyword(tok::objc_protocol) && 11417ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff "ParseObjCAtProtocolDeclaration(): Expected @protocol"); 11427ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff ConsumeToken(); // the "protocol" identifier 11431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1144083128f6b13dfa4fc615a838c49b516d901b1ac0Douglas Gregor if (Tok.is(tok::code_completion)) { 114523c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCProtocolDecl(getCurScope()); 1146dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 1147083128f6b13dfa4fc615a838c49b516d901b1ac0Douglas Gregor } 1148083128f6b13dfa4fc615a838c49b516d901b1ac0Douglas Gregor 1149df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 11507ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff Diag(Tok, diag::err_expected_ident); // missing protocol name. 1151d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 11527ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff } 11537ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff // Save the protocol name, then consume it. 11547ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff IdentifierInfo *protocolName = Tok.getIdentifierInfo(); 11557ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff SourceLocation nameLoc = ConsumeToken(); 11561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1157df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::semi)) { // forward declaration of one protocol. 11587caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner IdentifierLocPair ProtoInfo(protocolName, nameLoc); 11597ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff ConsumeToken(); 11601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return Actions.ActOnForwardProtocolDeclaration(AtLoc, &ProtoInfo, 1, 1161bc1c877fe28fb6a825f0b226a0a2da99e713ea03Fariborz Jahanian attrList); 11627ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff } 11631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1164df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::comma)) { // list of forward declarations. 11657caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner llvm::SmallVector<IdentifierLocPair, 8> ProtocolRefs; 11667caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner ProtocolRefs.push_back(std::make_pair(protocolName, nameLoc)); 11677caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner 11687ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff // Parse the list of forward declarations. 11697ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff while (1) { 11707ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff ConsumeToken(); // the ',' 1171df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 11727ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff Diag(Tok, diag::err_expected_ident); 11737ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff SkipUntil(tok::semi); 1174d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 11757ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff } 11767caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner ProtocolRefs.push_back(IdentifierLocPair(Tok.getIdentifierInfo(), 11777caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner Tok.getLocation())); 11787ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff ConsumeToken(); // the identifier 11791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1180df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::comma)) 11817ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff break; 11827ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff } 11837ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff // Consume the ';'. 11847ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff if (ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@protocol")) 1185d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 11861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1187e440eb8158e71deb1e4ab11618ae3d680aac6da1Steve Naroff return Actions.ActOnForwardProtocolDeclaration(AtLoc, 11881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump &ProtocolRefs[0], 1189bc1c877fe28fb6a825f0b226a0a2da99e713ea03Fariborz Jahanian ProtocolRefs.size(), 1190bc1c877fe28fb6a825f0b226a0a2da99e713ea03Fariborz Jahanian attrList); 11917caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner } 11921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11937ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff // Last, and definitely not least, parse a protocol declaration. 119471b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis SourceLocation LAngleLoc, EndProtoLoc; 11957caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner 1196d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall llvm::SmallVector<Decl *, 8> ProtocolRefs; 119771b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis llvm::SmallVector<SourceLocation, 8> ProtocolLocs; 11987caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner if (Tok.is(tok::less) && 119971b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis ParseObjCProtocolReferences(ProtocolRefs, ProtocolLocs, false, 120071b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis LAngleLoc, EndProtoLoc)) 1201d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 12021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1203d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ProtoType = 1204e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner Actions.ActOnStartProtocolInterface(AtLoc, protocolName, nameLoc, 1205beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad ProtocolRefs.data(), 1206beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad ProtocolRefs.size(), 120718df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor ProtocolLocs.data(), 1208246e70f69cb8aeb67225c54690f1c6b25abd5a86Daniel Dunbar EndProtoLoc, attrList); 120925e077d59a8e8e43b65882b69610a3d5e2aaf53cFariborz Jahanian ParseObjCInterfaceDeclList(ProtoType, tok::objc_protocol); 1210bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner return ProtoType; 1211dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff} 1212dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff 1213dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-implementation: 1214dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-implementation-prologue 1215dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-category-implementation-prologue 1216dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1217dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-implementation-prologue: 1218dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @implementation identifier objc-superclass[opt] 1219dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-instance-variables[opt] 1220dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1221dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-category-implementation-prologue: 1222dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @implementation identifier ( identifier ) 1223d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseObjCAtImplementationDeclaration( 1224ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian SourceLocation atLoc) { 1225ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian assert(Tok.isObjCAtKeyword(tok::objc_implementation) && 1226ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian "ParseObjCAtImplementationDeclaration(): Expected @implementation"); 1227ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); // the "implementation" identifier 12281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12293b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor // Code completion after '@implementation'. 12303b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor if (Tok.is(tok::code_completion)) { 123123c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCImplementationDecl(getCurScope()); 1232dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 12333b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor } 12343b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor 1235df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 1236ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian Diag(Tok, diag::err_expected_ident); // missing class or category name. 1237d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 1238ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1239ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian // We have a class or category name - consume it. 1240ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian IdentifierInfo *nameId = Tok.getIdentifierInfo(); 1241ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian SourceLocation nameLoc = ConsumeToken(); // consume class or category name 12421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (Tok.is(tok::l_paren)) { 1244ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian // we have a category implementation. 1245ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian SourceLocation lparenLoc = ConsumeParen(); 1246ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian SourceLocation categoryLoc, rparenLoc; 1247ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian IdentifierInfo *categoryId = 0; 12481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 124933ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor if (Tok.is(tok::code_completion)) { 125023c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCImplementationCategory(getCurScope(), nameId, nameLoc); 1251dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 125233ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor } 125333ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor 1254df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::identifier)) { 1255ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian categoryId = Tok.getIdentifierInfo(); 1256ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian categoryLoc = ConsumeToken(); 1257ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } else { 1258ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian Diag(Tok, diag::err_expected_ident); // missing category name. 1259d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 12601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 1261df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::r_paren)) { 1262ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian Diag(Tok, diag::err_expected_rparen); 1263ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian SkipUntil(tok::r_paren, false); // don't stop at ';' 1264d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 1265ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1266ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian rparenLoc = ConsumeParen(); 1267d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ImplCatType = Actions.ActOnStartCategoryImplementation( 12681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump atLoc, nameId, nameLoc, categoryId, 12698f3fde00ad4d4f943321e338b914ae4740711c84Fariborz Jahanian categoryLoc); 1270a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCImpDecl = ImplCatType; 127163e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian PendingObjCImpDecl.push_back(ObjCImpDecl); 1272d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 1273ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1274ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian // We have a class implementation 1275ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian SourceLocation superClassLoc; 1276ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian IdentifierInfo *superClassId = 0; 1277df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::colon)) { 1278ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian // We have a super class 1279ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); 1280df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 1281ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian Diag(Tok, diag::err_expected_ident); // missing super class name. 1282d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 1283ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1284ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian superClassId = Tok.getIdentifierInfo(); 1285ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian superClassLoc = ConsumeToken(); // Consume super class name 1286ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1287d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ImplClsType = Actions.ActOnStartClassImplementation( 1288cb53b361bce341c8591333c6997f62e480acc0b4Chris Lattner atLoc, nameId, nameLoc, 1289ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian superClassId, superClassLoc); 12901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 129160fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff if (Tok.is(tok::l_brace)) // we have ivars 129283c481ade785a919ba21a33f9a8b1b21c1212fb3Fariborz Jahanian ParseObjCClassInstanceVariables(ImplClsType/*FIXME*/, 129301f1bfc3284d5817517d35217885ea9ecb252817Fariborz Jahanian tok::objc_private, atLoc); 1294a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCImpDecl = ImplClsType; 129563e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian PendingObjCImpDecl.push_back(ObjCImpDecl); 129663e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian 1297d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 12985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 129960fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff 1300d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseObjCAtEndDeclaration(SourceRange atEnd) { 1301ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian assert(Tok.isObjCAtKeyword(tok::objc_end) && 1302ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian "ParseObjCAtEndDeclaration(): Expected @end"); 1303d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *Result = ObjCImpDecl; 1304ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); // the "end" identifier 1305a6e3ac514c924879699c6b0b1201028f0091044fFariborz Jahanian if (ObjCImpDecl) { 130623c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.ActOnAtEnd(getCurScope(), atEnd, ObjCImpDecl); 1307d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall ObjCImpDecl = 0; 130863e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian PendingObjCImpDecl.pop_back(); 1309a6e3ac514c924879699c6b0b1201028f0091044fFariborz Jahanian } 1310782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek else { 1311782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek // missing @implementation 1312782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek Diag(atEnd.getBegin(), diag::warn_expected_implementation); 1313782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek } 1314a6e3ac514c924879699c6b0b1201028f0091044fFariborz Jahanian return Result; 13155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 1316e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian 13173fe104154dd2e8ffb351142d74f308938b5c99bfFariborz JahanianParser::DeclGroupPtrTy Parser::FinishPendingObjCActions() { 13183fe104154dd2e8ffb351142d74f308938b5c99bfFariborz Jahanian Actions.DiagnoseUseOfUnimplementedSelectors(); 131963e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian if (PendingObjCImpDecl.empty()) 1320d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return Actions.ConvertDeclToDeclGroup(0); 1321d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ImpDecl = PendingObjCImpDecl.pop_back_val(); 132223c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.ActOnAtEnd(getCurScope(), SourceRange(), ImpDecl); 132363e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian return Actions.ConvertDeclToDeclGroup(ImpDecl); 132463e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian} 132563e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian 1326e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian/// compatibility-alias-decl: 1327e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian/// @compatibility_alias alias-name class-name ';' 1328e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian/// 1329d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseObjCAtAliasDeclaration(SourceLocation atLoc) { 1330e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian assert(Tok.isObjCAtKeyword(tok::objc_compatibility_alias) && 1331e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian "ParseObjCAtAliasDeclaration(): Expected @compatibility_alias"); 1332e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian ConsumeToken(); // consume compatibility_alias 1333df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 1334e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian Diag(Tok, diag::err_expected_ident); 1335d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 1336e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian } 1337243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian IdentifierInfo *aliasId = Tok.getIdentifierInfo(); 1338243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian SourceLocation aliasLoc = ConsumeToken(); // consume alias-name 1339df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 1340e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian Diag(Tok, diag::err_expected_ident); 1341d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 1342e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian } 1343243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian IdentifierInfo *classId = Tok.getIdentifierInfo(); 1344243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian SourceLocation classLoc = ConsumeToken(); // consume class-name; 1345243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian if (Tok.isNot(tok::semi)) { 13461ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_semi_after) << "@compatibility_alias"; 1347d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 1348243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian } 1349b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return Actions.ActOnCompatiblityAlias(atLoc, aliasId, aliasLoc, 1350b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner classId, classLoc); 13515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 13525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1353ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-synthesis: 1354ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// @synthesize property-ivar-list ';' 1355ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// 1356ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-ivar-list: 1357ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-ivar 1358ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-ivar-list ',' property-ivar 1359ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// 1360ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-ivar: 1361ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// identifier 1362ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// identifier '=' identifier 1363ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// 1364d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseObjCPropertySynthesize(SourceLocation atLoc) { 1365ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian assert(Tok.isObjCAtKeyword(tok::objc_synthesize) && 1366ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian "ParseObjCPropertyDynamic(): Expected '@synthesize'"); 1367f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian SourceLocation loc = ConsumeToken(); // consume synthesize 13681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1369b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor while (true) { 1370322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor if (Tok.is(tok::code_completion)) { 137123c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCPropertyDefinition(getCurScope(), ObjCImpDecl); 1372dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 1373322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor } 1374322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor 1375b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor if (Tok.isNot(tok::identifier)) { 1376b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor Diag(Tok, diag::err_synthesized_property_name); 1377b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor SkipUntil(tok::semi); 1378d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 1379b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor } 1380b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor 1381f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian IdentifierInfo *propertyIvar = 0; 1382f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian IdentifierInfo *propertyId = Tok.getIdentifierInfo(); 1383f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian SourceLocation propertyLoc = ConsumeToken(); // consume property name 1384df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::equal)) { 1385ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian // property '=' ivar-name 1386ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); // consume '=' 1387322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor 1388322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor if (Tok.is(tok::code_completion)) { 138923c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCPropertySynthesizeIvar(getCurScope(), propertyId, 1390322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor ObjCImpDecl); 1391dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 1392322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor } 1393322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor 1394df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 1395ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian Diag(Tok, diag::err_expected_ident); 1396ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian break; 1397ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1398f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian propertyIvar = Tok.getIdentifierInfo(); 1399ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); // consume ivar-name 1400ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 140123c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.ActOnPropertyImplDecl(getCurScope(), atLoc, propertyLoc, true, ObjCImpDecl, 1402f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian propertyId, propertyIvar); 1403df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::comma)) 1404ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian break; 1405ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); // consume ',' 1406ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1407b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor if (Tok.isNot(tok::semi)) { 14081ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_semi_after) << "@synthesize"; 1409b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor SkipUntil(tok::semi); 1410b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor } 1411d3fdcb5a1bf6bd5e54e18579c054ea3c292a0e28Fariborz Jahanian else 1412d3fdcb5a1bf6bd5e54e18579c054ea3c292a0e28Fariborz Jahanian ConsumeToken(); // consume ';' 1413d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 1414ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian} 1415ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian 1416ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-dynamic: 1417ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// @dynamic property-list 1418ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// 1419ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-list: 1420ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// identifier 1421ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-list ',' identifier 1422ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// 1423d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseObjCPropertyDynamic(SourceLocation atLoc) { 1424ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian assert(Tok.isObjCAtKeyword(tok::objc_dynamic) && 1425ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian "ParseObjCPropertyDynamic(): Expected '@dynamic'"); 1426ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian SourceLocation loc = ConsumeToken(); // consume dynamic 1427424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor while (true) { 1428424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor if (Tok.is(tok::code_completion)) { 142923c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCPropertyDefinition(getCurScope(), ObjCImpDecl); 1430dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 1431424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor } 1432424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor 1433424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor if (Tok.isNot(tok::identifier)) { 1434424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor Diag(Tok, diag::err_expected_ident); 1435424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor SkipUntil(tok::semi); 1436d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 1437424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor } 1438424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor 1439c35b9e4e2efad727538c848cf30d4b0eb1031dc9Fariborz Jahanian IdentifierInfo *propertyId = Tok.getIdentifierInfo(); 1440c35b9e4e2efad727538c848cf30d4b0eb1031dc9Fariborz Jahanian SourceLocation propertyLoc = ConsumeToken(); // consume property name 144123c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.ActOnPropertyImplDecl(getCurScope(), atLoc, propertyLoc, false, ObjCImpDecl, 1442c35b9e4e2efad727538c848cf30d4b0eb1031dc9Fariborz Jahanian propertyId, 0); 1443c35b9e4e2efad727538c848cf30d4b0eb1031dc9Fariborz Jahanian 1444df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::comma)) 1445ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian break; 1446ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); // consume ',' 1447ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 144894b24db37e80a75c4088e592d4150fb12b00bfb3Fariborz Jahanian if (Tok.isNot(tok::semi)) { 14491ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_semi_after) << "@dynamic"; 145094b24db37e80a75c4088e592d4150fb12b00bfb3Fariborz Jahanian SkipUntil(tok::semi); 145194b24db37e80a75c4088e592d4150fb12b00bfb3Fariborz Jahanian } 145294b24db37e80a75c4088e592d4150fb12b00bfb3Fariborz Jahanian else 145394b24db37e80a75c4088e592d4150fb12b00bfb3Fariborz Jahanian ConsumeToken(); // consume ';' 1454d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 1455ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian} 14561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1457397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// objc-throw-statement: 1458397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// throw expression[opt]; 1459397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// 146043bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian RedlParser::OwningStmtResult Parser::ParseObjCThrowStmt(SourceLocation atLoc) { 1461ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall OwningExprResult Res; 1462397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian ConsumeToken(); // consume throw 1463df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::semi)) { 146439f8f159c488a900e5958d5aab3e467af9ec8a2bFariborz Jahanian Res = ParseExpression(); 14650e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Res.isInvalid()) { 1466397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian SkipUntil(tok::semi); 146743bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 1468397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian } 1469397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian } 147002418c7f0cb8bb83f1a1a1fad9bf6104efa83e0eTed Kremenek // consume ';' 147102418c7f0cb8bb83f1a1a1fad9bf6104efa83e0eTed Kremenek ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@throw"); 147223c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor return Actions.ActOnObjCAtThrowStmt(atLoc, move(Res), getCurScope()); 1473397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian} 1474397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian 1475c385c90c68dfa376650e2facfbb444b2ec9bd110Fariborz Jahanian/// objc-synchronized-statement: 147678a677bbb5fa115fa0995b5783adeeefad67167eFariborz Jahanian/// @synchronized '(' expression ')' compound-statement 1477c385c90c68dfa376650e2facfbb444b2ec9bd110Fariborz Jahanian/// 147843bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian RedlParser::OwningStmtResult 147943bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian RedlParser::ParseObjCSynchronizedStmt(SourceLocation atLoc) { 1480fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian ConsumeToken(); // consume synchronized 1481fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian if (Tok.isNot(tok::l_paren)) { 14821ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_lparen_after) << "@synchronized"; 148343bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 1484fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian } 1485fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian ConsumeParen(); // '(' 14862f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl OwningExprResult Res(ParseExpression()); 14870e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Res.isInvalid()) { 1488fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian SkipUntil(tok::semi); 148943bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 1490fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian } 1491fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian if (Tok.isNot(tok::r_paren)) { 14921ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_lbrace); 149343bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 1494fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian } 1495fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian ConsumeParen(); // ')' 149678a677bbb5fa115fa0995b5783adeeefad67167eFariborz Jahanian if (Tok.isNot(tok::l_brace)) { 14971ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_lbrace); 149843bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 149978a677bbb5fa115fa0995b5783adeeefad67167eFariborz Jahanian } 15003ac438c383a4a9a73c76a05c76ec5d02f10a3c52Steve Naroff // Enter a scope to hold everything within the compound stmt. Compound 15013ac438c383a4a9a73c76a05c76ec5d02f10a3c52Steve Naroff // statements can always hold declarations. 15028935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor ParseScope BodyScope(this, Scope::DeclScope); 15033ac438c383a4a9a73c76a05c76ec5d02f10a3c52Steve Naroff 150461364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl OwningStmtResult SynchBody(ParseCompoundStatementBody()); 15050e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl 15068935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor BodyScope.Exit(); 15070e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (SynchBody.isInvalid()) 1508fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian SynchBody = Actions.ActOnNullStmt(Tok.getLocation()); 150976ad2e85575722e8a38a2bd4648ab4304d9fcd24Sebastian Redl return Actions.ActOnObjCAtSynchronizedStmt(atLoc, move(Res), move(SynchBody)); 1510c385c90c68dfa376650e2facfbb444b2ec9bd110Fariborz Jahanian} 1511c385c90c68dfa376650e2facfbb444b2ec9bd110Fariborz Jahanian 1512397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// objc-try-catch-statement: 1513397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// @try compound-statement objc-catch-list[opt] 1514397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// @try compound-statement objc-catch-list[opt] @finally compound-statement 1515397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// 1516397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// objc-catch-list: 1517397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// @catch ( parameter-declaration ) compound-statement 1518397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// objc-catch-list @catch ( catch-parameter-declaration ) compound-statement 1519397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// catch-parameter-declaration: 1520397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// parameter-declaration 1521397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// '...' [OBJC2] 1522397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// 152343bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian RedlParser::OwningStmtResult Parser::ParseObjCTryStmt(SourceLocation atLoc) { 1524397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian bool catch_or_finally_seen = false; 152543bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl 1526397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian ConsumeToken(); // consume try 1527df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::l_brace)) { 15281ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_lbrace); 152943bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 1530397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian } 15318f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor StmtVector CatchStmts(Actions); 1532ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall OwningStmtResult FinallyStmt; 15338935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor ParseScope TryScope(this, Scope::DeclScope); 153461364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl OwningStmtResult TryBody(ParseCompoundStatementBody()); 15358935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor TryScope.Exit(); 15360e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (TryBody.isInvalid()) 1537bd49a647afd9cc534fef13cadf652d4e9c396e2bFariborz Jahanian TryBody = Actions.ActOnNullStmt(Tok.getLocation()); 1538a55e52c0802cae3b7c366a05c461d3d15074c1a3Sebastian Redl 1539df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner while (Tok.is(tok::at)) { 15406b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner // At this point, we need to lookahead to determine if this @ is the start 15416b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner // of an @catch or @finally. We don't want to consume the @ token if this 15426b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner // is an @try or @encode or something else. 15436b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner Token AfterAt = GetLookAheadToken(1); 15446b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner if (!AfterAt.isObjCAtKeyword(tok::objc_catch) && 15456b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner !AfterAt.isObjCAtKeyword(tok::objc_finally)) 15466b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner break; 15470e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl 1548161a9c5afaafb4d527b7efba9675a8b2cbbe32e0Fariborz Jahanian SourceLocation AtCatchFinallyLoc = ConsumeToken(); 1549cb53b361bce341c8591333c6997f62e480acc0b4Chris Lattner if (Tok.isObjCAtKeyword(tok::objc_catch)) { 1550d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *FirstPart = 0; 15513b1191d7eaf2f4984564e01ab84b6713a9d80e70Fariborz Jahanian ConsumeToken(); // consume catch 1552df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::l_paren)) { 1553397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian ConsumeParen(); 1554e21dd6ffef4585fa43cd3586ed971217d65bf56cSteve Naroff ParseScope CatchScope(this, Scope::DeclScope|Scope::AtCatchScope); 1555df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::ellipsis)) { 1556397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian DeclSpec DS; 1557397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian ParseDeclarationSpecifiers(DS); 155843bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl // For some odd reason, the name of the exception variable is 15591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // optional. As a result, we need to use "PrototypeContext", because 15607ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff // we must accept either 'declarator' or 'abstract-declarator' here. 15617ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff Declarator ParmDecl(DS, Declarator::PrototypeContext); 15627ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff ParseDeclarator(ParmDecl); 15637ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff 15644e6c0d19b7c072758922cf80525a81aeefc6e64bDouglas Gregor // Inform the actions module about the declarator, so it 15657ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff // gets added to the current scope. 156623c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor FirstPart = Actions.ActOnObjCExceptionDecl(getCurScope(), ParmDecl); 156764515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff } else 1568397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian ConsumeToken(); // consume '...' 15691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 157093a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff SourceLocation RParenLoc; 15711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 157293a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff if (Tok.is(tok::r_paren)) 157393a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff RParenLoc = ConsumeParen(); 157493a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff else // Skip over garbage, until we get to ')'. Eat the ')'. 157593a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff SkipUntil(tok::r_paren, true, false); 157693a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff 1577ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall OwningStmtResult CatchBody(true); 1578c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner if (Tok.is(tok::l_brace)) 1579c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner CatchBody = ParseCompoundStatementBody(); 1580c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner else 1581c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner Diag(Tok, diag::err_expected_lbrace); 15820e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (CatchBody.isInvalid()) 15833b1191d7eaf2f4984564e01ab84b6713a9d80e70Fariborz Jahanian CatchBody = Actions.ActOnNullStmt(Tok.getLocation()); 15848f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor 15858f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor OwningStmtResult Catch = Actions.ActOnObjCAtCatchStmt(AtCatchFinallyLoc, 15868f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor RParenLoc, 15878f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor FirstPart, 15888f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor move(CatchBody)); 15898f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor if (!Catch.isInvalid()) 15908f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor CatchStmts.push_back(Catch.release()); 15918f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor 159264515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff } else { 15931ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(AtCatchFinallyLoc, diag::err_expected_lparen_after) 15941ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner << "@catch clause"; 159543bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 1596397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian } 1597397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian catch_or_finally_seen = true; 15986b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner } else { 15996b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner assert(Tok.isObjCAtKeyword(tok::objc_finally) && "Lookahead confused?"); 160064515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff ConsumeToken(); // consume finally 16018935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor ParseScope FinallyScope(this, Scope::DeclScope); 16020e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl 1603ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall OwningStmtResult FinallyBody(true); 1604c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner if (Tok.is(tok::l_brace)) 1605c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner FinallyBody = ParseCompoundStatementBody(); 1606c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner else 1607c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner Diag(Tok, diag::err_expected_lbrace); 16080e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (FinallyBody.isInvalid()) 1609161a9c5afaafb4d527b7efba9675a8b2cbbe32e0Fariborz Jahanian FinallyBody = Actions.ActOnNullStmt(Tok.getLocation()); 16100e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl FinallyStmt = Actions.ActOnObjCAtFinallyStmt(AtCatchFinallyLoc, 161176ad2e85575722e8a38a2bd4648ab4304d9fcd24Sebastian Redl move(FinallyBody)); 1612397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian catch_or_finally_seen = true; 1613397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian break; 1614397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian } 1615397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian } 1616bd49a647afd9cc534fef13cadf652d4e9c396e2bFariborz Jahanian if (!catch_or_finally_seen) { 1617397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian Diag(atLoc, diag::err_missing_catch_finally); 161843bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 1619bd49a647afd9cc534fef13cadf652d4e9c396e2bFariborz Jahanian } 16208f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor 16218f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor return Actions.ActOnObjCAtTryStmt(atLoc, move(TryBody), 16228f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor move_arg(CatchStmts), 162376ad2e85575722e8a38a2bd4648ab4304d9fcd24Sebastian Redl move(FinallyStmt)); 1624397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian} 1625ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian 16263536b443bc50d58a79f14fca9b6842541a434854Steve Naroff/// objc-method-def: objc-method-proto ';'[opt] '{' body '}' 1627ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// 1628d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseObjCMethodDefinition() { 1629d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *MDecl = ParseObjCMethodPrototype(ObjCImpDecl); 16301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 163149f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner PrettyStackTraceActionsDecl CrashInfo(MDecl, Tok.getLocation(), Actions, 163249f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner PP.getSourceManager(), 163349f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner "parsing Objective-C method"); 16341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1635ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian // parse optional ';' 1636209a8c2fa23636f6d065d618e7078e164903f5cdFariborz Jahanian if (Tok.is(tok::semi)) { 1637496e45ef3350fabc312c5a807d308c65c50af4dbTed Kremenek if (ObjCImpDecl) { 1638496e45ef3350fabc312c5a807d308c65c50af4dbTed Kremenek Diag(Tok, diag::warn_semicolon_before_method_body) 1639849b243d4065f56742a4677d6dc8277609a151f8Douglas Gregor << FixItHint::CreateRemoval(Tok.getLocation()); 1640496e45ef3350fabc312c5a807d308c65c50af4dbTed Kremenek } 1641ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); 1642209a8c2fa23636f6d065d618e7078e164903f5cdFariborz Jahanian } 1643ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian 1644409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // We should have an opening brace now. 1645df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::l_brace)) { 1646da323adbb99cee19a203ead852d5d9bfebb23fb7Steve Naroff Diag(Tok, diag::err_expected_method_body); 16471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1648409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // Skip over garbage, until we get to '{'. Don't eat the '{'. 1649409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff SkipUntil(tok::l_brace, true, true); 16501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1651409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // If we didn't find the '{', bail out. 1652409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff if (Tok.isNot(tok::l_brace)) 1653d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 1654ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1655409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff SourceLocation BraceLoc = Tok.getLocation(); 16561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1657409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // Enter a scope for the method body. 165815faee19fdb9017dd6d08a690427b18c3b062c2dChris Lattner ParseScope BodyScope(this, 165915faee19fdb9017dd6d08a690427b18c3b062c2dChris Lattner Scope::ObjCMethodScope|Scope::FnScope|Scope::DeclScope); 16601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1661409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // Tell the actions module that we have entered a method definition with the 1662394f3f483fa4e7b472630cfcd03f7840520958c5Steve Naroff // specified Declarator for the method. 166323c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.ActOnStartOfObjCMethodDef(getCurScope(), MDecl); 166461364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl 166561364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl OwningStmtResult FnBody(ParseCompoundStatementBody()); 166661364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl 1667409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // If the function body could not be parsed, make a bogus compoundstmt. 16680e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (FnBody.isInvalid()) 1669a60528cdac7deee3991c2b48af4df4f315e49e9dSebastian Redl FnBody = Actions.ActOnCompoundStmt(BraceLoc, BraceLoc, 1670a60528cdac7deee3991c2b48af4df4f315e49e9dSebastian Redl MultiStmtArg(Actions), false); 1671798d119415323ebcd029ffe1e0fb442a4ca8adbbSebastian Redl 167232ce8376efb7e0d70e5f7e8fcf685130293f412bSteve Naroff // TODO: Pass argument information. 167332ce8376efb7e0d70e5f7e8fcf685130293f412bSteve Naroff Actions.ActOnFinishFunctionBody(MDecl, move(FnBody)); 16741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1675409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // Leave the function body scope. 16768935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor BodyScope.Exit(); 1677798d119415323ebcd029ffe1e0fb442a4ca8adbbSebastian Redl 167871c0a951d08dc7a2a057df8c15f22b36f6aa47c7Steve Naroff return MDecl; 16795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 16805508518a2702b00be3b15a26d772bde968972f54Anders Carlsson 168143bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian RedlParser::OwningStmtResult Parser::ParseObjCAtStatement(SourceLocation AtLoc) { 16829a0c85e640a08174569a303db22981612f05d385Douglas Gregor if (Tok.is(tok::code_completion)) { 168323c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCAtStatement(getCurScope()); 1684dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 16859a0c85e640a08174569a303db22981612f05d385Douglas Gregor return StmtError(); 16865d8031687d086701b4dadaab3e0de1def448da9dChris Lattner } 16875d8031687d086701b4dadaab3e0de1def448da9dChris Lattner 16885d8031687d086701b4dadaab3e0de1def448da9dChris Lattner if (Tok.isObjCAtKeyword(tok::objc_try)) 16896b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner return ParseObjCTryStmt(AtLoc); 16905d8031687d086701b4dadaab3e0de1def448da9dChris Lattner 16915d8031687d086701b4dadaab3e0de1def448da9dChris Lattner if (Tok.isObjCAtKeyword(tok::objc_throw)) 169264515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff return ParseObjCThrowStmt(AtLoc); 16935d8031687d086701b4dadaab3e0de1def448da9dChris Lattner 16945d8031687d086701b4dadaab3e0de1def448da9dChris Lattner if (Tok.isObjCAtKeyword(tok::objc_synchronized)) 169564515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff return ParseObjCSynchronizedStmt(AtLoc); 16965d8031687d086701b4dadaab3e0de1def448da9dChris Lattner 1697d8c4e15138e69a51754cc259c8a592cc47950c8eSebastian Redl OwningExprResult Res(ParseExpressionWithLeadingAt(AtLoc)); 16980e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Res.isInvalid()) { 169964515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff // If the expression is invalid, skip ahead to the next semicolon. Not 170064515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff // doing this opens us up to the possibility of infinite loops if 170164515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff // ParseExpression does not consume any tokens. 170264515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff SkipUntil(tok::semi); 170343bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 170464515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff } 17055d8031687d086701b4dadaab3e0de1def448da9dChris Lattner 170664515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff // Otherwise, eat the semicolon. 170764515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff ExpectAndConsume(tok::semi, diag::err_expected_semi_after_expr); 17085ee56e95c3905d2e7bc403631b03865cdbdd8a42Anders Carlsson return Actions.ActOnExprStmt(Actions.MakeFullExpr(Res)); 170964515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff} 171064515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff 17111d922960e083906a586609ac6978678147250177Sebastian RedlParser::OwningExprResult Parser::ParseObjCAtExpression(SourceLocation AtLoc) { 17125508518a2702b00be3b15a26d772bde968972f54Anders Carlsson switch (Tok.getKind()) { 17139a0c85e640a08174569a303db22981612f05d385Douglas Gregor case tok::code_completion: 171423c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCAtExpression(getCurScope()); 1715dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 17169a0c85e640a08174569a303db22981612f05d385Douglas Gregor return ExprError(); 17179a0c85e640a08174569a303db22981612f05d385Douglas Gregor 1718b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner case tok::string_literal: // primary-expression: string-literal 1719b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner case tok::wide_string_literal: 17201d922960e083906a586609ac6978678147250177Sebastian Redl return ParsePostfixExpressionSuffix(ParseObjCStringLiteral(AtLoc)); 1721b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner default: 17224fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner if (Tok.getIdentifierInfo() == 0) 17231d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(AtLoc, diag::err_unexpected_at)); 17242f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl 17254fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner switch (Tok.getIdentifierInfo()->getObjCKeywordID()) { 17264fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner case tok::objc_encode: 17271d922960e083906a586609ac6978678147250177Sebastian Redl return ParsePostfixExpressionSuffix(ParseObjCEncodeExpression(AtLoc)); 17284fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner case tok::objc_protocol: 17291d922960e083906a586609ac6978678147250177Sebastian Redl return ParsePostfixExpressionSuffix(ParseObjCProtocolExpression(AtLoc)); 17304fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner case tok::objc_selector: 17311d922960e083906a586609ac6978678147250177Sebastian Redl return ParsePostfixExpressionSuffix(ParseObjCSelectorExpression(AtLoc)); 17324fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner default: 17331d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(AtLoc, diag::err_unexpected_at)); 17344fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner } 17355508518a2702b00be3b15a26d772bde968972f54Anders Carlsson } 17365508518a2702b00be3b15a26d772bde968972f54Anders Carlsson} 17375508518a2702b00be3b15a26d772bde968972f54Anders Carlsson 17386aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// \brirg Parse the receiver of an Objective-C++ message send. 17396aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// 17406aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// This routine parses the receiver of a message send in 17416aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// Objective-C++ either as a type or as an expression. Note that this 17426aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// routine must not be called to parse a send to 'super', since it 17436aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// has no way to return such a result. 17446aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// 17456aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// \param IsExpr Whether the receiver was parsed as an expression. 17466aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// 17476aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// \param TypeOrExpr If the receiver was parsed as an expression (\c 17486aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// IsExpr is true), the parsed expression. If the receiver was parsed 17496aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// as a type (\c IsExpr is false), the parsed type. 17506aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// 17516aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// \returns True if an error occurred during parsing or semantic 17526aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// analysis, in which case the arguments do not have valid 17536aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// values. Otherwise, returns false for a successful parse. 17546aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// 17556aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// objc-receiver: [C++] 17566aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// 'super' [not parsed here] 17576aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// expression 17586aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// simple-type-specifier 17596aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// typename-specifier 17606aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregorbool Parser::ParseObjCXXMessageReceiver(bool &IsExpr, void *&TypeOrExpr) { 17616aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor if (Tok.is(tok::identifier) || Tok.is(tok::coloncolon) || 17626aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor Tok.is(tok::kw_typename) || Tok.is(tok::annot_cxxscope)) 17636aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor TryAnnotateTypeOrScopeToken(); 17646aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 17656aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor if (!isCXXSimpleTypeSpecifier()) { 17666aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // objc-receiver: 17676aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // expression 17686aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor OwningExprResult Receiver = ParseExpression(); 17696aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor if (Receiver.isInvalid()) 17706aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor return true; 17716aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 17726aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor IsExpr = true; 17736aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor TypeOrExpr = Receiver.take(); 17746aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor return false; 17756aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor } 17766aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 17776aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // objc-receiver: 17786aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // typename-specifier 17796aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // simple-type-specifier 17806aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // expression (that starts with one of the above) 17816aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor DeclSpec DS; 17826aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor ParseCXXSimpleTypeSpecifier(DS); 17836aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 17846aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor if (Tok.is(tok::l_paren)) { 17856aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // If we see an opening parentheses at this point, we are 17866aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // actually parsing an expression that starts with a 17876aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // function-style cast, e.g., 17886aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // 17896aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // postfix-expression: 17906aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // simple-type-specifier ( expression-list [opt] ) 17916aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // typename-specifier ( expression-list [opt] ) 17926aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // 17936aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // Parse the remainder of this case, then the (optional) 17946aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // postfix-expression suffix, followed by the (optional) 17956aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // right-hand side of the binary expression. We have an 17966aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // instance method. 17976aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor OwningExprResult Receiver = ParseCXXTypeConstructExpression(DS); 17986aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor if (!Receiver.isInvalid()) 17996aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor Receiver = ParsePostfixExpressionSuffix(move(Receiver)); 18006aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor if (!Receiver.isInvalid()) 18016aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor Receiver = ParseRHSOfBinaryExpression(move(Receiver), prec::Comma); 18026aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor if (Receiver.isInvalid()) 18036aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor return true; 18046aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 18056aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor IsExpr = true; 18066aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor TypeOrExpr = Receiver.take(); 18076aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor return false; 18086aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor } 18096aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 18106aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // We have a class message. Turn the simple-type-specifier or 18116aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // typename-specifier we parsed into a type and parse the 18126aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // remainder of the class message. 18136aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor Declarator DeclaratorInfo(DS, Declarator::TypeNameContext); 181423c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor TypeResult Type = Actions.ActOnTypeName(getCurScope(), DeclaratorInfo); 18156aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor if (Type.isInvalid()) 18166aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor return true; 18176aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 18186aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor IsExpr = false; 18196aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor TypeOrExpr = Type.get(); 18206aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor return false; 18216aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor} 18226aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 18231b730e847ded503f2e615154035c083c4f94a067Douglas Gregor/// \brief Determine whether the parser is currently referring to a an 18241b730e847ded503f2e615154035c083c4f94a067Douglas Gregor/// Objective-C message send, using a simplified heuristic to avoid overhead. 18251b730e847ded503f2e615154035c083c4f94a067Douglas Gregor/// 18261b730e847ded503f2e615154035c083c4f94a067Douglas Gregor/// This routine will only return true for a subset of valid message-send 18271b730e847ded503f2e615154035c083c4f94a067Douglas Gregor/// expressions. 18281b730e847ded503f2e615154035c083c4f94a067Douglas Gregorbool Parser::isSimpleObjCMessageExpression() { 1829c59cb38810c63a806270385f79ea84e0203754eaChris Lattner assert(Tok.is(tok::l_square) && getLang().ObjC1 && 18301b730e847ded503f2e615154035c083c4f94a067Douglas Gregor "Incorrect start for isSimpleObjCMessageExpression"); 18311b730e847ded503f2e615154035c083c4f94a067Douglas Gregor return GetLookAheadToken(1).is(tok::identifier) && 18321b730e847ded503f2e615154035c083c4f94a067Douglas Gregor GetLookAheadToken(2).is(tok::identifier); 18331b730e847ded503f2e615154035c083c4f94a067Douglas Gregor} 18341b730e847ded503f2e615154035c083c4f94a067Douglas Gregor 18351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// objc-message-expr: 18360ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// '[' objc-receiver objc-message-args ']' 18370ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// 18382725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// objc-receiver: [C] 1839eb483eb3ee80300f15d6d13573d82493c2194461Chris Lattner/// 'super' 18400ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// expression 18410ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// class-name 18420ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// type-name 18436aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// 18441d922960e083906a586609ac6978678147250177Sebastian RedlParser::OwningExprResult Parser::ParseObjCMessageExpression() { 1845699b66138ac307a32e238463e0eff513ff17d337Chris Lattner assert(Tok.is(tok::l_square) && "'[' expected"); 1846699b66138ac307a32e238463e0eff513ff17d337Chris Lattner SourceLocation LBracLoc = ConsumeBracket(); // consume '[' 1847699b66138ac307a32e238463e0eff513ff17d337Chris Lattner 18488e254cfe5a6ab4202c7fcc4b64bdd1ca0fe071acDouglas Gregor if (Tok.is(tok::code_completion)) { 184923c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCMessageReceiver(getCurScope()); 18508e254cfe5a6ab4202c7fcc4b64bdd1ca0fe071acDouglas Gregor ConsumeCodeCompletionToken(); 18518e254cfe5a6ab4202c7fcc4b64bdd1ca0fe071acDouglas Gregor SkipUntil(tok::r_square); 18528e254cfe5a6ab4202c7fcc4b64bdd1ca0fe071acDouglas Gregor return ExprError(); 18538e254cfe5a6ab4202c7fcc4b64bdd1ca0fe071acDouglas Gregor } 18548e254cfe5a6ab4202c7fcc4b64bdd1ca0fe071acDouglas Gregor 18556aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor if (getLang().CPlusPlus) { 18566aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // We completely separate the C and C++ cases because C++ requires 18576aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // more complicated (read: slower) parsing. 18586aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 18596aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // Handle send to super. 18606aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // FIXME: This doesn't benefit from the same typo-correction we 18616aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // get in Objective-C. 18626aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor if (Tok.is(tok::identifier) && Tok.getIdentifierInfo() == Ident_super && 186323c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor NextToken().isNot(tok::period) && getCurScope()->isInObjcMethodScope()) 18646aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor return ParseObjCMessageExpressionBody(LBracLoc, ConsumeToken(), 0, 18656aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor ExprArg(Actions)); 18666aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 18676aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor // Parse the receiver, which is either a type or an expression. 18686aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor bool IsExpr; 18696aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor void *TypeOrExpr; 18706aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor if (ParseObjCXXMessageReceiver(IsExpr, TypeOrExpr)) { 18716aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor SkipUntil(tok::r_square); 18726aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor return ExprError(); 18736aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor } 18746aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 18756aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor if (IsExpr) 18766aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(), 0, 1877ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall OwningExprResult(static_cast<Expr*>(TypeOrExpr))); 18786aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 18796aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(), 18806aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor TypeOrExpr, ExprArg(Actions)); 1881c59cb38810c63a806270385f79ea84e0203754eaChris Lattner } 1882c59cb38810c63a806270385f79ea84e0203754eaChris Lattner 1883c59cb38810c63a806270385f79ea84e0203754eaChris Lattner if (Tok.is(tok::identifier)) { 18841dbca6ea983231b4cab1a8f1edda8f6e13c21f12Douglas Gregor IdentifierInfo *Name = Tok.getIdentifierInfo(); 18851dbca6ea983231b4cab1a8f1edda8f6e13c21f12Douglas Gregor SourceLocation NameLoc = Tok.getLocation(); 18861569f95831a8c99e9f664137bf8f40e47ee3d90fDouglas Gregor TypeTy *ReceiverType; 188723c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor switch (Actions.getObjCMessageKind(getCurScope(), Name, NameLoc, 18881dbca6ea983231b4cab1a8f1edda8f6e13c21f12Douglas Gregor Name == Ident_super, 18891569f95831a8c99e9f664137bf8f40e47ee3d90fDouglas Gregor NextToken().is(tok::period), 18901569f95831a8c99e9f664137bf8f40e47ee3d90fDouglas Gregor ReceiverType)) { 18911dbca6ea983231b4cab1a8f1edda8f6e13c21f12Douglas Gregor case Action::ObjCSuperMessage: 18922725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor return ParseObjCMessageExpressionBody(LBracLoc, ConsumeToken(), 0, 1893d2869925b5f10e00b13fbf3f41bbb17e4c9adbe0Fariborz Jahanian ExprArg(Actions)); 18942725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor 18951569f95831a8c99e9f664137bf8f40e47ee3d90fDouglas Gregor case Action::ObjCClassMessage: 18961569f95831a8c99e9f664137bf8f40e47ee3d90fDouglas Gregor if (!ReceiverType) { 18972725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor SkipUntil(tok::r_square); 18982725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor return ExprError(); 18992725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor } 19002725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor 19011569f95831a8c99e9f664137bf8f40e47ee3d90fDouglas Gregor ConsumeToken(); // the type name 19021569f95831a8c99e9f664137bf8f40e47ee3d90fDouglas Gregor 19031569f95831a8c99e9f664137bf8f40e47ee3d90fDouglas Gregor return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(), 19041569f95831a8c99e9f664137bf8f40e47ee3d90fDouglas Gregor ReceiverType, 19052725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor ExprArg(Actions)); 19061dbca6ea983231b4cab1a8f1edda8f6e13c21f12Douglas Gregor 19071dbca6ea983231b4cab1a8f1edda8f6e13c21f12Douglas Gregor case Action::ObjCInstanceMessage: 19082725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor // Fall through to parse an expression. 19091dbca6ea983231b4cab1a8f1edda8f6e13c21f12Douglas Gregor break; 1910d2869925b5f10e00b13fbf3f41bbb17e4c9adbe0Fariborz Jahanian } 1911699b66138ac307a32e238463e0eff513ff17d337Chris Lattner } 1912eb483eb3ee80300f15d6d13573d82493c2194461Chris Lattner 1913eb483eb3ee80300f15d6d13573d82493c2194461Chris Lattner // Otherwise, an arbitrary expression can be the receiver of a send. 19142f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl OwningExprResult Res(ParseExpression()); 19150e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Res.isInvalid()) { 19165c749428a9938d5e2e9564b1c9b7a9252c30ee27Chris Lattner SkipUntil(tok::r_square); 19171d922960e083906a586609ac6978678147250177Sebastian Redl return move(Res); 1918699b66138ac307a32e238463e0eff513ff17d337Chris Lattner } 19191d922960e083906a586609ac6978678147250177Sebastian Redl 19202725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(), 0, 19212725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor move(Res)); 1922699b66138ac307a32e238463e0eff513ff17d337Chris Lattner} 19231d922960e083906a586609ac6978678147250177Sebastian Redl 19242725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// \brief Parse the remainder of an Objective-C message following the 19252725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// '[' objc-receiver. 19262725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// 19272725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// This routine handles sends to super, class messages (sent to a 19282725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// class name), and instance messages (sent to an object), and the 19292725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// target is represented by \p SuperLoc, \p ReceiverType, or \p 19302725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// ReceiverExpr, respectively. Only one of these parameters may have 19312725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// a valid value. 19322725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// 19332725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// \param LBracLoc The location of the opening '['. 19342725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// 19352725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// \param SuperLoc If this is a send to 'super', the location of the 19362725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// 'super' keyword that indicates a send to the superclass. 19372725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// 19382725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// \param ReceiverType If this is a class message, the type of the 19392725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// class we are sending a message to. 19402725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// 19412725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// \param ReceiverExpr If this is an instance message, the expression 19422725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// used to compute the receiver object. 19431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 19440ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-message-args: 19450ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-selector 19460ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-keywordarg-list 19470ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// 19480ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-keywordarg-list: 19490ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-keywordarg 19500ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-keywordarg-list objc-keywordarg 19510ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// 19521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// objc-keywordarg: 19530ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// selector-name[opt] ':' objc-keywordexpr 19540ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// 19550ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-keywordexpr: 19560ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// nonempty-expr-list 19570ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// 19580ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// nonempty-expr-list: 19590ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// assignment-expression 19600ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// nonempty-expr-list , assignment-expression 19611d922960e083906a586609ac6978678147250177Sebastian Redl/// 19621d922960e083906a586609ac6978678147250177Sebastian RedlParser::OwningExprResult 1963699b66138ac307a32e238463e0eff513ff17d337Chris LattnerParser::ParseObjCMessageExpressionBody(SourceLocation LBracLoc, 19642725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor SourceLocation SuperLoc, 19652725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor TypeTy *ReceiverType, 19661d922960e083906a586609ac6978678147250177Sebastian Redl ExprArg ReceiverExpr) { 1967c4df6d2c05c647a6a5770ba0c749782b6c023a3aSteve Naroff if (Tok.is(tok::code_completion)) { 19682725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor if (SuperLoc.isValid()) 196923c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCSuperMessage(getCurScope(), SuperLoc, 0, 0); 19702725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor else if (ReceiverType) 197123c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCClassMessage(getCurScope(), ReceiverType, 0, 0); 1972c4df6d2c05c647a6a5770ba0c749782b6c023a3aSteve Naroff else 197323c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCInstanceMessage(getCurScope(), ReceiverExpr.get(), 1974d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor 0, 0); 1975dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 1976c4df6d2c05c647a6a5770ba0c749782b6c023a3aSteve Naroff } 1977d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor 1978a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian // Parse objc-selector 19794b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian SourceLocation Loc; 19802fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner IdentifierInfo *selIdent = ParseObjCSelectorPiece(Loc); 198168d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff 1982ff975cfab9ada27df86038286d1678084aeb3428Anders Carlsson SourceLocation SelectorLoc = Loc; 19831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 198468d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff llvm::SmallVector<IdentifierInfo *, 12> KeyIdents; 1985a55e52c0802cae3b7c366a05c461d3d15074c1a3Sebastian Redl ExprVector KeyExprs(Actions); 198668d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff 1987df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::colon)) { 1988a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian while (1) { 1989a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian // Each iteration parses a single keyword argument. 199068d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff KeyIdents.push_back(selIdent); 199137387c932855c6d58d70bdd705cd3a9fdcd2a931Steve Naroff 1992df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::colon)) { 1993a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian Diag(Tok, diag::err_expected_colon); 19944fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // We must manually skip to a ']', otherwise the expression skipper will 19954fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // stop at the ']' when it skips to the ';'. We want it to skip beyond 19964fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // the enclosing expression. 19974fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner SkipUntil(tok::r_square); 19981d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(); 1999a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian } 20001d922960e083906a586609ac6978678147250177Sebastian Redl 200168d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff ConsumeToken(); // Eat the ':'. 20021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// Parse the expression after ':' 20032f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl OwningExprResult Res(ParseAssignmentExpression()); 20040e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Res.isInvalid()) { 20054fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // We must manually skip to a ']', otherwise the expression skipper will 20064fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // stop at the ']' when it skips to the ';'. We want it to skip beyond 20074fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // the enclosing expression. 20084fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner SkipUntil(tok::r_square); 20091d922960e083906a586609ac6978678147250177Sebastian Redl return move(Res); 201037387c932855c6d58d70bdd705cd3a9fdcd2a931Steve Naroff } 20111d922960e083906a586609ac6978678147250177Sebastian Redl 201237387c932855c6d58d70bdd705cd3a9fdcd2a931Steve Naroff // We have a valid expression. 2013effa8d1c97b00a3f53e972b0e61d9aade5ea1c57Sebastian Redl KeyExprs.push_back(Res.release()); 20141d922960e083906a586609ac6978678147250177Sebastian Redl 2015d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor // Code completion after each argument. 2016d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor if (Tok.is(tok::code_completion)) { 20172725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor if (SuperLoc.isValid()) 201823c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCSuperMessage(getCurScope(), SuperLoc, 20192725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor KeyIdents.data(), 20202725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor KeyIdents.size()); 20212725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor else if (ReceiverType) 202223c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCClassMessage(getCurScope(), ReceiverType, 2023d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor KeyIdents.data(), 2024d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor KeyIdents.size()); 2025d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor else 202623c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteObjCInstanceMessage(getCurScope(), ReceiverExpr.get(), 2027d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor KeyIdents.data(), 2028d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor KeyIdents.size()); 2029dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 2030d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor } 2031d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor 203237387c932855c6d58d70bdd705cd3a9fdcd2a931Steve Naroff // Check for another keyword selector. 20332fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner selIdent = ParseObjCSelectorPiece(Loc); 2034df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (!selIdent && Tok.isNot(tok::colon)) 2035a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian break; 2036a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian // We have a selector or a colon, continue parsing. 2037a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian } 2038a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian // Parse the, optional, argument list, comma separated. 2039df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner while (Tok.is(tok::comma)) { 204049f109c786f99eb7468dac3976db083a65493444Steve Naroff ConsumeToken(); // Eat the ','. 20411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// Parse the expression after ',' 20422f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl OwningExprResult Res(ParseAssignmentExpression()); 20430e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Res.isInvalid()) { 20444fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // We must manually skip to a ']', otherwise the expression skipper will 20454fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // stop at the ']' when it skips to the ';'. We want it to skip beyond 20464fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // the enclosing expression. 20474fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner SkipUntil(tok::r_square); 20481d922960e083906a586609ac6978678147250177Sebastian Redl return move(Res); 204949f109c786f99eb7468dac3976db083a65493444Steve Naroff } 20500e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl 205149f109c786f99eb7468dac3976db083a65493444Steve Naroff // We have a valid expression. 2052effa8d1c97b00a3f53e972b0e61d9aade5ea1c57Sebastian Redl KeyExprs.push_back(Res.release()); 2053a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian } 2054a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian } else if (!selIdent) { 2055a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian Diag(Tok, diag::err_expected_ident); // missing selector name. 20561d922960e083906a586609ac6978678147250177Sebastian Redl 20574fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // We must manually skip to a ']', otherwise the expression skipper will 20584fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // stop at the ']' when it skips to the ';'. We want it to skip beyond 20594fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // the enclosing expression. 20604fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner SkipUntil(tok::r_square); 20611d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(); 2062a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian } 2063809872eca7f6c024e2ab41ddffbbeeae807bf5dcFariborz Jahanian 2064df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::r_square)) { 2065809872eca7f6c024e2ab41ddffbbeeae807bf5dcFariborz Jahanian if (Tok.is(tok::identifier)) 2066809872eca7f6c024e2ab41ddffbbeeae807bf5dcFariborz Jahanian Diag(Tok, diag::err_expected_colon); 2067809872eca7f6c024e2ab41ddffbbeeae807bf5dcFariborz Jahanian else 2068809872eca7f6c024e2ab41ddffbbeeae807bf5dcFariborz Jahanian Diag(Tok, diag::err_expected_rsquare); 20694fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // We must manually skip to a ']', otherwise the expression skipper will 20704fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // stop at the ']' when it skips to the ';'. We want it to skip beyond 20714fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // the enclosing expression. 20724fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner SkipUntil(tok::r_square); 20731d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(); 2074a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian } 20751d922960e083906a586609ac6978678147250177Sebastian Redl 2076699b66138ac307a32e238463e0eff513ff17d337Chris Lattner SourceLocation RBracLoc = ConsumeBracket(); // consume ']' 20771d922960e083906a586609ac6978678147250177Sebastian Redl 207829238a0bf7cbf5b396efb451a0adb5fe4aa037caSteve Naroff unsigned nKeys = KeyIdents.size(); 2079ff38491c18b060526d754765b952f4a497a89416Chris Lattner if (nKeys == 0) 2080ff38491c18b060526d754765b952f4a497a89416Chris Lattner KeyIdents.push_back(selIdent); 2081ff38491c18b060526d754765b952f4a497a89416Chris Lattner Selector Sel = PP.getSelectorTable().getSelector(nKeys, &KeyIdents[0]); 20821d922960e083906a586609ac6978678147250177Sebastian Redl 20832725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor if (SuperLoc.isValid()) 208423c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor return Actions.ActOnSuperMessage(getCurScope(), SuperLoc, Sel, 20852725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor LBracLoc, SelectorLoc, RBracLoc, 20862725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor Action::MultiExprArg(Actions, 20872725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor KeyExprs.take(), 20882725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor KeyExprs.size())); 20892725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor else if (ReceiverType) 209023c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor return Actions.ActOnClassMessage(getCurScope(), ReceiverType, Sel, 20912725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor LBracLoc, SelectorLoc, RBracLoc, 20922725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor Action::MultiExprArg(Actions, 20932725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor KeyExprs.take(), 20942725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor KeyExprs.size())); 209523c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor return Actions.ActOnInstanceMessage(getCurScope(), move(ReceiverExpr), Sel, 20962725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor LBracLoc, SelectorLoc, RBracLoc, 20972725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor Action::MultiExprArg(Actions, 20982725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor KeyExprs.take(), 20992725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor KeyExprs.size())); 21000ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian} 21010ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian 21021d922960e083906a586609ac6978678147250177Sebastian RedlParser::OwningExprResult Parser::ParseObjCStringLiteral(SourceLocation AtLoc) { 210320df9b7ab9388b2a488c5b1293cd196b1e073b4eSebastian Redl OwningExprResult Res(ParseStringLiteralExpression()); 21041d922960e083906a586609ac6978678147250177Sebastian Redl if (Res.isInvalid()) return move(Res); 21051d922960e083906a586609ac6978678147250177Sebastian Redl 2106b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner // @"foo" @"bar" is a valid concatenated string. Eat any subsequent string 2107b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner // expressions. At this point, we know that the only valid thing that starts 2108b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner // with '@' is an @"". 2109b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner llvm::SmallVector<SourceLocation, 4> AtLocs; 2110a55e52c0802cae3b7c366a05c461d3d15074c1a3Sebastian Redl ExprVector AtStrings(Actions); 2111b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner AtLocs.push_back(AtLoc); 2112effa8d1c97b00a3f53e972b0e61d9aade5ea1c57Sebastian Redl AtStrings.push_back(Res.release()); 21130e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl 2114b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner while (Tok.is(tok::at)) { 2115b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner AtLocs.push_back(ConsumeToken()); // eat the @. 2116b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner 211715faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl // Invalid unless there is a string literal. 211897cf6eb380016db868866faf27a086cd55a316d4Chris Lattner if (!isTokenStringLiteral()) 211997cf6eb380016db868866faf27a086cd55a316d4Chris Lattner return ExprError(Diag(Tok, diag::err_objc_concat_string)); 2120b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner 212197cf6eb380016db868866faf27a086cd55a316d4Chris Lattner OwningExprResult Lit(ParseStringLiteralExpression()); 21220e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Lit.isInvalid()) 21231d922960e083906a586609ac6978678147250177Sebastian Redl return move(Lit); 21240e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl 2125effa8d1c97b00a3f53e972b0e61d9aade5ea1c57Sebastian Redl AtStrings.push_back(Lit.release()); 2126b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner } 21271d922960e083906a586609ac6978678147250177Sebastian Redl 21281d922960e083906a586609ac6978678147250177Sebastian Redl return Owned(Actions.ParseObjCStringLiteral(&AtLocs[0], AtStrings.take(), 21291d922960e083906a586609ac6978678147250177Sebastian Redl AtStrings.size())); 21305508518a2702b00be3b15a26d772bde968972f54Anders Carlsson} 2131f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson 2132f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson/// objc-encode-expression: 2133f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson/// @encode ( type-name ) 21341d922960e083906a586609ac6978678147250177Sebastian RedlParser::OwningExprResult 21351d922960e083906a586609ac6978678147250177Sebastian RedlParser::ParseObjCEncodeExpression(SourceLocation AtLoc) { 2136861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff assert(Tok.isObjCAtKeyword(tok::objc_encode) && "Not an @encode expression!"); 21371d922960e083906a586609ac6978678147250177Sebastian Redl 2138f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson SourceLocation EncLoc = ConsumeToken(); 21391d922960e083906a586609ac6978678147250177Sebastian Redl 21404fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner if (Tok.isNot(tok::l_paren)) 21411d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(Tok, diag::err_expected_lparen_after) << "@encode"); 21421d922960e083906a586609ac6978678147250177Sebastian Redl 2143f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson SourceLocation LParenLoc = ConsumeParen(); 21441d922960e083906a586609ac6978678147250177Sebastian Redl 2145809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor TypeResult Ty = ParseTypeName(); 21461d922960e083906a586609ac6978678147250177Sebastian Redl 21474988ae3fda10743c8ed8a98cdcb5a783362587b4Anders Carlsson SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); 21481d922960e083906a586609ac6978678147250177Sebastian Redl 2149809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor if (Ty.isInvalid()) 2150809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor return ExprError(); 2151809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor 21521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return Owned(Actions.ParseObjCEncodeExpression(AtLoc, EncLoc, LParenLoc, 2153809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor Ty.get(), RParenLoc)); 2154f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson} 215529b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson 215629b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson/// objc-protocol-expression 215729b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson/// @protocol ( protocol-name ) 21581d922960e083906a586609ac6978678147250177Sebastian RedlParser::OwningExprResult 21591d922960e083906a586609ac6978678147250177Sebastian RedlParser::ParseObjCProtocolExpression(SourceLocation AtLoc) { 216029b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson SourceLocation ProtoLoc = ConsumeToken(); 21611d922960e083906a586609ac6978678147250177Sebastian Redl 21624fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner if (Tok.isNot(tok::l_paren)) 21631d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(Tok, diag::err_expected_lparen_after) << "@protocol"); 21641d922960e083906a586609ac6978678147250177Sebastian Redl 216529b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson SourceLocation LParenLoc = ConsumeParen(); 21661d922960e083906a586609ac6978678147250177Sebastian Redl 21674fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner if (Tok.isNot(tok::identifier)) 21681d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(Tok, diag::err_expected_ident)); 21691d922960e083906a586609ac6978678147250177Sebastian Redl 2170390d50a725497e99247dc104a7d2c2a255d3af14Fariborz Jahanian IdentifierInfo *protocolId = Tok.getIdentifierInfo(); 217129b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson ConsumeToken(); 21721d922960e083906a586609ac6978678147250177Sebastian Redl 21734988ae3fda10743c8ed8a98cdcb5a783362587b4Anders Carlsson SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); 217429b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson 21751d922960e083906a586609ac6978678147250177Sebastian Redl return Owned(Actions.ParseObjCProtocolExpression(protocolId, AtLoc, ProtoLoc, 21761d922960e083906a586609ac6978678147250177Sebastian Redl LParenLoc, RParenLoc)); 217729b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson} 2178a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian 2179a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian/// objc-selector-expression 2180a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian/// @selector '(' objc-keyword-selector ')' 21811d922960e083906a586609ac6978678147250177Sebastian RedlParser::OwningExprResult 21821d922960e083906a586609ac6978678147250177Sebastian RedlParser::ParseObjCSelectorExpression(SourceLocation AtLoc) { 2183a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian SourceLocation SelectorLoc = ConsumeToken(); 21841d922960e083906a586609ac6978678147250177Sebastian Redl 21854fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner if (Tok.isNot(tok::l_paren)) 21861d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(Tok, diag::err_expected_lparen_after) << "@selector"); 21871d922960e083906a586609ac6978678147250177Sebastian Redl 2188b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian llvm::SmallVector<IdentifierInfo *, 12> KeyIdents; 2189a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian SourceLocation LParenLoc = ConsumeParen(); 2190a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian SourceLocation sLoc; 21912fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner IdentifierInfo *SelIdent = ParseObjCSelectorPiece(sLoc); 21921d922960e083906a586609ac6978678147250177Sebastian Redl if (!SelIdent && Tok.isNot(tok::colon)) // missing selector name. 21931d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(Tok, diag::err_expected_ident)); 21941d922960e083906a586609ac6978678147250177Sebastian Redl 2195b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian KeyIdents.push_back(SelIdent); 2196887407e71fd58de452361b77d72970e32b20ebe0Steve Naroff unsigned nColons = 0; 2197887407e71fd58de452361b77d72970e32b20ebe0Steve Naroff if (Tok.isNot(tok::r_paren)) { 2198a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian while (1) { 21994fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner if (Tok.isNot(tok::colon)) 22001d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(Tok, diag::err_expected_colon)); 22011d922960e083906a586609ac6978678147250177Sebastian Redl 2202cb53b361bce341c8591333c6997f62e480acc0b4Chris Lattner nColons++; 2203a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian ConsumeToken(); // Eat the ':'. 2204a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian if (Tok.is(tok::r_paren)) 2205a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian break; 2206a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian // Check for another keyword selector. 2207a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian SourceLocation Loc; 22082fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner SelIdent = ParseObjCSelectorPiece(Loc); 2209b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian KeyIdents.push_back(SelIdent); 2210a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian if (!SelIdent && Tok.isNot(tok::colon)) 2211a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian break; 2212a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian } 2213887407e71fd58de452361b77d72970e32b20ebe0Steve Naroff } 2214a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); 2215887407e71fd58de452361b77d72970e32b20ebe0Steve Naroff Selector Sel = PP.getSelectorTable().getSelector(nColons, &KeyIdents[0]); 22161d922960e083906a586609ac6978678147250177Sebastian Redl return Owned(Actions.ParseObjCSelectorExpression(Sel, AtLoc, SelectorLoc, 22171d922960e083906a586609ac6978678147250177Sebastian Redl LParenLoc, RParenLoc)); 221858065b2d8038a4e9a91ea4813bd1774c0f6efacbGabor Greif } 2219