ParseObjc.cpp revision 15faee19fdb9017dd6d08a690427b18c3b062c2d
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 145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/Parse/Parser.h" 154985aceceb9b9261b876b515d32726175c13a775Steve Naroff#include "clang/Parse/DeclSpec.h" 163b1191d7eaf2f4984564e01ab84b6713a9d80e70Fariborz Jahanian#include "clang/Parse/Scope.h" 17500d3297d2a21edeac4d46cbcbe21bc2352c2a28Chris Lattner#include "clang/Parse/ParseDiagnostic.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' 30b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris LattnerParser::DeclPtrTy Parser::ParseObjCAtDirectives() { 315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation AtLoc = ConsumeToken(); // the "@" 321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 33c464ae8444edb6d07ea49b7a0eae1674c0fa1bb8Douglas Gregor if (Tok.is(tok::code_completion)) { 34c464ae8444edb6d07ea49b7a0eae1674c0fa1bb8Douglas Gregor Actions.CodeCompleteObjCAtDirective(CurScope, ObjCImpDecl, false); 35c464ae8444edb6d07ea49b7a0eae1674c0fa1bb8Douglas Gregor ConsumeToken(); 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); 58b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// objc-class-declaration: 645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// '@' 'class' identifier-list ';' 651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 66b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris LattnerParser::DeclPtrTy 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); 76b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 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")) 90b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 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/// 125b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris LattnerParser::DeclPtrTy 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)) { 1333b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor Actions.CodeCompleteObjCInterfaceDecl(CurScope); 1343b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor ConsumeToken(); 1353b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor } 1363b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor 137df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 138dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff Diag(Tok, diag::err_expected_ident); // missing class or category name. 139b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 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(); 14505511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian bool Err = false; 146df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::l_paren)) { // 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)) { 15133ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor Actions.CodeCompleteObjCInterfaceCategory(CurScope, nameId); 15233ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor ConsumeToken(); 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 (isKnownToBeTypeSpecifier(Tok)) { 16105511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian // Fall thru after diagnosing for better error recovery. 16205511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian Diag(Tok, diag::err_expected_minus_or_plus); 16305511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian ConsumeToken(); 16405511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian Err = true; 16505511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian } 16605511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian else if (!getLang().ObjC2) { 167527fe23f8cbc6a4da1737a547a2517bc92fa88c8Steve Naroff Diag(Tok, diag::err_expected_ident); // missing category name. 168b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 169dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff } 170df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::r_paren)) { 171dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff Diag(Tok, diag::err_expected_rparen); 172dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff SkipUntil(tok::r_paren, false); // don't stop at ';' 173b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 174dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff } 175dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff rparenLoc = ConsumeParen(); 17605511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian if (!Err) { 17705511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian // Next, we need to check for any protocol references. 17805511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian SourceLocation LAngleLoc, EndProtoLoc; 17905511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian llvm::SmallVector<DeclPtrTy, 8> ProtocolRefs; 18005511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian llvm::SmallVector<SourceLocation, 8> ProtocolLocs; 18105511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian if (Tok.is(tok::less) && 18205511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian ParseObjCProtocolReferences(ProtocolRefs, ProtocolLocs, true, 18371b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis LAngleLoc, EndProtoLoc)) 18405511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian return DeclPtrTy(); 18505511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian 18605511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian if (attrList) // categories don't support attributes. 18705511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian Diag(Tok, diag::err_objc_no_attributes_on_category); 18805511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian 18905511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian DeclPtrTy CategoryType = 19005511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian Actions.ActOnStartCategoryInterface(atLoc, 19105511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian nameId, nameLoc, 19205511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian categoryId, categoryLoc, 19305511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian ProtocolRefs.data(), 19405511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian ProtocolRefs.size(), 19505511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian ProtocolLocs.data(), 19605511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian EndProtoLoc); 19705511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian if (Tok.is(tok::l_brace)) 19883c481ade785a919ba21a33f9a8b1b21c1212fb3Fariborz Jahanian ParseObjCClassInstanceVariables(CategoryType, tok::objc_private, 19983c481ade785a919ba21a33f9a8b1b21c1212fb3Fariborz Jahanian atLoc); 20083c481ade785a919ba21a33f9a8b1b21c1212fb3Fariborz Jahanian 20105511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian ParseObjCInterfaceDeclList(CategoryType, tok::objc_not_keyword); 20205511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian return CategoryType; 20305511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian } 204dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff } 205dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff // Parse a class interface. 206dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff IdentifierInfo *superClassId = 0; 207dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff SourceLocation superClassLoc; 2087ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff 209df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::colon)) { // a super class is specified. 210dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff ConsumeToken(); 2113b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor 2123b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor // Code completion of superclass names. 2133b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor if (Tok.is(tok::code_completion)) { 2143b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor Actions.CodeCompleteObjCSuperclass(CurScope, nameId); 2153b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor ConsumeToken(); 2163b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor } 2173b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor 218df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 219dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff Diag(Tok, diag::err_expected_ident); // missing super class name. 220b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 221dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff } 222dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff superClassId = Tok.getIdentifierInfo(); 223dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff superClassLoc = ConsumeToken(); 224dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff } 225dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff // Next, we need to check for any protocol references. 226b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner llvm::SmallVector<Action::DeclPtrTy, 8> ProtocolRefs; 22771b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis llvm::SmallVector<SourceLocation, 8> ProtocolLocs; 22871b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis SourceLocation LAngleLoc, EndProtoLoc; 22906036d3709955a53297b4cbe14e20db88f321470Chris Lattner if (Tok.is(tok::less) && 23071b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis ParseObjCProtocolReferences(ProtocolRefs, ProtocolLocs, true, 23171b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis LAngleLoc, EndProtoLoc)) 232b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 2331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DeclPtrTy ClsType = 2351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Actions.ActOnStartClassInterface(atLoc, nameId, nameLoc, 23606036d3709955a53297b4cbe14e20db88f321470Chris Lattner superClassId, superClassLoc, 237beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad ProtocolRefs.data(), ProtocolRefs.size(), 23818df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor ProtocolLocs.data(), 23906036d3709955a53297b4cbe14e20db88f321470Chris Lattner EndProtoLoc, attrList); 2401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 241df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::l_brace)) 24283c481ade785a919ba21a33f9a8b1b21c1212fb3Fariborz Jahanian ParseObjCClassInstanceVariables(ClsType, tok::objc_protected, atLoc); 243dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff 24425e077d59a8e8e43b65882b69610a3d5e2aaf53cFariborz Jahanian ParseObjCInterfaceDeclList(ClsType, tok::objc_interface); 24505511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian return Err ? DeclPtrTy() : ClsType; 246dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff} 247dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff 248d0014540005f2a5ab837365db6bd40f479406758John McCall/// The Objective-C property callback. This should be defined where 249d0014540005f2a5ab837365db6bd40f479406758John McCall/// it's used, but instead it's been lifted to here to support VS2005. 250d0014540005f2a5ab837365db6bd40f479406758John McCallstruct Parser::ObjCPropertyCallback : FieldCallback { 251d0014540005f2a5ab837365db6bd40f479406758John McCall Parser &P; 252d0014540005f2a5ab837365db6bd40f479406758John McCall DeclPtrTy IDecl; 253d0014540005f2a5ab837365db6bd40f479406758John McCall llvm::SmallVectorImpl<DeclPtrTy> &Props; 254d0014540005f2a5ab837365db6bd40f479406758John McCall ObjCDeclSpec &OCDS; 255d0014540005f2a5ab837365db6bd40f479406758John McCall SourceLocation AtLoc; 256d0014540005f2a5ab837365db6bd40f479406758John McCall tok::ObjCKeywordKind MethodImplKind; 257d0014540005f2a5ab837365db6bd40f479406758John McCall 258d0014540005f2a5ab837365db6bd40f479406758John McCall ObjCPropertyCallback(Parser &P, DeclPtrTy IDecl, 259d0014540005f2a5ab837365db6bd40f479406758John McCall llvm::SmallVectorImpl<DeclPtrTy> &Props, 260d0014540005f2a5ab837365db6bd40f479406758John McCall ObjCDeclSpec &OCDS, SourceLocation AtLoc, 261d0014540005f2a5ab837365db6bd40f479406758John McCall tok::ObjCKeywordKind MethodImplKind) : 262d0014540005f2a5ab837365db6bd40f479406758John McCall P(P), IDecl(IDecl), Props(Props), OCDS(OCDS), AtLoc(AtLoc), 263d0014540005f2a5ab837365db6bd40f479406758John McCall MethodImplKind(MethodImplKind) { 264d0014540005f2a5ab837365db6bd40f479406758John McCall } 265d0014540005f2a5ab837365db6bd40f479406758John McCall 266d0014540005f2a5ab837365db6bd40f479406758John McCall DeclPtrTy invoke(FieldDeclarator &FD) { 267d0014540005f2a5ab837365db6bd40f479406758John McCall if (FD.D.getIdentifier() == 0) { 268d0014540005f2a5ab837365db6bd40f479406758John McCall P.Diag(AtLoc, diag::err_objc_property_requires_field_name) 269d0014540005f2a5ab837365db6bd40f479406758John McCall << FD.D.getSourceRange(); 270d0014540005f2a5ab837365db6bd40f479406758John McCall return DeclPtrTy(); 271d0014540005f2a5ab837365db6bd40f479406758John McCall } 272d0014540005f2a5ab837365db6bd40f479406758John McCall if (FD.BitfieldSize) { 273d0014540005f2a5ab837365db6bd40f479406758John McCall P.Diag(AtLoc, diag::err_objc_property_bitfield) 274d0014540005f2a5ab837365db6bd40f479406758John McCall << FD.D.getSourceRange(); 275d0014540005f2a5ab837365db6bd40f479406758John McCall return DeclPtrTy(); 276d0014540005f2a5ab837365db6bd40f479406758John McCall } 277d0014540005f2a5ab837365db6bd40f479406758John McCall 278d0014540005f2a5ab837365db6bd40f479406758John McCall // Install the property declarator into interfaceDecl. 279d0014540005f2a5ab837365db6bd40f479406758John McCall IdentifierInfo *SelName = 280d0014540005f2a5ab837365db6bd40f479406758John McCall OCDS.getGetterName() ? OCDS.getGetterName() : FD.D.getIdentifier(); 281d0014540005f2a5ab837365db6bd40f479406758John McCall 282d0014540005f2a5ab837365db6bd40f479406758John McCall Selector GetterSel = 283d0014540005f2a5ab837365db6bd40f479406758John McCall P.PP.getSelectorTable().getNullarySelector(SelName); 284d0014540005f2a5ab837365db6bd40f479406758John McCall IdentifierInfo *SetterName = OCDS.getSetterName(); 285d0014540005f2a5ab837365db6bd40f479406758John McCall Selector SetterSel; 286d0014540005f2a5ab837365db6bd40f479406758John McCall if (SetterName) 287d0014540005f2a5ab837365db6bd40f479406758John McCall SetterSel = P.PP.getSelectorTable().getSelector(1, &SetterName); 288d0014540005f2a5ab837365db6bd40f479406758John McCall else 289d0014540005f2a5ab837365db6bd40f479406758John McCall SetterSel = SelectorTable::constructSetterName(P.PP.getIdentifierTable(), 290d0014540005f2a5ab837365db6bd40f479406758John McCall P.PP.getSelectorTable(), 291d0014540005f2a5ab837365db6bd40f479406758John McCall FD.D.getIdentifier()); 292d0014540005f2a5ab837365db6bd40f479406758John McCall bool isOverridingProperty = false; 293d0014540005f2a5ab837365db6bd40f479406758John McCall DeclPtrTy Property = 294d0014540005f2a5ab837365db6bd40f479406758John McCall P.Actions.ActOnProperty(P.CurScope, AtLoc, FD, OCDS, 295d0014540005f2a5ab837365db6bd40f479406758John McCall GetterSel, SetterSel, IDecl, 296d0014540005f2a5ab837365db6bd40f479406758John McCall &isOverridingProperty, 297d0014540005f2a5ab837365db6bd40f479406758John McCall MethodImplKind); 298d0014540005f2a5ab837365db6bd40f479406758John McCall if (!isOverridingProperty) 299d0014540005f2a5ab837365db6bd40f479406758John McCall Props.push_back(Property); 300d0014540005f2a5ab837365db6bd40f479406758John McCall 301d0014540005f2a5ab837365db6bd40f479406758John McCall return Property; 302d0014540005f2a5ab837365db6bd40f479406758John McCall } 303d0014540005f2a5ab837365db6bd40f479406758John McCall}; 304d0014540005f2a5ab837365db6bd40f479406758John McCall 305dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-interface-decl-list: 306dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// empty 307dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-interface-decl-list objc-property-decl [OBJC2] 308294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-interface-decl-list objc-method-requirement [OBJC2] 3093536b443bc50d58a79f14fca9b6842541a434854Steve Naroff/// objc-interface-decl-list objc-method-proto ';' 310dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-interface-decl-list declaration 311dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-interface-decl-list ';' 312dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 313294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-method-requirement: [OBJC2] 314294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// @required 315294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// @optional 316294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 317b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattnervoid Parser::ParseObjCInterfaceDeclList(DeclPtrTy interfaceDecl, 318cb53b361bce341c8591333c6997f62e480acc0b4Chris Lattner tok::ObjCKeywordKind contextKey) { 319b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner llvm::SmallVector<DeclPtrTy, 32> allMethods; 320b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner llvm::SmallVector<DeclPtrTy, 16> allProperties; 321682bf92db408a6cbc3d37b5496a99b6ef85041ecChris Lattner llvm::SmallVector<DeclGroupPtrTy, 8> allTUVariables; 32200933591a2795d09dd1acff12a2d21bce7cb12c5Fariborz Jahanian tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword; 3231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 324782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek SourceRange AtEnd; 325bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner 326294494e1cce92043562b4680c613df7fd028c02eSteve Naroff while (1) { 327e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner // If this is a method prototype, parse it. 328df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::minus) || Tok.is(tok::plus)) { 3291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DeclPtrTy methodPrototype = 330df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner ParseObjCMethodPrototype(interfaceDecl, MethodImplKind); 33125e077d59a8e8e43b65882b69610a3d5e2aaf53cFariborz Jahanian allMethods.push_back(methodPrototype); 3323536b443bc50d58a79f14fca9b6842541a434854Steve Naroff // Consume the ';' here, since ParseObjCMethodPrototype() is re-used for 3333536b443bc50d58a79f14fca9b6842541a434854Steve Naroff // method definitions. 334b6d74a158a9c002e3c0fcbda8ad8d0ccbb2e5088Chris Lattner ExpectAndConsume(tok::semi, diag::err_expected_semi_after_method_proto, 335b6d74a158a9c002e3c0fcbda8ad8d0ccbb2e5088Chris Lattner "", tok::semi); 336294494e1cce92043562b4680c613df7fd028c02eSteve Naroff continue; 337294494e1cce92043562b4680c613df7fd028c02eSteve Naroff } 33805511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian if (Tok.is(tok::l_paren)) { 33905511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian Diag(Tok, diag::err_expected_minus_or_plus); 34005511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian DeclPtrTy methodPrototype = ParseObjCMethodDecl(Tok.getLocation(), 34105511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian tok::minus, 34205511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian interfaceDecl, 34305511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian MethodImplKind); 34405511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian continue; 34505511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian } 346e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner // Ignore excess semicolons. 347e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner if (Tok.is(tok::semi)) { 348294494e1cce92043562b4680c613df7fd028c02eSteve Naroff ConsumeToken(); 349e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner continue; 350e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner } 3511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 352bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // If we got to the end of the file, exit the loop. 353e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner if (Tok.is(tok::eof)) 354e3a2ca7e30601cdd31c77a830f4cc487851e8096Fariborz Jahanian break; 3551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 356b6ac2451bfed36206c5cec7217372c4299f67f2bDouglas Gregor // Code completion within an Objective-C interface. 357b6ac2451bfed36206c5cec7217372c4299f67f2bDouglas Gregor if (Tok.is(tok::code_completion)) { 358b6ac2451bfed36206c5cec7217372c4299f67f2bDouglas Gregor Actions.CodeCompleteOrdinaryName(CurScope, 359b6ac2451bfed36206c5cec7217372c4299f67f2bDouglas Gregor ObjCImpDecl? Action::CCC_ObjCImplementation 360b6ac2451bfed36206c5cec7217372c4299f67f2bDouglas Gregor : Action::CCC_ObjCInterface); 361b6ac2451bfed36206c5cec7217372c4299f67f2bDouglas Gregor ConsumeToken(); 362b6ac2451bfed36206c5cec7217372c4299f67f2bDouglas Gregor } 363b6ac2451bfed36206c5cec7217372c4299f67f2bDouglas Gregor 364e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner // If we don't have an @ directive, parse it as a function definition. 365e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner if (Tok.isNot(tok::at)) { 3661fd80116b49782c367ff5d5f50a8b76dd8a5d7f7Chris Lattner // The code below does not consume '}'s because it is afraid of eating the 3671fd80116b49782c367ff5d5f50a8b76dd8a5d7f7Chris Lattner // end of a namespace. Because of the way this code is structured, an 3681fd80116b49782c367ff5d5f50a8b76dd8a5d7f7Chris Lattner // erroneous r_brace would cause an infinite loop if not handled here. 3691fd80116b49782c367ff5d5f50a8b76dd8a5d7f7Chris Lattner if (Tok.is(tok::r_brace)) 3701fd80116b49782c367ff5d5f50a8b76dd8a5d7f7Chris Lattner break; 3711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3724985aceceb9b9261b876b515d32726175c13a775Steve Naroff // FIXME: as the name implies, this rule allows function definitions. 3734985aceceb9b9261b876b515d32726175c13a775Steve Naroff // We could pass a flag or check for functions during semantic analysis. 374bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt allTUVariables.push_back(ParseDeclarationOrFunctionDefinition(0)); 375e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner continue; 376e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner } 3771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 378e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner // Otherwise, we have an @ directive, eat the @. 379e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner SourceLocation AtLoc = ConsumeToken(); // the "@" 380c464ae8444edb6d07ea49b7a0eae1674c0fa1bb8Douglas Gregor if (Tok.is(tok::code_completion)) { 381c464ae8444edb6d07ea49b7a0eae1674c0fa1bb8Douglas Gregor Actions.CodeCompleteObjCAtDirective(CurScope, ObjCImpDecl, true); 382c464ae8444edb6d07ea49b7a0eae1674c0fa1bb8Douglas Gregor ConsumeToken(); 383c464ae8444edb6d07ea49b7a0eae1674c0fa1bb8Douglas Gregor break; 384c464ae8444edb6d07ea49b7a0eae1674c0fa1bb8Douglas Gregor } 385c464ae8444edb6d07ea49b7a0eae1674c0fa1bb8Douglas Gregor 386a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner tok::ObjCKeywordKind DirectiveKind = Tok.getObjCKeywordID(); 3871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 388a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner if (DirectiveKind == tok::objc_end) { // @end -> terminate list 389782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek AtEnd.setBegin(AtLoc); 390782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek AtEnd.setEnd(Tok.getLocation()); 391e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner break; 392c3d43b783dfb1a1502aa8b31ab1985cf237b1f77Douglas Gregor } else if (DirectiveKind == tok::objc_not_keyword) { 393c3d43b783dfb1a1502aa8b31ab1985cf237b1f77Douglas Gregor Diag(Tok, diag::err_objc_unknown_at); 394c3d43b783dfb1a1502aa8b31ab1985cf237b1f77Douglas Gregor SkipUntil(tok::semi); 395c3d43b783dfb1a1502aa8b31ab1985cf237b1f77Douglas Gregor continue; 396bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner } 3971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 398bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // Eat the identifier. 399bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner ConsumeToken(); 400bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner 401a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner switch (DirectiveKind) { 402a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner default: 403bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // FIXME: If someone forgets an @end on a protocol, this loop will 404bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // continue to eat up tons of stuff and spew lots of nonsense errors. It 405bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // would probably be better to bail out if we saw an @class or @interface 406bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // or something like that. 407f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner Diag(AtLoc, diag::err_objc_illegal_interface_qual); 408bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // Skip until we see an '@' or '}' or ';'. 409a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner SkipUntil(tok::r_brace, tok::at); 410a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner break; 4111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 412a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner case tok::objc_required: 413a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner case tok::objc_optional: 414a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner // This is only valid on protocols. 415bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // FIXME: Should this check for ObjC2 being enabled? 416e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner if (contextKey != tok::objc_protocol) 417bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner Diag(AtLoc, diag::err_objc_directive_only_in_protocol); 418a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner else 419bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner MethodImplKind = DirectiveKind; 420a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner break; 4211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 422a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner case tok::objc_property: 423f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner if (!getLang().ObjC2) 424f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner Diag(AtLoc, diag::err_objc_propertoes_require_objc2); 425f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner 426e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner ObjCDeclSpec OCDS; 4271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // Parse property attribute list, if any. 4288ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner if (Tok.is(tok::l_paren)) 4294ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor ParseObjCPropertyAttribute(OCDS, interfaceDecl, 4304ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor allMethods.data(), allMethods.size()); 4311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 432d0014540005f2a5ab837365db6bd40f479406758John McCall ObjCPropertyCallback Callback(*this, interfaceDecl, allProperties, 433d0014540005f2a5ab837365db6bd40f479406758John McCall OCDS, AtLoc, MethodImplKind); 434bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall 435e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner // Parse all the comma separated declarators. 436e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner DeclSpec DS; 437bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall ParseStructDeclaration(DS, Callback); 4381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 439a1fed7e3beebf9bb1bc85123f283be3eb631c120Chris Lattner ExpectAndConsume(tok::semi, diag::err_expected_semi_decl_list, "", 440a1fed7e3beebf9bb1bc85123f283be3eb631c120Chris Lattner tok::at); 441a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner break; 442f28b264437053fb0deacc9ba02b18a0966f7290aSteve Naroff } 443294494e1cce92043562b4680c613df7fd028c02eSteve Naroff } 444bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner 445bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // We break out of the big loop in two cases: when we see @end or when we see 446bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // EOF. In the former case, eat the @end. In the later case, emit an error. 447c464ae8444edb6d07ea49b7a0eae1674c0fa1bb8Douglas Gregor if (Tok.is(tok::code_completion)) { 448c464ae8444edb6d07ea49b7a0eae1674c0fa1bb8Douglas Gregor Actions.CodeCompleteObjCAtDirective(CurScope, ObjCImpDecl, true); 449c464ae8444edb6d07ea49b7a0eae1674c0fa1bb8Douglas Gregor ConsumeToken(); 450c464ae8444edb6d07ea49b7a0eae1674c0fa1bb8Douglas Gregor } else if (Tok.isObjCAtKeyword(tok::objc_end)) 451bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner ConsumeToken(); // the "end" identifier 452bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner else 453bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner Diag(Tok, diag::err_objc_missing_end); 4541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 455a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner // Insert collected methods declarations into the @interface object. 456bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner // This passes in an invalid SourceLocation for AtEndLoc when EOF is hit. 457782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek Actions.ActOnAtEnd(AtEnd, interfaceDecl, 4581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump allMethods.data(), allMethods.size(), 459beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad allProperties.data(), allProperties.size(), 460beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad allTUVariables.data(), allTUVariables.size()); 461294494e1cce92043562b4680c613df7fd028c02eSteve Naroff} 462294494e1cce92043562b4680c613df7fd028c02eSteve Naroff 463d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// Parse property attribute declarations. 464d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// 465d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// property-attr-decl: '(' property-attrlist ')' 466d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// property-attrlist: 467d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// property-attribute 468d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// property-attrlist ',' property-attribute 469d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// property-attribute: 470d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// getter '=' identifier 471d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// setter '=' identifier ':' 472d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// readonly 473d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// readwrite 474d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// assign 475d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// retain 476d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// copy 477d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// nonatomic 478d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian/// 4794ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregorvoid Parser::ParseObjCPropertyAttribute(ObjCDeclSpec &DS, DeclPtrTy ClassDecl, 4804ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor DeclPtrTy *Methods, 4814ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor unsigned NumMethods) { 4828ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner assert(Tok.getKind() == tok::l_paren); 483dd5b5f2bb73d037745940431b71eb98393d12d4fChris Lattner SourceLocation LHSLoc = ConsumeParen(); // consume '(' 4841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 485cd9f4b31c4fe5b77b5519cc17b4583fab912bad1Chris Lattner while (1) { 486ece8e71d12b6f4cb2dc501297afef126dab8ad74Steve Naroff if (Tok.is(tok::code_completion)) { 487a93b108e025ef2480fa867cc533e7781a40a639bDouglas Gregor Actions.CodeCompleteObjCPropertyFlags(CurScope, DS); 488ece8e71d12b6f4cb2dc501297afef126dab8ad74Steve Naroff ConsumeToken(); 489ece8e71d12b6f4cb2dc501297afef126dab8ad74Steve Naroff } 490d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian const IdentifierInfo *II = Tok.getIdentifierInfo(); 4911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 492f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner // If this is not an identifier at all, bail out early. 493f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner if (II == 0) { 494f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner MatchRHSPunctuation(tok::r_paren, LHSLoc); 495f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner return; 496f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner } 4971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 498156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner SourceLocation AttrName = ConsumeToken(); // consume last attribute name 4991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 50092e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner if (II->isStr("readonly")) 501e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_readonly); 50292e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner else if (II->isStr("assign")) 503e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_assign); 50492e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner else if (II->isStr("readwrite")) 505e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_readwrite); 50692e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner else if (II->isStr("retain")) 507e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_retain); 50892e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner else if (II->isStr("copy")) 509e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_copy); 51092e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner else if (II->isStr("nonatomic")) 511e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_nonatomic); 51292e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner else if (II->isStr("getter") || II->isStr("setter")) { 513e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner // getter/setter require extra treatment. 514156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner if (ExpectAndConsume(tok::equal, diag::err_objc_expected_equal, "", 515156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner tok::r_paren)) 516dd5b5f2bb73d037745940431b71eb98393d12d4fChris Lattner return; 5171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5184ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor if (Tok.is(tok::code_completion)) { 5194ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor if (II->getNameStart()[0] == 's') 5204ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor Actions.CodeCompleteObjCPropertySetter(CurScope, ClassDecl, 5214ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor Methods, NumMethods); 5224ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor else 5234ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor Actions.CodeCompleteObjCPropertyGetter(CurScope, ClassDecl, 5244ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor Methods, NumMethods); 5254ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor ConsumeToken(); 5264ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor } 5274ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor 5288ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner if (Tok.isNot(tok::identifier)) { 5291ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_ident); 5308ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner SkipUntil(tok::r_paren); 5318ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner return; 5328ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner } 5331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 534e013d685c6689ac7ae103ee88acf573422d1ed6aDaniel Dunbar if (II->getNameStart()[0] == 's') { 5358ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_setter); 5368ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner DS.setSetterName(Tok.getIdentifierInfo()); 537156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner ConsumeToken(); // consume method name 5381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 539e0097db2848c463a534c18c235c6d3e53f2f1b87Fariborz Jahanian if (ExpectAndConsume(tok::colon, 540e0097db2848c463a534c18c235c6d3e53f2f1b87Fariborz Jahanian diag::err_expected_colon_after_setter_name, "", 541156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner tok::r_paren)) 5428ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner return; 5438ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner } else { 5448ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_getter); 5458ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner DS.setGetterName(Tok.getIdentifierInfo()); 546156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner ConsumeToken(); // consume method name 5478ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner } 548e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner } else { 549a9500f05ba6c09bbd84d342236863833067cd816Chris Lattner Diag(AttrName, diag::err_objc_expected_property_attr) << II; 550cd9f4b31c4fe5b77b5519cc17b4583fab912bad1Chris Lattner SkipUntil(tok::r_paren); 551cd9f4b31c4fe5b77b5519cc17b4583fab912bad1Chris Lattner return; 552cd9f4b31c4fe5b77b5519cc17b4583fab912bad1Chris Lattner } 5531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 554156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner if (Tok.isNot(tok::comma)) 555156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner break; 5561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 557156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner ConsumeToken(); 558d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian } 5591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 560156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner MatchRHSPunctuation(tok::r_paren, LHSLoc); 561d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian} 562d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian 5633536b443bc50d58a79f14fca9b6842541a434854Steve Naroff/// objc-method-proto: 5641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// objc-instance-method objc-method-decl objc-method-attributes[opt] 5653536b443bc50d58a79f14fca9b6842541a434854Steve Naroff/// objc-class-method objc-method-decl objc-method-attributes[opt] 566294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 567294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-instance-method: '-' 568294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-class-method: '+' 569294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 5704985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-method-attributes: [OBJC2] 5714985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// __attribute__((deprecated)) 5724985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// 5731eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpParser::DeclPtrTy Parser::ParseObjCMethodPrototype(DeclPtrTy IDecl, 574b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner tok::ObjCKeywordKind MethodImplKind) { 575df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner assert((Tok.is(tok::minus) || Tok.is(tok::plus)) && "expected +/-"); 576294494e1cce92043562b4680c613df7fd028c02eSteve Naroff 5771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump tok::TokenKind methodType = Tok.getKind(); 578bef1185418705e16012b3dd50cd7c260c8d6b79cSteve Naroff SourceLocation mLoc = ConsumeToken(); 5791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 580b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy MDecl = ParseObjCMethodDecl(mLoc, methodType, IDecl,MethodImplKind); 5813536b443bc50d58a79f14fca9b6842541a434854Steve Naroff // Since this rule is used for both method declarations and definitions, 5822bd42fadafddc8acf744b57a970bdc96a077c617Steve Naroff // the caller is (optionally) responsible for consuming the ';'. 583f28b264437053fb0deacc9ba02b18a0966f7290aSteve Naroff return MDecl; 584294494e1cce92043562b4680c613df7fd028c02eSteve Naroff} 585294494e1cce92043562b4680c613df7fd028c02eSteve Naroff 586294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-selector: 587294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// identifier 588294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// one of 589294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// enum struct union if else while do for switch case default 590294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// break continue return goto asm sizeof typeof __alignof 591294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// unsigned long const short volatile signed restrict _Complex 592294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// in out inout bycopy byref oneway int char float double void _Bool 593294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 5942fc5c2428ecb450a3256c8316b93b8655cb76a0fChris LattnerIdentifierInfo *Parser::ParseObjCSelectorPiece(SourceLocation &SelectorLoc) { 595ff38491c18b060526d754765b952f4a497a89416Chris Lattner switch (Tok.getKind()) { 596ff38491c18b060526d754765b952f4a497a89416Chris Lattner default: 597ff38491c18b060526d754765b952f4a497a89416Chris Lattner return 0; 598ff38491c18b060526d754765b952f4a497a89416Chris Lattner case tok::identifier: 599ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_asm: 600ff38491c18b060526d754765b952f4a497a89416Chris Lattner case tok::kw_auto: 6019298d9655aed28b2d9f6cc65c81401b209f03fdcChris Lattner case tok::kw_bool: 602ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_break: 603ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_case: 604ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_catch: 605ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_char: 606ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_class: 607ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_const: 608ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_const_cast: 609ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_continue: 610ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_default: 611ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_delete: 612ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_do: 613ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_double: 614ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_dynamic_cast: 615ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_else: 616ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_enum: 617ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_explicit: 618ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_export: 619ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_extern: 620ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_false: 621ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_float: 622ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_for: 623ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_friend: 624ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_goto: 625ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_if: 626ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_inline: 627ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_int: 628ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_long: 629ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_mutable: 630ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_namespace: 631ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_new: 632ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_operator: 633ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_private: 634ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_protected: 635ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_public: 636ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_register: 637ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_reinterpret_cast: 638ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_restrict: 639ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_return: 640ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_short: 641ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_signed: 642ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_sizeof: 643ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_static: 644ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_static_cast: 645ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_struct: 646ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_switch: 647ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_template: 648ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_this: 649ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_throw: 650ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_true: 651ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_try: 652ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_typedef: 653ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_typeid: 654ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_typename: 655ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_typeof: 656ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_union: 657ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_unsigned: 658ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_using: 659ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_virtual: 660ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_void: 661ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_volatile: 662ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_wchar_t: 663ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw_while: 664ff38491c18b060526d754765b952f4a497a89416Chris Lattner case tok::kw__Bool: 665ff38491c18b060526d754765b952f4a497a89416Chris Lattner case tok::kw__Complex: 666ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson case tok::kw___alignof: 667ff38491c18b060526d754765b952f4a497a89416Chris Lattner IdentifierInfo *II = Tok.getIdentifierInfo(); 6684b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian SelectorLoc = ConsumeToken(); 669ff38491c18b060526d754765b952f4a497a89416Chris Lattner return II; 670d064951b0dcc95f8604d0d69ae82d9ecbd38c796Fariborz Jahanian } 671294494e1cce92043562b4680c613df7fd028c02eSteve Naroff} 672294494e1cce92043562b4680c613df7fd028c02eSteve Naroff 6730196cab54007ff072ec2642da8911c6b7e8d3fb5Fariborz Jahanian/// objc-for-collection-in: 'in' 6740196cab54007ff072ec2642da8911c6b7e8d3fb5Fariborz Jahanian/// 675335a2d4122e41343fe11a775889b8bec5b14be60Fariborz Jahanianbool Parser::isTokIdentifier_in() const { 6763ba5a0f90a03d5e13d02cbee9abd2a1ba01b18bcFariborz Jahanian // FIXME: May have to do additional look-ahead to only allow for 6773ba5a0f90a03d5e13d02cbee9abd2a1ba01b18bcFariborz Jahanian // valid tokens following an 'in'; such as an identifier, unary operators, 6783ba5a0f90a03d5e13d02cbee9abd2a1ba01b18bcFariborz Jahanian // '[' etc. 6791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return (getLang().ObjC2 && Tok.is(tok::identifier) && 6805ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner Tok.getIdentifierInfo() == ObjCTypeQuals[objc_in]); 6810196cab54007ff072ec2642da8911c6b7e8d3fb5Fariborz Jahanian} 6820196cab54007ff072ec2642da8911c6b7e8d3fb5Fariborz Jahanian 683a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ParseObjCTypeQualifierList - This routine parses the objective-c's type 684e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner/// qualifier list and builds their bitmask representation in the input 685e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner/// argument. 686294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 687294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-type-qualifiers: 688294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-type-qualifier 689294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-type-qualifiers objc-type-qualifier 690294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 691a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekvoid Parser::ParseObjCTypeQualifierList(ObjCDeclSpec &DS) { 692e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner while (1) { 693cb53b361bce341c8591333c6997f62e480acc0b4Chris Lattner if (Tok.isNot(tok::identifier)) 694e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner return; 6951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 696e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner const IdentifierInfo *II = Tok.getIdentifierInfo(); 697e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner for (unsigned i = 0; i != objc_NumQuals; ++i) { 698a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek if (II != ObjCTypeQuals[i]) 699e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner continue; 7001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 701a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCDeclSpec::ObjCDeclQualifier Qual; 702e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner switch (i) { 703e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner default: assert(0 && "Unknown decl qualifier"); 704a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek case objc_in: Qual = ObjCDeclSpec::DQ_In; break; 705a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek case objc_out: Qual = ObjCDeclSpec::DQ_Out; break; 706a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek case objc_inout: Qual = ObjCDeclSpec::DQ_Inout; break; 707a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek case objc_oneway: Qual = ObjCDeclSpec::DQ_Oneway; break; 708a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek case objc_bycopy: Qual = ObjCDeclSpec::DQ_Bycopy; break; 709a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek case objc_byref: Qual = ObjCDeclSpec::DQ_Byref; break; 710e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner } 711a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek DS.setObjCDeclQualifier(Qual); 712e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner ConsumeToken(); 713e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner II = 0; 714e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner break; 715e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner } 7161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 717e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner // If this wasn't a recognized qualifier, bail out. 718e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner if (II) return; 719e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner } 720e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner} 721e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner 722e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner/// objc-type-name: 723e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner/// '(' objc-type-qualifiers[opt] type-name ')' 724e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner/// '(' objc-type-qualifiers[opt] ')' 725e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner/// 726a526c5c67e5a0473c340903ee542ce570119665fTed KremenekParser::TypeTy *Parser::ParseObjCTypeName(ObjCDeclSpec &DS) { 727df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner assert(Tok.is(tok::l_paren) && "expected ("); 7281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7294a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner SourceLocation LParenLoc = ConsumeParen(); 730e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner SourceLocation TypeStartLoc = Tok.getLocation(); 7311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 73219d74e1494fe399f0e2a94e9419c095f8214851bFariborz Jahanian // Parse type qualifiers, in, inout, etc. 733a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ParseObjCTypeQualifierList(DS); 7344fa7afd07421e7276d1717e4fdf43a5fdd65a622Steve Naroff 7354a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner TypeTy *Ty = 0; 736809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor if (isTypeSpecifierQualifier()) { 737809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor TypeResult TypeSpec = ParseTypeName(); 738809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor if (!TypeSpec.isInvalid()) 739809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor Ty = TypeSpec.get(); 740809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor } 7411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7424a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner if (Tok.is(tok::r_paren)) 7434a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner ConsumeParen(); 7444a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner else if (Tok.getLocation() == TypeStartLoc) { 745e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner // If we didn't eat any tokens, then this isn't a type. 7461ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_type); 7474a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner SkipUntil(tok::r_paren); 7484a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner } else { 7494a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner // Otherwise, we found *something*, but didn't get a ')' in the right 7504a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner // place. Emit an error then return what we have as the type. 7514a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner MatchRHSPunctuation(tok::r_paren, LParenLoc); 752294494e1cce92043562b4680c613df7fd028c02eSteve Naroff } 753f28b264437053fb0deacc9ba02b18a0966f7290aSteve Naroff return Ty; 754294494e1cce92043562b4680c613df7fd028c02eSteve Naroff} 755294494e1cce92043562b4680c613df7fd028c02eSteve Naroff 756294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-method-decl: 757294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-selector 7584985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-keyword-selector objc-parmlist[opt] 759294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-type-name objc-selector 7604985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-type-name objc-keyword-selector objc-parmlist[opt] 761294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 762294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-keyword-selector: 7631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// objc-keyword-decl 764294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-keyword-selector objc-keyword-decl 765294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 766294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// objc-keyword-decl: 7677ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// objc-selector ':' objc-type-name objc-keyword-attributes[opt] identifier 7687ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// objc-selector ':' objc-keyword-attributes[opt] identifier 7697ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// ':' objc-type-name objc-keyword-attributes[opt] identifier 7707ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// ':' objc-keyword-attributes[opt] identifier 771294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 7724985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-parmlist: 7734985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-parms objc-ellipsis[opt] 774294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 7754985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-parms: 7764985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-parms , parameter-declaration 777294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 7784985aceceb9b9261b876b515d32726175c13a775Steve Naroff/// objc-ellipsis: 779294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// , ... 780294494e1cce92043562b4680c613df7fd028c02eSteve Naroff/// 7817ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// objc-keyword-attributes: [OBJC2] 7827ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// __attribute__((unused)) 7837ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff/// 784b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris LattnerParser::DeclPtrTy Parser::ParseObjCMethodDecl(SourceLocation mLoc, 785b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner tok::TokenKind mType, 786b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy IDecl, 787b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner tok::ObjCKeywordKind MethodImplKind) { 78854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ParsingDeclRAIIObject PD(*this); 78954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 790e8f5a1710a7738deff40e10efcd05b1bd6af184fDouglas Gregor if (Tok.is(tok::code_completion)) { 791e8f5a1710a7738deff40e10efcd05b1bd6af184fDouglas Gregor Actions.CodeCompleteObjCMethodDecl(CurScope, mType == tok::minus, 792e8f5a1710a7738deff40e10efcd05b1bd6af184fDouglas Gregor /*ReturnType=*/0, IDecl); 793e8f5a1710a7738deff40e10efcd05b1bd6af184fDouglas Gregor ConsumeToken(); 794e8f5a1710a7738deff40e10efcd05b1bd6af184fDouglas Gregor } 795e8f5a1710a7738deff40e10efcd05b1bd6af184fDouglas Gregor 796e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner // Parse the return type if present. 797ff38491c18b060526d754765b952f4a497a89416Chris Lattner TypeTy *ReturnType = 0; 798a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCDeclSpec DSRet; 799df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::l_paren)) 800f1de0ca05e2df6f23bd559028693a12d1ebdaaf6Fariborz Jahanian ReturnType = ParseObjCTypeName(DSRet); 8011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8029e0493576af77dba1c48858c03e31a2897d0681eTed Kremenek // If attributes exist before the method, parse them. 8039e0493576af77dba1c48858c03e31a2897d0681eTed Kremenek llvm::OwningPtr<AttributeList> MethodAttrs; 8049e0493576af77dba1c48858c03e31a2897d0681eTed Kremenek if (getLang().ObjC2 && Tok.is(tok::kw___attribute)) 8059e0493576af77dba1c48858c03e31a2897d0681eTed Kremenek MethodAttrs.reset(ParseGNUAttributes()); 8069e0493576af77dba1c48858c03e31a2897d0681eTed Kremenek 807e8f5a1710a7738deff40e10efcd05b1bd6af184fDouglas Gregor if (Tok.is(tok::code_completion)) { 808e8f5a1710a7738deff40e10efcd05b1bd6af184fDouglas Gregor Actions.CodeCompleteObjCMethodDecl(CurScope, mType == tok::minus, 809e8f5a1710a7738deff40e10efcd05b1bd6af184fDouglas Gregor ReturnType, IDecl); 810e8f5a1710a7738deff40e10efcd05b1bd6af184fDouglas Gregor ConsumeToken(); 811e8f5a1710a7738deff40e10efcd05b1bd6af184fDouglas Gregor } 812e8f5a1710a7738deff40e10efcd05b1bd6af184fDouglas Gregor 8139e0493576af77dba1c48858c03e31a2897d0681eTed Kremenek // Now parse the selector. 814bef1185418705e16012b3dd50cd7c260c8d6b79cSteve Naroff SourceLocation selLoc; 8152fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner IdentifierInfo *SelIdent = ParseObjCSelectorPiece(selLoc); 816e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner 81784c431088693e216193094d1dbf327a01173f57fSteve Naroff // An unnamed colon is valid. 81884c431088693e216193094d1dbf327a01173f57fSteve Naroff if (!SelIdent && Tok.isNot(tok::colon)) { // missing selector name. 8191ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_selector_for_method) 8201ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner << SourceRange(mLoc, Tok.getLocation()); 821e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner // Skip until we get a ; or {}. 822e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner SkipUntil(tok::r_brace); 823b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 824e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner } 8251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8264f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian llvm::SmallVector<DeclaratorChunk::ParamInfo, 8> CParamInfo; 827df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::colon)) { 828ff38491c18b060526d754765b952f4a497a89416Chris Lattner // If attributes exist after the method, parse them. 8291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (getLang().ObjC2 && Tok.is(tok::kw___attribute)) 8309e0493576af77dba1c48858c03e31a2897d0681eTed Kremenek MethodAttrs.reset(addAttributeLists(MethodAttrs.take(), 8319e0493576af77dba1c48858c03e31a2897d0681eTed Kremenek ParseGNUAttributes())); 8321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 833ff38491c18b060526d754765b952f4a497a89416Chris Lattner Selector Sel = PP.getSelectorTable().getNullarySelector(SelIdent); 83454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall DeclPtrTy Result 83554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall = Actions.ActOnMethodDeclaration(mLoc, Tok.getLocation(), 8361f7b6f88f18d7f6b10265acec5d41c4ed1897487Fariborz Jahanian mType, IDecl, DSRet, ReturnType, Sel, 8374f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian 0, 8384f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian CParamInfo.data(), CParamInfo.size(), 8394f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian MethodAttrs.get(), 8401c6a3cc88177c67498fccdf14cfdf09959214e41Ted Kremenek MethodImplKind); 84154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall PD.complete(Result); 84254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall return Result; 843ff38491c18b060526d754765b952f4a497a89416Chris Lattner } 844f28b264437053fb0deacc9ba02b18a0966f7290aSteve Naroff 84568d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff llvm::SmallVector<IdentifierInfo *, 12> KeyIdents; 846e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner llvm::SmallVector<Action::ObjCArgInfo, 12> ArgInfos; 8471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 848ff38491c18b060526d754765b952f4a497a89416Chris Lattner while (1) { 849e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner Action::ObjCArgInfo ArgInfo; 8501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 851ff38491c18b060526d754765b952f4a497a89416Chris Lattner // Each iteration parses a single keyword argument. 852df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::colon)) { 853ff38491c18b060526d754765b952f4a497a89416Chris Lattner Diag(Tok, diag::err_expected_colon); 854ff38491c18b060526d754765b952f4a497a89416Chris Lattner break; 855ff38491c18b060526d754765b952f4a497a89416Chris Lattner } 856ff38491c18b060526d754765b952f4a497a89416Chris Lattner ConsumeToken(); // Eat the ':'. 8571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 858e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner ArgInfo.Type = 0; 859e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner if (Tok.is(tok::l_paren)) // Parse the argument type if present. 860e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner ArgInfo.Type = ParseObjCTypeName(ArgInfo.DeclSpec); 861e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner 862ff38491c18b060526d754765b952f4a497a89416Chris Lattner // If attributes exist before the argument name, parse them. 863e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner ArgInfo.ArgAttrs = 0; 864df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (getLang().ObjC2 && Tok.is(tok::kw___attribute)) 865bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt ArgInfo.ArgAttrs = ParseGNUAttributes(); 8667ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff 867df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 868ff38491c18b060526d754765b952f4a497a89416Chris Lattner Diag(Tok, diag::err_expected_ident); // missing argument name. 869ff38491c18b060526d754765b952f4a497a89416Chris Lattner break; 8704985aceceb9b9261b876b515d32726175c13a775Steve Naroff } 8711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 872e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner ArgInfo.Name = Tok.getIdentifierInfo(); 873e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner ArgInfo.NameLoc = Tok.getLocation(); 874ff38491c18b060526d754765b952f4a497a89416Chris Lattner ConsumeToken(); // Eat the identifier. 8751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 876e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner ArgInfos.push_back(ArgInfo); 877e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner KeyIdents.push_back(SelIdent); 878e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner 879ff38491c18b060526d754765b952f4a497a89416Chris Lattner // Check for another keyword selector. 8804b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian SourceLocation Loc; 8812fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner SelIdent = ParseObjCSelectorPiece(Loc); 882df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (!SelIdent && Tok.isNot(tok::colon)) 883ff38491c18b060526d754765b952f4a497a89416Chris Lattner break; 884ff38491c18b060526d754765b952f4a497a89416Chris Lattner // We have a selector or a colon, continue parsing. 885ff38491c18b060526d754765b952f4a497a89416Chris Lattner } 8861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 887335eafa5be51f6440672a74c73d588af72e96732Steve Naroff bool isVariadic = false; 8881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 889ff38491c18b060526d754765b952f4a497a89416Chris Lattner // Parse the (optional) parameter list. 890df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner while (Tok.is(tok::comma)) { 891ff38491c18b060526d754765b952f4a497a89416Chris Lattner ConsumeToken(); 892df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::ellipsis)) { 893335eafa5be51f6440672a74c73d588af72e96732Steve Naroff isVariadic = true; 8944985aceceb9b9261b876b515d32726175c13a775Steve Naroff ConsumeToken(); 895ff38491c18b060526d754765b952f4a497a89416Chris Lattner break; 8964985aceceb9b9261b876b515d32726175c13a775Steve Naroff } 897ff38491c18b060526d754765b952f4a497a89416Chris Lattner DeclSpec DS; 898ff38491c18b060526d754765b952f4a497a89416Chris Lattner ParseDeclarationSpecifiers(DS); 8991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // Parse the declarator. 900ff38491c18b060526d754765b952f4a497a89416Chris Lattner Declarator ParmDecl(DS, Declarator::PrototypeContext); 901ff38491c18b060526d754765b952f4a497a89416Chris Lattner ParseDeclarator(ParmDecl); 9024f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian IdentifierInfo *ParmII = ParmDecl.getIdentifier(); 9034f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian DeclPtrTy Param = Actions.ActOnParamDeclarator(CurScope, ParmDecl); 9044f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian CParamInfo.push_back(DeclaratorChunk::ParamInfo(ParmII, 9054f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian ParmDecl.getIdentifierLoc(), 9064f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian Param, 9074f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian 0)); 9084f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian 9094985aceceb9b9261b876b515d32726175c13a775Steve Naroff } 9101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 911ff38491c18b060526d754765b952f4a497a89416Chris Lattner // FIXME: Add support for optional parmameter list... 912e3a2ca7e30601cdd31c77a830f4cc487851e8096Fariborz Jahanian // If attributes exist after the method, parse them. 9131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (getLang().ObjC2 && Tok.is(tok::kw___attribute)) 9149e0493576af77dba1c48858c03e31a2897d0681eTed Kremenek MethodAttrs.reset(addAttributeLists(MethodAttrs.take(), 9159e0493576af77dba1c48858c03e31a2897d0681eTed Kremenek ParseGNUAttributes())); 9161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9173688fc679389d67b6755e62406998f9ea84d886aFariborz Jahanian if (KeyIdents.size() == 0) 9183688fc679389d67b6755e62406998f9ea84d886aFariborz Jahanian return DeclPtrTy(); 919ff38491c18b060526d754765b952f4a497a89416Chris Lattner Selector Sel = PP.getSelectorTable().getSelector(KeyIdents.size(), 920ff38491c18b060526d754765b952f4a497a89416Chris Lattner &KeyIdents[0]); 92154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall DeclPtrTy Result 92254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall = Actions.ActOnMethodDeclaration(mLoc, Tok.getLocation(), 9233688fc679389d67b6755e62406998f9ea84d886aFariborz Jahanian mType, IDecl, DSRet, ReturnType, Sel, 9244f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian &ArgInfos[0], 9254f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian CParamInfo.data(), CParamInfo.size(), 9261e37765c9257ef1d051f54a674eaa964bdba9693Ted Kremenek MethodAttrs.get(), 927335eafa5be51f6440672a74c73d588af72e96732Steve Naroff MethodImplKind, isVariadic); 92854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall PD.complete(Result); 9291e37765c9257ef1d051f54a674eaa964bdba9693Ted Kremenek 9301e37765c9257ef1d051f54a674eaa964bdba9693Ted Kremenek // Delete referenced AttributeList objects. 9311e37765c9257ef1d051f54a674eaa964bdba9693Ted Kremenek for (llvm::SmallVectorImpl<Action::ObjCArgInfo>::iterator 9321e37765c9257ef1d051f54a674eaa964bdba9693Ted Kremenek I = ArgInfos.begin(), E = ArgInfos.end(); I != E; ++I) 9331e37765c9257ef1d051f54a674eaa964bdba9693Ted Kremenek delete I->ArgAttrs; 9341e37765c9257ef1d051f54a674eaa964bdba9693Ted Kremenek 93554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall return Result; 936294494e1cce92043562b4680c613df7fd028c02eSteve Naroff} 937294494e1cce92043562b4680c613df7fd028c02eSteve Naroff 938dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-refs: 939dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// '<' identifier-list '>' 940dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 9417caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattnerbool Parser:: 942b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris LattnerParseObjCProtocolReferences(llvm::SmallVectorImpl<Action::DeclPtrTy> &Protocols, 94371b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis llvm::SmallVectorImpl<SourceLocation> &ProtocolLocs, 94471b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis bool WarnOnDeclarations, 94571b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis SourceLocation &LAngleLoc, SourceLocation &EndLoc) { 946e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner assert(Tok.is(tok::less) && "expected <"); 9471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 94871b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis LAngleLoc = ConsumeToken(); // the "<" 9491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 950e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner llvm::SmallVector<IdentifierLocPair, 8> ProtocolIdents; 9511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 952e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner while (1) { 95355385fe3e723cd675001e45f42d61adde6b7f075Douglas Gregor if (Tok.is(tok::code_completion)) { 95455385fe3e723cd675001e45f42d61adde6b7f075Douglas Gregor Actions.CodeCompleteObjCProtocolReferences(ProtocolIdents.data(), 95555385fe3e723cd675001e45f42d61adde6b7f075Douglas Gregor ProtocolIdents.size()); 95655385fe3e723cd675001e45f42d61adde6b7f075Douglas Gregor ConsumeToken(); 95755385fe3e723cd675001e45f42d61adde6b7f075Douglas Gregor } 95855385fe3e723cd675001e45f42d61adde6b7f075Douglas Gregor 959e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner if (Tok.isNot(tok::identifier)) { 960e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner Diag(Tok, diag::err_expected_ident); 961e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner SkipUntil(tok::greater); 962e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner return true; 963e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner } 964e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner ProtocolIdents.push_back(std::make_pair(Tok.getIdentifierInfo(), 965e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner Tok.getLocation())); 96671b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis ProtocolLocs.push_back(Tok.getLocation()); 967e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner ConsumeToken(); 9681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 969e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner if (Tok.isNot(tok::comma)) 970e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner break; 971e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner ConsumeToken(); 972e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner } 9731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 974e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner // Consume the '>'. 975e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner if (Tok.isNot(tok::greater)) { 976e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner Diag(Tok, diag::err_expected_greater); 977e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner return true; 978e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner } 9791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 980e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner EndLoc = ConsumeAnyToken(); 9811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 982e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner // Convert the list of protocols identifiers into a list of protocol decls. 983e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner Actions.FindProtocolDeclaration(WarnOnDeclarations, 984e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner &ProtocolIdents[0], ProtocolIdents.size(), 985e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner Protocols); 986e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner return false; 987e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner} 988e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner 989dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-instance-variables: 990dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// '{' objc-instance-variable-decl-list[opt] '}' 991dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 992dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-instance-variable-decl-list: 993dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-visibility-spec 994dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-instance-variable-decl ';' 995dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// ';' 996dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-instance-variable-decl-list objc-visibility-spec 997dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-instance-variable-decl-list objc-instance-variable-decl ';' 998dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-instance-variable-decl-list ';' 999dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1000dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-visibility-spec: 1001dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @private 1002dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @protected 1003dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @public 1004ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff/// @package [OBJC2] 1005dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1006dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-instance-variable-decl: 10071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// struct-declaration 1008dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1009b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattnervoid Parser::ParseObjCClassInstanceVariables(DeclPtrTy interfaceDecl, 101083c481ade785a919ba21a33f9a8b1b21c1212fb3Fariborz Jahanian tok::ObjCKeywordKind visibility, 101160fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff SourceLocation atLoc) { 1012df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner assert(Tok.is(tok::l_brace) && "expected {"); 1013b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner llvm::SmallVector<DeclPtrTy, 32> AllIvarDecls; 1014e13594279a952537ac903325efff57e3edca79d9Chris Lattner 10151a0d31a3d7f14ddc6370ba912c778aece6c12cf0Douglas Gregor ParseScope ClassScope(this, Scope::DeclScope|Scope::ClassScope); 101672de6676bd30f9081ee4166bbe07b4c270258ce6Douglas Gregor 1017ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff SourceLocation LBraceLoc = ConsumeBrace(); // the "{" 10181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1019ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff // While we still have something to read, read the instance variables. 1020df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner while (Tok.isNot(tok::r_brace) && Tok.isNot(tok::eof)) { 1021ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff // Each iteration of this loop reads one objc-instance-variable-decl. 10221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1023ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff // Check for extraneous top-level semicolon. 1024df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::semi)) { 1025c2253f5ca170984fcd4f30f8823148e8cb71336bChris Lattner Diag(Tok, diag::ext_extra_struct_semi) 1026849b243d4065f56742a4677d6dc8277609a151f8Douglas Gregor << FixItHint::CreateRemoval(Tok.getLocation()); 1027ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff ConsumeToken(); 1028ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff continue; 1029ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff } 10301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1031ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff // Set the default visibility to private. 1032df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::at)) { // parse objc-visibility-spec 1033ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff ConsumeToken(); // eat the @ sign 1034c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor 1035c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor if (Tok.is(tok::code_completion)) { 1036c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor Actions.CodeCompleteObjCAtVisibility(CurScope); 1037c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor ConsumeToken(); 1038c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor } 1039c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor 1040861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff switch (Tok.getObjCKeywordID()) { 1041ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff case tok::objc_private: 1042ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff case tok::objc_public: 1043ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff case tok::objc_protected: 1044ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff case tok::objc_package: 1045861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff visibility = Tok.getObjCKeywordID(); 1046ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff ConsumeToken(); 10471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump continue; 1048ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff default: 1049ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff Diag(Tok, diag::err_objc_illegal_visibility_spec); 1050ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff continue; 1051ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff } 1052ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff } 10531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1054c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor if (Tok.is(tok::code_completion)) { 1055c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor Actions.CodeCompleteOrdinaryName(CurScope, 1056c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor Action::CCC_ObjCInstanceVariableList); 1057c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor ConsumeToken(); 1058c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor } 1059c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor 1060bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall struct ObjCIvarCallback : FieldCallback { 1061bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall Parser &P; 1062bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall DeclPtrTy IDecl; 1063bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall tok::ObjCKeywordKind visibility; 1064bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall llvm::SmallVectorImpl<DeclPtrTy> &AllIvarDecls; 1065bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall 1066bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall ObjCIvarCallback(Parser &P, DeclPtrTy IDecl, tok::ObjCKeywordKind V, 1067bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall llvm::SmallVectorImpl<DeclPtrTy> &AllIvarDecls) : 1068bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall P(P), IDecl(IDecl), visibility(V), AllIvarDecls(AllIvarDecls) { 1069bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall } 1070bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall 1071bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall DeclPtrTy invoke(FieldDeclarator &FD) { 1072bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall // Install the declarator into the interface decl. 1073bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall DeclPtrTy Field 1074bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall = P.Actions.ActOnIvar(P.CurScope, 1075bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall FD.D.getDeclSpec().getSourceRange().getBegin(), 1076bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall IDecl, FD.D, FD.BitfieldSize, visibility); 10770bd04596e4645ff145a046dfb3475f39674060d9Fariborz Jahanian if (Field) 10780bd04596e4645ff145a046dfb3475f39674060d9Fariborz Jahanian AllIvarDecls.push_back(Field); 1079bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall return Field; 1080bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall } 1081bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall } Callback(*this, interfaceDecl, visibility, AllIvarDecls); 1082bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall 1083e13594279a952537ac903325efff57e3edca79d9Chris Lattner // Parse all the comma separated declarators. 1084e13594279a952537ac903325efff57e3edca79d9Chris Lattner DeclSpec DS; 1085bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall ParseStructDeclaration(DS, Callback); 10861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1087df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::semi)) { 1088ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff ConsumeToken(); 1089ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff } else { 1090ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff Diag(Tok, diag::err_expected_semi_decl_list); 1091ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff // Skip to end of block or statement 1092ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff SkipUntil(tok::r_brace, true, true); 1093ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff } 1094ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff } 109560fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff SourceLocation RBraceLoc = MatchRHSPunctuation(tok::r_brace, LBraceLoc); 10968749be53f53384e7846502791ceda6c657228d07Steve Naroff // Call ActOnFields() even if we don't have any decls. This is useful 10978749be53f53384e7846502791ceda6c657228d07Steve Naroff // for code rewriting tools that need to be aware of the empty list. 10988749be53f53384e7846502791ceda6c657228d07Steve Naroff Actions.ActOnFields(CurScope, atLoc, interfaceDecl, 1099beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad AllIvarDecls.data(), AllIvarDecls.size(), 11001bfe1c2129771c06fb58ae5e8c079ae30e138309Daniel Dunbar LBraceLoc, RBraceLoc, 0); 1101ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff return; 11025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 1103dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff 1104dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-declaration: 1105dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-definition 1106dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-forward-reference 1107dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1108dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-definition: 11091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// @protocol identifier 11101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// objc-protocol-refs[opt] 11111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// objc-interface-decl-list 1112dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @end 1113dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1114dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-forward-reference: 1115dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @protocol identifier-list ';' 1116dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1117dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// "@protocol identifier ;" should be resolved as "@protocol 11183536b443bc50d58a79f14fca9b6842541a434854Steve Naroff/// identifier-list ;": objc-interface-decl-list may not start with a 1119dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// semicolon in the first alternative if objc-protocol-refs are omitted. 1120b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris LattnerParser::DeclPtrTy Parser::ParseObjCAtProtocolDeclaration(SourceLocation AtLoc, 1121b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner AttributeList *attrList) { 1122861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff assert(Tok.isObjCAtKeyword(tok::objc_protocol) && 11237ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff "ParseObjCAtProtocolDeclaration(): Expected @protocol"); 11247ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff ConsumeToken(); // the "protocol" identifier 11251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1126083128f6b13dfa4fc615a838c49b516d901b1ac0Douglas Gregor if (Tok.is(tok::code_completion)) { 1127083128f6b13dfa4fc615a838c49b516d901b1ac0Douglas Gregor Actions.CodeCompleteObjCProtocolDecl(CurScope); 1128083128f6b13dfa4fc615a838c49b516d901b1ac0Douglas Gregor ConsumeToken(); 1129083128f6b13dfa4fc615a838c49b516d901b1ac0Douglas Gregor } 1130083128f6b13dfa4fc615a838c49b516d901b1ac0Douglas Gregor 1131df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 11327ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff Diag(Tok, diag::err_expected_ident); // missing protocol name. 1133b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 11347ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff } 11357ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff // Save the protocol name, then consume it. 11367ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff IdentifierInfo *protocolName = Tok.getIdentifierInfo(); 11377ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff SourceLocation nameLoc = ConsumeToken(); 11381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1139df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::semi)) { // forward declaration of one protocol. 11407caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner IdentifierLocPair ProtoInfo(protocolName, nameLoc); 11417ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff ConsumeToken(); 11421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return Actions.ActOnForwardProtocolDeclaration(AtLoc, &ProtoInfo, 1, 1143bc1c877fe28fb6a825f0b226a0a2da99e713ea03Fariborz Jahanian attrList); 11447ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff } 11451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1146df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::comma)) { // list of forward declarations. 11477caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner llvm::SmallVector<IdentifierLocPair, 8> ProtocolRefs; 11487caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner ProtocolRefs.push_back(std::make_pair(protocolName, nameLoc)); 11497caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner 11507ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff // Parse the list of forward declarations. 11517ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff while (1) { 11527ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff ConsumeToken(); // the ',' 1153df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 11547ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff Diag(Tok, diag::err_expected_ident); 11557ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff SkipUntil(tok::semi); 1156b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 11577ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff } 11587caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner ProtocolRefs.push_back(IdentifierLocPair(Tok.getIdentifierInfo(), 11597caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner Tok.getLocation())); 11607ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff ConsumeToken(); // the identifier 11611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1162df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::comma)) 11637ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff break; 11647ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff } 11657ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff // Consume the ';'. 11667ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff if (ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@protocol")) 1167b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 11681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1169e440eb8158e71deb1e4ab11618ae3d680aac6da1Steve Naroff return Actions.ActOnForwardProtocolDeclaration(AtLoc, 11701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump &ProtocolRefs[0], 1171bc1c877fe28fb6a825f0b226a0a2da99e713ea03Fariborz Jahanian ProtocolRefs.size(), 1172bc1c877fe28fb6a825f0b226a0a2da99e713ea03Fariborz Jahanian attrList); 11737caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner } 11741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11757ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff // Last, and definitely not least, parse a protocol declaration. 117671b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis SourceLocation LAngleLoc, EndProtoLoc; 11777caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner 1178b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner llvm::SmallVector<DeclPtrTy, 8> ProtocolRefs; 117971b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis llvm::SmallVector<SourceLocation, 8> ProtocolLocs; 11807caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner if (Tok.is(tok::less) && 118171b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis ParseObjCProtocolReferences(ProtocolRefs, ProtocolLocs, false, 118271b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis LAngleLoc, EndProtoLoc)) 1183b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 11841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1185b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy ProtoType = 1186e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner Actions.ActOnStartProtocolInterface(AtLoc, protocolName, nameLoc, 1187beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad ProtocolRefs.data(), 1188beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad ProtocolRefs.size(), 118918df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor ProtocolLocs.data(), 1190246e70f69cb8aeb67225c54690f1c6b25abd5a86Daniel Dunbar EndProtoLoc, attrList); 119125e077d59a8e8e43b65882b69610a3d5e2aaf53cFariborz Jahanian ParseObjCInterfaceDeclList(ProtoType, tok::objc_protocol); 1192bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner return ProtoType; 1193dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff} 1194dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff 1195dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-implementation: 1196dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-implementation-prologue 1197dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-category-implementation-prologue 1198dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1199dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-implementation-prologue: 1200dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @implementation identifier objc-superclass[opt] 1201dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-instance-variables[opt] 1202dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1203dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-category-implementation-prologue: 1204dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @implementation identifier ( identifier ) 1205b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris LattnerParser::DeclPtrTy Parser::ParseObjCAtImplementationDeclaration( 1206ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian SourceLocation atLoc) { 1207ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian assert(Tok.isObjCAtKeyword(tok::objc_implementation) && 1208ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian "ParseObjCAtImplementationDeclaration(): Expected @implementation"); 1209ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); // the "implementation" identifier 12101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12113b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor // Code completion after '@implementation'. 12123b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor if (Tok.is(tok::code_completion)) { 12133b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor Actions.CodeCompleteObjCImplementationDecl(CurScope); 12143b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor ConsumeToken(); 12153b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor } 12163b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor 1217df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 1218ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian Diag(Tok, diag::err_expected_ident); // missing class or category name. 1219b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 1220ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1221ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian // We have a class or category name - consume it. 1222ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian IdentifierInfo *nameId = Tok.getIdentifierInfo(); 1223ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian SourceLocation nameLoc = ConsumeToken(); // consume class or category name 12241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (Tok.is(tok::l_paren)) { 1226ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian // we have a category implementation. 1227ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian SourceLocation lparenLoc = ConsumeParen(); 1228ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian SourceLocation categoryLoc, rparenLoc; 1229ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian IdentifierInfo *categoryId = 0; 12301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 123133ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor if (Tok.is(tok::code_completion)) { 123233ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor Actions.CodeCompleteObjCImplementationCategory(CurScope, nameId); 123333ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor ConsumeToken(); 123433ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor } 123533ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor 1236df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::identifier)) { 1237ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian categoryId = Tok.getIdentifierInfo(); 1238ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian categoryLoc = ConsumeToken(); 1239ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } else { 1240ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian Diag(Tok, diag::err_expected_ident); // missing category name. 1241b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 12421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 1243df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::r_paren)) { 1244ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian Diag(Tok, diag::err_expected_rparen); 1245ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian SkipUntil(tok::r_paren, false); // don't stop at ';' 1246b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 1247ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1248ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian rparenLoc = ConsumeParen(); 1249b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy ImplCatType = Actions.ActOnStartCategoryImplementation( 12501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump atLoc, nameId, nameLoc, categoryId, 12518f3fde00ad4d4f943321e338b914ae4740711c84Fariborz Jahanian categoryLoc); 1252a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCImpDecl = ImplCatType; 125363e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian PendingObjCImpDecl.push_back(ObjCImpDecl); 1254b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 1255ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1256ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian // We have a class implementation 1257ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian SourceLocation superClassLoc; 1258ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian IdentifierInfo *superClassId = 0; 1259df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::colon)) { 1260ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian // We have a super class 1261ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); 1262df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 1263ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian Diag(Tok, diag::err_expected_ident); // missing super class name. 1264b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 1265ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1266ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian superClassId = Tok.getIdentifierInfo(); 1267ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian superClassLoc = ConsumeToken(); // Consume super class name 1268ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1269b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy ImplClsType = Actions.ActOnStartClassImplementation( 1270cb53b361bce341c8591333c6997f62e480acc0b4Chris Lattner atLoc, nameId, nameLoc, 1271ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian superClassId, superClassLoc); 12721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 127360fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff if (Tok.is(tok::l_brace)) // we have ivars 127483c481ade785a919ba21a33f9a8b1b21c1212fb3Fariborz Jahanian ParseObjCClassInstanceVariables(ImplClsType/*FIXME*/, 127501f1bfc3284d5817517d35217885ea9ecb252817Fariborz Jahanian tok::objc_private, atLoc); 1276a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCImpDecl = ImplClsType; 127763e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian PendingObjCImpDecl.push_back(ObjCImpDecl); 127863e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian 1279b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 12805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 128160fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff 1282782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted KremenekParser::DeclPtrTy Parser::ParseObjCAtEndDeclaration(SourceRange atEnd) { 1283ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian assert(Tok.isObjCAtKeyword(tok::objc_end) && 1284ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian "ParseObjCAtEndDeclaration(): Expected @end"); 1285b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy Result = ObjCImpDecl; 1286ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); // the "end" identifier 1287a6e3ac514c924879699c6b0b1201028f0091044fFariborz Jahanian if (ObjCImpDecl) { 1288782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek Actions.ActOnAtEnd(atEnd, ObjCImpDecl); 1289b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner ObjCImpDecl = DeclPtrTy(); 129063e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian PendingObjCImpDecl.pop_back(); 1291a6e3ac514c924879699c6b0b1201028f0091044fFariborz Jahanian } 1292782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek else { 1293782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek // missing @implementation 1294782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek Diag(atEnd.getBegin(), diag::warn_expected_implementation); 1295782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek } 1296a6e3ac514c924879699c6b0b1201028f0091044fFariborz Jahanian return Result; 12975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 1298e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian 12991ac7104947020a60430ba6f519cd5869af77046fFariborz JahanianParser::DeclGroupPtrTy Parser::RetrievePendingObjCImpDecl() { 130063e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian if (PendingObjCImpDecl.empty()) 130163e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian return Actions.ConvertDeclToDeclGroup(DeclPtrTy()); 130263e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian DeclPtrTy ImpDecl = PendingObjCImpDecl.pop_back_val(); 1303782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek Actions.ActOnAtEnd(SourceRange(), ImpDecl); 130463e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian return Actions.ConvertDeclToDeclGroup(ImpDecl); 130563e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian} 130663e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian 1307e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian/// compatibility-alias-decl: 1308e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian/// @compatibility_alias alias-name class-name ';' 1309e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian/// 1310b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris LattnerParser::DeclPtrTy Parser::ParseObjCAtAliasDeclaration(SourceLocation atLoc) { 1311e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian assert(Tok.isObjCAtKeyword(tok::objc_compatibility_alias) && 1312e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian "ParseObjCAtAliasDeclaration(): Expected @compatibility_alias"); 1313e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian ConsumeToken(); // consume compatibility_alias 1314df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 1315e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian Diag(Tok, diag::err_expected_ident); 1316b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 1317e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian } 1318243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian IdentifierInfo *aliasId = Tok.getIdentifierInfo(); 1319243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian SourceLocation aliasLoc = ConsumeToken(); // consume alias-name 1320df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 1321e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian Diag(Tok, diag::err_expected_ident); 1322b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 1323e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian } 1324243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian IdentifierInfo *classId = Tok.getIdentifierInfo(); 1325243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian SourceLocation classLoc = ConsumeToken(); // consume class-name; 1326243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian if (Tok.isNot(tok::semi)) { 13271ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_semi_after) << "@compatibility_alias"; 1328b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 1329243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian } 1330b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return Actions.ActOnCompatiblityAlias(atLoc, aliasId, aliasLoc, 1331b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner classId, classLoc); 13325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 13335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1334ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-synthesis: 1335ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// @synthesize property-ivar-list ';' 1336ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// 1337ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-ivar-list: 1338ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-ivar 1339ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-ivar-list ',' property-ivar 1340ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// 1341ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-ivar: 1342ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// identifier 1343ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// identifier '=' identifier 1344ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// 1345b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris LattnerParser::DeclPtrTy Parser::ParseObjCPropertySynthesize(SourceLocation atLoc) { 1346ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian assert(Tok.isObjCAtKeyword(tok::objc_synthesize) && 1347ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian "ParseObjCPropertyDynamic(): Expected '@synthesize'"); 1348f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian SourceLocation loc = ConsumeToken(); // consume synthesize 13491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1350b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor while (true) { 1351322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor if (Tok.is(tok::code_completion)) { 1352424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor Actions.CodeCompleteObjCPropertyDefinition(CurScope, ObjCImpDecl); 1353322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor ConsumeToken(); 1354322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor } 1355322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor 1356b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor if (Tok.isNot(tok::identifier)) { 1357b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor Diag(Tok, diag::err_synthesized_property_name); 1358b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor SkipUntil(tok::semi); 1359b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor return DeclPtrTy(); 1360b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor } 1361b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor 1362f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian IdentifierInfo *propertyIvar = 0; 1363f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian IdentifierInfo *propertyId = Tok.getIdentifierInfo(); 1364f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian SourceLocation propertyLoc = ConsumeToken(); // consume property name 1365df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::equal)) { 1366ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian // property '=' ivar-name 1367ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); // consume '=' 1368322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor 1369322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor if (Tok.is(tok::code_completion)) { 1370322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor Actions.CodeCompleteObjCPropertySynthesizeIvar(CurScope, propertyId, 1371322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor ObjCImpDecl); 1372322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor ConsumeToken(); 1373322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor } 1374322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor 1375df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 1376ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian Diag(Tok, diag::err_expected_ident); 1377ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian break; 1378ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1379f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian propertyIvar = Tok.getIdentifierInfo(); 1380ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); // consume ivar-name 1381ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1382f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian Actions.ActOnPropertyImplDecl(atLoc, propertyLoc, true, ObjCImpDecl, 1383f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian propertyId, propertyIvar); 1384df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::comma)) 1385ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian break; 1386ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); // consume ',' 1387ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1388b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor if (Tok.isNot(tok::semi)) { 13891ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_semi_after) << "@synthesize"; 1390b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor SkipUntil(tok::semi); 1391b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor } 1392d3fdcb5a1bf6bd5e54e18579c054ea3c292a0e28Fariborz Jahanian else 1393d3fdcb5a1bf6bd5e54e18579c054ea3c292a0e28Fariborz Jahanian ConsumeToken(); // consume ';' 1394b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 1395ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian} 1396ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian 1397ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-dynamic: 1398ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// @dynamic property-list 1399ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// 1400ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-list: 1401ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// identifier 1402ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-list ',' identifier 1403ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// 1404b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris LattnerParser::DeclPtrTy Parser::ParseObjCPropertyDynamic(SourceLocation atLoc) { 1405ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian assert(Tok.isObjCAtKeyword(tok::objc_dynamic) && 1406ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian "ParseObjCPropertyDynamic(): Expected '@dynamic'"); 1407ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian SourceLocation loc = ConsumeToken(); // consume dynamic 1408424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor while (true) { 1409424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor if (Tok.is(tok::code_completion)) { 1410424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor Actions.CodeCompleteObjCPropertyDefinition(CurScope, ObjCImpDecl); 1411424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor ConsumeToken(); 1412424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor } 1413424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor 1414424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor if (Tok.isNot(tok::identifier)) { 1415424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor Diag(Tok, diag::err_expected_ident); 1416424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor SkipUntil(tok::semi); 1417424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor return DeclPtrTy(); 1418424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor } 1419424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor 1420c35b9e4e2efad727538c848cf30d4b0eb1031dc9Fariborz Jahanian IdentifierInfo *propertyId = Tok.getIdentifierInfo(); 1421c35b9e4e2efad727538c848cf30d4b0eb1031dc9Fariborz Jahanian SourceLocation propertyLoc = ConsumeToken(); // consume property name 1422c35b9e4e2efad727538c848cf30d4b0eb1031dc9Fariborz Jahanian Actions.ActOnPropertyImplDecl(atLoc, propertyLoc, false, ObjCImpDecl, 1423c35b9e4e2efad727538c848cf30d4b0eb1031dc9Fariborz Jahanian propertyId, 0); 1424c35b9e4e2efad727538c848cf30d4b0eb1031dc9Fariborz Jahanian 1425df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::comma)) 1426ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian break; 1427ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); // consume ',' 1428ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1429df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::semi)) 14301ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_semi_after) << "@dynamic"; 1431b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 1432ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian} 14331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1434397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// objc-throw-statement: 1435397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// throw expression[opt]; 1436397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// 143743bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian RedlParser::OwningStmtResult Parser::ParseObjCThrowStmt(SourceLocation atLoc) { 143815faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl OwningExprResult Res(Actions); 1439397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian ConsumeToken(); // consume throw 1440df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::semi)) { 144139f8f159c488a900e5958d5aab3e467af9ec8a2bFariborz Jahanian Res = ParseExpression(); 14420e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Res.isInvalid()) { 1443397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian SkipUntil(tok::semi); 144443bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 1445397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian } 1446397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian } 144739f8f159c488a900e5958d5aab3e467af9ec8a2bFariborz Jahanian ConsumeToken(); // consume ';' 1448e21dd6ffef4585fa43cd3586ed971217d65bf56cSteve Naroff return Actions.ActOnObjCAtThrowStmt(atLoc, move(Res), CurScope); 1449397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian} 1450397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian 1451c385c90c68dfa376650e2facfbb444b2ec9bd110Fariborz Jahanian/// objc-synchronized-statement: 145278a677bbb5fa115fa0995b5783adeeefad67167eFariborz Jahanian/// @synchronized '(' expression ')' compound-statement 1453c385c90c68dfa376650e2facfbb444b2ec9bd110Fariborz Jahanian/// 145443bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian RedlParser::OwningStmtResult 145543bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian RedlParser::ParseObjCSynchronizedStmt(SourceLocation atLoc) { 1456fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian ConsumeToken(); // consume synchronized 1457fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian if (Tok.isNot(tok::l_paren)) { 14581ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_lparen_after) << "@synchronized"; 145943bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 1460fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian } 1461fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian ConsumeParen(); // '(' 14622f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl OwningExprResult Res(ParseExpression()); 14630e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Res.isInvalid()) { 1464fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian SkipUntil(tok::semi); 146543bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 1466fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian } 1467fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian if (Tok.isNot(tok::r_paren)) { 14681ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_lbrace); 146943bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 1470fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian } 1471fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian ConsumeParen(); // ')' 147278a677bbb5fa115fa0995b5783adeeefad67167eFariborz Jahanian if (Tok.isNot(tok::l_brace)) { 14731ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_lbrace); 147443bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 147578a677bbb5fa115fa0995b5783adeeefad67167eFariborz Jahanian } 14763ac438c383a4a9a73c76a05c76ec5d02f10a3c52Steve Naroff // Enter a scope to hold everything within the compound stmt. Compound 14773ac438c383a4a9a73c76a05c76ec5d02f10a3c52Steve Naroff // statements can always hold declarations. 14788935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor ParseScope BodyScope(this, Scope::DeclScope); 14793ac438c383a4a9a73c76a05c76ec5d02f10a3c52Steve Naroff 148061364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl OwningStmtResult SynchBody(ParseCompoundStatementBody()); 14810e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl 14828935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor BodyScope.Exit(); 14830e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (SynchBody.isInvalid()) 1484fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian SynchBody = Actions.ActOnNullStmt(Tok.getLocation()); 148576ad2e85575722e8a38a2bd4648ab4304d9fcd24Sebastian Redl return Actions.ActOnObjCAtSynchronizedStmt(atLoc, move(Res), move(SynchBody)); 1486c385c90c68dfa376650e2facfbb444b2ec9bd110Fariborz Jahanian} 1487c385c90c68dfa376650e2facfbb444b2ec9bd110Fariborz Jahanian 1488397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// objc-try-catch-statement: 1489397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// @try compound-statement objc-catch-list[opt] 1490397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// @try compound-statement objc-catch-list[opt] @finally compound-statement 1491397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// 1492397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// objc-catch-list: 1493397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// @catch ( parameter-declaration ) compound-statement 1494397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// objc-catch-list @catch ( catch-parameter-declaration ) compound-statement 1495397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// catch-parameter-declaration: 1496397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// parameter-declaration 1497397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// '...' [OBJC2] 1498397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// 149943bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian RedlParser::OwningStmtResult Parser::ParseObjCTryStmt(SourceLocation atLoc) { 1500397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian bool catch_or_finally_seen = false; 150143bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl 1502397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian ConsumeToken(); // consume try 1503df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::l_brace)) { 15041ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_lbrace); 150543bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 1506397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian } 150715faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl OwningStmtResult CatchStmts(Actions); 150815faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl OwningStmtResult FinallyStmt(Actions); 15098935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor ParseScope TryScope(this, Scope::DeclScope); 151061364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl OwningStmtResult TryBody(ParseCompoundStatementBody()); 15118935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor TryScope.Exit(); 15120e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (TryBody.isInvalid()) 1513bd49a647afd9cc534fef13cadf652d4e9c396e2bFariborz Jahanian TryBody = Actions.ActOnNullStmt(Tok.getLocation()); 1514a55e52c0802cae3b7c366a05c461d3d15074c1a3Sebastian Redl 1515df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner while (Tok.is(tok::at)) { 15166b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner // At this point, we need to lookahead to determine if this @ is the start 15176b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner // of an @catch or @finally. We don't want to consume the @ token if this 15186b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner // is an @try or @encode or something else. 15196b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner Token AfterAt = GetLookAheadToken(1); 15206b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner if (!AfterAt.isObjCAtKeyword(tok::objc_catch) && 15216b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner !AfterAt.isObjCAtKeyword(tok::objc_finally)) 15226b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner break; 15230e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl 1524161a9c5afaafb4d527b7efba9675a8b2cbbe32e0Fariborz Jahanian SourceLocation AtCatchFinallyLoc = ConsumeToken(); 1525cb53b361bce341c8591333c6997f62e480acc0b4Chris Lattner if (Tok.isObjCAtKeyword(tok::objc_catch)) { 1526b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy FirstPart; 15273b1191d7eaf2f4984564e01ab84b6713a9d80e70Fariborz Jahanian ConsumeToken(); // consume catch 1528df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::l_paren)) { 1529397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian ConsumeParen(); 1530e21dd6ffef4585fa43cd3586ed971217d65bf56cSteve Naroff ParseScope CatchScope(this, Scope::DeclScope|Scope::AtCatchScope); 1531df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::ellipsis)) { 1532397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian DeclSpec DS; 1533397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian ParseDeclarationSpecifiers(DS); 153443bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl // For some odd reason, the name of the exception variable is 15351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // optional. As a result, we need to use "PrototypeContext", because 15367ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff // we must accept either 'declarator' or 'abstract-declarator' here. 15377ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff Declarator ParmDecl(DS, Declarator::PrototypeContext); 15387ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff ParseDeclarator(ParmDecl); 15397ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff 15407ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff // Inform the actions module about the parameter declarator, so it 15417ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff // gets added to the current scope. 1542d219a3a462c31fc9aa0c0bcfb749e9e8e56b5e35Fariborz Jahanian // FIXME. Probably can build a VarDecl and avoid setting DeclContext. 15437ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff FirstPart = Actions.ActOnParamDeclarator(CurScope, ParmDecl); 15442f764f11f513c7b51c716fffa5d02e5de816836fFariborz Jahanian Actions.ActOnObjCCatchParam(FirstPart); 154564515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff } else 1546397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian ConsumeToken(); // consume '...' 15471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 154893a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff SourceLocation RParenLoc; 15491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 155093a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff if (Tok.is(tok::r_paren)) 155193a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff RParenLoc = ConsumeParen(); 155293a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff else // Skip over garbage, until we get to ')'. Eat the ')'. 155393a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff SkipUntil(tok::r_paren, true, false); 155493a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff 155515faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl OwningStmtResult CatchBody(Actions, true); 1556c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner if (Tok.is(tok::l_brace)) 1557c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner CatchBody = ParseCompoundStatementBody(); 1558c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner else 1559c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner Diag(Tok, diag::err_expected_lbrace); 15600e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (CatchBody.isInvalid()) 15613b1191d7eaf2f4984564e01ab84b6713a9d80e70Fariborz Jahanian CatchBody = Actions.ActOnNullStmt(Tok.getLocation()); 15620e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl CatchStmts = Actions.ActOnObjCAtCatchStmt(AtCatchFinallyLoc, 15637ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff RParenLoc, FirstPart, move(CatchBody), 156476ad2e85575722e8a38a2bd4648ab4304d9fcd24Sebastian Redl move(CatchStmts)); 156564515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff } else { 15661ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(AtCatchFinallyLoc, diag::err_expected_lparen_after) 15671ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner << "@catch clause"; 156843bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 1569397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian } 1570397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian catch_or_finally_seen = true; 15716b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner } else { 15726b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner assert(Tok.isObjCAtKeyword(tok::objc_finally) && "Lookahead confused?"); 157364515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff ConsumeToken(); // consume finally 15748935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor ParseScope FinallyScope(this, Scope::DeclScope); 15750e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl 157615faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl OwningStmtResult FinallyBody(Actions, true); 1577c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner if (Tok.is(tok::l_brace)) 1578c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner FinallyBody = ParseCompoundStatementBody(); 1579c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner else 1580c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner Diag(Tok, diag::err_expected_lbrace); 15810e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (FinallyBody.isInvalid()) 1582161a9c5afaafb4d527b7efba9675a8b2cbbe32e0Fariborz Jahanian FinallyBody = Actions.ActOnNullStmt(Tok.getLocation()); 15830e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl FinallyStmt = Actions.ActOnObjCAtFinallyStmt(AtCatchFinallyLoc, 158476ad2e85575722e8a38a2bd4648ab4304d9fcd24Sebastian Redl move(FinallyBody)); 1585397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian catch_or_finally_seen = true; 1586397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian break; 1587397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian } 1588397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian } 1589bd49a647afd9cc534fef13cadf652d4e9c396e2bFariborz Jahanian if (!catch_or_finally_seen) { 1590397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian Diag(atLoc, diag::err_missing_catch_finally); 159143bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 1592bd49a647afd9cc534fef13cadf652d4e9c396e2bFariborz Jahanian } 159376ad2e85575722e8a38a2bd4648ab4304d9fcd24Sebastian Redl return Actions.ActOnObjCAtTryStmt(atLoc, move(TryBody), move(CatchStmts), 159476ad2e85575722e8a38a2bd4648ab4304d9fcd24Sebastian Redl move(FinallyStmt)); 1595397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian} 1596ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian 15973536b443bc50d58a79f14fca9b6842541a434854Steve Naroff/// objc-method-def: objc-method-proto ';'[opt] '{' body '}' 1598ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// 1599b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris LattnerParser::DeclPtrTy Parser::ParseObjCMethodDefinition() { 1600b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy MDecl = ParseObjCMethodPrototype(ObjCImpDecl); 16011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 160249f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner PrettyStackTraceActionsDecl CrashInfo(MDecl, Tok.getLocation(), Actions, 160349f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner PP.getSourceManager(), 160449f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner "parsing Objective-C method"); 16051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1606ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian // parse optional ';' 1607209a8c2fa23636f6d065d618e7078e164903f5cdFariborz Jahanian if (Tok.is(tok::semi)) { 1608496e45ef3350fabc312c5a807d308c65c50af4dbTed Kremenek if (ObjCImpDecl) { 1609496e45ef3350fabc312c5a807d308c65c50af4dbTed Kremenek Diag(Tok, diag::warn_semicolon_before_method_body) 1610849b243d4065f56742a4677d6dc8277609a151f8Douglas Gregor << FixItHint::CreateRemoval(Tok.getLocation()); 1611496e45ef3350fabc312c5a807d308c65c50af4dbTed Kremenek } 1612ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); 1613209a8c2fa23636f6d065d618e7078e164903f5cdFariborz Jahanian } 1614ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian 1615409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // We should have an opening brace now. 1616df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::l_brace)) { 1617da323adbb99cee19a203ead852d5d9bfebb23fb7Steve Naroff Diag(Tok, diag::err_expected_method_body); 16181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1619409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // Skip over garbage, until we get to '{'. Don't eat the '{'. 1620409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff SkipUntil(tok::l_brace, true, true); 16211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1622409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // If we didn't find the '{', bail out. 1623409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff if (Tok.isNot(tok::l_brace)) 1624b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 1625ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1626409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff SourceLocation BraceLoc = Tok.getLocation(); 16271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1628409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // Enter a scope for the method body. 162915faee19fdb9017dd6d08a690427b18c3b062c2dChris Lattner ParseScope BodyScope(this, 163015faee19fdb9017dd6d08a690427b18c3b062c2dChris Lattner Scope::ObjCMethodScope|Scope::FnScope|Scope::DeclScope); 16311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1632409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // Tell the actions module that we have entered a method definition with the 1633394f3f483fa4e7b472630cfcd03f7840520958c5Steve Naroff // specified Declarator for the method. 1634ebf6443a4f493233f7e8d92b3a991848c8b1c00dSteve Naroff Actions.ActOnStartOfObjCMethodDef(CurScope, MDecl); 163561364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl 163661364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl OwningStmtResult FnBody(ParseCompoundStatementBody()); 163761364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl 1638409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // If the function body could not be parsed, make a bogus compoundstmt. 16390e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (FnBody.isInvalid()) 1640a60528cdac7deee3991c2b48af4df4f315e49e9dSebastian Redl FnBody = Actions.ActOnCompoundStmt(BraceLoc, BraceLoc, 1641a60528cdac7deee3991c2b48af4df4f315e49e9dSebastian Redl MultiStmtArg(Actions), false); 1642798d119415323ebcd029ffe1e0fb442a4ca8adbbSebastian Redl 164332ce8376efb7e0d70e5f7e8fcf685130293f412bSteve Naroff // TODO: Pass argument information. 164432ce8376efb7e0d70e5f7e8fcf685130293f412bSteve Naroff Actions.ActOnFinishFunctionBody(MDecl, move(FnBody)); 16451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1646409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // Leave the function body scope. 16478935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor BodyScope.Exit(); 1648798d119415323ebcd029ffe1e0fb442a4ca8adbbSebastian Redl 164971c0a951d08dc7a2a057df8c15f22b36f6aa47c7Steve Naroff return MDecl; 16505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 16515508518a2702b00be3b15a26d772bde968972f54Anders Carlsson 165243bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian RedlParser::OwningStmtResult Parser::ParseObjCAtStatement(SourceLocation AtLoc) { 16539a0c85e640a08174569a303db22981612f05d385Douglas Gregor if (Tok.is(tok::code_completion)) { 16549a0c85e640a08174569a303db22981612f05d385Douglas Gregor Actions.CodeCompleteObjCAtStatement(CurScope); 16559a0c85e640a08174569a303db22981612f05d385Douglas Gregor ConsumeToken(); 16569a0c85e640a08174569a303db22981612f05d385Douglas Gregor return StmtError(); 16575d8031687d086701b4dadaab3e0de1def448da9dChris Lattner } 16585d8031687d086701b4dadaab3e0de1def448da9dChris Lattner 16595d8031687d086701b4dadaab3e0de1def448da9dChris Lattner if (Tok.isObjCAtKeyword(tok::objc_try)) 16606b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner return ParseObjCTryStmt(AtLoc); 16615d8031687d086701b4dadaab3e0de1def448da9dChris Lattner 16625d8031687d086701b4dadaab3e0de1def448da9dChris Lattner if (Tok.isObjCAtKeyword(tok::objc_throw)) 166364515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff return ParseObjCThrowStmt(AtLoc); 16645d8031687d086701b4dadaab3e0de1def448da9dChris Lattner 16655d8031687d086701b4dadaab3e0de1def448da9dChris Lattner if (Tok.isObjCAtKeyword(tok::objc_synchronized)) 166664515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff return ParseObjCSynchronizedStmt(AtLoc); 16675d8031687d086701b4dadaab3e0de1def448da9dChris Lattner 1668d8c4e15138e69a51754cc259c8a592cc47950c8eSebastian Redl OwningExprResult Res(ParseExpressionWithLeadingAt(AtLoc)); 16690e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Res.isInvalid()) { 167064515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff // If the expression is invalid, skip ahead to the next semicolon. Not 167164515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff // doing this opens us up to the possibility of infinite loops if 167264515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff // ParseExpression does not consume any tokens. 167364515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff SkipUntil(tok::semi); 167443bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 167564515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff } 16765d8031687d086701b4dadaab3e0de1def448da9dChris Lattner 167764515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff // Otherwise, eat the semicolon. 167864515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff ExpectAndConsume(tok::semi, diag::err_expected_semi_after_expr); 16795ee56e95c3905d2e7bc403631b03865cdbdd8a42Anders Carlsson return Actions.ActOnExprStmt(Actions.MakeFullExpr(Res)); 168064515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff} 168164515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff 16821d922960e083906a586609ac6978678147250177Sebastian RedlParser::OwningExprResult Parser::ParseObjCAtExpression(SourceLocation AtLoc) { 16835508518a2702b00be3b15a26d772bde968972f54Anders Carlsson switch (Tok.getKind()) { 16849a0c85e640a08174569a303db22981612f05d385Douglas Gregor case tok::code_completion: 16859a0c85e640a08174569a303db22981612f05d385Douglas Gregor Actions.CodeCompleteObjCAtExpression(CurScope); 16869a0c85e640a08174569a303db22981612f05d385Douglas Gregor ConsumeToken(); 16879a0c85e640a08174569a303db22981612f05d385Douglas Gregor return ExprError(); 16889a0c85e640a08174569a303db22981612f05d385Douglas Gregor 1689b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner case tok::string_literal: // primary-expression: string-literal 1690b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner case tok::wide_string_literal: 16911d922960e083906a586609ac6978678147250177Sebastian Redl return ParsePostfixExpressionSuffix(ParseObjCStringLiteral(AtLoc)); 1692b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner default: 16934fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner if (Tok.getIdentifierInfo() == 0) 16941d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(AtLoc, diag::err_unexpected_at)); 16952f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl 16964fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner switch (Tok.getIdentifierInfo()->getObjCKeywordID()) { 16974fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner case tok::objc_encode: 16981d922960e083906a586609ac6978678147250177Sebastian Redl return ParsePostfixExpressionSuffix(ParseObjCEncodeExpression(AtLoc)); 16994fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner case tok::objc_protocol: 17001d922960e083906a586609ac6978678147250177Sebastian Redl return ParsePostfixExpressionSuffix(ParseObjCProtocolExpression(AtLoc)); 17014fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner case tok::objc_selector: 17021d922960e083906a586609ac6978678147250177Sebastian Redl return ParsePostfixExpressionSuffix(ParseObjCSelectorExpression(AtLoc)); 17034fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner default: 17041d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(AtLoc, diag::err_unexpected_at)); 17054fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner } 17065508518a2702b00be3b15a26d772bde968972f54Anders Carlsson } 17075508518a2702b00be3b15a26d772bde968972f54Anders Carlsson} 17085508518a2702b00be3b15a26d772bde968972f54Anders Carlsson 17091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// objc-message-expr: 17100ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// '[' objc-receiver objc-message-args ']' 17110ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// 17120ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-receiver: 1713eb483eb3ee80300f15d6d13573d82493c2194461Chris Lattner/// 'super' 17140ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// expression 17150ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// class-name 17160ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// type-name 17171d922960e083906a586609ac6978678147250177Sebastian RedlParser::OwningExprResult Parser::ParseObjCMessageExpression() { 1718699b66138ac307a32e238463e0eff513ff17d337Chris Lattner assert(Tok.is(tok::l_square) && "'[' expected"); 1719699b66138ac307a32e238463e0eff513ff17d337Chris Lattner SourceLocation LBracLoc = ConsumeBracket(); // consume '[' 1720699b66138ac307a32e238463e0eff513ff17d337Chris Lattner 1721eb483eb3ee80300f15d6d13573d82493c2194461Chris Lattner if (Tok.is(tok::identifier)) { 1722eb483eb3ee80300f15d6d13573d82493c2194461Chris Lattner IdentifierInfo *II = Tok.getIdentifierInfo(); 1723eb483eb3ee80300f15d6d13573d82493c2194461Chris Lattner 1724eb483eb3ee80300f15d6d13573d82493c2194461Chris Lattner // If this is '[' 'super', then this is a magic superclass message. 1725eb483eb3ee80300f15d6d13573d82493c2194461Chris Lattner // We parse '[' 'super' '.' 'foo' as an expression? 1726eb483eb3ee80300f15d6d13573d82493c2194461Chris Lattner // FIXME: Not in ParseInit.cpp? 172715faee19fdb9017dd6d08a690427b18c3b062c2dChris Lattner if ((II == Ident_super && GetLookAheadToken(1).isNot(tok::period) && 172815faee19fdb9017dd6d08a690427b18c3b062c2dChris Lattner CurScope->isInObjcMethodScope()) || 1729eb483eb3ee80300f15d6d13573d82493c2194461Chris Lattner // Check to see if this is a typename. If so, it is a class message. 1730eb483eb3ee80300f15d6d13573d82493c2194461Chris Lattner Actions.getTypeName(*II, Tok.getLocation(), CurScope)) { 1731d2869925b5f10e00b13fbf3f41bbb17e4c9adbe0Fariborz Jahanian SourceLocation NameLoc = ConsumeToken(); 1732eb483eb3ee80300f15d6d13573d82493c2194461Chris Lattner return ParseObjCMessageExpressionBody(LBracLoc, NameLoc, II, 1733d2869925b5f10e00b13fbf3f41bbb17e4c9adbe0Fariborz Jahanian ExprArg(Actions)); 1734d2869925b5f10e00b13fbf3f41bbb17e4c9adbe0Fariborz Jahanian } 1735699b66138ac307a32e238463e0eff513ff17d337Chris Lattner } 1736eb483eb3ee80300f15d6d13573d82493c2194461Chris Lattner 1737eb483eb3ee80300f15d6d13573d82493c2194461Chris Lattner // Otherwise, an arbitrary expression can be the receiver of a send. 17382f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl OwningExprResult Res(ParseExpression()); 17390e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Res.isInvalid()) { 17405c749428a9938d5e2e9564b1c9b7a9252c30ee27Chris Lattner SkipUntil(tok::r_square); 17411d922960e083906a586609ac6978678147250177Sebastian Redl return move(Res); 1742699b66138ac307a32e238463e0eff513ff17d337Chris Lattner } 17431d922960e083906a586609ac6978678147250177Sebastian Redl 17440e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(), 174576ad2e85575722e8a38a2bd4648ab4304d9fcd24Sebastian Redl 0, move(Res)); 1746699b66138ac307a32e238463e0eff513ff17d337Chris Lattner} 17471d922960e083906a586609ac6978678147250177Sebastian Redl 1748699b66138ac307a32e238463e0eff513ff17d337Chris Lattner/// ParseObjCMessageExpressionBody - Having parsed "'[' objc-receiver", parse 1749699b66138ac307a32e238463e0eff513ff17d337Chris Lattner/// the rest of a message expression. 17501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 17510ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-message-args: 17520ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-selector 17530ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-keywordarg-list 17540ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// 17550ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-keywordarg-list: 17560ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-keywordarg 17570ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-keywordarg-list objc-keywordarg 17580ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// 17591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// objc-keywordarg: 17600ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// selector-name[opt] ':' objc-keywordexpr 17610ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// 17620ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-keywordexpr: 17630ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// nonempty-expr-list 17640ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// 17650ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// nonempty-expr-list: 17660ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// assignment-expression 17670ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// nonempty-expr-list , assignment-expression 17681d922960e083906a586609ac6978678147250177Sebastian Redl/// 17691d922960e083906a586609ac6978678147250177Sebastian RedlParser::OwningExprResult 1770699b66138ac307a32e238463e0eff513ff17d337Chris LattnerParser::ParseObjCMessageExpressionBody(SourceLocation LBracLoc, 17715cb93b8bf009c4b0ae09b71ba85f54b2a7ea8022Steve Naroff SourceLocation NameLoc, 1772699b66138ac307a32e238463e0eff513ff17d337Chris Lattner IdentifierInfo *ReceiverName, 17731d922960e083906a586609ac6978678147250177Sebastian Redl ExprArg ReceiverExpr) { 1774c4df6d2c05c647a6a5770ba0c749782b6c023a3aSteve Naroff if (Tok.is(tok::code_completion)) { 1775c4df6d2c05c647a6a5770ba0c749782b6c023a3aSteve Naroff if (ReceiverName) 1776d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor Actions.CodeCompleteObjCClassMessage(CurScope, ReceiverName, NameLoc, 1777d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor 0, 0); 1778c4df6d2c05c647a6a5770ba0c749782b6c023a3aSteve Naroff else 1779d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor Actions.CodeCompleteObjCInstanceMessage(CurScope, ReceiverExpr.get(), 1780d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor 0, 0); 1781c4df6d2c05c647a6a5770ba0c749782b6c023a3aSteve Naroff ConsumeToken(); 1782c4df6d2c05c647a6a5770ba0c749782b6c023a3aSteve Naroff } 1783d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor 1784a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian // Parse objc-selector 17854b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian SourceLocation Loc; 17862fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner IdentifierInfo *selIdent = ParseObjCSelectorPiece(Loc); 178768d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff 1788ff975cfab9ada27df86038286d1678084aeb3428Anders Carlsson SourceLocation SelectorLoc = Loc; 17891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 179068d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff llvm::SmallVector<IdentifierInfo *, 12> KeyIdents; 1791a55e52c0802cae3b7c366a05c461d3d15074c1a3Sebastian Redl ExprVector KeyExprs(Actions); 179268d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff 1793df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::colon)) { 1794a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian while (1) { 1795a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian // Each iteration parses a single keyword argument. 179668d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff KeyIdents.push_back(selIdent); 179737387c932855c6d58d70bdd705cd3a9fdcd2a931Steve Naroff 1798df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::colon)) { 1799a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian Diag(Tok, diag::err_expected_colon); 18004fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // We must manually skip to a ']', otherwise the expression skipper will 18014fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // stop at the ']' when it skips to the ';'. We want it to skip beyond 18024fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // the enclosing expression. 18034fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner SkipUntil(tok::r_square); 18041d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(); 1805a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian } 18061d922960e083906a586609ac6978678147250177Sebastian Redl 180768d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff ConsumeToken(); // Eat the ':'. 18081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// Parse the expression after ':' 18092f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl OwningExprResult Res(ParseAssignmentExpression()); 18100e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Res.isInvalid()) { 18114fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // We must manually skip to a ']', otherwise the expression skipper will 18124fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // stop at the ']' when it skips to the ';'. We want it to skip beyond 18134fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // the enclosing expression. 18144fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner SkipUntil(tok::r_square); 18151d922960e083906a586609ac6978678147250177Sebastian Redl return move(Res); 181637387c932855c6d58d70bdd705cd3a9fdcd2a931Steve Naroff } 18171d922960e083906a586609ac6978678147250177Sebastian Redl 181837387c932855c6d58d70bdd705cd3a9fdcd2a931Steve Naroff // We have a valid expression. 1819effa8d1c97b00a3f53e972b0e61d9aade5ea1c57Sebastian Redl KeyExprs.push_back(Res.release()); 18201d922960e083906a586609ac6978678147250177Sebastian Redl 1821d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor // Code completion after each argument. 1822d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor if (Tok.is(tok::code_completion)) { 1823d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor if (ReceiverName) 1824d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor Actions.CodeCompleteObjCClassMessage(CurScope, ReceiverName, NameLoc, 1825d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor KeyIdents.data(), 1826d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor KeyIdents.size()); 1827d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor else 1828d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor Actions.CodeCompleteObjCInstanceMessage(CurScope, ReceiverExpr.get(), 1829d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor KeyIdents.data(), 1830d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor KeyIdents.size()); 1831d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor ConsumeToken(); 1832d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor } 1833d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor 183437387c932855c6d58d70bdd705cd3a9fdcd2a931Steve Naroff // Check for another keyword selector. 18352fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner selIdent = ParseObjCSelectorPiece(Loc); 1836df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (!selIdent && Tok.isNot(tok::colon)) 1837a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian break; 1838a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian // We have a selector or a colon, continue parsing. 1839a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian } 1840a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian // Parse the, optional, argument list, comma separated. 1841df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner while (Tok.is(tok::comma)) { 184249f109c786f99eb7468dac3976db083a65493444Steve Naroff ConsumeToken(); // Eat the ','. 18431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// Parse the expression after ',' 18442f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl OwningExprResult Res(ParseAssignmentExpression()); 18450e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Res.isInvalid()) { 18464fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // We must manually skip to a ']', otherwise the expression skipper will 18474fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // stop at the ']' when it skips to the ';'. We want it to skip beyond 18484fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // the enclosing expression. 18494fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner SkipUntil(tok::r_square); 18501d922960e083906a586609ac6978678147250177Sebastian Redl return move(Res); 185149f109c786f99eb7468dac3976db083a65493444Steve Naroff } 18520e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl 185349f109c786f99eb7468dac3976db083a65493444Steve Naroff // We have a valid expression. 1854effa8d1c97b00a3f53e972b0e61d9aade5ea1c57Sebastian Redl KeyExprs.push_back(Res.release()); 1855a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian } 1856a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian } else if (!selIdent) { 1857a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian Diag(Tok, diag::err_expected_ident); // missing selector name. 18581d922960e083906a586609ac6978678147250177Sebastian Redl 18594fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // We must manually skip to a ']', otherwise the expression skipper will 18604fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // stop at the ']' when it skips to the ';'. We want it to skip beyond 18614fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // the enclosing expression. 18624fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner SkipUntil(tok::r_square); 18631d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(); 1864a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian } 1865809872eca7f6c024e2ab41ddffbbeeae807bf5dcFariborz Jahanian 1866df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::r_square)) { 1867809872eca7f6c024e2ab41ddffbbeeae807bf5dcFariborz Jahanian if (Tok.is(tok::identifier)) 1868809872eca7f6c024e2ab41ddffbbeeae807bf5dcFariborz Jahanian Diag(Tok, diag::err_expected_colon); 1869809872eca7f6c024e2ab41ddffbbeeae807bf5dcFariborz Jahanian else 1870809872eca7f6c024e2ab41ddffbbeeae807bf5dcFariborz Jahanian Diag(Tok, diag::err_expected_rsquare); 18714fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // We must manually skip to a ']', otherwise the expression skipper will 18724fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // stop at the ']' when it skips to the ';'. We want it to skip beyond 18734fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // the enclosing expression. 18744fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner SkipUntil(tok::r_square); 18751d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(); 1876a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian } 18771d922960e083906a586609ac6978678147250177Sebastian Redl 1878699b66138ac307a32e238463e0eff513ff17d337Chris Lattner SourceLocation RBracLoc = ConsumeBracket(); // consume ']' 18791d922960e083906a586609ac6978678147250177Sebastian Redl 188029238a0bf7cbf5b396efb451a0adb5fe4aa037caSteve Naroff unsigned nKeys = KeyIdents.size(); 1881ff38491c18b060526d754765b952f4a497a89416Chris Lattner if (nKeys == 0) 1882ff38491c18b060526d754765b952f4a497a89416Chris Lattner KeyIdents.push_back(selIdent); 1883ff38491c18b060526d754765b952f4a497a89416Chris Lattner Selector Sel = PP.getSelectorTable().getSelector(nKeys, &KeyIdents[0]); 18841d922960e083906a586609ac6978678147250177Sebastian Redl 1885ff38491c18b060526d754765b952f4a497a89416Chris Lattner // We've just parsed a keyword message. 18861d922960e083906a586609ac6978678147250177Sebastian Redl if (ReceiverName) 18871d922960e083906a586609ac6978678147250177Sebastian Redl return Owned(Actions.ActOnClassMessage(CurScope, ReceiverName, Sel, 18881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump LBracLoc, NameLoc, SelectorLoc, 1889ff975cfab9ada27df86038286d1678084aeb3428Anders Carlsson RBracLoc, 18901d922960e083906a586609ac6978678147250177Sebastian Redl KeyExprs.take(), KeyExprs.size())); 18911d922960e083906a586609ac6978678147250177Sebastian Redl return Owned(Actions.ActOnInstanceMessage(ReceiverExpr.release(), Sel, 1892ff975cfab9ada27df86038286d1678084aeb3428Anders Carlsson LBracLoc, SelectorLoc, RBracLoc, 18931d922960e083906a586609ac6978678147250177Sebastian Redl KeyExprs.take(), KeyExprs.size())); 18940ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian} 18950ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian 18961d922960e083906a586609ac6978678147250177Sebastian RedlParser::OwningExprResult Parser::ParseObjCStringLiteral(SourceLocation AtLoc) { 189720df9b7ab9388b2a488c5b1293cd196b1e073b4eSebastian Redl OwningExprResult Res(ParseStringLiteralExpression()); 18981d922960e083906a586609ac6978678147250177Sebastian Redl if (Res.isInvalid()) return move(Res); 18991d922960e083906a586609ac6978678147250177Sebastian Redl 1900b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner // @"foo" @"bar" is a valid concatenated string. Eat any subsequent string 1901b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner // expressions. At this point, we know that the only valid thing that starts 1902b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner // with '@' is an @"". 1903b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner llvm::SmallVector<SourceLocation, 4> AtLocs; 1904a55e52c0802cae3b7c366a05c461d3d15074c1a3Sebastian Redl ExprVector AtStrings(Actions); 1905b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner AtLocs.push_back(AtLoc); 1906effa8d1c97b00a3f53e972b0e61d9aade5ea1c57Sebastian Redl AtStrings.push_back(Res.release()); 19070e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl 1908b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner while (Tok.is(tok::at)) { 1909b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner AtLocs.push_back(ConsumeToken()); // eat the @. 1910b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner 191115faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl // Invalid unless there is a string literal. 191297cf6eb380016db868866faf27a086cd55a316d4Chris Lattner if (!isTokenStringLiteral()) 191397cf6eb380016db868866faf27a086cd55a316d4Chris Lattner return ExprError(Diag(Tok, diag::err_objc_concat_string)); 1914b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner 191597cf6eb380016db868866faf27a086cd55a316d4Chris Lattner OwningExprResult Lit(ParseStringLiteralExpression()); 19160e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Lit.isInvalid()) 19171d922960e083906a586609ac6978678147250177Sebastian Redl return move(Lit); 19180e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl 1919effa8d1c97b00a3f53e972b0e61d9aade5ea1c57Sebastian Redl AtStrings.push_back(Lit.release()); 1920b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner } 19211d922960e083906a586609ac6978678147250177Sebastian Redl 19221d922960e083906a586609ac6978678147250177Sebastian Redl return Owned(Actions.ParseObjCStringLiteral(&AtLocs[0], AtStrings.take(), 19231d922960e083906a586609ac6978678147250177Sebastian Redl AtStrings.size())); 19245508518a2702b00be3b15a26d772bde968972f54Anders Carlsson} 1925f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson 1926f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson/// objc-encode-expression: 1927f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson/// @encode ( type-name ) 19281d922960e083906a586609ac6978678147250177Sebastian RedlParser::OwningExprResult 19291d922960e083906a586609ac6978678147250177Sebastian RedlParser::ParseObjCEncodeExpression(SourceLocation AtLoc) { 1930861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff assert(Tok.isObjCAtKeyword(tok::objc_encode) && "Not an @encode expression!"); 19311d922960e083906a586609ac6978678147250177Sebastian Redl 1932f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson SourceLocation EncLoc = ConsumeToken(); 19331d922960e083906a586609ac6978678147250177Sebastian Redl 19344fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner if (Tok.isNot(tok::l_paren)) 19351d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(Tok, diag::err_expected_lparen_after) << "@encode"); 19361d922960e083906a586609ac6978678147250177Sebastian Redl 1937f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson SourceLocation LParenLoc = ConsumeParen(); 19381d922960e083906a586609ac6978678147250177Sebastian Redl 1939809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor TypeResult Ty = ParseTypeName(); 19401d922960e083906a586609ac6978678147250177Sebastian Redl 19414988ae3fda10743c8ed8a98cdcb5a783362587b4Anders Carlsson SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); 19421d922960e083906a586609ac6978678147250177Sebastian Redl 1943809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor if (Ty.isInvalid()) 1944809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor return ExprError(); 1945809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor 19461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return Owned(Actions.ParseObjCEncodeExpression(AtLoc, EncLoc, LParenLoc, 1947809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor Ty.get(), RParenLoc)); 1948f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson} 194929b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson 195029b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson/// objc-protocol-expression 195129b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson/// @protocol ( protocol-name ) 19521d922960e083906a586609ac6978678147250177Sebastian RedlParser::OwningExprResult 19531d922960e083906a586609ac6978678147250177Sebastian RedlParser::ParseObjCProtocolExpression(SourceLocation AtLoc) { 195429b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson SourceLocation ProtoLoc = ConsumeToken(); 19551d922960e083906a586609ac6978678147250177Sebastian Redl 19564fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner if (Tok.isNot(tok::l_paren)) 19571d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(Tok, diag::err_expected_lparen_after) << "@protocol"); 19581d922960e083906a586609ac6978678147250177Sebastian Redl 195929b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson SourceLocation LParenLoc = ConsumeParen(); 19601d922960e083906a586609ac6978678147250177Sebastian Redl 19614fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner if (Tok.isNot(tok::identifier)) 19621d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(Tok, diag::err_expected_ident)); 19631d922960e083906a586609ac6978678147250177Sebastian Redl 1964390d50a725497e99247dc104a7d2c2a255d3af14Fariborz Jahanian IdentifierInfo *protocolId = Tok.getIdentifierInfo(); 196529b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson ConsumeToken(); 19661d922960e083906a586609ac6978678147250177Sebastian Redl 19674988ae3fda10743c8ed8a98cdcb5a783362587b4Anders Carlsson SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); 196829b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson 19691d922960e083906a586609ac6978678147250177Sebastian Redl return Owned(Actions.ParseObjCProtocolExpression(protocolId, AtLoc, ProtoLoc, 19701d922960e083906a586609ac6978678147250177Sebastian Redl LParenLoc, RParenLoc)); 197129b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson} 1972a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian 1973a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian/// objc-selector-expression 1974a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian/// @selector '(' objc-keyword-selector ')' 19751d922960e083906a586609ac6978678147250177Sebastian RedlParser::OwningExprResult 19761d922960e083906a586609ac6978678147250177Sebastian RedlParser::ParseObjCSelectorExpression(SourceLocation AtLoc) { 1977a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian SourceLocation SelectorLoc = ConsumeToken(); 19781d922960e083906a586609ac6978678147250177Sebastian Redl 19794fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner if (Tok.isNot(tok::l_paren)) 19801d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(Tok, diag::err_expected_lparen_after) << "@selector"); 19811d922960e083906a586609ac6978678147250177Sebastian Redl 1982b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian llvm::SmallVector<IdentifierInfo *, 12> KeyIdents; 1983a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian SourceLocation LParenLoc = ConsumeParen(); 1984a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian SourceLocation sLoc; 19852fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner IdentifierInfo *SelIdent = ParseObjCSelectorPiece(sLoc); 19861d922960e083906a586609ac6978678147250177Sebastian Redl if (!SelIdent && Tok.isNot(tok::colon)) // missing selector name. 19871d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(Tok, diag::err_expected_ident)); 19881d922960e083906a586609ac6978678147250177Sebastian Redl 1989b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian KeyIdents.push_back(SelIdent); 1990887407e71fd58de452361b77d72970e32b20ebe0Steve Naroff unsigned nColons = 0; 1991887407e71fd58de452361b77d72970e32b20ebe0Steve Naroff if (Tok.isNot(tok::r_paren)) { 1992a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian while (1) { 19934fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner if (Tok.isNot(tok::colon)) 19941d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(Tok, diag::err_expected_colon)); 19951d922960e083906a586609ac6978678147250177Sebastian Redl 1996cb53b361bce341c8591333c6997f62e480acc0b4Chris Lattner nColons++; 1997a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian ConsumeToken(); // Eat the ':'. 1998a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian if (Tok.is(tok::r_paren)) 1999a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian break; 2000a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian // Check for another keyword selector. 2001a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian SourceLocation Loc; 20022fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner SelIdent = ParseObjCSelectorPiece(Loc); 2003b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian KeyIdents.push_back(SelIdent); 2004a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian if (!SelIdent && Tok.isNot(tok::colon)) 2005a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian break; 2006a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian } 2007887407e71fd58de452361b77d72970e32b20ebe0Steve Naroff } 2008a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); 2009887407e71fd58de452361b77d72970e32b20ebe0Steve Naroff Selector Sel = PP.getSelectorTable().getSelector(nColons, &KeyIdents[0]); 20101d922960e083906a586609ac6978678147250177Sebastian Redl return Owned(Actions.ParseObjCSelectorExpression(Sel, AtLoc, SelectorLoc, 20111d922960e083906a586609ac6978678147250177Sebastian Redl LParenLoc, RParenLoc)); 201258065b2d8038a4e9a91ea4813bd1774c0f6efacbGabor Greif } 2013