ParseObjc.cpp revision 05511fa6349ef0820a778f8c840d0b64e05e9aee
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 790e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner // Parse the return type if present. 791ff38491c18b060526d754765b952f4a497a89416Chris Lattner TypeTy *ReturnType = 0; 792a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCDeclSpec DSRet; 793df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::l_paren)) 794f1de0ca05e2df6f23bd559028693a12d1ebdaaf6Fariborz Jahanian ReturnType = ParseObjCTypeName(DSRet); 7951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7969e0493576af77dba1c48858c03e31a2897d0681eTed Kremenek // If attributes exist before the method, parse them. 7979e0493576af77dba1c48858c03e31a2897d0681eTed Kremenek llvm::OwningPtr<AttributeList> MethodAttrs; 7989e0493576af77dba1c48858c03e31a2897d0681eTed Kremenek if (getLang().ObjC2 && Tok.is(tok::kw___attribute)) 7999e0493576af77dba1c48858c03e31a2897d0681eTed Kremenek MethodAttrs.reset(ParseGNUAttributes()); 8009e0493576af77dba1c48858c03e31a2897d0681eTed Kremenek 8019e0493576af77dba1c48858c03e31a2897d0681eTed Kremenek // Now parse the selector. 802bef1185418705e16012b3dd50cd7c260c8d6b79cSteve Naroff SourceLocation selLoc; 8032fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner IdentifierInfo *SelIdent = ParseObjCSelectorPiece(selLoc); 804e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner 80584c431088693e216193094d1dbf327a01173f57fSteve Naroff // An unnamed colon is valid. 80684c431088693e216193094d1dbf327a01173f57fSteve Naroff if (!SelIdent && Tok.isNot(tok::colon)) { // missing selector name. 8071ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_selector_for_method) 8081ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner << SourceRange(mLoc, Tok.getLocation()); 809e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner // Skip until we get a ; or {}. 810e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner SkipUntil(tok::r_brace); 811b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 812e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner } 8131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 814439c65892cc8629bbf541e0b8bda6b64cbcc4e6bFariborz Jahanian llvm::SmallVector<Declarator, 8> CargNames; 815df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::colon)) { 816ff38491c18b060526d754765b952f4a497a89416Chris Lattner // If attributes exist after the method, parse them. 8171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (getLang().ObjC2 && Tok.is(tok::kw___attribute)) 8189e0493576af77dba1c48858c03e31a2897d0681eTed Kremenek MethodAttrs.reset(addAttributeLists(MethodAttrs.take(), 8199e0493576af77dba1c48858c03e31a2897d0681eTed Kremenek ParseGNUAttributes())); 8201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 821ff38491c18b060526d754765b952f4a497a89416Chris Lattner Selector Sel = PP.getSelectorTable().getNullarySelector(SelIdent); 82254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall DeclPtrTy Result 82354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall = Actions.ActOnMethodDeclaration(mLoc, Tok.getLocation(), 8241f7b6f88f18d7f6b10265acec5d41c4ed1897487Fariborz Jahanian mType, IDecl, DSRet, ReturnType, Sel, 8251e37765c9257ef1d051f54a674eaa964bdba9693Ted Kremenek 0, CargNames, MethodAttrs.get(), 8261c6a3cc88177c67498fccdf14cfdf09959214e41Ted Kremenek MethodImplKind); 82754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall PD.complete(Result); 82854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall return Result; 829ff38491c18b060526d754765b952f4a497a89416Chris Lattner } 830f28b264437053fb0deacc9ba02b18a0966f7290aSteve Naroff 83168d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff llvm::SmallVector<IdentifierInfo *, 12> KeyIdents; 832e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner llvm::SmallVector<Action::ObjCArgInfo, 12> ArgInfos; 8331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 834ff38491c18b060526d754765b952f4a497a89416Chris Lattner while (1) { 835e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner Action::ObjCArgInfo ArgInfo; 8361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 837ff38491c18b060526d754765b952f4a497a89416Chris Lattner // Each iteration parses a single keyword argument. 838df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::colon)) { 839ff38491c18b060526d754765b952f4a497a89416Chris Lattner Diag(Tok, diag::err_expected_colon); 840ff38491c18b060526d754765b952f4a497a89416Chris Lattner break; 841ff38491c18b060526d754765b952f4a497a89416Chris Lattner } 842ff38491c18b060526d754765b952f4a497a89416Chris Lattner ConsumeToken(); // Eat the ':'. 8431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 844e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner ArgInfo.Type = 0; 845e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner if (Tok.is(tok::l_paren)) // Parse the argument type if present. 846e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner ArgInfo.Type = ParseObjCTypeName(ArgInfo.DeclSpec); 847e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner 848ff38491c18b060526d754765b952f4a497a89416Chris Lattner // If attributes exist before the argument name, parse them. 849e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner ArgInfo.ArgAttrs = 0; 850df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (getLang().ObjC2 && Tok.is(tok::kw___attribute)) 851bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt ArgInfo.ArgAttrs = ParseGNUAttributes(); 8527ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff 853df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 854ff38491c18b060526d754765b952f4a497a89416Chris Lattner Diag(Tok, diag::err_expected_ident); // missing argument name. 855ff38491c18b060526d754765b952f4a497a89416Chris Lattner break; 8564985aceceb9b9261b876b515d32726175c13a775Steve Naroff } 8571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 858e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner ArgInfo.Name = Tok.getIdentifierInfo(); 859e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner ArgInfo.NameLoc = Tok.getLocation(); 860ff38491c18b060526d754765b952f4a497a89416Chris Lattner ConsumeToken(); // Eat the identifier. 8611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 862e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner ArgInfos.push_back(ArgInfo); 863e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner KeyIdents.push_back(SelIdent); 864e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner 865ff38491c18b060526d754765b952f4a497a89416Chris Lattner // Check for another keyword selector. 8664b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian SourceLocation Loc; 8672fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner SelIdent = ParseObjCSelectorPiece(Loc); 868df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (!SelIdent && Tok.isNot(tok::colon)) 869ff38491c18b060526d754765b952f4a497a89416Chris Lattner break; 870ff38491c18b060526d754765b952f4a497a89416Chris Lattner // We have a selector or a colon, continue parsing. 871ff38491c18b060526d754765b952f4a497a89416Chris Lattner } 8721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 873335eafa5be51f6440672a74c73d588af72e96732Steve Naroff bool isVariadic = false; 8741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 875ff38491c18b060526d754765b952f4a497a89416Chris Lattner // Parse the (optional) parameter list. 876df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner while (Tok.is(tok::comma)) { 877ff38491c18b060526d754765b952f4a497a89416Chris Lattner ConsumeToken(); 878df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::ellipsis)) { 879335eafa5be51f6440672a74c73d588af72e96732Steve Naroff isVariadic = true; 8804985aceceb9b9261b876b515d32726175c13a775Steve Naroff ConsumeToken(); 881ff38491c18b060526d754765b952f4a497a89416Chris Lattner break; 8824985aceceb9b9261b876b515d32726175c13a775Steve Naroff } 883ff38491c18b060526d754765b952f4a497a89416Chris Lattner DeclSpec DS; 884ff38491c18b060526d754765b952f4a497a89416Chris Lattner ParseDeclarationSpecifiers(DS); 8851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // Parse the declarator. 886ff38491c18b060526d754765b952f4a497a89416Chris Lattner Declarator ParmDecl(DS, Declarator::PrototypeContext); 887ff38491c18b060526d754765b952f4a497a89416Chris Lattner ParseDeclarator(ParmDecl); 888439c65892cc8629bbf541e0b8bda6b64cbcc4e6bFariborz Jahanian CargNames.push_back(ParmDecl); 8894985aceceb9b9261b876b515d32726175c13a775Steve Naroff } 8901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 891ff38491c18b060526d754765b952f4a497a89416Chris Lattner // FIXME: Add support for optional parmameter list... 892e3a2ca7e30601cdd31c77a830f4cc487851e8096Fariborz Jahanian // If attributes exist after the method, parse them. 8931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (getLang().ObjC2 && Tok.is(tok::kw___attribute)) 8949e0493576af77dba1c48858c03e31a2897d0681eTed Kremenek MethodAttrs.reset(addAttributeLists(MethodAttrs.take(), 8959e0493576af77dba1c48858c03e31a2897d0681eTed Kremenek ParseGNUAttributes())); 8961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8973688fc679389d67b6755e62406998f9ea84d886aFariborz Jahanian if (KeyIdents.size() == 0) 8983688fc679389d67b6755e62406998f9ea84d886aFariborz Jahanian return DeclPtrTy(); 899ff38491c18b060526d754765b952f4a497a89416Chris Lattner Selector Sel = PP.getSelectorTable().getSelector(KeyIdents.size(), 900ff38491c18b060526d754765b952f4a497a89416Chris Lattner &KeyIdents[0]); 90154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall DeclPtrTy Result 90254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall = Actions.ActOnMethodDeclaration(mLoc, Tok.getLocation(), 9033688fc679389d67b6755e62406998f9ea84d886aFariborz Jahanian mType, IDecl, DSRet, ReturnType, Sel, 9041e37765c9257ef1d051f54a674eaa964bdba9693Ted Kremenek &ArgInfos[0], CargNames, 9051e37765c9257ef1d051f54a674eaa964bdba9693Ted Kremenek MethodAttrs.get(), 906335eafa5be51f6440672a74c73d588af72e96732Steve Naroff MethodImplKind, isVariadic); 90754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall PD.complete(Result); 9081e37765c9257ef1d051f54a674eaa964bdba9693Ted Kremenek 9091e37765c9257ef1d051f54a674eaa964bdba9693Ted Kremenek // Delete referenced AttributeList objects. 9101e37765c9257ef1d051f54a674eaa964bdba9693Ted Kremenek for (llvm::SmallVectorImpl<Action::ObjCArgInfo>::iterator 9111e37765c9257ef1d051f54a674eaa964bdba9693Ted Kremenek I = ArgInfos.begin(), E = ArgInfos.end(); I != E; ++I) 9121e37765c9257ef1d051f54a674eaa964bdba9693Ted Kremenek delete I->ArgAttrs; 9131e37765c9257ef1d051f54a674eaa964bdba9693Ted Kremenek 91454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall return Result; 915294494e1cce92043562b4680c613df7fd028c02eSteve Naroff} 916294494e1cce92043562b4680c613df7fd028c02eSteve Naroff 917dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-refs: 918dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// '<' identifier-list '>' 919dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 9207caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattnerbool Parser:: 921b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris LattnerParseObjCProtocolReferences(llvm::SmallVectorImpl<Action::DeclPtrTy> &Protocols, 92271b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis llvm::SmallVectorImpl<SourceLocation> &ProtocolLocs, 92371b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis bool WarnOnDeclarations, 92471b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis SourceLocation &LAngleLoc, SourceLocation &EndLoc) { 925e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner assert(Tok.is(tok::less) && "expected <"); 9261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 92771b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis LAngleLoc = ConsumeToken(); // the "<" 9281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 929e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner llvm::SmallVector<IdentifierLocPair, 8> ProtocolIdents; 9301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 931e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner while (1) { 93255385fe3e723cd675001e45f42d61adde6b7f075Douglas Gregor if (Tok.is(tok::code_completion)) { 93355385fe3e723cd675001e45f42d61adde6b7f075Douglas Gregor Actions.CodeCompleteObjCProtocolReferences(ProtocolIdents.data(), 93455385fe3e723cd675001e45f42d61adde6b7f075Douglas Gregor ProtocolIdents.size()); 93555385fe3e723cd675001e45f42d61adde6b7f075Douglas Gregor ConsumeToken(); 93655385fe3e723cd675001e45f42d61adde6b7f075Douglas Gregor } 93755385fe3e723cd675001e45f42d61adde6b7f075Douglas Gregor 938e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner if (Tok.isNot(tok::identifier)) { 939e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner Diag(Tok, diag::err_expected_ident); 940e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner SkipUntil(tok::greater); 941e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner return true; 942e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner } 943e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner ProtocolIdents.push_back(std::make_pair(Tok.getIdentifierInfo(), 944e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner Tok.getLocation())); 94571b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis ProtocolLocs.push_back(Tok.getLocation()); 946e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner ConsumeToken(); 9471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 948e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner if (Tok.isNot(tok::comma)) 949e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner break; 950e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner ConsumeToken(); 951e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner } 9521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 953e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner // Consume the '>'. 954e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner if (Tok.isNot(tok::greater)) { 955e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner Diag(Tok, diag::err_expected_greater); 956e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner return true; 957e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner } 9581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 959e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner EndLoc = ConsumeAnyToken(); 9601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 961e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner // Convert the list of protocols identifiers into a list of protocol decls. 962e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner Actions.FindProtocolDeclaration(WarnOnDeclarations, 963e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner &ProtocolIdents[0], ProtocolIdents.size(), 964e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner Protocols); 965e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner return false; 966e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner} 967e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner 968dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-instance-variables: 969dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// '{' objc-instance-variable-decl-list[opt] '}' 970dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 971dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-instance-variable-decl-list: 972dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-visibility-spec 973dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-instance-variable-decl ';' 974dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// ';' 975dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-instance-variable-decl-list objc-visibility-spec 976dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-instance-variable-decl-list objc-instance-variable-decl ';' 977dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-instance-variable-decl-list ';' 978dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 979dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-visibility-spec: 980dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @private 981dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @protected 982dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @public 983ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff/// @package [OBJC2] 984dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 985dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-instance-variable-decl: 9861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// struct-declaration 987dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 988b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattnervoid Parser::ParseObjCClassInstanceVariables(DeclPtrTy interfaceDecl, 98983c481ade785a919ba21a33f9a8b1b21c1212fb3Fariborz Jahanian tok::ObjCKeywordKind visibility, 99060fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff SourceLocation atLoc) { 991df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner assert(Tok.is(tok::l_brace) && "expected {"); 992b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner llvm::SmallVector<DeclPtrTy, 32> AllIvarDecls; 993e13594279a952537ac903325efff57e3edca79d9Chris Lattner 9941a0d31a3d7f14ddc6370ba912c778aece6c12cf0Douglas Gregor ParseScope ClassScope(this, Scope::DeclScope|Scope::ClassScope); 99572de6676bd30f9081ee4166bbe07b4c270258ce6Douglas Gregor 996ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff SourceLocation LBraceLoc = ConsumeBrace(); // the "{" 9971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 998ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff // While we still have something to read, read the instance variables. 999df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner while (Tok.isNot(tok::r_brace) && Tok.isNot(tok::eof)) { 1000ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff // Each iteration of this loop reads one objc-instance-variable-decl. 10011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1002ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff // Check for extraneous top-level semicolon. 1003df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::semi)) { 1004c2253f5ca170984fcd4f30f8823148e8cb71336bChris Lattner Diag(Tok, diag::ext_extra_struct_semi) 1005849b243d4065f56742a4677d6dc8277609a151f8Douglas Gregor << FixItHint::CreateRemoval(Tok.getLocation()); 1006ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff ConsumeToken(); 1007ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff continue; 1008ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff } 10091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1010ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff // Set the default visibility to private. 1011df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::at)) { // parse objc-visibility-spec 1012ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff ConsumeToken(); // eat the @ sign 1013c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor 1014c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor if (Tok.is(tok::code_completion)) { 1015c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor Actions.CodeCompleteObjCAtVisibility(CurScope); 1016c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor ConsumeToken(); 1017c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor } 1018c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor 1019861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff switch (Tok.getObjCKeywordID()) { 1020ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff case tok::objc_private: 1021ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff case tok::objc_public: 1022ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff case tok::objc_protected: 1023ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff case tok::objc_package: 1024861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff visibility = Tok.getObjCKeywordID(); 1025ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff ConsumeToken(); 10261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump continue; 1027ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff default: 1028ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff Diag(Tok, diag::err_objc_illegal_visibility_spec); 1029ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff continue; 1030ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff } 1031ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff } 10321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1033c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor if (Tok.is(tok::code_completion)) { 1034c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor Actions.CodeCompleteOrdinaryName(CurScope, 1035c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor Action::CCC_ObjCInstanceVariableList); 1036c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor ConsumeToken(); 1037c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor } 1038c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor 1039bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall struct ObjCIvarCallback : FieldCallback { 1040bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall Parser &P; 1041bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall DeclPtrTy IDecl; 1042bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall tok::ObjCKeywordKind visibility; 1043bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall llvm::SmallVectorImpl<DeclPtrTy> &AllIvarDecls; 1044bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall 1045bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall ObjCIvarCallback(Parser &P, DeclPtrTy IDecl, tok::ObjCKeywordKind V, 1046bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall llvm::SmallVectorImpl<DeclPtrTy> &AllIvarDecls) : 1047bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall P(P), IDecl(IDecl), visibility(V), AllIvarDecls(AllIvarDecls) { 1048bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall } 1049bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall 1050bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall DeclPtrTy invoke(FieldDeclarator &FD) { 1051bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall // Install the declarator into the interface decl. 1052bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall DeclPtrTy Field 1053bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall = P.Actions.ActOnIvar(P.CurScope, 1054bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall FD.D.getDeclSpec().getSourceRange().getBegin(), 1055bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall IDecl, FD.D, FD.BitfieldSize, visibility); 1056bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall AllIvarDecls.push_back(Field); 1057bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall return Field; 1058bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall } 1059bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall } Callback(*this, interfaceDecl, visibility, AllIvarDecls); 1060bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall 1061e13594279a952537ac903325efff57e3edca79d9Chris Lattner // Parse all the comma separated declarators. 1062e13594279a952537ac903325efff57e3edca79d9Chris Lattner DeclSpec DS; 1063bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall ParseStructDeclaration(DS, Callback); 10641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1065df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::semi)) { 1066ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff ConsumeToken(); 1067ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff } else { 1068ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff Diag(Tok, diag::err_expected_semi_decl_list); 1069ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff // Skip to end of block or statement 1070ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff SkipUntil(tok::r_brace, true, true); 1071ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff } 1072ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff } 107360fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff SourceLocation RBraceLoc = MatchRHSPunctuation(tok::r_brace, LBraceLoc); 10748749be53f53384e7846502791ceda6c657228d07Steve Naroff // Call ActOnFields() even if we don't have any decls. This is useful 10758749be53f53384e7846502791ceda6c657228d07Steve Naroff // for code rewriting tools that need to be aware of the empty list. 10768749be53f53384e7846502791ceda6c657228d07Steve Naroff Actions.ActOnFields(CurScope, atLoc, interfaceDecl, 1077beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad AllIvarDecls.data(), AllIvarDecls.size(), 10781bfe1c2129771c06fb58ae5e8c079ae30e138309Daniel Dunbar LBraceLoc, RBraceLoc, 0); 1079ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff return; 10805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 1081dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff 1082dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-declaration: 1083dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-definition 1084dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-forward-reference 1085dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1086dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-definition: 10871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// @protocol identifier 10881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// objc-protocol-refs[opt] 10891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// objc-interface-decl-list 1090dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @end 1091dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1092dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-protocol-forward-reference: 1093dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @protocol identifier-list ';' 1094dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1095dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// "@protocol identifier ;" should be resolved as "@protocol 10963536b443bc50d58a79f14fca9b6842541a434854Steve Naroff/// identifier-list ;": objc-interface-decl-list may not start with a 1097dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// semicolon in the first alternative if objc-protocol-refs are omitted. 1098b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris LattnerParser::DeclPtrTy Parser::ParseObjCAtProtocolDeclaration(SourceLocation AtLoc, 1099b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner AttributeList *attrList) { 1100861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff assert(Tok.isObjCAtKeyword(tok::objc_protocol) && 11017ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff "ParseObjCAtProtocolDeclaration(): Expected @protocol"); 11027ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff ConsumeToken(); // the "protocol" identifier 11031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1104083128f6b13dfa4fc615a838c49b516d901b1ac0Douglas Gregor if (Tok.is(tok::code_completion)) { 1105083128f6b13dfa4fc615a838c49b516d901b1ac0Douglas Gregor Actions.CodeCompleteObjCProtocolDecl(CurScope); 1106083128f6b13dfa4fc615a838c49b516d901b1ac0Douglas Gregor ConsumeToken(); 1107083128f6b13dfa4fc615a838c49b516d901b1ac0Douglas Gregor } 1108083128f6b13dfa4fc615a838c49b516d901b1ac0Douglas Gregor 1109df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 11107ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff Diag(Tok, diag::err_expected_ident); // missing protocol name. 1111b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 11127ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff } 11137ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff // Save the protocol name, then consume it. 11147ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff IdentifierInfo *protocolName = Tok.getIdentifierInfo(); 11157ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff SourceLocation nameLoc = ConsumeToken(); 11161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1117df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::semi)) { // forward declaration of one protocol. 11187caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner IdentifierLocPair ProtoInfo(protocolName, nameLoc); 11197ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff ConsumeToken(); 11201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return Actions.ActOnForwardProtocolDeclaration(AtLoc, &ProtoInfo, 1, 1121bc1c877fe28fb6a825f0b226a0a2da99e713ea03Fariborz Jahanian attrList); 11227ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff } 11231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1124df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::comma)) { // list of forward declarations. 11257caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner llvm::SmallVector<IdentifierLocPair, 8> ProtocolRefs; 11267caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner ProtocolRefs.push_back(std::make_pair(protocolName, nameLoc)); 11277caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner 11287ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff // Parse the list of forward declarations. 11297ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff while (1) { 11307ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff ConsumeToken(); // the ',' 1131df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 11327ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff Diag(Tok, diag::err_expected_ident); 11337ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff SkipUntil(tok::semi); 1134b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 11357ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff } 11367caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner ProtocolRefs.push_back(IdentifierLocPair(Tok.getIdentifierInfo(), 11377caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner Tok.getLocation())); 11387ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff ConsumeToken(); // the identifier 11391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1140df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::comma)) 11417ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff break; 11427ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff } 11437ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff // Consume the ';'. 11447ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff if (ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@protocol")) 1145b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 11461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1147e440eb8158e71deb1e4ab11618ae3d680aac6da1Steve Naroff return Actions.ActOnForwardProtocolDeclaration(AtLoc, 11481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump &ProtocolRefs[0], 1149bc1c877fe28fb6a825f0b226a0a2da99e713ea03Fariborz Jahanian ProtocolRefs.size(), 1150bc1c877fe28fb6a825f0b226a0a2da99e713ea03Fariborz Jahanian attrList); 11517caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner } 11521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11537ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff // Last, and definitely not least, parse a protocol declaration. 115471b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis SourceLocation LAngleLoc, EndProtoLoc; 11557caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner 1156b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner llvm::SmallVector<DeclPtrTy, 8> ProtocolRefs; 115771b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis llvm::SmallVector<SourceLocation, 8> ProtocolLocs; 11587caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner if (Tok.is(tok::less) && 115971b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis ParseObjCProtocolReferences(ProtocolRefs, ProtocolLocs, false, 116071b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis LAngleLoc, EndProtoLoc)) 1161b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 11621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1163b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy ProtoType = 1164e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner Actions.ActOnStartProtocolInterface(AtLoc, protocolName, nameLoc, 1165beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad ProtocolRefs.data(), 1166beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad ProtocolRefs.size(), 116718df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor ProtocolLocs.data(), 1168246e70f69cb8aeb67225c54690f1c6b25abd5a86Daniel Dunbar EndProtoLoc, attrList); 116925e077d59a8e8e43b65882b69610a3d5e2aaf53cFariborz Jahanian ParseObjCInterfaceDeclList(ProtoType, tok::objc_protocol); 1170bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner return ProtoType; 1171dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff} 1172dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff 1173dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-implementation: 1174dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-implementation-prologue 1175dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-category-implementation-prologue 1176dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1177dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-implementation-prologue: 1178dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @implementation identifier objc-superclass[opt] 1179dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-class-instance-variables[opt] 1180dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// 1181dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// objc-category-implementation-prologue: 1182dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff/// @implementation identifier ( identifier ) 1183b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris LattnerParser::DeclPtrTy Parser::ParseObjCAtImplementationDeclaration( 1184ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian SourceLocation atLoc) { 1185ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian assert(Tok.isObjCAtKeyword(tok::objc_implementation) && 1186ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian "ParseObjCAtImplementationDeclaration(): Expected @implementation"); 1187ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); // the "implementation" identifier 11881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11893b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor // Code completion after '@implementation'. 11903b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor if (Tok.is(tok::code_completion)) { 11913b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor Actions.CodeCompleteObjCImplementationDecl(CurScope); 11923b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor ConsumeToken(); 11933b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor } 11943b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor 1195df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 1196ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian Diag(Tok, diag::err_expected_ident); // missing class or category name. 1197b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 1198ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1199ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian // We have a class or category name - consume it. 1200ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian IdentifierInfo *nameId = Tok.getIdentifierInfo(); 1201ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian SourceLocation nameLoc = ConsumeToken(); // consume class or category name 12021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (Tok.is(tok::l_paren)) { 1204ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian // we have a category implementation. 1205ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian SourceLocation lparenLoc = ConsumeParen(); 1206ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian SourceLocation categoryLoc, rparenLoc; 1207ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian IdentifierInfo *categoryId = 0; 12081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 120933ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor if (Tok.is(tok::code_completion)) { 121033ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor Actions.CodeCompleteObjCImplementationCategory(CurScope, nameId); 121133ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor ConsumeToken(); 121233ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor } 121333ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor 1214df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::identifier)) { 1215ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian categoryId = Tok.getIdentifierInfo(); 1216ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian categoryLoc = ConsumeToken(); 1217ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } else { 1218ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian Diag(Tok, diag::err_expected_ident); // missing category name. 1219b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 12201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 1221df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::r_paren)) { 1222ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian Diag(Tok, diag::err_expected_rparen); 1223ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian SkipUntil(tok::r_paren, false); // don't stop at ';' 1224b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 1225ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1226ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian rparenLoc = ConsumeParen(); 1227b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy ImplCatType = Actions.ActOnStartCategoryImplementation( 12281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump atLoc, nameId, nameLoc, categoryId, 12298f3fde00ad4d4f943321e338b914ae4740711c84Fariborz Jahanian categoryLoc); 1230a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCImpDecl = ImplCatType; 123163e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian PendingObjCImpDecl.push_back(ObjCImpDecl); 1232b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 1233ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1234ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian // We have a class implementation 1235ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian SourceLocation superClassLoc; 1236ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian IdentifierInfo *superClassId = 0; 1237df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::colon)) { 1238ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian // We have a super class 1239ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); 1240df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 1241ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian Diag(Tok, diag::err_expected_ident); // missing super class name. 1242b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 1243ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1244ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian superClassId = Tok.getIdentifierInfo(); 1245ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian superClassLoc = ConsumeToken(); // Consume super class name 1246ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1247b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy ImplClsType = Actions.ActOnStartClassImplementation( 1248cb53b361bce341c8591333c6997f62e480acc0b4Chris Lattner atLoc, nameId, nameLoc, 1249ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian superClassId, superClassLoc); 12501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 125160fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff if (Tok.is(tok::l_brace)) // we have ivars 125283c481ade785a919ba21a33f9a8b1b21c1212fb3Fariborz Jahanian ParseObjCClassInstanceVariables(ImplClsType/*FIXME*/, 125301f1bfc3284d5817517d35217885ea9ecb252817Fariborz Jahanian tok::objc_private, atLoc); 1254a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCImpDecl = ImplClsType; 125563e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian PendingObjCImpDecl.push_back(ObjCImpDecl); 125663e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian 1257b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 12585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 125960fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff 1260782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted KremenekParser::DeclPtrTy Parser::ParseObjCAtEndDeclaration(SourceRange atEnd) { 1261ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian assert(Tok.isObjCAtKeyword(tok::objc_end) && 1262ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian "ParseObjCAtEndDeclaration(): Expected @end"); 1263b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy Result = ObjCImpDecl; 1264ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); // the "end" identifier 1265a6e3ac514c924879699c6b0b1201028f0091044fFariborz Jahanian if (ObjCImpDecl) { 1266782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek Actions.ActOnAtEnd(atEnd, ObjCImpDecl); 1267b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner ObjCImpDecl = DeclPtrTy(); 126863e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian PendingObjCImpDecl.pop_back(); 1269a6e3ac514c924879699c6b0b1201028f0091044fFariborz Jahanian } 1270782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek else { 1271782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek // missing @implementation 1272782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek Diag(atEnd.getBegin(), diag::warn_expected_implementation); 1273782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek } 1274a6e3ac514c924879699c6b0b1201028f0091044fFariborz Jahanian return Result; 12755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 1276e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian 12771ac7104947020a60430ba6f519cd5869af77046fFariborz JahanianParser::DeclGroupPtrTy Parser::RetrievePendingObjCImpDecl() { 127863e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian if (PendingObjCImpDecl.empty()) 127963e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian return Actions.ConvertDeclToDeclGroup(DeclPtrTy()); 128063e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian DeclPtrTy ImpDecl = PendingObjCImpDecl.pop_back_val(); 1281782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek Actions.ActOnAtEnd(SourceRange(), ImpDecl); 128263e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian return Actions.ConvertDeclToDeclGroup(ImpDecl); 128363e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian} 128463e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian 1285e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian/// compatibility-alias-decl: 1286e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian/// @compatibility_alias alias-name class-name ';' 1287e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian/// 1288b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris LattnerParser::DeclPtrTy Parser::ParseObjCAtAliasDeclaration(SourceLocation atLoc) { 1289e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian assert(Tok.isObjCAtKeyword(tok::objc_compatibility_alias) && 1290e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian "ParseObjCAtAliasDeclaration(): Expected @compatibility_alias"); 1291e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian ConsumeToken(); // consume compatibility_alias 1292df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 1293e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian Diag(Tok, diag::err_expected_ident); 1294b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 1295e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian } 1296243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian IdentifierInfo *aliasId = Tok.getIdentifierInfo(); 1297243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian SourceLocation aliasLoc = ConsumeToken(); // consume alias-name 1298df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 1299e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian Diag(Tok, diag::err_expected_ident); 1300b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 1301e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian } 1302243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian IdentifierInfo *classId = Tok.getIdentifierInfo(); 1303243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian SourceLocation classLoc = ConsumeToken(); // consume class-name; 1304243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian if (Tok.isNot(tok::semi)) { 13051ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_semi_after) << "@compatibility_alias"; 1306b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 1307243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian } 1308b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return Actions.ActOnCompatiblityAlias(atLoc, aliasId, aliasLoc, 1309b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner classId, classLoc); 13105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 13115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1312ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-synthesis: 1313ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// @synthesize property-ivar-list ';' 1314ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// 1315ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-ivar-list: 1316ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-ivar 1317ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-ivar-list ',' property-ivar 1318ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// 1319ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-ivar: 1320ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// identifier 1321ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// identifier '=' identifier 1322ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// 1323b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris LattnerParser::DeclPtrTy Parser::ParseObjCPropertySynthesize(SourceLocation atLoc) { 1324ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian assert(Tok.isObjCAtKeyword(tok::objc_synthesize) && 1325ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian "ParseObjCPropertyDynamic(): Expected '@synthesize'"); 1326f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian SourceLocation loc = ConsumeToken(); // consume synthesize 13271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1328b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor while (true) { 1329322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor if (Tok.is(tok::code_completion)) { 1330424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor Actions.CodeCompleteObjCPropertyDefinition(CurScope, ObjCImpDecl); 1331322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor ConsumeToken(); 1332322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor } 1333322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor 1334b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor if (Tok.isNot(tok::identifier)) { 1335b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor Diag(Tok, diag::err_synthesized_property_name); 1336b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor SkipUntil(tok::semi); 1337b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor return DeclPtrTy(); 1338b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor } 1339b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor 1340f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian IdentifierInfo *propertyIvar = 0; 1341f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian IdentifierInfo *propertyId = Tok.getIdentifierInfo(); 1342f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian SourceLocation propertyLoc = ConsumeToken(); // consume property name 1343df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::equal)) { 1344ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian // property '=' ivar-name 1345ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); // consume '=' 1346322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor 1347322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor if (Tok.is(tok::code_completion)) { 1348322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor Actions.CodeCompleteObjCPropertySynthesizeIvar(CurScope, propertyId, 1349322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor ObjCImpDecl); 1350322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor ConsumeToken(); 1351322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor } 1352322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor 1353df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::identifier)) { 1354ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian Diag(Tok, diag::err_expected_ident); 1355ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian break; 1356ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1357f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian propertyIvar = Tok.getIdentifierInfo(); 1358ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); // consume ivar-name 1359ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1360f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian Actions.ActOnPropertyImplDecl(atLoc, propertyLoc, true, ObjCImpDecl, 1361f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian propertyId, propertyIvar); 1362df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::comma)) 1363ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian break; 1364ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); // consume ',' 1365ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1366b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor if (Tok.isNot(tok::semi)) { 13671ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_semi_after) << "@synthesize"; 1368b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor SkipUntil(tok::semi); 1369b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor } 1370d3fdcb5a1bf6bd5e54e18579c054ea3c292a0e28Fariborz Jahanian else 1371d3fdcb5a1bf6bd5e54e18579c054ea3c292a0e28Fariborz Jahanian ConsumeToken(); // consume ';' 1372b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 1373ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian} 1374ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian 1375ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-dynamic: 1376ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// @dynamic property-list 1377ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// 1378ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-list: 1379ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// identifier 1380ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// property-list ',' identifier 1381ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// 1382b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris LattnerParser::DeclPtrTy Parser::ParseObjCPropertyDynamic(SourceLocation atLoc) { 1383ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian assert(Tok.isObjCAtKeyword(tok::objc_dynamic) && 1384ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian "ParseObjCPropertyDynamic(): Expected '@dynamic'"); 1385ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian SourceLocation loc = ConsumeToken(); // consume dynamic 1386424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor while (true) { 1387424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor if (Tok.is(tok::code_completion)) { 1388424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor Actions.CodeCompleteObjCPropertyDefinition(CurScope, ObjCImpDecl); 1389424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor ConsumeToken(); 1390424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor } 1391424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor 1392424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor if (Tok.isNot(tok::identifier)) { 1393424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor Diag(Tok, diag::err_expected_ident); 1394424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor SkipUntil(tok::semi); 1395424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor return DeclPtrTy(); 1396424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor } 1397424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor 1398c35b9e4e2efad727538c848cf30d4b0eb1031dc9Fariborz Jahanian IdentifierInfo *propertyId = Tok.getIdentifierInfo(); 1399c35b9e4e2efad727538c848cf30d4b0eb1031dc9Fariborz Jahanian SourceLocation propertyLoc = ConsumeToken(); // consume property name 1400c35b9e4e2efad727538c848cf30d4b0eb1031dc9Fariborz Jahanian Actions.ActOnPropertyImplDecl(atLoc, propertyLoc, false, ObjCImpDecl, 1401c35b9e4e2efad727538c848cf30d4b0eb1031dc9Fariborz Jahanian propertyId, 0); 1402c35b9e4e2efad727538c848cf30d4b0eb1031dc9Fariborz Jahanian 1403df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::comma)) 1404ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian break; 1405ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); // consume ',' 1406ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1407df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::semi)) 14081ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_semi_after) << "@dynamic"; 1409b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 1410ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian} 14111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1412397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// objc-throw-statement: 1413397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// throw expression[opt]; 1414397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// 141543bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian RedlParser::OwningStmtResult Parser::ParseObjCThrowStmt(SourceLocation atLoc) { 141615faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl OwningExprResult Res(Actions); 1417397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian ConsumeToken(); // consume throw 1418df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::semi)) { 141939f8f159c488a900e5958d5aab3e467af9ec8a2bFariborz Jahanian Res = ParseExpression(); 14200e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Res.isInvalid()) { 1421397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian SkipUntil(tok::semi); 142243bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 1423397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian } 1424397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian } 142539f8f159c488a900e5958d5aab3e467af9ec8a2bFariborz Jahanian ConsumeToken(); // consume ';' 1426e21dd6ffef4585fa43cd3586ed971217d65bf56cSteve Naroff return Actions.ActOnObjCAtThrowStmt(atLoc, move(Res), CurScope); 1427397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian} 1428397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian 1429c385c90c68dfa376650e2facfbb444b2ec9bd110Fariborz Jahanian/// objc-synchronized-statement: 143078a677bbb5fa115fa0995b5783adeeefad67167eFariborz Jahanian/// @synchronized '(' expression ')' compound-statement 1431c385c90c68dfa376650e2facfbb444b2ec9bd110Fariborz Jahanian/// 143243bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian RedlParser::OwningStmtResult 143343bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian RedlParser::ParseObjCSynchronizedStmt(SourceLocation atLoc) { 1434fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian ConsumeToken(); // consume synchronized 1435fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian if (Tok.isNot(tok::l_paren)) { 14361ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_lparen_after) << "@synchronized"; 143743bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 1438fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian } 1439fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian ConsumeParen(); // '(' 14402f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl OwningExprResult Res(ParseExpression()); 14410e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Res.isInvalid()) { 1442fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian SkipUntil(tok::semi); 144343bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 1444fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian } 1445fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian if (Tok.isNot(tok::r_paren)) { 14461ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_lbrace); 144743bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 1448fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian } 1449fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian ConsumeParen(); // ')' 145078a677bbb5fa115fa0995b5783adeeefad67167eFariborz Jahanian if (Tok.isNot(tok::l_brace)) { 14511ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_lbrace); 145243bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 145378a677bbb5fa115fa0995b5783adeeefad67167eFariborz Jahanian } 14543ac438c383a4a9a73c76a05c76ec5d02f10a3c52Steve Naroff // Enter a scope to hold everything within the compound stmt. Compound 14553ac438c383a4a9a73c76a05c76ec5d02f10a3c52Steve Naroff // statements can always hold declarations. 14568935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor ParseScope BodyScope(this, Scope::DeclScope); 14573ac438c383a4a9a73c76a05c76ec5d02f10a3c52Steve Naroff 145861364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl OwningStmtResult SynchBody(ParseCompoundStatementBody()); 14590e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl 14608935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor BodyScope.Exit(); 14610e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (SynchBody.isInvalid()) 1462fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian SynchBody = Actions.ActOnNullStmt(Tok.getLocation()); 146376ad2e85575722e8a38a2bd4648ab4304d9fcd24Sebastian Redl return Actions.ActOnObjCAtSynchronizedStmt(atLoc, move(Res), move(SynchBody)); 1464c385c90c68dfa376650e2facfbb444b2ec9bd110Fariborz Jahanian} 1465c385c90c68dfa376650e2facfbb444b2ec9bd110Fariborz Jahanian 1466397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// objc-try-catch-statement: 1467397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// @try compound-statement objc-catch-list[opt] 1468397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// @try compound-statement objc-catch-list[opt] @finally compound-statement 1469397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// 1470397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// objc-catch-list: 1471397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// @catch ( parameter-declaration ) compound-statement 1472397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// objc-catch-list @catch ( catch-parameter-declaration ) compound-statement 1473397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// catch-parameter-declaration: 1474397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// parameter-declaration 1475397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// '...' [OBJC2] 1476397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian/// 147743bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian RedlParser::OwningStmtResult Parser::ParseObjCTryStmt(SourceLocation atLoc) { 1478397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian bool catch_or_finally_seen = false; 147943bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl 1480397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian ConsumeToken(); // consume try 1481df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::l_brace)) { 14821ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_lbrace); 148343bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 1484397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian } 148515faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl OwningStmtResult CatchStmts(Actions); 148615faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl OwningStmtResult FinallyStmt(Actions); 14878935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor ParseScope TryScope(this, Scope::DeclScope); 148861364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl OwningStmtResult TryBody(ParseCompoundStatementBody()); 14898935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor TryScope.Exit(); 14900e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (TryBody.isInvalid()) 1491bd49a647afd9cc534fef13cadf652d4e9c396e2bFariborz Jahanian TryBody = Actions.ActOnNullStmt(Tok.getLocation()); 1492a55e52c0802cae3b7c366a05c461d3d15074c1a3Sebastian Redl 1493df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner while (Tok.is(tok::at)) { 14946b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner // At this point, we need to lookahead to determine if this @ is the start 14956b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner // of an @catch or @finally. We don't want to consume the @ token if this 14966b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner // is an @try or @encode or something else. 14976b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner Token AfterAt = GetLookAheadToken(1); 14986b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner if (!AfterAt.isObjCAtKeyword(tok::objc_catch) && 14996b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner !AfterAt.isObjCAtKeyword(tok::objc_finally)) 15006b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner break; 15010e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl 1502161a9c5afaafb4d527b7efba9675a8b2cbbe32e0Fariborz Jahanian SourceLocation AtCatchFinallyLoc = ConsumeToken(); 1503cb53b361bce341c8591333c6997f62e480acc0b4Chris Lattner if (Tok.isObjCAtKeyword(tok::objc_catch)) { 1504b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy FirstPart; 15053b1191d7eaf2f4984564e01ab84b6713a9d80e70Fariborz Jahanian ConsumeToken(); // consume catch 1506df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::l_paren)) { 1507397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian ConsumeParen(); 1508e21dd6ffef4585fa43cd3586ed971217d65bf56cSteve Naroff ParseScope CatchScope(this, Scope::DeclScope|Scope::AtCatchScope); 1509df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::ellipsis)) { 1510397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian DeclSpec DS; 1511397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian ParseDeclarationSpecifiers(DS); 151243bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl // For some odd reason, the name of the exception variable is 15131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // optional. As a result, we need to use "PrototypeContext", because 15147ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff // we must accept either 'declarator' or 'abstract-declarator' here. 15157ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff Declarator ParmDecl(DS, Declarator::PrototypeContext); 15167ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff ParseDeclarator(ParmDecl); 15177ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff 15187ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff // Inform the actions module about the parameter declarator, so it 15197ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff // gets added to the current scope. 1520d219a3a462c31fc9aa0c0bcfb749e9e8e56b5e35Fariborz Jahanian // FIXME. Probably can build a VarDecl and avoid setting DeclContext. 15217ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff FirstPart = Actions.ActOnParamDeclarator(CurScope, ParmDecl); 15222f764f11f513c7b51c716fffa5d02e5de816836fFariborz Jahanian Actions.ActOnObjCCatchParam(FirstPart); 152364515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff } else 1524397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian ConsumeToken(); // consume '...' 15251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 152693a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff SourceLocation RParenLoc; 15271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 152893a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff if (Tok.is(tok::r_paren)) 152993a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff RParenLoc = ConsumeParen(); 153093a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff else // Skip over garbage, until we get to ')'. Eat the ')'. 153193a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff SkipUntil(tok::r_paren, true, false); 153293a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff 153315faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl OwningStmtResult CatchBody(Actions, true); 1534c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner if (Tok.is(tok::l_brace)) 1535c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner CatchBody = ParseCompoundStatementBody(); 1536c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner else 1537c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner Diag(Tok, diag::err_expected_lbrace); 15380e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (CatchBody.isInvalid()) 15393b1191d7eaf2f4984564e01ab84b6713a9d80e70Fariborz Jahanian CatchBody = Actions.ActOnNullStmt(Tok.getLocation()); 15400e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl CatchStmts = Actions.ActOnObjCAtCatchStmt(AtCatchFinallyLoc, 15417ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff RParenLoc, FirstPart, move(CatchBody), 154276ad2e85575722e8a38a2bd4648ab4304d9fcd24Sebastian Redl move(CatchStmts)); 154364515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff } else { 15441ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(AtCatchFinallyLoc, diag::err_expected_lparen_after) 15451ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner << "@catch clause"; 154643bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 1547397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian } 1548397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian catch_or_finally_seen = true; 15496b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner } else { 15506b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner assert(Tok.isObjCAtKeyword(tok::objc_finally) && "Lookahead confused?"); 155164515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff ConsumeToken(); // consume finally 15528935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor ParseScope FinallyScope(this, Scope::DeclScope); 15530e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl 155415faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl OwningStmtResult FinallyBody(Actions, true); 1555c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner if (Tok.is(tok::l_brace)) 1556c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner FinallyBody = ParseCompoundStatementBody(); 1557c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner else 1558c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner Diag(Tok, diag::err_expected_lbrace); 15590e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (FinallyBody.isInvalid()) 1560161a9c5afaafb4d527b7efba9675a8b2cbbe32e0Fariborz Jahanian FinallyBody = Actions.ActOnNullStmt(Tok.getLocation()); 15610e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl FinallyStmt = Actions.ActOnObjCAtFinallyStmt(AtCatchFinallyLoc, 156276ad2e85575722e8a38a2bd4648ab4304d9fcd24Sebastian Redl move(FinallyBody)); 1563397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian catch_or_finally_seen = true; 1564397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian break; 1565397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian } 1566397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian } 1567bd49a647afd9cc534fef13cadf652d4e9c396e2bFariborz Jahanian if (!catch_or_finally_seen) { 1568397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian Diag(atLoc, diag::err_missing_catch_finally); 156943bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 1570bd49a647afd9cc534fef13cadf652d4e9c396e2bFariborz Jahanian } 157176ad2e85575722e8a38a2bd4648ab4304d9fcd24Sebastian Redl return Actions.ActOnObjCAtTryStmt(atLoc, move(TryBody), move(CatchStmts), 157276ad2e85575722e8a38a2bd4648ab4304d9fcd24Sebastian Redl move(FinallyStmt)); 1573397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian} 1574ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian 15753536b443bc50d58a79f14fca9b6842541a434854Steve Naroff/// objc-method-def: objc-method-proto ';'[opt] '{' body '}' 1576ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian/// 1577b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris LattnerParser::DeclPtrTy Parser::ParseObjCMethodDefinition() { 1578b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy MDecl = ParseObjCMethodPrototype(ObjCImpDecl); 15791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 158049f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner PrettyStackTraceActionsDecl CrashInfo(MDecl, Tok.getLocation(), Actions, 158149f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner PP.getSourceManager(), 158249f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner "parsing Objective-C method"); 15831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1584ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian // parse optional ';' 1585209a8c2fa23636f6d065d618e7078e164903f5cdFariborz Jahanian if (Tok.is(tok::semi)) { 1586496e45ef3350fabc312c5a807d308c65c50af4dbTed Kremenek if (ObjCImpDecl) { 1587496e45ef3350fabc312c5a807d308c65c50af4dbTed Kremenek Diag(Tok, diag::warn_semicolon_before_method_body) 1588849b243d4065f56742a4677d6dc8277609a151f8Douglas Gregor << FixItHint::CreateRemoval(Tok.getLocation()); 1589496e45ef3350fabc312c5a807d308c65c50af4dbTed Kremenek } 1590ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian ConsumeToken(); 1591209a8c2fa23636f6d065d618e7078e164903f5cdFariborz Jahanian } 1592ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian 1593409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // We should have an opening brace now. 1594df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::l_brace)) { 1595da323adbb99cee19a203ead852d5d9bfebb23fb7Steve Naroff Diag(Tok, diag::err_expected_method_body); 15961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1597409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // Skip over garbage, until we get to '{'. Don't eat the '{'. 1598409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff SkipUntil(tok::l_brace, true, true); 15991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1600409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // If we didn't find the '{', bail out. 1601409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff if (Tok.isNot(tok::l_brace)) 1602b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner return DeclPtrTy(); 1603ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian } 1604409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff SourceLocation BraceLoc = Tok.getLocation(); 16051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1606409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // Enter a scope for the method body. 16078935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor ParseScope BodyScope(this, Scope::FnScope|Scope::DeclScope); 16081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1609409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // Tell the actions module that we have entered a method definition with the 1610394f3f483fa4e7b472630cfcd03f7840520958c5Steve Naroff // specified Declarator for the method. 1611ebf6443a4f493233f7e8d92b3a991848c8b1c00dSteve Naroff Actions.ActOnStartOfObjCMethodDef(CurScope, MDecl); 161261364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl 161361364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl OwningStmtResult FnBody(ParseCompoundStatementBody()); 161461364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl 1615409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // If the function body could not be parsed, make a bogus compoundstmt. 16160e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (FnBody.isInvalid()) 1617a60528cdac7deee3991c2b48af4df4f315e49e9dSebastian Redl FnBody = Actions.ActOnCompoundStmt(BraceLoc, BraceLoc, 1618a60528cdac7deee3991c2b48af4df4f315e49e9dSebastian Redl MultiStmtArg(Actions), false); 1619798d119415323ebcd029ffe1e0fb442a4ca8adbbSebastian Redl 162032ce8376efb7e0d70e5f7e8fcf685130293f412bSteve Naroff // TODO: Pass argument information. 162132ce8376efb7e0d70e5f7e8fcf685130293f412bSteve Naroff Actions.ActOnFinishFunctionBody(MDecl, move(FnBody)); 16221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1623409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff // Leave the function body scope. 16248935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor BodyScope.Exit(); 1625798d119415323ebcd029ffe1e0fb442a4ca8adbbSebastian Redl 162671c0a951d08dc7a2a057df8c15f22b36f6aa47c7Steve Naroff return MDecl; 16275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 16285508518a2702b00be3b15a26d772bde968972f54Anders Carlsson 162943bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian RedlParser::OwningStmtResult Parser::ParseObjCAtStatement(SourceLocation AtLoc) { 16309a0c85e640a08174569a303db22981612f05d385Douglas Gregor if (Tok.is(tok::code_completion)) { 16319a0c85e640a08174569a303db22981612f05d385Douglas Gregor Actions.CodeCompleteObjCAtStatement(CurScope); 16329a0c85e640a08174569a303db22981612f05d385Douglas Gregor ConsumeToken(); 16339a0c85e640a08174569a303db22981612f05d385Douglas Gregor return StmtError(); 16345d8031687d086701b4dadaab3e0de1def448da9dChris Lattner } 16355d8031687d086701b4dadaab3e0de1def448da9dChris Lattner 16365d8031687d086701b4dadaab3e0de1def448da9dChris Lattner if (Tok.isObjCAtKeyword(tok::objc_try)) 16376b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner return ParseObjCTryStmt(AtLoc); 16385d8031687d086701b4dadaab3e0de1def448da9dChris Lattner 16395d8031687d086701b4dadaab3e0de1def448da9dChris Lattner if (Tok.isObjCAtKeyword(tok::objc_throw)) 164064515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff return ParseObjCThrowStmt(AtLoc); 16415d8031687d086701b4dadaab3e0de1def448da9dChris Lattner 16425d8031687d086701b4dadaab3e0de1def448da9dChris Lattner if (Tok.isObjCAtKeyword(tok::objc_synchronized)) 164364515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff return ParseObjCSynchronizedStmt(AtLoc); 16445d8031687d086701b4dadaab3e0de1def448da9dChris Lattner 1645d8c4e15138e69a51754cc259c8a592cc47950c8eSebastian Redl OwningExprResult Res(ParseExpressionWithLeadingAt(AtLoc)); 16460e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Res.isInvalid()) { 164764515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff // If the expression is invalid, skip ahead to the next semicolon. Not 164864515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff // doing this opens us up to the possibility of infinite loops if 164964515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff // ParseExpression does not consume any tokens. 165064515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff SkipUntil(tok::semi); 165143bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl return StmtError(); 165264515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff } 16535d8031687d086701b4dadaab3e0de1def448da9dChris Lattner 165464515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff // Otherwise, eat the semicolon. 165564515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff ExpectAndConsume(tok::semi, diag::err_expected_semi_after_expr); 16565ee56e95c3905d2e7bc403631b03865cdbdd8a42Anders Carlsson return Actions.ActOnExprStmt(Actions.MakeFullExpr(Res)); 165764515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff} 165864515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff 16591d922960e083906a586609ac6978678147250177Sebastian RedlParser::OwningExprResult Parser::ParseObjCAtExpression(SourceLocation AtLoc) { 16605508518a2702b00be3b15a26d772bde968972f54Anders Carlsson switch (Tok.getKind()) { 16619a0c85e640a08174569a303db22981612f05d385Douglas Gregor case tok::code_completion: 16629a0c85e640a08174569a303db22981612f05d385Douglas Gregor Actions.CodeCompleteObjCAtExpression(CurScope); 16639a0c85e640a08174569a303db22981612f05d385Douglas Gregor ConsumeToken(); 16649a0c85e640a08174569a303db22981612f05d385Douglas Gregor return ExprError(); 16659a0c85e640a08174569a303db22981612f05d385Douglas Gregor 1666b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner case tok::string_literal: // primary-expression: string-literal 1667b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner case tok::wide_string_literal: 16681d922960e083906a586609ac6978678147250177Sebastian Redl return ParsePostfixExpressionSuffix(ParseObjCStringLiteral(AtLoc)); 1669b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner default: 16704fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner if (Tok.getIdentifierInfo() == 0) 16711d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(AtLoc, diag::err_unexpected_at)); 16722f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl 16734fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner switch (Tok.getIdentifierInfo()->getObjCKeywordID()) { 16744fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner case tok::objc_encode: 16751d922960e083906a586609ac6978678147250177Sebastian Redl return ParsePostfixExpressionSuffix(ParseObjCEncodeExpression(AtLoc)); 16764fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner case tok::objc_protocol: 16771d922960e083906a586609ac6978678147250177Sebastian Redl return ParsePostfixExpressionSuffix(ParseObjCProtocolExpression(AtLoc)); 16784fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner case tok::objc_selector: 16791d922960e083906a586609ac6978678147250177Sebastian Redl return ParsePostfixExpressionSuffix(ParseObjCSelectorExpression(AtLoc)); 16804fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner default: 16811d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(AtLoc, diag::err_unexpected_at)); 16824fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner } 16835508518a2702b00be3b15a26d772bde968972f54Anders Carlsson } 16845508518a2702b00be3b15a26d772bde968972f54Anders Carlsson} 16855508518a2702b00be3b15a26d772bde968972f54Anders Carlsson 16861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// objc-message-expr: 16870ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// '[' objc-receiver objc-message-args ']' 16880ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// 16890ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-receiver: 16900ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// expression 16910ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// class-name 16920ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// type-name 16931d922960e083906a586609ac6978678147250177Sebastian RedlParser::OwningExprResult Parser::ParseObjCMessageExpression() { 1694699b66138ac307a32e238463e0eff513ff17d337Chris Lattner assert(Tok.is(tok::l_square) && "'[' expected"); 1695699b66138ac307a32e238463e0eff513ff17d337Chris Lattner SourceLocation LBracLoc = ConsumeBracket(); // consume '[' 1696699b66138ac307a32e238463e0eff513ff17d337Chris Lattner 1697699b66138ac307a32e238463e0eff513ff17d337Chris Lattner // Parse receiver 169814dd98a7952c9559e0d17fff8272bf3be67135afChris Lattner if (isTokObjCMessageIdentifierReceiver()) { 1699699b66138ac307a32e238463e0eff513ff17d337Chris Lattner IdentifierInfo *ReceiverName = Tok.getIdentifierInfo(); 1700d2869925b5f10e00b13fbf3f41bbb17e4c9adbe0Fariborz Jahanian if (ReceiverName != Ident_super || GetLookAheadToken(1).isNot(tok::period)) { 1701d2869925b5f10e00b13fbf3f41bbb17e4c9adbe0Fariborz Jahanian SourceLocation NameLoc = ConsumeToken(); 1702d2869925b5f10e00b13fbf3f41bbb17e4c9adbe0Fariborz Jahanian return ParseObjCMessageExpressionBody(LBracLoc, NameLoc, ReceiverName, 1703d2869925b5f10e00b13fbf3f41bbb17e4c9adbe0Fariborz Jahanian ExprArg(Actions)); 1704d2869925b5f10e00b13fbf3f41bbb17e4c9adbe0Fariborz Jahanian } 1705699b66138ac307a32e238463e0eff513ff17d337Chris Lattner } 1706699b66138ac307a32e238463e0eff513ff17d337Chris Lattner 17072f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl OwningExprResult Res(ParseExpression()); 17080e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Res.isInvalid()) { 17095c749428a9938d5e2e9564b1c9b7a9252c30ee27Chris Lattner SkipUntil(tok::r_square); 17101d922960e083906a586609ac6978678147250177Sebastian Redl return move(Res); 1711699b66138ac307a32e238463e0eff513ff17d337Chris Lattner } 17121d922960e083906a586609ac6978678147250177Sebastian Redl 17130e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(), 171476ad2e85575722e8a38a2bd4648ab4304d9fcd24Sebastian Redl 0, move(Res)); 1715699b66138ac307a32e238463e0eff513ff17d337Chris Lattner} 17161d922960e083906a586609ac6978678147250177Sebastian Redl 1717699b66138ac307a32e238463e0eff513ff17d337Chris Lattner/// ParseObjCMessageExpressionBody - Having parsed "'[' objc-receiver", parse 1718699b66138ac307a32e238463e0eff513ff17d337Chris Lattner/// the rest of a message expression. 17191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 17200ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-message-args: 17210ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-selector 17220ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-keywordarg-list 17230ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// 17240ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-keywordarg-list: 17250ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-keywordarg 17260ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-keywordarg-list objc-keywordarg 17270ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// 17281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// objc-keywordarg: 17290ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// selector-name[opt] ':' objc-keywordexpr 17300ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// 17310ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// objc-keywordexpr: 17320ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// nonempty-expr-list 17330ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// 17340ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// nonempty-expr-list: 17350ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// assignment-expression 17360ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian/// nonempty-expr-list , assignment-expression 17371d922960e083906a586609ac6978678147250177Sebastian Redl/// 17381d922960e083906a586609ac6978678147250177Sebastian RedlParser::OwningExprResult 1739699b66138ac307a32e238463e0eff513ff17d337Chris LattnerParser::ParseObjCMessageExpressionBody(SourceLocation LBracLoc, 17405cb93b8bf009c4b0ae09b71ba85f54b2a7ea8022Steve Naroff SourceLocation NameLoc, 1741699b66138ac307a32e238463e0eff513ff17d337Chris Lattner IdentifierInfo *ReceiverName, 17421d922960e083906a586609ac6978678147250177Sebastian Redl ExprArg ReceiverExpr) { 1743c4df6d2c05c647a6a5770ba0c749782b6c023a3aSteve Naroff if (Tok.is(tok::code_completion)) { 1744c4df6d2c05c647a6a5770ba0c749782b6c023a3aSteve Naroff if (ReceiverName) 1745d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor Actions.CodeCompleteObjCClassMessage(CurScope, ReceiverName, NameLoc, 1746d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor 0, 0); 1747c4df6d2c05c647a6a5770ba0c749782b6c023a3aSteve Naroff else 1748d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor Actions.CodeCompleteObjCInstanceMessage(CurScope, ReceiverExpr.get(), 1749d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor 0, 0); 1750c4df6d2c05c647a6a5770ba0c749782b6c023a3aSteve Naroff ConsumeToken(); 1751c4df6d2c05c647a6a5770ba0c749782b6c023a3aSteve Naroff } 1752d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor 1753a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian // Parse objc-selector 17544b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian SourceLocation Loc; 17552fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner IdentifierInfo *selIdent = ParseObjCSelectorPiece(Loc); 175668d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff 1757ff975cfab9ada27df86038286d1678084aeb3428Anders Carlsson SourceLocation SelectorLoc = Loc; 17581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 175968d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff llvm::SmallVector<IdentifierInfo *, 12> KeyIdents; 1760a55e52c0802cae3b7c366a05c461d3d15074c1a3Sebastian Redl ExprVector KeyExprs(Actions); 176168d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff 1762df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.is(tok::colon)) { 1763a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian while (1) { 1764a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian // Each iteration parses a single keyword argument. 176568d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff KeyIdents.push_back(selIdent); 176637387c932855c6d58d70bdd705cd3a9fdcd2a931Steve Naroff 1767df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::colon)) { 1768a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian Diag(Tok, diag::err_expected_colon); 17694fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // We must manually skip to a ']', otherwise the expression skipper will 17704fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // stop at the ']' when it skips to the ';'. We want it to skip beyond 17714fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // the enclosing expression. 17724fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner SkipUntil(tok::r_square); 17731d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(); 1774a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian } 17751d922960e083906a586609ac6978678147250177Sebastian Redl 177668d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff ConsumeToken(); // Eat the ':'. 17771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// Parse the expression after ':' 17782f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl OwningExprResult Res(ParseAssignmentExpression()); 17790e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Res.isInvalid()) { 17804fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // We must manually skip to a ']', otherwise the expression skipper will 17814fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // stop at the ']' when it skips to the ';'. We want it to skip beyond 17824fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // the enclosing expression. 17834fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner SkipUntil(tok::r_square); 17841d922960e083906a586609ac6978678147250177Sebastian Redl return move(Res); 178537387c932855c6d58d70bdd705cd3a9fdcd2a931Steve Naroff } 17861d922960e083906a586609ac6978678147250177Sebastian Redl 178737387c932855c6d58d70bdd705cd3a9fdcd2a931Steve Naroff // We have a valid expression. 1788effa8d1c97b00a3f53e972b0e61d9aade5ea1c57Sebastian Redl KeyExprs.push_back(Res.release()); 17891d922960e083906a586609ac6978678147250177Sebastian Redl 1790d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor // Code completion after each argument. 1791d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor if (Tok.is(tok::code_completion)) { 1792d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor if (ReceiverName) 1793d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor Actions.CodeCompleteObjCClassMessage(CurScope, ReceiverName, NameLoc, 1794d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor KeyIdents.data(), 1795d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor KeyIdents.size()); 1796d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor else 1797d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor Actions.CodeCompleteObjCInstanceMessage(CurScope, ReceiverExpr.get(), 1798d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor KeyIdents.data(), 1799d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor KeyIdents.size()); 1800d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor ConsumeToken(); 1801d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor } 1802d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor 180337387c932855c6d58d70bdd705cd3a9fdcd2a931Steve Naroff // Check for another keyword selector. 18042fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner selIdent = ParseObjCSelectorPiece(Loc); 1805df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (!selIdent && Tok.isNot(tok::colon)) 1806a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian break; 1807a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian // We have a selector or a colon, continue parsing. 1808a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian } 1809a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian // Parse the, optional, argument list, comma separated. 1810df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner while (Tok.is(tok::comma)) { 181149f109c786f99eb7468dac3976db083a65493444Steve Naroff ConsumeToken(); // Eat the ','. 18121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// Parse the expression after ',' 18132f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl OwningExprResult Res(ParseAssignmentExpression()); 18140e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Res.isInvalid()) { 18154fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // We must manually skip to a ']', otherwise the expression skipper will 18164fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // stop at the ']' when it skips to the ';'. We want it to skip beyond 18174fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // the enclosing expression. 18184fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner SkipUntil(tok::r_square); 18191d922960e083906a586609ac6978678147250177Sebastian Redl return move(Res); 182049f109c786f99eb7468dac3976db083a65493444Steve Naroff } 18210e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl 182249f109c786f99eb7468dac3976db083a65493444Steve Naroff // We have a valid expression. 1823effa8d1c97b00a3f53e972b0e61d9aade5ea1c57Sebastian Redl KeyExprs.push_back(Res.release()); 1824a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian } 1825a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian } else if (!selIdent) { 1826a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian Diag(Tok, diag::err_expected_ident); // missing selector name. 18271d922960e083906a586609ac6978678147250177Sebastian Redl 18284fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // We must manually skip to a ']', otherwise the expression skipper will 18294fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // stop at the ']' when it skips to the ';'. We want it to skip beyond 18304fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // the enclosing expression. 18314fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner SkipUntil(tok::r_square); 18321d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(); 1833a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian } 1834809872eca7f6c024e2ab41ddffbbeeae807bf5dcFariborz Jahanian 1835df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner if (Tok.isNot(tok::r_square)) { 1836809872eca7f6c024e2ab41ddffbbeeae807bf5dcFariborz Jahanian if (Tok.is(tok::identifier)) 1837809872eca7f6c024e2ab41ddffbbeeae807bf5dcFariborz Jahanian Diag(Tok, diag::err_expected_colon); 1838809872eca7f6c024e2ab41ddffbbeeae807bf5dcFariborz Jahanian else 1839809872eca7f6c024e2ab41ddffbbeeae807bf5dcFariborz Jahanian Diag(Tok, diag::err_expected_rsquare); 18404fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // We must manually skip to a ']', otherwise the expression skipper will 18414fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // stop at the ']' when it skips to the ';'. We want it to skip beyond 18424fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner // the enclosing expression. 18434fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner SkipUntil(tok::r_square); 18441d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(); 1845a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian } 18461d922960e083906a586609ac6978678147250177Sebastian Redl 1847699b66138ac307a32e238463e0eff513ff17d337Chris Lattner SourceLocation RBracLoc = ConsumeBracket(); // consume ']' 18481d922960e083906a586609ac6978678147250177Sebastian Redl 184929238a0bf7cbf5b396efb451a0adb5fe4aa037caSteve Naroff unsigned nKeys = KeyIdents.size(); 1850ff38491c18b060526d754765b952f4a497a89416Chris Lattner if (nKeys == 0) 1851ff38491c18b060526d754765b952f4a497a89416Chris Lattner KeyIdents.push_back(selIdent); 1852ff38491c18b060526d754765b952f4a497a89416Chris Lattner Selector Sel = PP.getSelectorTable().getSelector(nKeys, &KeyIdents[0]); 18531d922960e083906a586609ac6978678147250177Sebastian Redl 1854ff38491c18b060526d754765b952f4a497a89416Chris Lattner // We've just parsed a keyword message. 18551d922960e083906a586609ac6978678147250177Sebastian Redl if (ReceiverName) 18561d922960e083906a586609ac6978678147250177Sebastian Redl return Owned(Actions.ActOnClassMessage(CurScope, ReceiverName, Sel, 18571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump LBracLoc, NameLoc, SelectorLoc, 1858ff975cfab9ada27df86038286d1678084aeb3428Anders Carlsson RBracLoc, 18591d922960e083906a586609ac6978678147250177Sebastian Redl KeyExprs.take(), KeyExprs.size())); 18601d922960e083906a586609ac6978678147250177Sebastian Redl return Owned(Actions.ActOnInstanceMessage(ReceiverExpr.release(), Sel, 1861ff975cfab9ada27df86038286d1678084aeb3428Anders Carlsson LBracLoc, SelectorLoc, RBracLoc, 18621d922960e083906a586609ac6978678147250177Sebastian Redl KeyExprs.take(), KeyExprs.size())); 18630ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian} 18640ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian 18651d922960e083906a586609ac6978678147250177Sebastian RedlParser::OwningExprResult Parser::ParseObjCStringLiteral(SourceLocation AtLoc) { 186620df9b7ab9388b2a488c5b1293cd196b1e073b4eSebastian Redl OwningExprResult Res(ParseStringLiteralExpression()); 18671d922960e083906a586609ac6978678147250177Sebastian Redl if (Res.isInvalid()) return move(Res); 18681d922960e083906a586609ac6978678147250177Sebastian Redl 1869b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner // @"foo" @"bar" is a valid concatenated string. Eat any subsequent string 1870b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner // expressions. At this point, we know that the only valid thing that starts 1871b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner // with '@' is an @"". 1872b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner llvm::SmallVector<SourceLocation, 4> AtLocs; 1873a55e52c0802cae3b7c366a05c461d3d15074c1a3Sebastian Redl ExprVector AtStrings(Actions); 1874b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner AtLocs.push_back(AtLoc); 1875effa8d1c97b00a3f53e972b0e61d9aade5ea1c57Sebastian Redl AtStrings.push_back(Res.release()); 18760e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl 1877b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner while (Tok.is(tok::at)) { 1878b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner AtLocs.push_back(ConsumeToken()); // eat the @. 1879b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner 188015faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl // Invalid unless there is a string literal. 188197cf6eb380016db868866faf27a086cd55a316d4Chris Lattner if (!isTokenStringLiteral()) 188297cf6eb380016db868866faf27a086cd55a316d4Chris Lattner return ExprError(Diag(Tok, diag::err_objc_concat_string)); 1883b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner 188497cf6eb380016db868866faf27a086cd55a316d4Chris Lattner OwningExprResult Lit(ParseStringLiteralExpression()); 18850e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Lit.isInvalid()) 18861d922960e083906a586609ac6978678147250177Sebastian Redl return move(Lit); 18870e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl 1888effa8d1c97b00a3f53e972b0e61d9aade5ea1c57Sebastian Redl AtStrings.push_back(Lit.release()); 1889b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner } 18901d922960e083906a586609ac6978678147250177Sebastian Redl 18911d922960e083906a586609ac6978678147250177Sebastian Redl return Owned(Actions.ParseObjCStringLiteral(&AtLocs[0], AtStrings.take(), 18921d922960e083906a586609ac6978678147250177Sebastian Redl AtStrings.size())); 18935508518a2702b00be3b15a26d772bde968972f54Anders Carlsson} 1894f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson 1895f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson/// objc-encode-expression: 1896f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson/// @encode ( type-name ) 18971d922960e083906a586609ac6978678147250177Sebastian RedlParser::OwningExprResult 18981d922960e083906a586609ac6978678147250177Sebastian RedlParser::ParseObjCEncodeExpression(SourceLocation AtLoc) { 1899861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff assert(Tok.isObjCAtKeyword(tok::objc_encode) && "Not an @encode expression!"); 19001d922960e083906a586609ac6978678147250177Sebastian Redl 1901f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson SourceLocation EncLoc = ConsumeToken(); 19021d922960e083906a586609ac6978678147250177Sebastian Redl 19034fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner if (Tok.isNot(tok::l_paren)) 19041d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(Tok, diag::err_expected_lparen_after) << "@encode"); 19051d922960e083906a586609ac6978678147250177Sebastian Redl 1906f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson SourceLocation LParenLoc = ConsumeParen(); 19071d922960e083906a586609ac6978678147250177Sebastian Redl 1908809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor TypeResult Ty = ParseTypeName(); 19091d922960e083906a586609ac6978678147250177Sebastian Redl 19104988ae3fda10743c8ed8a98cdcb5a783362587b4Anders Carlsson SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); 19111d922960e083906a586609ac6978678147250177Sebastian Redl 1912809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor if (Ty.isInvalid()) 1913809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor return ExprError(); 1914809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor 19151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return Owned(Actions.ParseObjCEncodeExpression(AtLoc, EncLoc, LParenLoc, 1916809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor Ty.get(), RParenLoc)); 1917f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson} 191829b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson 191929b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson/// objc-protocol-expression 192029b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson/// @protocol ( protocol-name ) 19211d922960e083906a586609ac6978678147250177Sebastian RedlParser::OwningExprResult 19221d922960e083906a586609ac6978678147250177Sebastian RedlParser::ParseObjCProtocolExpression(SourceLocation AtLoc) { 192329b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson SourceLocation ProtoLoc = ConsumeToken(); 19241d922960e083906a586609ac6978678147250177Sebastian Redl 19254fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner if (Tok.isNot(tok::l_paren)) 19261d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(Tok, diag::err_expected_lparen_after) << "@protocol"); 19271d922960e083906a586609ac6978678147250177Sebastian Redl 192829b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson SourceLocation LParenLoc = ConsumeParen(); 19291d922960e083906a586609ac6978678147250177Sebastian Redl 19304fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner if (Tok.isNot(tok::identifier)) 19311d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(Tok, diag::err_expected_ident)); 19321d922960e083906a586609ac6978678147250177Sebastian Redl 1933390d50a725497e99247dc104a7d2c2a255d3af14Fariborz Jahanian IdentifierInfo *protocolId = Tok.getIdentifierInfo(); 193429b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson ConsumeToken(); 19351d922960e083906a586609ac6978678147250177Sebastian Redl 19364988ae3fda10743c8ed8a98cdcb5a783362587b4Anders Carlsson SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); 193729b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson 19381d922960e083906a586609ac6978678147250177Sebastian Redl return Owned(Actions.ParseObjCProtocolExpression(protocolId, AtLoc, ProtoLoc, 19391d922960e083906a586609ac6978678147250177Sebastian Redl LParenLoc, RParenLoc)); 194029b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson} 1941a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian 1942a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian/// objc-selector-expression 1943a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian/// @selector '(' objc-keyword-selector ')' 19441d922960e083906a586609ac6978678147250177Sebastian RedlParser::OwningExprResult 19451d922960e083906a586609ac6978678147250177Sebastian RedlParser::ParseObjCSelectorExpression(SourceLocation AtLoc) { 1946a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian SourceLocation SelectorLoc = ConsumeToken(); 19471d922960e083906a586609ac6978678147250177Sebastian Redl 19484fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner if (Tok.isNot(tok::l_paren)) 19491d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(Tok, diag::err_expected_lparen_after) << "@selector"); 19501d922960e083906a586609ac6978678147250177Sebastian Redl 1951b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian llvm::SmallVector<IdentifierInfo *, 12> KeyIdents; 1952a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian SourceLocation LParenLoc = ConsumeParen(); 1953a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian SourceLocation sLoc; 19542fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner IdentifierInfo *SelIdent = ParseObjCSelectorPiece(sLoc); 19551d922960e083906a586609ac6978678147250177Sebastian Redl if (!SelIdent && Tok.isNot(tok::colon)) // missing selector name. 19561d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(Tok, diag::err_expected_ident)); 19571d922960e083906a586609ac6978678147250177Sebastian Redl 1958b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian KeyIdents.push_back(SelIdent); 1959887407e71fd58de452361b77d72970e32b20ebe0Steve Naroff unsigned nColons = 0; 1960887407e71fd58de452361b77d72970e32b20ebe0Steve Naroff if (Tok.isNot(tok::r_paren)) { 1961a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian while (1) { 19624fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner if (Tok.isNot(tok::colon)) 19631d922960e083906a586609ac6978678147250177Sebastian Redl return ExprError(Diag(Tok, diag::err_expected_colon)); 19641d922960e083906a586609ac6978678147250177Sebastian Redl 1965cb53b361bce341c8591333c6997f62e480acc0b4Chris Lattner nColons++; 1966a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian ConsumeToken(); // Eat the ':'. 1967a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian if (Tok.is(tok::r_paren)) 1968a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian break; 1969a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian // Check for another keyword selector. 1970a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian SourceLocation Loc; 19712fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner SelIdent = ParseObjCSelectorPiece(Loc); 1972b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian KeyIdents.push_back(SelIdent); 1973a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian if (!SelIdent && Tok.isNot(tok::colon)) 1974a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian break; 1975a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian } 1976887407e71fd58de452361b77d72970e32b20ebe0Steve Naroff } 1977a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); 1978887407e71fd58de452361b77d72970e32b20ebe0Steve Naroff Selector Sel = PP.getSelectorTable().getSelector(nColons, &KeyIdents[0]); 19791d922960e083906a586609ac6978678147250177Sebastian Redl return Owned(Actions.ParseObjCSelectorExpression(Sel, AtLoc, SelectorLoc, 19801d922960e083906a586609ac6978678147250177Sebastian Redl LParenLoc, RParenLoc)); 198158065b2d8038a4e9a91ea4813bd1774c0f6efacbGabor Greif } 1982