ParseObjc.cpp revision 2725ca8eb3354975ca77ed4b88ede7b60b216b9a
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)) {
151c83c6874e3bf1432d3df5e8d3530f8561ff5441fDouglas Gregor      Actions.CodeCompleteObjCInterfaceCategory(CurScope, nameId, nameLoc);
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)) {
214c83c6874e3bf1432d3df5e8d3530f8561ff5441fDouglas Gregor      Actions.CodeCompleteObjCSuperclass(CurScope, nameId, nameLoc);
2153b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor      ConsumeToken();
2163b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor    }
2173b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor
218df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner    if (Tok.isNot(tok::identifier)) {
219dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff      Diag(Tok, diag::err_expected_ident); // missing super class name.
220b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner      return DeclPtrTy();
221dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff    }
222dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff    superClassId = Tok.getIdentifierInfo();
223dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff    superClassLoc = ConsumeToken();
224dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff  }
225dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff  // Next, we need to check for any protocol references.
226b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner  llvm::SmallVector<Action::DeclPtrTy, 8> ProtocolRefs;
22771b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis  llvm::SmallVector<SourceLocation, 8> ProtocolLocs;
22871b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis  SourceLocation LAngleLoc, EndProtoLoc;
22906036d3709955a53297b4cbe14e20db88f321470Chris Lattner  if (Tok.is(tok::less) &&
23071b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis      ParseObjCProtocolReferences(ProtocolRefs, ProtocolLocs, true,
23171b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis                                  LAngleLoc, EndProtoLoc))
232b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner    return DeclPtrTy();
2331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  DeclPtrTy ClsType =
2351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    Actions.ActOnStartClassInterface(atLoc, nameId, nameLoc,
23606036d3709955a53297b4cbe14e20db88f321470Chris Lattner                                     superClassId, superClassLoc,
237beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad                                     ProtocolRefs.data(), ProtocolRefs.size(),
23818df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor                                     ProtocolLocs.data(),
23906036d3709955a53297b4cbe14e20db88f321470Chris Lattner                                     EndProtoLoc, attrList);
2401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
241df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  if (Tok.is(tok::l_brace))
24283c481ade785a919ba21a33f9a8b1b21c1212fb3Fariborz Jahanian    ParseObjCClassInstanceVariables(ClsType, tok::objc_protected, atLoc);
243dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff
24425e077d59a8e8e43b65882b69610a3d5e2aaf53cFariborz Jahanian  ParseObjCInterfaceDeclList(ClsType, tok::objc_interface);
24505511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian  return Err ? DeclPtrTy() : ClsType;
246dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff}
247dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff
248d0014540005f2a5ab837365db6bd40f479406758John McCall/// The Objective-C property callback.  This should be defined where
249d0014540005f2a5ab837365db6bd40f479406758John McCall/// it's used, but instead it's been lifted to here to support VS2005.
250d0014540005f2a5ab837365db6bd40f479406758John McCallstruct Parser::ObjCPropertyCallback : FieldCallback {
251d0014540005f2a5ab837365db6bd40f479406758John McCall  Parser &P;
252d0014540005f2a5ab837365db6bd40f479406758John McCall  DeclPtrTy IDecl;
253d0014540005f2a5ab837365db6bd40f479406758John McCall  llvm::SmallVectorImpl<DeclPtrTy> &Props;
254d0014540005f2a5ab837365db6bd40f479406758John McCall  ObjCDeclSpec &OCDS;
255d0014540005f2a5ab837365db6bd40f479406758John McCall  SourceLocation AtLoc;
256d0014540005f2a5ab837365db6bd40f479406758John McCall  tok::ObjCKeywordKind MethodImplKind;
257d0014540005f2a5ab837365db6bd40f479406758John McCall
258d0014540005f2a5ab837365db6bd40f479406758John McCall  ObjCPropertyCallback(Parser &P, DeclPtrTy IDecl,
259d0014540005f2a5ab837365db6bd40f479406758John McCall                       llvm::SmallVectorImpl<DeclPtrTy> &Props,
260d0014540005f2a5ab837365db6bd40f479406758John McCall                       ObjCDeclSpec &OCDS, SourceLocation AtLoc,
261d0014540005f2a5ab837365db6bd40f479406758John McCall                       tok::ObjCKeywordKind MethodImplKind) :
262d0014540005f2a5ab837365db6bd40f479406758John McCall    P(P), IDecl(IDecl), Props(Props), OCDS(OCDS), AtLoc(AtLoc),
263d0014540005f2a5ab837365db6bd40f479406758John McCall    MethodImplKind(MethodImplKind) {
264d0014540005f2a5ab837365db6bd40f479406758John McCall  }
265d0014540005f2a5ab837365db6bd40f479406758John McCall
266d0014540005f2a5ab837365db6bd40f479406758John McCall  DeclPtrTy invoke(FieldDeclarator &FD) {
267d0014540005f2a5ab837365db6bd40f479406758John McCall    if (FD.D.getIdentifier() == 0) {
268d0014540005f2a5ab837365db6bd40f479406758John McCall      P.Diag(AtLoc, diag::err_objc_property_requires_field_name)
269d0014540005f2a5ab837365db6bd40f479406758John McCall        << FD.D.getSourceRange();
270d0014540005f2a5ab837365db6bd40f479406758John McCall      return DeclPtrTy();
271d0014540005f2a5ab837365db6bd40f479406758John McCall    }
272d0014540005f2a5ab837365db6bd40f479406758John McCall    if (FD.BitfieldSize) {
273d0014540005f2a5ab837365db6bd40f479406758John McCall      P.Diag(AtLoc, diag::err_objc_property_bitfield)
274d0014540005f2a5ab837365db6bd40f479406758John McCall        << FD.D.getSourceRange();
275d0014540005f2a5ab837365db6bd40f479406758John McCall      return DeclPtrTy();
276d0014540005f2a5ab837365db6bd40f479406758John McCall    }
277d0014540005f2a5ab837365db6bd40f479406758John McCall
278d0014540005f2a5ab837365db6bd40f479406758John McCall    // Install the property declarator into interfaceDecl.
279d0014540005f2a5ab837365db6bd40f479406758John McCall    IdentifierInfo *SelName =
280d0014540005f2a5ab837365db6bd40f479406758John McCall      OCDS.getGetterName() ? OCDS.getGetterName() : FD.D.getIdentifier();
281d0014540005f2a5ab837365db6bd40f479406758John McCall
282d0014540005f2a5ab837365db6bd40f479406758John McCall    Selector GetterSel =
283d0014540005f2a5ab837365db6bd40f479406758John McCall      P.PP.getSelectorTable().getNullarySelector(SelName);
284d0014540005f2a5ab837365db6bd40f479406758John McCall    IdentifierInfo *SetterName = OCDS.getSetterName();
285d0014540005f2a5ab837365db6bd40f479406758John McCall    Selector SetterSel;
286d0014540005f2a5ab837365db6bd40f479406758John McCall    if (SetterName)
287d0014540005f2a5ab837365db6bd40f479406758John McCall      SetterSel = P.PP.getSelectorTable().getSelector(1, &SetterName);
288d0014540005f2a5ab837365db6bd40f479406758John McCall    else
289d0014540005f2a5ab837365db6bd40f479406758John McCall      SetterSel = SelectorTable::constructSetterName(P.PP.getIdentifierTable(),
290d0014540005f2a5ab837365db6bd40f479406758John McCall                                                     P.PP.getSelectorTable(),
291d0014540005f2a5ab837365db6bd40f479406758John McCall                                                     FD.D.getIdentifier());
292d0014540005f2a5ab837365db6bd40f479406758John McCall    bool isOverridingProperty = false;
293d0014540005f2a5ab837365db6bd40f479406758John McCall    DeclPtrTy Property =
294d0014540005f2a5ab837365db6bd40f479406758John McCall      P.Actions.ActOnProperty(P.CurScope, AtLoc, FD, OCDS,
295d0014540005f2a5ab837365db6bd40f479406758John McCall                              GetterSel, SetterSel, IDecl,
296d0014540005f2a5ab837365db6bd40f479406758John McCall                              &isOverridingProperty,
297d0014540005f2a5ab837365db6bd40f479406758John McCall                              MethodImplKind);
298d0014540005f2a5ab837365db6bd40f479406758John McCall    if (!isOverridingProperty)
299d0014540005f2a5ab837365db6bd40f479406758John McCall      Props.push_back(Property);
300d0014540005f2a5ab837365db6bd40f479406758John McCall
301d0014540005f2a5ab837365db6bd40f479406758John McCall    return Property;
302d0014540005f2a5ab837365db6bd40f479406758John McCall  }
303d0014540005f2a5ab837365db6bd40f479406758John McCall};
304d0014540005f2a5ab837365db6bd40f479406758John McCall
305dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///   objc-interface-decl-list:
306dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     empty
307dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     objc-interface-decl-list objc-property-decl [OBJC2]
308294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///     objc-interface-decl-list objc-method-requirement [OBJC2]
3093536b443bc50d58a79f14fca9b6842541a434854Steve Naroff///     objc-interface-decl-list objc-method-proto ';'
310dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     objc-interface-decl-list declaration
311dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     objc-interface-decl-list ';'
312dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///
313294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///   objc-method-requirement: [OBJC2]
314294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///     @required
315294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///     @optional
316294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///
317b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattnervoid Parser::ParseObjCInterfaceDeclList(DeclPtrTy interfaceDecl,
318cb53b361bce341c8591333c6997f62e480acc0b4Chris Lattner                                        tok::ObjCKeywordKind contextKey) {
319b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner  llvm::SmallVector<DeclPtrTy, 32> allMethods;
320b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner  llvm::SmallVector<DeclPtrTy, 16> allProperties;
321682bf92db408a6cbc3d37b5496a99b6ef85041ecChris Lattner  llvm::SmallVector<DeclGroupPtrTy, 8> allTUVariables;
32200933591a2795d09dd1acff12a2d21bce7cb12c5Fariborz Jahanian  tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword;
3231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
324782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek  SourceRange AtEnd;
325bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner
326294494e1cce92043562b4680c613df7fd028c02eSteve Naroff  while (1) {
327e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner    // If this is a method prototype, parse it.
328df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner    if (Tok.is(tok::minus) || Tok.is(tok::plus)) {
3291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      DeclPtrTy methodPrototype =
330df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner        ParseObjCMethodPrototype(interfaceDecl, MethodImplKind);
33125e077d59a8e8e43b65882b69610a3d5e2aaf53cFariborz Jahanian      allMethods.push_back(methodPrototype);
3323536b443bc50d58a79f14fca9b6842541a434854Steve Naroff      // Consume the ';' here, since ParseObjCMethodPrototype() is re-used for
3333536b443bc50d58a79f14fca9b6842541a434854Steve Naroff      // method definitions.
334b6d74a158a9c002e3c0fcbda8ad8d0ccbb2e5088Chris Lattner      ExpectAndConsume(tok::semi, diag::err_expected_semi_after_method_proto,
335b6d74a158a9c002e3c0fcbda8ad8d0ccbb2e5088Chris Lattner                       "", tok::semi);
336294494e1cce92043562b4680c613df7fd028c02eSteve Naroff      continue;
337294494e1cce92043562b4680c613df7fd028c02eSteve Naroff    }
33805511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian    if (Tok.is(tok::l_paren)) {
33905511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian      Diag(Tok, diag::err_expected_minus_or_plus);
34005511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian      DeclPtrTy methodPrototype = ParseObjCMethodDecl(Tok.getLocation(),
34105511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian                                                      tok::minus,
34205511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian                                                      interfaceDecl,
34305511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian                                                      MethodImplKind);
34405511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian      continue;
34505511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian    }
346e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner    // Ignore excess semicolons.
347e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner    if (Tok.is(tok::semi)) {
348294494e1cce92043562b4680c613df7fd028c02eSteve Naroff      ConsumeToken();
349e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner      continue;
350e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner    }
3511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
352bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner    // If we got to the end of the file, exit the loop.
353e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner    if (Tok.is(tok::eof))
354e3a2ca7e30601cdd31c77a830f4cc487851e8096Fariborz Jahanian      break;
3551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
356b6ac2451bfed36206c5cec7217372c4299f67f2bDouglas Gregor    // Code completion within an Objective-C interface.
357b6ac2451bfed36206c5cec7217372c4299f67f2bDouglas Gregor    if (Tok.is(tok::code_completion)) {
358b6ac2451bfed36206c5cec7217372c4299f67f2bDouglas Gregor      Actions.CodeCompleteOrdinaryName(CurScope,
359b6ac2451bfed36206c5cec7217372c4299f67f2bDouglas Gregor                                  ObjCImpDecl? Action::CCC_ObjCImplementation
360b6ac2451bfed36206c5cec7217372c4299f67f2bDouglas Gregor                                             : Action::CCC_ObjCInterface);
361b6ac2451bfed36206c5cec7217372c4299f67f2bDouglas Gregor      ConsumeToken();
362b6ac2451bfed36206c5cec7217372c4299f67f2bDouglas Gregor    }
363b6ac2451bfed36206c5cec7217372c4299f67f2bDouglas Gregor
364e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner    // If we don't have an @ directive, parse it as a function definition.
365e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner    if (Tok.isNot(tok::at)) {
3661fd80116b49782c367ff5d5f50a8b76dd8a5d7f7Chris Lattner      // The code below does not consume '}'s because it is afraid of eating the
3671fd80116b49782c367ff5d5f50a8b76dd8a5d7f7Chris Lattner      // end of a namespace.  Because of the way this code is structured, an
3681fd80116b49782c367ff5d5f50a8b76dd8a5d7f7Chris Lattner      // erroneous r_brace would cause an infinite loop if not handled here.
3691fd80116b49782c367ff5d5f50a8b76dd8a5d7f7Chris Lattner      if (Tok.is(tok::r_brace))
3701fd80116b49782c367ff5d5f50a8b76dd8a5d7f7Chris Lattner        break;
3711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3724985aceceb9b9261b876b515d32726175c13a775Steve Naroff      // FIXME: as the name implies, this rule allows function definitions.
3734985aceceb9b9261b876b515d32726175c13a775Steve Naroff      // We could pass a flag or check for functions during semantic analysis.
374bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt      allTUVariables.push_back(ParseDeclarationOrFunctionDefinition(0));
375e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner      continue;
376e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner    }
3771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
378e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner    // Otherwise, we have an @ directive, eat the @.
379e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner    SourceLocation AtLoc = ConsumeToken(); // the "@"
380c464ae8444edb6d07ea49b7a0eae1674c0fa1bb8Douglas Gregor    if (Tok.is(tok::code_completion)) {
381c464ae8444edb6d07ea49b7a0eae1674c0fa1bb8Douglas Gregor      Actions.CodeCompleteObjCAtDirective(CurScope, ObjCImpDecl, true);
382c464ae8444edb6d07ea49b7a0eae1674c0fa1bb8Douglas Gregor      ConsumeToken();
383c464ae8444edb6d07ea49b7a0eae1674c0fa1bb8Douglas Gregor      break;
384c464ae8444edb6d07ea49b7a0eae1674c0fa1bb8Douglas Gregor    }
385c464ae8444edb6d07ea49b7a0eae1674c0fa1bb8Douglas Gregor
386a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner    tok::ObjCKeywordKind DirectiveKind = Tok.getObjCKeywordID();
3871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
388a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner    if (DirectiveKind == tok::objc_end) { // @end -> terminate list
389782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek      AtEnd.setBegin(AtLoc);
390782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek      AtEnd.setEnd(Tok.getLocation());
391e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner      break;
392c3d43b783dfb1a1502aa8b31ab1985cf237b1f77Douglas Gregor    } else if (DirectiveKind == tok::objc_not_keyword) {
393c3d43b783dfb1a1502aa8b31ab1985cf237b1f77Douglas Gregor      Diag(Tok, diag::err_objc_unknown_at);
394c3d43b783dfb1a1502aa8b31ab1985cf237b1f77Douglas Gregor      SkipUntil(tok::semi);
395c3d43b783dfb1a1502aa8b31ab1985cf237b1f77Douglas Gregor      continue;
396bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner    }
3971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
398bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner    // Eat the identifier.
399bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner    ConsumeToken();
400bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner
401a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner    switch (DirectiveKind) {
402a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner    default:
403bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner      // FIXME: If someone forgets an @end on a protocol, this loop will
404bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner      // continue to eat up tons of stuff and spew lots of nonsense errors.  It
405bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner      // would probably be better to bail out if we saw an @class or @interface
406bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner      // or something like that.
407f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner      Diag(AtLoc, diag::err_objc_illegal_interface_qual);
408bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner      // Skip until we see an '@' or '}' or ';'.
409a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner      SkipUntil(tok::r_brace, tok::at);
410a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner      break;
4111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
412a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner    case tok::objc_required:
413a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner    case tok::objc_optional:
414a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner      // This is only valid on protocols.
415bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner      // FIXME: Should this check for ObjC2 being enabled?
416e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner      if (contextKey != tok::objc_protocol)
417bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner        Diag(AtLoc, diag::err_objc_directive_only_in_protocol);
418a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner      else
419bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner        MethodImplKind = DirectiveKind;
420a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner      break;
4211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
422a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner    case tok::objc_property:
423f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner      if (!getLang().ObjC2)
424f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner        Diag(AtLoc, diag::err_objc_propertoes_require_objc2);
425f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner
426e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner      ObjCDeclSpec OCDS;
4271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      // Parse property attribute list, if any.
4288ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner      if (Tok.is(tok::l_paren))
4294ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor        ParseObjCPropertyAttribute(OCDS, interfaceDecl,
4304ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor                                   allMethods.data(), allMethods.size());
4311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
432d0014540005f2a5ab837365db6bd40f479406758John McCall      ObjCPropertyCallback Callback(*this, interfaceDecl, allProperties,
433d0014540005f2a5ab837365db6bd40f479406758John McCall                                    OCDS, AtLoc, MethodImplKind);
434bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall
435e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner      // Parse all the comma separated declarators.
436e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner      DeclSpec DS;
437bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall      ParseStructDeclaration(DS, Callback);
4381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
439a1fed7e3beebf9bb1bc85123f283be3eb631c120Chris Lattner      ExpectAndConsume(tok::semi, diag::err_expected_semi_decl_list, "",
440a1fed7e3beebf9bb1bc85123f283be3eb631c120Chris Lattner                       tok::at);
441a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner      break;
442f28b264437053fb0deacc9ba02b18a0966f7290aSteve Naroff    }
443294494e1cce92043562b4680c613df7fd028c02eSteve Naroff  }
444bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner
445bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner  // We break out of the big loop in two cases: when we see @end or when we see
446bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner  // EOF.  In the former case, eat the @end.  In the later case, emit an error.
447c464ae8444edb6d07ea49b7a0eae1674c0fa1bb8Douglas Gregor  if (Tok.is(tok::code_completion)) {
448c464ae8444edb6d07ea49b7a0eae1674c0fa1bb8Douglas Gregor    Actions.CodeCompleteObjCAtDirective(CurScope, ObjCImpDecl, true);
449c464ae8444edb6d07ea49b7a0eae1674c0fa1bb8Douglas Gregor    ConsumeToken();
450c464ae8444edb6d07ea49b7a0eae1674c0fa1bb8Douglas Gregor  } else if (Tok.isObjCAtKeyword(tok::objc_end))
451bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner    ConsumeToken(); // the "end" identifier
452bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner  else
453bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner    Diag(Tok, diag::err_objc_missing_end);
4541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
455a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner  // Insert collected methods declarations into the @interface object.
456bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner  // This passes in an invalid SourceLocation for AtEndLoc when EOF is hit.
457782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek  Actions.ActOnAtEnd(AtEnd, interfaceDecl,
4581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                     allMethods.data(), allMethods.size(),
459beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad                     allProperties.data(), allProperties.size(),
460beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad                     allTUVariables.data(), allTUVariables.size());
461294494e1cce92043562b4680c613df7fd028c02eSteve Naroff}
462294494e1cce92043562b4680c613df7fd028c02eSteve Naroff
463d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian///   Parse property attribute declarations.
464d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian///
465d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian///   property-attr-decl: '(' property-attrlist ')'
466d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian///   property-attrlist:
467d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian///     property-attribute
468d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian///     property-attrlist ',' property-attribute
469d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian///   property-attribute:
470d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian///     getter '=' identifier
471d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian///     setter '=' identifier ':'
472d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian///     readonly
473d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian///     readwrite
474d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian///     assign
475d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian///     retain
476d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian///     copy
477d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian///     nonatomic
478d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian///
4794ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregorvoid Parser::ParseObjCPropertyAttribute(ObjCDeclSpec &DS, DeclPtrTy ClassDecl,
4804ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor                                        DeclPtrTy *Methods,
4814ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor                                        unsigned NumMethods) {
4828ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner  assert(Tok.getKind() == tok::l_paren);
483dd5b5f2bb73d037745940431b71eb98393d12d4fChris Lattner  SourceLocation LHSLoc = ConsumeParen(); // consume '('
4841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
485cd9f4b31c4fe5b77b5519cc17b4583fab912bad1Chris Lattner  while (1) {
486ece8e71d12b6f4cb2dc501297afef126dab8ad74Steve Naroff    if (Tok.is(tok::code_completion)) {
487a93b108e025ef2480fa867cc533e7781a40a639bDouglas Gregor      Actions.CodeCompleteObjCPropertyFlags(CurScope, DS);
488ece8e71d12b6f4cb2dc501297afef126dab8ad74Steve Naroff      ConsumeToken();
489ece8e71d12b6f4cb2dc501297afef126dab8ad74Steve Naroff    }
490d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian    const IdentifierInfo *II = Tok.getIdentifierInfo();
4911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
492f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner    // If this is not an identifier at all, bail out early.
493f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner    if (II == 0) {
494f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner      MatchRHSPunctuation(tok::r_paren, LHSLoc);
495f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner      return;
496f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner    }
4971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
498156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner    SourceLocation AttrName = ConsumeToken(); // consume last attribute name
4991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
50092e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner    if (II->isStr("readonly"))
501e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner      DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_readonly);
50292e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner    else if (II->isStr("assign"))
503e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner      DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_assign);
50492e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner    else if (II->isStr("readwrite"))
505e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner      DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_readwrite);
50692e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner    else if (II->isStr("retain"))
507e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner      DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_retain);
50892e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner    else if (II->isStr("copy"))
509e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner      DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_copy);
51092e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner    else if (II->isStr("nonatomic"))
511e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner      DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_nonatomic);
51292e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner    else if (II->isStr("getter") || II->isStr("setter")) {
513e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner      // getter/setter require extra treatment.
514156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner      if (ExpectAndConsume(tok::equal, diag::err_objc_expected_equal, "",
515156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner                           tok::r_paren))
516dd5b5f2bb73d037745940431b71eb98393d12d4fChris Lattner        return;
5171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5184ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor      if (Tok.is(tok::code_completion)) {
5194ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor        if (II->getNameStart()[0] == 's')
5204ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor          Actions.CodeCompleteObjCPropertySetter(CurScope, ClassDecl,
5214ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor                                                 Methods, NumMethods);
5224ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor        else
5234ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor          Actions.CodeCompleteObjCPropertyGetter(CurScope, ClassDecl,
5244ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor                                                 Methods, NumMethods);
5254ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor        ConsumeToken();
5264ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor      }
5274ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor
5288ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner      if (Tok.isNot(tok::identifier)) {
5291ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner        Diag(Tok, diag::err_expected_ident);
5308ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner        SkipUntil(tok::r_paren);
5318ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner        return;
5328ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner      }
5331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
534e013d685c6689ac7ae103ee88acf573422d1ed6aDaniel Dunbar      if (II->getNameStart()[0] == 's') {
5358ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner        DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_setter);
5368ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner        DS.setSetterName(Tok.getIdentifierInfo());
537156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner        ConsumeToken();  // consume method name
5381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
539e0097db2848c463a534c18c235c6d3e53f2f1b87Fariborz Jahanian        if (ExpectAndConsume(tok::colon,
540e0097db2848c463a534c18c235c6d3e53f2f1b87Fariborz Jahanian                             diag::err_expected_colon_after_setter_name, "",
541156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner                             tok::r_paren))
5428ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner          return;
5438ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner      } else {
5448ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner        DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_getter);
5458ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner        DS.setGetterName(Tok.getIdentifierInfo());
546156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner        ConsumeToken();  // consume method name
5478ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner      }
548e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner    } else {
549a9500f05ba6c09bbd84d342236863833067cd816Chris Lattner      Diag(AttrName, diag::err_objc_expected_property_attr) << II;
550cd9f4b31c4fe5b77b5519cc17b4583fab912bad1Chris Lattner      SkipUntil(tok::r_paren);
551cd9f4b31c4fe5b77b5519cc17b4583fab912bad1Chris Lattner      return;
552cd9f4b31c4fe5b77b5519cc17b4583fab912bad1Chris Lattner    }
5531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
554156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner    if (Tok.isNot(tok::comma))
555156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner      break;
5561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
557156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner    ConsumeToken();
558d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian  }
5591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
560156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner  MatchRHSPunctuation(tok::r_paren, LHSLoc);
561d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian}
562d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian
5633536b443bc50d58a79f14fca9b6842541a434854Steve Naroff///   objc-method-proto:
5641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///     objc-instance-method objc-method-decl objc-method-attributes[opt]
5653536b443bc50d58a79f14fca9b6842541a434854Steve Naroff///     objc-class-method objc-method-decl objc-method-attributes[opt]
566294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///
567294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///   objc-instance-method: '-'
568294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///   objc-class-method: '+'
569294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///
5704985aceceb9b9261b876b515d32726175c13a775Steve Naroff///   objc-method-attributes:         [OBJC2]
5714985aceceb9b9261b876b515d32726175c13a775Steve Naroff///     __attribute__((deprecated))
5724985aceceb9b9261b876b515d32726175c13a775Steve Naroff///
5731eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpParser::DeclPtrTy Parser::ParseObjCMethodPrototype(DeclPtrTy IDecl,
574b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner                                          tok::ObjCKeywordKind MethodImplKind) {
575df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  assert((Tok.is(tok::minus) || Tok.is(tok::plus)) && "expected +/-");
576294494e1cce92043562b4680c613df7fd028c02eSteve Naroff
5771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  tok::TokenKind methodType = Tok.getKind();
578bef1185418705e16012b3dd50cd7c260c8d6b79cSteve Naroff  SourceLocation mLoc = ConsumeToken();
5791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
580b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner  DeclPtrTy MDecl = ParseObjCMethodDecl(mLoc, methodType, IDecl,MethodImplKind);
5813536b443bc50d58a79f14fca9b6842541a434854Steve Naroff  // Since this rule is used for both method declarations and definitions,
5822bd42fadafddc8acf744b57a970bdc96a077c617Steve Naroff  // the caller is (optionally) responsible for consuming the ';'.
583f28b264437053fb0deacc9ba02b18a0966f7290aSteve Naroff  return MDecl;
584294494e1cce92043562b4680c613df7fd028c02eSteve Naroff}
585294494e1cce92043562b4680c613df7fd028c02eSteve Naroff
586294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///   objc-selector:
587294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///     identifier
588294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///     one of
589294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///       enum struct union if else while do for switch case default
590294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///       break continue return goto asm sizeof typeof __alignof
591294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///       unsigned long const short volatile signed restrict _Complex
592294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///       in out inout bycopy byref oneway int char float double void _Bool
593294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///
5942fc5c2428ecb450a3256c8316b93b8655cb76a0fChris LattnerIdentifierInfo *Parser::ParseObjCSelectorPiece(SourceLocation &SelectorLoc) {
595ff38491c18b060526d754765b952f4a497a89416Chris Lattner  switch (Tok.getKind()) {
596ff38491c18b060526d754765b952f4a497a89416Chris Lattner  default:
597ff38491c18b060526d754765b952f4a497a89416Chris Lattner    return 0;
598ff38491c18b060526d754765b952f4a497a89416Chris Lattner  case tok::identifier:
599ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_asm:
600ff38491c18b060526d754765b952f4a497a89416Chris Lattner  case tok::kw_auto:
6019298d9655aed28b2d9f6cc65c81401b209f03fdcChris Lattner  case tok::kw_bool:
602ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_break:
603ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_case:
604ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_catch:
605ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_char:
606ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_class:
607ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_const:
608ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_const_cast:
609ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_continue:
610ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_default:
611ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_delete:
612ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_do:
613ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_double:
614ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_dynamic_cast:
615ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_else:
616ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_enum:
617ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_explicit:
618ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_export:
619ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_extern:
620ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_false:
621ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_float:
622ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_for:
623ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_friend:
624ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_goto:
625ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_if:
626ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_inline:
627ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_int:
628ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_long:
629ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_mutable:
630ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_namespace:
631ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_new:
632ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_operator:
633ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_private:
634ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_protected:
635ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_public:
636ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_register:
637ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_reinterpret_cast:
638ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_restrict:
639ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_return:
640ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_short:
641ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_signed:
642ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_sizeof:
643ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_static:
644ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_static_cast:
645ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_struct:
646ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_switch:
647ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_template:
648ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_this:
649ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_throw:
650ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_true:
651ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_try:
652ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_typedef:
653ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_typeid:
654ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_typename:
655ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_typeof:
656ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_union:
657ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_unsigned:
658ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_using:
659ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_virtual:
660ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_void:
661ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_volatile:
662ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_wchar_t:
663ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_while:
664ff38491c18b060526d754765b952f4a497a89416Chris Lattner  case tok::kw__Bool:
665ff38491c18b060526d754765b952f4a497a89416Chris Lattner  case tok::kw__Complex:
666ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw___alignof:
667ff38491c18b060526d754765b952f4a497a89416Chris Lattner    IdentifierInfo *II = Tok.getIdentifierInfo();
6684b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian    SelectorLoc = ConsumeToken();
669ff38491c18b060526d754765b952f4a497a89416Chris Lattner    return II;
670d064951b0dcc95f8604d0d69ae82d9ecbd38c796Fariborz Jahanian  }
671294494e1cce92043562b4680c613df7fd028c02eSteve Naroff}
672294494e1cce92043562b4680c613df7fd028c02eSteve Naroff
6730196cab54007ff072ec2642da8911c6b7e8d3fb5Fariborz Jahanian///  objc-for-collection-in: 'in'
6740196cab54007ff072ec2642da8911c6b7e8d3fb5Fariborz Jahanian///
675335a2d4122e41343fe11a775889b8bec5b14be60Fariborz Jahanianbool Parser::isTokIdentifier_in() const {
6763ba5a0f90a03d5e13d02cbee9abd2a1ba01b18bcFariborz Jahanian  // FIXME: May have to do additional look-ahead to only allow for
6773ba5a0f90a03d5e13d02cbee9abd2a1ba01b18bcFariborz Jahanian  // valid tokens following an 'in'; such as an identifier, unary operators,
6783ba5a0f90a03d5e13d02cbee9abd2a1ba01b18bcFariborz Jahanian  // '[' etc.
6791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return (getLang().ObjC2 && Tok.is(tok::identifier) &&
6805ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner          Tok.getIdentifierInfo() == ObjCTypeQuals[objc_in]);
6810196cab54007ff072ec2642da8911c6b7e8d3fb5Fariborz Jahanian}
6820196cab54007ff072ec2642da8911c6b7e8d3fb5Fariborz Jahanian
683a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ParseObjCTypeQualifierList - This routine parses the objective-c's type
684e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner/// qualifier list and builds their bitmask representation in the input
685e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner/// argument.
686294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///
687294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///   objc-type-qualifiers:
688294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///     objc-type-qualifier
689294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///     objc-type-qualifiers objc-type-qualifier
690294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///
691a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekvoid Parser::ParseObjCTypeQualifierList(ObjCDeclSpec &DS) {
692e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner  while (1) {
693cb53b361bce341c8591333c6997f62e480acc0b4Chris Lattner    if (Tok.isNot(tok::identifier))
694e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner      return;
6951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
696e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner    const IdentifierInfo *II = Tok.getIdentifierInfo();
697e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner    for (unsigned i = 0; i != objc_NumQuals; ++i) {
698a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek      if (II != ObjCTypeQuals[i])
699e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner        continue;
7001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
701a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek      ObjCDeclSpec::ObjCDeclQualifier Qual;
702e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner      switch (i) {
703e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner      default: assert(0 && "Unknown decl qualifier");
704a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek      case objc_in:     Qual = ObjCDeclSpec::DQ_In; break;
705a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek      case objc_out:    Qual = ObjCDeclSpec::DQ_Out; break;
706a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek      case objc_inout:  Qual = ObjCDeclSpec::DQ_Inout; break;
707a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek      case objc_oneway: Qual = ObjCDeclSpec::DQ_Oneway; break;
708a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek      case objc_bycopy: Qual = ObjCDeclSpec::DQ_Bycopy; break;
709a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek      case objc_byref:  Qual = ObjCDeclSpec::DQ_Byref; break;
710e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner      }
711a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek      DS.setObjCDeclQualifier(Qual);
712e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner      ConsumeToken();
713e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner      II = 0;
714e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner      break;
715e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner    }
7161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
717e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner    // If this wasn't a recognized qualifier, bail out.
718e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner    if (II) return;
719e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner  }
720e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner}
721e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner
722e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner///   objc-type-name:
723e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner///     '(' objc-type-qualifiers[opt] type-name ')'
724e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner///     '(' objc-type-qualifiers[opt] ')'
725e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner///
726a526c5c67e5a0473c340903ee542ce570119665fTed KremenekParser::TypeTy *Parser::ParseObjCTypeName(ObjCDeclSpec &DS) {
727df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  assert(Tok.is(tok::l_paren) && "expected (");
7281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7294a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner  SourceLocation LParenLoc = ConsumeParen();
730e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner  SourceLocation TypeStartLoc = Tok.getLocation();
7311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
73219d74e1494fe399f0e2a94e9419c095f8214851bFariborz Jahanian  // Parse type qualifiers, in, inout, etc.
733a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ParseObjCTypeQualifierList(DS);
7344fa7afd07421e7276d1717e4fdf43a5fdd65a622Steve Naroff
7354a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner  TypeTy *Ty = 0;
736809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor  if (isTypeSpecifierQualifier()) {
737809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor    TypeResult TypeSpec = ParseTypeName();
738809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor    if (!TypeSpec.isInvalid())
739809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor      Ty = TypeSpec.get();
740809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor  }
7411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7424a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner  if (Tok.is(tok::r_paren))
7434a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner    ConsumeParen();
7444a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner  else if (Tok.getLocation() == TypeStartLoc) {
745e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner    // If we didn't eat any tokens, then this isn't a type.
7461ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner    Diag(Tok, diag::err_expected_type);
7474a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner    SkipUntil(tok::r_paren);
7484a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner  } else {
7494a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner    // Otherwise, we found *something*, but didn't get a ')' in the right
7504a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner    // place.  Emit an error then return what we have as the type.
7514a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner    MatchRHSPunctuation(tok::r_paren, LParenLoc);
752294494e1cce92043562b4680c613df7fd028c02eSteve Naroff  }
753f28b264437053fb0deacc9ba02b18a0966f7290aSteve Naroff  return Ty;
754294494e1cce92043562b4680c613df7fd028c02eSteve Naroff}
755294494e1cce92043562b4680c613df7fd028c02eSteve Naroff
756294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///   objc-method-decl:
757294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///     objc-selector
7584985aceceb9b9261b876b515d32726175c13a775Steve Naroff///     objc-keyword-selector objc-parmlist[opt]
759294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///     objc-type-name objc-selector
7604985aceceb9b9261b876b515d32726175c13a775Steve Naroff///     objc-type-name objc-keyword-selector objc-parmlist[opt]
761294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///
762294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///   objc-keyword-selector:
7631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///     objc-keyword-decl
764294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///     objc-keyword-selector objc-keyword-decl
765294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///
766294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///   objc-keyword-decl:
7677ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff///     objc-selector ':' objc-type-name objc-keyword-attributes[opt] identifier
7687ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff///     objc-selector ':' objc-keyword-attributes[opt] identifier
7697ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff///     ':' objc-type-name objc-keyword-attributes[opt] identifier
7707ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff///     ':' objc-keyword-attributes[opt] identifier
771294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///
7724985aceceb9b9261b876b515d32726175c13a775Steve Naroff///   objc-parmlist:
7734985aceceb9b9261b876b515d32726175c13a775Steve Naroff///     objc-parms objc-ellipsis[opt]
774294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///
7754985aceceb9b9261b876b515d32726175c13a775Steve Naroff///   objc-parms:
7764985aceceb9b9261b876b515d32726175c13a775Steve Naroff///     objc-parms , parameter-declaration
777294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///
7784985aceceb9b9261b876b515d32726175c13a775Steve Naroff///   objc-ellipsis:
779294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///     , ...
780294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///
7817ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff///   objc-keyword-attributes:         [OBJC2]
7827ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff///     __attribute__((unused))
7837ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff///
784b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris LattnerParser::DeclPtrTy Parser::ParseObjCMethodDecl(SourceLocation mLoc,
785b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner                                              tok::TokenKind mType,
786b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner                                              DeclPtrTy IDecl,
787b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner                                          tok::ObjCKeywordKind MethodImplKind) {
78854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  ParsingDeclRAIIObject PD(*this);
78954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall
790e8f5a1710a7738deff40e10efcd05b1bd6af184fDouglas Gregor  if (Tok.is(tok::code_completion)) {
791e8f5a1710a7738deff40e10efcd05b1bd6af184fDouglas Gregor    Actions.CodeCompleteObjCMethodDecl(CurScope, mType == tok::minus,
792e8f5a1710a7738deff40e10efcd05b1bd6af184fDouglas Gregor                                       /*ReturnType=*/0, IDecl);
793e8f5a1710a7738deff40e10efcd05b1bd6af184fDouglas Gregor    ConsumeToken();
794e8f5a1710a7738deff40e10efcd05b1bd6af184fDouglas Gregor  }
795e8f5a1710a7738deff40e10efcd05b1bd6af184fDouglas Gregor
796e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner  // Parse the return type if present.
797ff38491c18b060526d754765b952f4a497a89416Chris Lattner  TypeTy *ReturnType = 0;
798a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCDeclSpec DSRet;
799df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  if (Tok.is(tok::l_paren))
800f1de0ca05e2df6f23bd559028693a12d1ebdaaf6Fariborz Jahanian    ReturnType = ParseObjCTypeName(DSRet);
8011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8029e0493576af77dba1c48858c03e31a2897d0681eTed Kremenek  // If attributes exist before the method, parse them.
8039e0493576af77dba1c48858c03e31a2897d0681eTed Kremenek  llvm::OwningPtr<AttributeList> MethodAttrs;
8049e0493576af77dba1c48858c03e31a2897d0681eTed Kremenek  if (getLang().ObjC2 && Tok.is(tok::kw___attribute))
8059e0493576af77dba1c48858c03e31a2897d0681eTed Kremenek    MethodAttrs.reset(ParseGNUAttributes());
8069e0493576af77dba1c48858c03e31a2897d0681eTed Kremenek
807e8f5a1710a7738deff40e10efcd05b1bd6af184fDouglas Gregor  if (Tok.is(tok::code_completion)) {
808e8f5a1710a7738deff40e10efcd05b1bd6af184fDouglas Gregor    Actions.CodeCompleteObjCMethodDecl(CurScope, mType == tok::minus,
809e8f5a1710a7738deff40e10efcd05b1bd6af184fDouglas Gregor                                       ReturnType, IDecl);
810e8f5a1710a7738deff40e10efcd05b1bd6af184fDouglas Gregor    ConsumeToken();
811e8f5a1710a7738deff40e10efcd05b1bd6af184fDouglas Gregor  }
812e8f5a1710a7738deff40e10efcd05b1bd6af184fDouglas Gregor
8139e0493576af77dba1c48858c03e31a2897d0681eTed Kremenek  // Now parse the selector.
814bef1185418705e16012b3dd50cd7c260c8d6b79cSteve Naroff  SourceLocation selLoc;
8152fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner  IdentifierInfo *SelIdent = ParseObjCSelectorPiece(selLoc);
816e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner
81784c431088693e216193094d1dbf327a01173f57fSteve Naroff  // An unnamed colon is valid.
81884c431088693e216193094d1dbf327a01173f57fSteve Naroff  if (!SelIdent && Tok.isNot(tok::colon)) { // missing selector name.
8191ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner    Diag(Tok, diag::err_expected_selector_for_method)
8201ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner      << SourceRange(mLoc, Tok.getLocation());
821e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner    // Skip until we get a ; or {}.
822e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner    SkipUntil(tok::r_brace);
823b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner    return DeclPtrTy();
824e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner  }
8251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8264f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian  llvm::SmallVector<DeclaratorChunk::ParamInfo, 8> CParamInfo;
827df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  if (Tok.isNot(tok::colon)) {
828ff38491c18b060526d754765b952f4a497a89416Chris Lattner    // If attributes exist after the method, parse them.
8291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    if (getLang().ObjC2 && Tok.is(tok::kw___attribute))
8309e0493576af77dba1c48858c03e31a2897d0681eTed Kremenek      MethodAttrs.reset(addAttributeLists(MethodAttrs.take(),
8319e0493576af77dba1c48858c03e31a2897d0681eTed Kremenek                                          ParseGNUAttributes()));
8321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
833ff38491c18b060526d754765b952f4a497a89416Chris Lattner    Selector Sel = PP.getSelectorTable().getNullarySelector(SelIdent);
83454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    DeclPtrTy Result
83554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall         = Actions.ActOnMethodDeclaration(mLoc, Tok.getLocation(),
8361f7b6f88f18d7f6b10265acec5d41c4ed1897487Fariborz Jahanian                                          mType, IDecl, DSRet, ReturnType, Sel,
8374f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian                                          0,
8384f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian                                          CParamInfo.data(), CParamInfo.size(),
8394f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian                                          MethodAttrs.get(),
8401c6a3cc88177c67498fccdf14cfdf09959214e41Ted Kremenek                                          MethodImplKind);
84154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    PD.complete(Result);
84254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    return Result;
843ff38491c18b060526d754765b952f4a497a89416Chris Lattner  }
844f28b264437053fb0deacc9ba02b18a0966f7290aSteve Naroff
84568d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff  llvm::SmallVector<IdentifierInfo *, 12> KeyIdents;
846e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner  llvm::SmallVector<Action::ObjCArgInfo, 12> ArgInfos;
8471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
848ff38491c18b060526d754765b952f4a497a89416Chris Lattner  while (1) {
849e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner    Action::ObjCArgInfo ArgInfo;
8501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
851ff38491c18b060526d754765b952f4a497a89416Chris Lattner    // Each iteration parses a single keyword argument.
852df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner    if (Tok.isNot(tok::colon)) {
853ff38491c18b060526d754765b952f4a497a89416Chris Lattner      Diag(Tok, diag::err_expected_colon);
854ff38491c18b060526d754765b952f4a497a89416Chris Lattner      break;
855ff38491c18b060526d754765b952f4a497a89416Chris Lattner    }
856ff38491c18b060526d754765b952f4a497a89416Chris Lattner    ConsumeToken(); // Eat the ':'.
8571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
858e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner    ArgInfo.Type = 0;
859e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner    if (Tok.is(tok::l_paren)) // Parse the argument type if present.
860e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner      ArgInfo.Type = ParseObjCTypeName(ArgInfo.DeclSpec);
861e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner
862ff38491c18b060526d754765b952f4a497a89416Chris Lattner    // If attributes exist before the argument name, parse them.
863e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner    ArgInfo.ArgAttrs = 0;
864df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner    if (getLang().ObjC2 && Tok.is(tok::kw___attribute))
865bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt      ArgInfo.ArgAttrs = ParseGNUAttributes();
8667ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff
867df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner    if (Tok.isNot(tok::identifier)) {
868ff38491c18b060526d754765b952f4a497a89416Chris Lattner      Diag(Tok, diag::err_expected_ident); // missing argument name.
869ff38491c18b060526d754765b952f4a497a89416Chris Lattner      break;
8704985aceceb9b9261b876b515d32726175c13a775Steve Naroff    }
8711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
872e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner    ArgInfo.Name = Tok.getIdentifierInfo();
873e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner    ArgInfo.NameLoc = Tok.getLocation();
874ff38491c18b060526d754765b952f4a497a89416Chris Lattner    ConsumeToken(); // Eat the identifier.
8751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
876e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner    ArgInfos.push_back(ArgInfo);
877e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner    KeyIdents.push_back(SelIdent);
878e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner
879ff38491c18b060526d754765b952f4a497a89416Chris Lattner    // Check for another keyword selector.
8804b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian    SourceLocation Loc;
8812fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner    SelIdent = ParseObjCSelectorPiece(Loc);
882df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner    if (!SelIdent && Tok.isNot(tok::colon))
883ff38491c18b060526d754765b952f4a497a89416Chris Lattner      break;
884ff38491c18b060526d754765b952f4a497a89416Chris Lattner    // We have a selector or a colon, continue parsing.
885ff38491c18b060526d754765b952f4a497a89416Chris Lattner  }
8861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
887335eafa5be51f6440672a74c73d588af72e96732Steve Naroff  bool isVariadic = false;
8881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
889ff38491c18b060526d754765b952f4a497a89416Chris Lattner  // Parse the (optional) parameter list.
890df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  while (Tok.is(tok::comma)) {
891ff38491c18b060526d754765b952f4a497a89416Chris Lattner    ConsumeToken();
892df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner    if (Tok.is(tok::ellipsis)) {
893335eafa5be51f6440672a74c73d588af72e96732Steve Naroff      isVariadic = true;
8944985aceceb9b9261b876b515d32726175c13a775Steve Naroff      ConsumeToken();
895ff38491c18b060526d754765b952f4a497a89416Chris Lattner      break;
8964985aceceb9b9261b876b515d32726175c13a775Steve Naroff    }
897ff38491c18b060526d754765b952f4a497a89416Chris Lattner    DeclSpec DS;
898ff38491c18b060526d754765b952f4a497a89416Chris Lattner    ParseDeclarationSpecifiers(DS);
8991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    // Parse the declarator.
900ff38491c18b060526d754765b952f4a497a89416Chris Lattner    Declarator ParmDecl(DS, Declarator::PrototypeContext);
901ff38491c18b060526d754765b952f4a497a89416Chris Lattner    ParseDeclarator(ParmDecl);
9024f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian    IdentifierInfo *ParmII = ParmDecl.getIdentifier();
9034f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian    DeclPtrTy Param = Actions.ActOnParamDeclarator(CurScope, ParmDecl);
9044f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian    CParamInfo.push_back(DeclaratorChunk::ParamInfo(ParmII,
9054f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian                                                    ParmDecl.getIdentifierLoc(),
9064f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian                                                    Param,
9074f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian                                                   0));
9084f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian
9094985aceceb9b9261b876b515d32726175c13a775Steve Naroff  }
9101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
911ff38491c18b060526d754765b952f4a497a89416Chris Lattner  // FIXME: Add support for optional parmameter list...
912e3a2ca7e30601cdd31c77a830f4cc487851e8096Fariborz Jahanian  // If attributes exist after the method, parse them.
9131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  if (getLang().ObjC2 && Tok.is(tok::kw___attribute))
9149e0493576af77dba1c48858c03e31a2897d0681eTed Kremenek    MethodAttrs.reset(addAttributeLists(MethodAttrs.take(),
9159e0493576af77dba1c48858c03e31a2897d0681eTed Kremenek                                        ParseGNUAttributes()));
9161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
9173688fc679389d67b6755e62406998f9ea84d886aFariborz Jahanian  if (KeyIdents.size() == 0)
9183688fc679389d67b6755e62406998f9ea84d886aFariborz Jahanian    return DeclPtrTy();
919ff38491c18b060526d754765b952f4a497a89416Chris Lattner  Selector Sel = PP.getSelectorTable().getSelector(KeyIdents.size(),
920ff38491c18b060526d754765b952f4a497a89416Chris Lattner                                                   &KeyIdents[0]);
92154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  DeclPtrTy Result
92254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall       = Actions.ActOnMethodDeclaration(mLoc, Tok.getLocation(),
9233688fc679389d67b6755e62406998f9ea84d886aFariborz Jahanian                                        mType, IDecl, DSRet, ReturnType, Sel,
9244f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian                                        &ArgInfos[0],
9254f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian                                        CParamInfo.data(), CParamInfo.size(),
9261e37765c9257ef1d051f54a674eaa964bdba9693Ted Kremenek                                        MethodAttrs.get(),
927335eafa5be51f6440672a74c73d588af72e96732Steve Naroff                                        MethodImplKind, isVariadic);
92854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  PD.complete(Result);
9291e37765c9257ef1d051f54a674eaa964bdba9693Ted Kremenek
9301e37765c9257ef1d051f54a674eaa964bdba9693Ted Kremenek  // Delete referenced AttributeList objects.
9311e37765c9257ef1d051f54a674eaa964bdba9693Ted Kremenek  for (llvm::SmallVectorImpl<Action::ObjCArgInfo>::iterator
9321e37765c9257ef1d051f54a674eaa964bdba9693Ted Kremenek       I = ArgInfos.begin(), E = ArgInfos.end(); I != E; ++I)
9331e37765c9257ef1d051f54a674eaa964bdba9693Ted Kremenek    delete I->ArgAttrs;
9341e37765c9257ef1d051f54a674eaa964bdba9693Ted Kremenek
93554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  return Result;
936294494e1cce92043562b4680c613df7fd028c02eSteve Naroff}
937294494e1cce92043562b4680c613df7fd028c02eSteve Naroff
938dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///   objc-protocol-refs:
939dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     '<' identifier-list '>'
940dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///
9417caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattnerbool Parser::
942b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris LattnerParseObjCProtocolReferences(llvm::SmallVectorImpl<Action::DeclPtrTy> &Protocols,
94371b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis                            llvm::SmallVectorImpl<SourceLocation> &ProtocolLocs,
94471b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis                            bool WarnOnDeclarations,
94571b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis                            SourceLocation &LAngleLoc, SourceLocation &EndLoc) {
946e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner  assert(Tok.is(tok::less) && "expected <");
9471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
94871b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis  LAngleLoc = ConsumeToken(); // the "<"
9491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
950e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner  llvm::SmallVector<IdentifierLocPair, 8> ProtocolIdents;
9511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
952e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner  while (1) {
95355385fe3e723cd675001e45f42d61adde6b7f075Douglas Gregor    if (Tok.is(tok::code_completion)) {
95455385fe3e723cd675001e45f42d61adde6b7f075Douglas Gregor      Actions.CodeCompleteObjCProtocolReferences(ProtocolIdents.data(),
95555385fe3e723cd675001e45f42d61adde6b7f075Douglas Gregor                                                 ProtocolIdents.size());
95655385fe3e723cd675001e45f42d61adde6b7f075Douglas Gregor      ConsumeToken();
95755385fe3e723cd675001e45f42d61adde6b7f075Douglas Gregor    }
95855385fe3e723cd675001e45f42d61adde6b7f075Douglas Gregor
959e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner    if (Tok.isNot(tok::identifier)) {
960e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner      Diag(Tok, diag::err_expected_ident);
961e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner      SkipUntil(tok::greater);
962e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner      return true;
963e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner    }
964e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner    ProtocolIdents.push_back(std::make_pair(Tok.getIdentifierInfo(),
965e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner                                       Tok.getLocation()));
96671b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis    ProtocolLocs.push_back(Tok.getLocation());
967e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner    ConsumeToken();
9681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
969e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner    if (Tok.isNot(tok::comma))
970e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner      break;
971e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner    ConsumeToken();
972e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner  }
9731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
974e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner  // Consume the '>'.
975e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner  if (Tok.isNot(tok::greater)) {
976e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner    Diag(Tok, diag::err_expected_greater);
977e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner    return true;
978e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner  }
9791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
980e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner  EndLoc = ConsumeAnyToken();
9811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
982e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner  // Convert the list of protocols identifiers into a list of protocol decls.
983e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner  Actions.FindProtocolDeclaration(WarnOnDeclarations,
984e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner                                  &ProtocolIdents[0], ProtocolIdents.size(),
985e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner                                  Protocols);
986e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner  return false;
987e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner}
988e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner
989dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///   objc-class-instance-variables:
990dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     '{' objc-instance-variable-decl-list[opt] '}'
991dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///
992dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///   objc-instance-variable-decl-list:
993dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     objc-visibility-spec
994dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     objc-instance-variable-decl ';'
995dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     ';'
996dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     objc-instance-variable-decl-list objc-visibility-spec
997dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     objc-instance-variable-decl-list objc-instance-variable-decl ';'
998dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     objc-instance-variable-decl-list ';'
999dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///
1000dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///   objc-visibility-spec:
1001dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     @private
1002dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     @protected
1003dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     @public
1004ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff///     @package [OBJC2]
1005dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///
1006dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///   objc-instance-variable-decl:
10071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///     struct-declaration
1008dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///
1009b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattnervoid Parser::ParseObjCClassInstanceVariables(DeclPtrTy interfaceDecl,
101083c481ade785a919ba21a33f9a8b1b21c1212fb3Fariborz Jahanian                                             tok::ObjCKeywordKind visibility,
101160fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff                                             SourceLocation atLoc) {
1012df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  assert(Tok.is(tok::l_brace) && "expected {");
1013b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner  llvm::SmallVector<DeclPtrTy, 32> AllIvarDecls;
1014e13594279a952537ac903325efff57e3edca79d9Chris Lattner
10151a0d31a3d7f14ddc6370ba912c778aece6c12cf0Douglas Gregor  ParseScope ClassScope(this, Scope::DeclScope|Scope::ClassScope);
101672de6676bd30f9081ee4166bbe07b4c270258ce6Douglas Gregor
1017ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff  SourceLocation LBraceLoc = ConsumeBrace(); // the "{"
10181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1019ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff  // While we still have something to read, read the instance variables.
1020df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  while (Tok.isNot(tok::r_brace) && Tok.isNot(tok::eof)) {
1021ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff    // Each iteration of this loop reads one objc-instance-variable-decl.
10221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1023ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff    // Check for extraneous top-level semicolon.
1024df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner    if (Tok.is(tok::semi)) {
1025c2253f5ca170984fcd4f30f8823148e8cb71336bChris Lattner      Diag(Tok, diag::ext_extra_struct_semi)
1026849b243d4065f56742a4677d6dc8277609a151f8Douglas Gregor        << FixItHint::CreateRemoval(Tok.getLocation());
1027ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff      ConsumeToken();
1028ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff      continue;
1029ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff    }
10301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1031ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff    // Set the default visibility to private.
1032df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner    if (Tok.is(tok::at)) { // parse objc-visibility-spec
1033ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff      ConsumeToken(); // eat the @ sign
1034c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor
1035c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor      if (Tok.is(tok::code_completion)) {
1036c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor        Actions.CodeCompleteObjCAtVisibility(CurScope);
1037c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor        ConsumeToken();
1038c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor      }
1039c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor
1040861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff      switch (Tok.getObjCKeywordID()) {
1041ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff      case tok::objc_private:
1042ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff      case tok::objc_public:
1043ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff      case tok::objc_protected:
1044ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff      case tok::objc_package:
1045861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff        visibility = Tok.getObjCKeywordID();
1046ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff        ConsumeToken();
10471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump        continue;
1048ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff      default:
1049ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff        Diag(Tok, diag::err_objc_illegal_visibility_spec);
1050ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff        continue;
1051ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff      }
1052ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff    }
10531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1054c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor    if (Tok.is(tok::code_completion)) {
1055c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor      Actions.CodeCompleteOrdinaryName(CurScope,
1056c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor                                       Action::CCC_ObjCInstanceVariableList);
1057c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor      ConsumeToken();
1058c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor    }
1059c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor
1060bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall    struct ObjCIvarCallback : FieldCallback {
1061bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall      Parser &P;
1062bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall      DeclPtrTy IDecl;
1063bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall      tok::ObjCKeywordKind visibility;
1064bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall      llvm::SmallVectorImpl<DeclPtrTy> &AllIvarDecls;
1065bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall
1066bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall      ObjCIvarCallback(Parser &P, DeclPtrTy IDecl, tok::ObjCKeywordKind V,
1067bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall                       llvm::SmallVectorImpl<DeclPtrTy> &AllIvarDecls) :
1068bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall        P(P), IDecl(IDecl), visibility(V), AllIvarDecls(AllIvarDecls) {
1069bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall      }
1070bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall
1071bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall      DeclPtrTy invoke(FieldDeclarator &FD) {
1072bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall        // Install the declarator into the interface decl.
1073bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall        DeclPtrTy Field
1074bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall          = P.Actions.ActOnIvar(P.CurScope,
1075bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall                                FD.D.getDeclSpec().getSourceRange().getBegin(),
1076bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall                                IDecl, FD.D, FD.BitfieldSize, visibility);
10770bd04596e4645ff145a046dfb3475f39674060d9Fariborz Jahanian        if (Field)
10780bd04596e4645ff145a046dfb3475f39674060d9Fariborz Jahanian          AllIvarDecls.push_back(Field);
1079bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall        return Field;
1080bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall      }
1081bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall    } Callback(*this, interfaceDecl, visibility, AllIvarDecls);
1082bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall
1083e13594279a952537ac903325efff57e3edca79d9Chris Lattner    // Parse all the comma separated declarators.
1084e13594279a952537ac903325efff57e3edca79d9Chris Lattner    DeclSpec DS;
1085bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall    ParseStructDeclaration(DS, Callback);
10861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1087df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner    if (Tok.is(tok::semi)) {
1088ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff      ConsumeToken();
1089ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff    } else {
1090ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff      Diag(Tok, diag::err_expected_semi_decl_list);
1091ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff      // Skip to end of block or statement
1092ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff      SkipUntil(tok::r_brace, true, true);
1093ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff    }
1094ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff  }
109560fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff  SourceLocation RBraceLoc = MatchRHSPunctuation(tok::r_brace, LBraceLoc);
10968749be53f53384e7846502791ceda6c657228d07Steve Naroff  // Call ActOnFields() even if we don't have any decls. This is useful
10978749be53f53384e7846502791ceda6c657228d07Steve Naroff  // for code rewriting tools that need to be aware of the empty list.
10988749be53f53384e7846502791ceda6c657228d07Steve Naroff  Actions.ActOnFields(CurScope, atLoc, interfaceDecl,
1099beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad                      AllIvarDecls.data(), AllIvarDecls.size(),
11001bfe1c2129771c06fb58ae5e8c079ae30e138309Daniel Dunbar                      LBraceLoc, RBraceLoc, 0);
1101ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff  return;
11025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
1103dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff
1104dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///   objc-protocol-declaration:
1105dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     objc-protocol-definition
1106dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     objc-protocol-forward-reference
1107dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///
1108dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///   objc-protocol-definition:
11091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///     @protocol identifier
11101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///       objc-protocol-refs[opt]
11111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///       objc-interface-decl-list
1112dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     @end
1113dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///
1114dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///   objc-protocol-forward-reference:
1115dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     @protocol identifier-list ';'
1116dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///
1117dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///   "@protocol identifier ;" should be resolved as "@protocol
11183536b443bc50d58a79f14fca9b6842541a434854Steve Naroff///   identifier-list ;": objc-interface-decl-list may not start with a
1119dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///   semicolon in the first alternative if objc-protocol-refs are omitted.
1120b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris LattnerParser::DeclPtrTy Parser::ParseObjCAtProtocolDeclaration(SourceLocation AtLoc,
1121b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner                                                      AttributeList *attrList) {
1122861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff  assert(Tok.isObjCAtKeyword(tok::objc_protocol) &&
11237ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff         "ParseObjCAtProtocolDeclaration(): Expected @protocol");
11247ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff  ConsumeToken(); // the "protocol" identifier
11251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1126083128f6b13dfa4fc615a838c49b516d901b1ac0Douglas Gregor  if (Tok.is(tok::code_completion)) {
1127083128f6b13dfa4fc615a838c49b516d901b1ac0Douglas Gregor    Actions.CodeCompleteObjCProtocolDecl(CurScope);
1128083128f6b13dfa4fc615a838c49b516d901b1ac0Douglas Gregor    ConsumeToken();
1129083128f6b13dfa4fc615a838c49b516d901b1ac0Douglas Gregor  }
1130083128f6b13dfa4fc615a838c49b516d901b1ac0Douglas Gregor
1131df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  if (Tok.isNot(tok::identifier)) {
11327ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff    Diag(Tok, diag::err_expected_ident); // missing protocol name.
1133b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner    return DeclPtrTy();
11347ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff  }
11357ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff  // Save the protocol name, then consume it.
11367ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff  IdentifierInfo *protocolName = Tok.getIdentifierInfo();
11377ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff  SourceLocation nameLoc = ConsumeToken();
11381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1139df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  if (Tok.is(tok::semi)) { // forward declaration of one protocol.
11407caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner    IdentifierLocPair ProtoInfo(protocolName, nameLoc);
11417ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff    ConsumeToken();
11421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return Actions.ActOnForwardProtocolDeclaration(AtLoc, &ProtoInfo, 1,
1143bc1c877fe28fb6a825f0b226a0a2da99e713ea03Fariborz Jahanian                                                   attrList);
11447ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff  }
11451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1146df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  if (Tok.is(tok::comma)) { // list of forward declarations.
11477caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner    llvm::SmallVector<IdentifierLocPair, 8> ProtocolRefs;
11487caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner    ProtocolRefs.push_back(std::make_pair(protocolName, nameLoc));
11497caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner
11507ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff    // Parse the list of forward declarations.
11517ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff    while (1) {
11527ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff      ConsumeToken(); // the ','
1153df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner      if (Tok.isNot(tok::identifier)) {
11547ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff        Diag(Tok, diag::err_expected_ident);
11557ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff        SkipUntil(tok::semi);
1156b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner        return DeclPtrTy();
11577ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff      }
11587caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner      ProtocolRefs.push_back(IdentifierLocPair(Tok.getIdentifierInfo(),
11597caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner                                               Tok.getLocation()));
11607ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff      ConsumeToken(); // the identifier
11611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1162df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner      if (Tok.isNot(tok::comma))
11637ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff        break;
11647ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff    }
11657ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff    // Consume the ';'.
11667ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff    if (ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@protocol"))
1167b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner      return DeclPtrTy();
11681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1169e440eb8158e71deb1e4ab11618ae3d680aac6da1Steve Naroff    return Actions.ActOnForwardProtocolDeclaration(AtLoc,
11701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                                   &ProtocolRefs[0],
1171bc1c877fe28fb6a825f0b226a0a2da99e713ea03Fariborz Jahanian                                                   ProtocolRefs.size(),
1172bc1c877fe28fb6a825f0b226a0a2da99e713ea03Fariborz Jahanian                                                   attrList);
11737caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner  }
11741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11757ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff  // Last, and definitely not least, parse a protocol declaration.
117671b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis  SourceLocation LAngleLoc, EndProtoLoc;
11777caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner
1178b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner  llvm::SmallVector<DeclPtrTy, 8> ProtocolRefs;
117971b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis  llvm::SmallVector<SourceLocation, 8> ProtocolLocs;
11807caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner  if (Tok.is(tok::less) &&
118171b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis      ParseObjCProtocolReferences(ProtocolRefs, ProtocolLocs, false,
118271b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis                                  LAngleLoc, EndProtoLoc))
1183b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner    return DeclPtrTy();
11841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1185b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner  DeclPtrTy ProtoType =
1186e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner    Actions.ActOnStartProtocolInterface(AtLoc, protocolName, nameLoc,
1187beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad                                        ProtocolRefs.data(),
1188beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad                                        ProtocolRefs.size(),
118918df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor                                        ProtocolLocs.data(),
1190246e70f69cb8aeb67225c54690f1c6b25abd5a86Daniel Dunbar                                        EndProtoLoc, attrList);
119125e077d59a8e8e43b65882b69610a3d5e2aaf53cFariborz Jahanian  ParseObjCInterfaceDeclList(ProtoType, tok::objc_protocol);
1192bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner  return ProtoType;
1193dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff}
1194dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff
1195dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///   objc-implementation:
1196dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     objc-class-implementation-prologue
1197dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     objc-category-implementation-prologue
1198dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///
1199dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///   objc-class-implementation-prologue:
1200dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     @implementation identifier objc-superclass[opt]
1201dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///       objc-class-instance-variables[opt]
1202dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///
1203dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///   objc-category-implementation-prologue:
1204dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     @implementation identifier ( identifier )
1205b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris LattnerParser::DeclPtrTy Parser::ParseObjCAtImplementationDeclaration(
1206ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian  SourceLocation atLoc) {
1207ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian  assert(Tok.isObjCAtKeyword(tok::objc_implementation) &&
1208ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian         "ParseObjCAtImplementationDeclaration(): Expected @implementation");
1209ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian  ConsumeToken(); // the "implementation" identifier
12101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12113b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor  // Code completion after '@implementation'.
12123b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor  if (Tok.is(tok::code_completion)) {
12133b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor    Actions.CodeCompleteObjCImplementationDecl(CurScope);
12143b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor    ConsumeToken();
12153b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor  }
12163b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor
1217df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  if (Tok.isNot(tok::identifier)) {
1218ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian    Diag(Tok, diag::err_expected_ident); // missing class or category name.
1219b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner    return DeclPtrTy();
1220ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian  }
1221ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian  // We have a class or category name - consume it.
1222ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian  IdentifierInfo *nameId = Tok.getIdentifierInfo();
1223ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian  SourceLocation nameLoc = ConsumeToken(); // consume class or category name
12241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  if (Tok.is(tok::l_paren)) {
1226ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian    // we have a category implementation.
1227ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian    SourceLocation lparenLoc = ConsumeParen();
1228ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian    SourceLocation categoryLoc, rparenLoc;
1229ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian    IdentifierInfo *categoryId = 0;
12301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
123133ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor    if (Tok.is(tok::code_completion)) {
1232c83c6874e3bf1432d3df5e8d3530f8561ff5441fDouglas Gregor      Actions.CodeCompleteObjCImplementationCategory(CurScope, nameId, nameLoc);
123333ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor      ConsumeToken();
123433ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor    }
123533ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor
1236df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner    if (Tok.is(tok::identifier)) {
1237ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian      categoryId = Tok.getIdentifierInfo();
1238ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian      categoryLoc = ConsumeToken();
1239ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian    } else {
1240ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian      Diag(Tok, diag::err_expected_ident); // missing category name.
1241b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner      return DeclPtrTy();
12421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    }
1243df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner    if (Tok.isNot(tok::r_paren)) {
1244ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian      Diag(Tok, diag::err_expected_rparen);
1245ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian      SkipUntil(tok::r_paren, false); // don't stop at ';'
1246b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner      return DeclPtrTy();
1247ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian    }
1248ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian    rparenLoc = ConsumeParen();
1249b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner    DeclPtrTy ImplCatType = Actions.ActOnStartCategoryImplementation(
12501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                    atLoc, nameId, nameLoc, categoryId,
12518f3fde00ad4d4f943321e338b914ae4740711c84Fariborz Jahanian                                    categoryLoc);
1252a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek    ObjCImpDecl = ImplCatType;
125363e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian    PendingObjCImpDecl.push_back(ObjCImpDecl);
1254b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner    return DeclPtrTy();
1255ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian  }
1256ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian  // We have a class implementation
1257ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian  SourceLocation superClassLoc;
1258ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian  IdentifierInfo *superClassId = 0;
1259df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  if (Tok.is(tok::colon)) {
1260ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian    // We have a super class
1261ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian    ConsumeToken();
1262df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner    if (Tok.isNot(tok::identifier)) {
1263ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian      Diag(Tok, diag::err_expected_ident); // missing super class name.
1264b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner      return DeclPtrTy();
1265ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian    }
1266ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian    superClassId = Tok.getIdentifierInfo();
1267ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian    superClassLoc = ConsumeToken(); // Consume super class name
1268ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian  }
1269b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner  DeclPtrTy ImplClsType = Actions.ActOnStartClassImplementation(
1270cb53b361bce341c8591333c6997f62e480acc0b4Chris Lattner                                  atLoc, nameId, nameLoc,
1271ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian                                  superClassId, superClassLoc);
12721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
127360fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff  if (Tok.is(tok::l_brace)) // we have ivars
127483c481ade785a919ba21a33f9a8b1b21c1212fb3Fariborz Jahanian    ParseObjCClassInstanceVariables(ImplClsType/*FIXME*/,
127501f1bfc3284d5817517d35217885ea9ecb252817Fariborz Jahanian                                    tok::objc_private, atLoc);
1276a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCImpDecl = ImplClsType;
127763e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian  PendingObjCImpDecl.push_back(ObjCImpDecl);
127863e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian
1279b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner  return DeclPtrTy();
12805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
128160fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff
1282782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted KremenekParser::DeclPtrTy Parser::ParseObjCAtEndDeclaration(SourceRange atEnd) {
1283ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian  assert(Tok.isObjCAtKeyword(tok::objc_end) &&
1284ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian         "ParseObjCAtEndDeclaration(): Expected @end");
1285b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner  DeclPtrTy Result = ObjCImpDecl;
1286ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian  ConsumeToken(); // the "end" identifier
1287a6e3ac514c924879699c6b0b1201028f0091044fFariborz Jahanian  if (ObjCImpDecl) {
1288782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek    Actions.ActOnAtEnd(atEnd, ObjCImpDecl);
1289b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner    ObjCImpDecl = DeclPtrTy();
129063e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian    PendingObjCImpDecl.pop_back();
1291a6e3ac514c924879699c6b0b1201028f0091044fFariborz Jahanian  }
1292782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek  else {
1293782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek    // missing @implementation
1294782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek    Diag(atEnd.getBegin(), diag::warn_expected_implementation);
1295782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek  }
1296a6e3ac514c924879699c6b0b1201028f0091044fFariborz Jahanian  return Result;
12975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
1298e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian
12991ac7104947020a60430ba6f519cd5869af77046fFariborz JahanianParser::DeclGroupPtrTy Parser::RetrievePendingObjCImpDecl() {
130063e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian  if (PendingObjCImpDecl.empty())
130163e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian    return Actions.ConvertDeclToDeclGroup(DeclPtrTy());
130263e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian  DeclPtrTy ImpDecl = PendingObjCImpDecl.pop_back_val();
1303782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek  Actions.ActOnAtEnd(SourceRange(), ImpDecl);
130463e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian  return Actions.ConvertDeclToDeclGroup(ImpDecl);
130563e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian}
130663e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian
1307e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian///   compatibility-alias-decl:
1308e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian///     @compatibility_alias alias-name  class-name ';'
1309e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian///
1310b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris LattnerParser::DeclPtrTy Parser::ParseObjCAtAliasDeclaration(SourceLocation atLoc) {
1311e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian  assert(Tok.isObjCAtKeyword(tok::objc_compatibility_alias) &&
1312e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian         "ParseObjCAtAliasDeclaration(): Expected @compatibility_alias");
1313e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian  ConsumeToken(); // consume compatibility_alias
1314df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  if (Tok.isNot(tok::identifier)) {
1315e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian    Diag(Tok, diag::err_expected_ident);
1316b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner    return DeclPtrTy();
1317e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian  }
1318243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian  IdentifierInfo *aliasId = Tok.getIdentifierInfo();
1319243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian  SourceLocation aliasLoc = ConsumeToken(); // consume alias-name
1320df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  if (Tok.isNot(tok::identifier)) {
1321e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian    Diag(Tok, diag::err_expected_ident);
1322b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner    return DeclPtrTy();
1323e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian  }
1324243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian  IdentifierInfo *classId = Tok.getIdentifierInfo();
1325243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian  SourceLocation classLoc = ConsumeToken(); // consume class-name;
1326243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian  if (Tok.isNot(tok::semi)) {
13271ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner    Diag(Tok, diag::err_expected_semi_after) << "@compatibility_alias";
1328b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner    return DeclPtrTy();
1329243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian  }
1330b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner  return Actions.ActOnCompatiblityAlias(atLoc, aliasId, aliasLoc,
1331b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner                                        classId, classLoc);
13325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
13335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1334ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian///   property-synthesis:
1335ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian///     @synthesize property-ivar-list ';'
1336ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian///
1337ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian///   property-ivar-list:
1338ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian///     property-ivar
1339ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian///     property-ivar-list ',' property-ivar
1340ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian///
1341ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian///   property-ivar:
1342ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian///     identifier
1343ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian///     identifier '=' identifier
1344ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian///
1345b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris LattnerParser::DeclPtrTy Parser::ParseObjCPropertySynthesize(SourceLocation atLoc) {
1346ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian  assert(Tok.isObjCAtKeyword(tok::objc_synthesize) &&
1347ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian         "ParseObjCPropertyDynamic(): Expected '@synthesize'");
1348f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian  SourceLocation loc = ConsumeToken(); // consume synthesize
13491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1350b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor  while (true) {
1351322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor    if (Tok.is(tok::code_completion)) {
1352424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor      Actions.CodeCompleteObjCPropertyDefinition(CurScope, ObjCImpDecl);
1353322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor      ConsumeToken();
1354322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor    }
1355322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor
1356b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor    if (Tok.isNot(tok::identifier)) {
1357b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor      Diag(Tok, diag::err_synthesized_property_name);
1358b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor      SkipUntil(tok::semi);
1359b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor      return DeclPtrTy();
1360b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor    }
1361b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor
1362f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian    IdentifierInfo *propertyIvar = 0;
1363f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian    IdentifierInfo *propertyId = Tok.getIdentifierInfo();
1364f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian    SourceLocation propertyLoc = ConsumeToken(); // consume property name
1365df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner    if (Tok.is(tok::equal)) {
1366ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian      // property '=' ivar-name
1367ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian      ConsumeToken(); // consume '='
1368322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor
1369322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor      if (Tok.is(tok::code_completion)) {
1370322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor        Actions.CodeCompleteObjCPropertySynthesizeIvar(CurScope, propertyId,
1371322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor                                                       ObjCImpDecl);
1372322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor        ConsumeToken();
1373322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor      }
1374322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor
1375df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner      if (Tok.isNot(tok::identifier)) {
1376ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian        Diag(Tok, diag::err_expected_ident);
1377ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian        break;
1378ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian      }
1379f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian      propertyIvar = Tok.getIdentifierInfo();
1380ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian      ConsumeToken(); // consume ivar-name
1381ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian    }
1382f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian    Actions.ActOnPropertyImplDecl(atLoc, propertyLoc, true, ObjCImpDecl,
1383f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian                                  propertyId, propertyIvar);
1384df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner    if (Tok.isNot(tok::comma))
1385ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian      break;
1386ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian    ConsumeToken(); // consume ','
1387ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian  }
1388b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor  if (Tok.isNot(tok::semi)) {
13891ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner    Diag(Tok, diag::err_expected_semi_after) << "@synthesize";
1390b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor    SkipUntil(tok::semi);
1391b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor  }
1392d3fdcb5a1bf6bd5e54e18579c054ea3c292a0e28Fariborz Jahanian  else
1393d3fdcb5a1bf6bd5e54e18579c054ea3c292a0e28Fariborz Jahanian    ConsumeToken(); // consume ';'
1394b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner  return DeclPtrTy();
1395ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian}
1396ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian
1397ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian///   property-dynamic:
1398ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian///     @dynamic  property-list
1399ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian///
1400ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian///   property-list:
1401ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian///     identifier
1402ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian///     property-list ',' identifier
1403ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian///
1404b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris LattnerParser::DeclPtrTy Parser::ParseObjCPropertyDynamic(SourceLocation atLoc) {
1405ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian  assert(Tok.isObjCAtKeyword(tok::objc_dynamic) &&
1406ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian         "ParseObjCPropertyDynamic(): Expected '@dynamic'");
1407ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian  SourceLocation loc = ConsumeToken(); // consume dynamic
1408424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor  while (true) {
1409424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor    if (Tok.is(tok::code_completion)) {
1410424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor      Actions.CodeCompleteObjCPropertyDefinition(CurScope, ObjCImpDecl);
1411424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor      ConsumeToken();
1412424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor    }
1413424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor
1414424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor    if (Tok.isNot(tok::identifier)) {
1415424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor      Diag(Tok, diag::err_expected_ident);
1416424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor      SkipUntil(tok::semi);
1417424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor      return DeclPtrTy();
1418424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor    }
1419424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor
1420c35b9e4e2efad727538c848cf30d4b0eb1031dc9Fariborz Jahanian    IdentifierInfo *propertyId = Tok.getIdentifierInfo();
1421c35b9e4e2efad727538c848cf30d4b0eb1031dc9Fariborz Jahanian    SourceLocation propertyLoc = ConsumeToken(); // consume property name
1422c35b9e4e2efad727538c848cf30d4b0eb1031dc9Fariborz Jahanian    Actions.ActOnPropertyImplDecl(atLoc, propertyLoc, false, ObjCImpDecl,
1423c35b9e4e2efad727538c848cf30d4b0eb1031dc9Fariborz Jahanian                                  propertyId, 0);
1424c35b9e4e2efad727538c848cf30d4b0eb1031dc9Fariborz Jahanian
1425df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner    if (Tok.isNot(tok::comma))
1426ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian      break;
1427ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian    ConsumeToken(); // consume ','
1428ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian  }
142994b24db37e80a75c4088e592d4150fb12b00bfb3Fariborz Jahanian  if (Tok.isNot(tok::semi)) {
14301ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner    Diag(Tok, diag::err_expected_semi_after) << "@dynamic";
143194b24db37e80a75c4088e592d4150fb12b00bfb3Fariborz Jahanian    SkipUntil(tok::semi);
143294b24db37e80a75c4088e592d4150fb12b00bfb3Fariborz Jahanian  }
143394b24db37e80a75c4088e592d4150fb12b00bfb3Fariborz Jahanian  else
143494b24db37e80a75c4088e592d4150fb12b00bfb3Fariborz Jahanian    ConsumeToken(); // consume ';'
1435b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner  return DeclPtrTy();
1436ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian}
14371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1438397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian///  objc-throw-statement:
1439397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian///    throw expression[opt];
1440397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian///
144143bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian RedlParser::OwningStmtResult Parser::ParseObjCThrowStmt(SourceLocation atLoc) {
144215faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl  OwningExprResult Res(Actions);
1443397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian  ConsumeToken(); // consume throw
1444df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  if (Tok.isNot(tok::semi)) {
144539f8f159c488a900e5958d5aab3e467af9ec8a2bFariborz Jahanian    Res = ParseExpression();
14460e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl    if (Res.isInvalid()) {
1447397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian      SkipUntil(tok::semi);
144843bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl      return StmtError();
1449397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian    }
1450397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian  }
145102418c7f0cb8bb83f1a1a1fad9bf6104efa83e0eTed Kremenek  // consume ';'
145202418c7f0cb8bb83f1a1a1fad9bf6104efa83e0eTed Kremenek  ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@throw");
1453e21dd6ffef4585fa43cd3586ed971217d65bf56cSteve Naroff  return Actions.ActOnObjCAtThrowStmt(atLoc, move(Res), CurScope);
1454397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian}
1455397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian
1456c385c90c68dfa376650e2facfbb444b2ec9bd110Fariborz Jahanian/// objc-synchronized-statement:
145778a677bbb5fa115fa0995b5783adeeefad67167eFariborz Jahanian///   @synchronized '(' expression ')' compound-statement
1458c385c90c68dfa376650e2facfbb444b2ec9bd110Fariborz Jahanian///
145943bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian RedlParser::OwningStmtResult
146043bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian RedlParser::ParseObjCSynchronizedStmt(SourceLocation atLoc) {
1461fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian  ConsumeToken(); // consume synchronized
1462fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian  if (Tok.isNot(tok::l_paren)) {
14631ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner    Diag(Tok, diag::err_expected_lparen_after) << "@synchronized";
146443bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl    return StmtError();
1465fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian  }
1466fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian  ConsumeParen();  // '('
14672f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl  OwningExprResult Res(ParseExpression());
14680e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl  if (Res.isInvalid()) {
1469fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian    SkipUntil(tok::semi);
147043bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl    return StmtError();
1471fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian  }
1472fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian  if (Tok.isNot(tok::r_paren)) {
14731ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner    Diag(Tok, diag::err_expected_lbrace);
147443bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl    return StmtError();
1475fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian  }
1476fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian  ConsumeParen();  // ')'
147778a677bbb5fa115fa0995b5783adeeefad67167eFariborz Jahanian  if (Tok.isNot(tok::l_brace)) {
14781ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner    Diag(Tok, diag::err_expected_lbrace);
147943bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl    return StmtError();
148078a677bbb5fa115fa0995b5783adeeefad67167eFariborz Jahanian  }
14813ac438c383a4a9a73c76a05c76ec5d02f10a3c52Steve Naroff  // Enter a scope to hold everything within the compound stmt.  Compound
14823ac438c383a4a9a73c76a05c76ec5d02f10a3c52Steve Naroff  // statements can always hold declarations.
14838935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor  ParseScope BodyScope(this, Scope::DeclScope);
14843ac438c383a4a9a73c76a05c76ec5d02f10a3c52Steve Naroff
148561364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl  OwningStmtResult SynchBody(ParseCompoundStatementBody());
14860e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl
14878935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor  BodyScope.Exit();
14880e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl  if (SynchBody.isInvalid())
1489fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian    SynchBody = Actions.ActOnNullStmt(Tok.getLocation());
149076ad2e85575722e8a38a2bd4648ab4304d9fcd24Sebastian Redl  return Actions.ActOnObjCAtSynchronizedStmt(atLoc, move(Res), move(SynchBody));
1491c385c90c68dfa376650e2facfbb444b2ec9bd110Fariborz Jahanian}
1492c385c90c68dfa376650e2facfbb444b2ec9bd110Fariborz Jahanian
1493397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian///  objc-try-catch-statement:
1494397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian///    @try compound-statement objc-catch-list[opt]
1495397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian///    @try compound-statement objc-catch-list[opt] @finally compound-statement
1496397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian///
1497397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian///  objc-catch-list:
1498397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian///    @catch ( parameter-declaration ) compound-statement
1499397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian///    objc-catch-list @catch ( catch-parameter-declaration ) compound-statement
1500397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian///  catch-parameter-declaration:
1501397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian///     parameter-declaration
1502397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian///     '...' [OBJC2]
1503397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian///
150443bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian RedlParser::OwningStmtResult Parser::ParseObjCTryStmt(SourceLocation atLoc) {
1505397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian  bool catch_or_finally_seen = false;
150643bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl
1507397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian  ConsumeToken(); // consume try
1508df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  if (Tok.isNot(tok::l_brace)) {
15091ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner    Diag(Tok, diag::err_expected_lbrace);
151043bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl    return StmtError();
1511397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian  }
151215faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl  OwningStmtResult CatchStmts(Actions);
151315faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl  OwningStmtResult FinallyStmt(Actions);
15148935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor  ParseScope TryScope(this, Scope::DeclScope);
151561364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl  OwningStmtResult TryBody(ParseCompoundStatementBody());
15168935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor  TryScope.Exit();
15170e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl  if (TryBody.isInvalid())
1518bd49a647afd9cc534fef13cadf652d4e9c396e2bFariborz Jahanian    TryBody = Actions.ActOnNullStmt(Tok.getLocation());
1519a55e52c0802cae3b7c366a05c461d3d15074c1a3Sebastian Redl
1520df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  while (Tok.is(tok::at)) {
15216b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner    // At this point, we need to lookahead to determine if this @ is the start
15226b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner    // of an @catch or @finally.  We don't want to consume the @ token if this
15236b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner    // is an @try or @encode or something else.
15246b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner    Token AfterAt = GetLookAheadToken(1);
15256b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner    if (!AfterAt.isObjCAtKeyword(tok::objc_catch) &&
15266b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner        !AfterAt.isObjCAtKeyword(tok::objc_finally))
15276b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner      break;
15280e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl
1529161a9c5afaafb4d527b7efba9675a8b2cbbe32e0Fariborz Jahanian    SourceLocation AtCatchFinallyLoc = ConsumeToken();
1530cb53b361bce341c8591333c6997f62e480acc0b4Chris Lattner    if (Tok.isObjCAtKeyword(tok::objc_catch)) {
1531b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner      DeclPtrTy FirstPart;
15323b1191d7eaf2f4984564e01ab84b6713a9d80e70Fariborz Jahanian      ConsumeToken(); // consume catch
1533df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner      if (Tok.is(tok::l_paren)) {
1534397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian        ConsumeParen();
1535e21dd6ffef4585fa43cd3586ed971217d65bf56cSteve Naroff        ParseScope CatchScope(this, Scope::DeclScope|Scope::AtCatchScope);
1536df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner        if (Tok.isNot(tok::ellipsis)) {
1537397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian          DeclSpec DS;
1538397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian          ParseDeclarationSpecifiers(DS);
153943bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl          // For some odd reason, the name of the exception variable is
15401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump          // optional. As a result, we need to use "PrototypeContext", because
15417ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff          // we must accept either 'declarator' or 'abstract-declarator' here.
15427ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff          Declarator ParmDecl(DS, Declarator::PrototypeContext);
15437ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff          ParseDeclarator(ParmDecl);
15447ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff
15457ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff          // Inform the actions module about the parameter declarator, so it
15467ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff          // gets added to the current scope.
1547d219a3a462c31fc9aa0c0bcfb749e9e8e56b5e35Fariborz Jahanian          // FIXME. Probably can build a VarDecl and avoid setting DeclContext.
15487ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff          FirstPart = Actions.ActOnParamDeclarator(CurScope, ParmDecl);
15492f764f11f513c7b51c716fffa5d02e5de816836fFariborz Jahanian          Actions.ActOnObjCCatchParam(FirstPart);
155064515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff        } else
1551397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian          ConsumeToken(); // consume '...'
15521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
155393a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff        SourceLocation RParenLoc;
15541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
155593a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff        if (Tok.is(tok::r_paren))
155693a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff          RParenLoc = ConsumeParen();
155793a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff        else // Skip over garbage, until we get to ')'.  Eat the ')'.
155893a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff          SkipUntil(tok::r_paren, true, false);
155993a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff
156015faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl        OwningStmtResult CatchBody(Actions, true);
1561c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner        if (Tok.is(tok::l_brace))
1562c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner          CatchBody = ParseCompoundStatementBody();
1563c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner        else
1564c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner          Diag(Tok, diag::err_expected_lbrace);
15650e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl        if (CatchBody.isInvalid())
15663b1191d7eaf2f4984564e01ab84b6713a9d80e70Fariborz Jahanian          CatchBody = Actions.ActOnNullStmt(Tok.getLocation());
15670e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl        CatchStmts = Actions.ActOnObjCAtCatchStmt(AtCatchFinallyLoc,
15687ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff                        RParenLoc, FirstPart, move(CatchBody),
156976ad2e85575722e8a38a2bd4648ab4304d9fcd24Sebastian Redl                        move(CatchStmts));
157064515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff      } else {
15711ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner        Diag(AtCatchFinallyLoc, diag::err_expected_lparen_after)
15721ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner          << "@catch clause";
157343bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl        return StmtError();
1574397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian      }
1575397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian      catch_or_finally_seen = true;
15766b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner    } else {
15776b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner      assert(Tok.isObjCAtKeyword(tok::objc_finally) && "Lookahead confused?");
157864515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff      ConsumeToken(); // consume finally
15798935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor      ParseScope FinallyScope(this, Scope::DeclScope);
15800e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl
158115faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl      OwningStmtResult FinallyBody(Actions, true);
1582c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner      if (Tok.is(tok::l_brace))
1583c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner        FinallyBody = ParseCompoundStatementBody();
1584c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner      else
1585c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner        Diag(Tok, diag::err_expected_lbrace);
15860e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl      if (FinallyBody.isInvalid())
1587161a9c5afaafb4d527b7efba9675a8b2cbbe32e0Fariborz Jahanian        FinallyBody = Actions.ActOnNullStmt(Tok.getLocation());
15880e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl      FinallyStmt = Actions.ActOnObjCAtFinallyStmt(AtCatchFinallyLoc,
158976ad2e85575722e8a38a2bd4648ab4304d9fcd24Sebastian Redl                                                   move(FinallyBody));
1590397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian      catch_or_finally_seen = true;
1591397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian      break;
1592397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian    }
1593397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian  }
1594bd49a647afd9cc534fef13cadf652d4e9c396e2bFariborz Jahanian  if (!catch_or_finally_seen) {
1595397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian    Diag(atLoc, diag::err_missing_catch_finally);
159643bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl    return StmtError();
1597bd49a647afd9cc534fef13cadf652d4e9c396e2bFariborz Jahanian  }
159876ad2e85575722e8a38a2bd4648ab4304d9fcd24Sebastian Redl  return Actions.ActOnObjCAtTryStmt(atLoc, move(TryBody), move(CatchStmts),
159976ad2e85575722e8a38a2bd4648ab4304d9fcd24Sebastian Redl                                    move(FinallyStmt));
1600397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian}
1601ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian
16023536b443bc50d58a79f14fca9b6842541a434854Steve Naroff///   objc-method-def: objc-method-proto ';'[opt] '{' body '}'
1603ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian///
1604b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris LattnerParser::DeclPtrTy Parser::ParseObjCMethodDefinition() {
1605b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner  DeclPtrTy MDecl = ParseObjCMethodPrototype(ObjCImpDecl);
16061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
160749f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner  PrettyStackTraceActionsDecl CrashInfo(MDecl, Tok.getLocation(), Actions,
160849f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner                                        PP.getSourceManager(),
160949f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner                                        "parsing Objective-C method");
16101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1611ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian  // parse optional ';'
1612209a8c2fa23636f6d065d618e7078e164903f5cdFariborz Jahanian  if (Tok.is(tok::semi)) {
1613496e45ef3350fabc312c5a807d308c65c50af4dbTed Kremenek    if (ObjCImpDecl) {
1614496e45ef3350fabc312c5a807d308c65c50af4dbTed Kremenek      Diag(Tok, diag::warn_semicolon_before_method_body)
1615849b243d4065f56742a4677d6dc8277609a151f8Douglas Gregor        << FixItHint::CreateRemoval(Tok.getLocation());
1616496e45ef3350fabc312c5a807d308c65c50af4dbTed Kremenek    }
1617ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian    ConsumeToken();
1618209a8c2fa23636f6d065d618e7078e164903f5cdFariborz Jahanian  }
1619ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian
1620409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff  // We should have an opening brace now.
1621df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  if (Tok.isNot(tok::l_brace)) {
1622da323adbb99cee19a203ead852d5d9bfebb23fb7Steve Naroff    Diag(Tok, diag::err_expected_method_body);
16231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1624409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff    // Skip over garbage, until we get to '{'.  Don't eat the '{'.
1625409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff    SkipUntil(tok::l_brace, true, true);
16261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1627409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff    // If we didn't find the '{', bail out.
1628409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff    if (Tok.isNot(tok::l_brace))
1629b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner      return DeclPtrTy();
1630ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian  }
1631409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff  SourceLocation BraceLoc = Tok.getLocation();
16321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1633409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff  // Enter a scope for the method body.
163415faee19fdb9017dd6d08a690427b18c3b062c2dChris Lattner  ParseScope BodyScope(this,
163515faee19fdb9017dd6d08a690427b18c3b062c2dChris Lattner                       Scope::ObjCMethodScope|Scope::FnScope|Scope::DeclScope);
16361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1637409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff  // Tell the actions module that we have entered a method definition with the
1638394f3f483fa4e7b472630cfcd03f7840520958c5Steve Naroff  // specified Declarator for the method.
1639ebf6443a4f493233f7e8d92b3a991848c8b1c00dSteve Naroff  Actions.ActOnStartOfObjCMethodDef(CurScope, MDecl);
164061364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl
164161364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl  OwningStmtResult FnBody(ParseCompoundStatementBody());
164261364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl
1643409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff  // If the function body could not be parsed, make a bogus compoundstmt.
16440e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl  if (FnBody.isInvalid())
1645a60528cdac7deee3991c2b48af4df4f315e49e9dSebastian Redl    FnBody = Actions.ActOnCompoundStmt(BraceLoc, BraceLoc,
1646a60528cdac7deee3991c2b48af4df4f315e49e9dSebastian Redl                                       MultiStmtArg(Actions), false);
1647798d119415323ebcd029ffe1e0fb442a4ca8adbbSebastian Redl
164832ce8376efb7e0d70e5f7e8fcf685130293f412bSteve Naroff  // TODO: Pass argument information.
164932ce8376efb7e0d70e5f7e8fcf685130293f412bSteve Naroff  Actions.ActOnFinishFunctionBody(MDecl, move(FnBody));
16501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1651409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff  // Leave the function body scope.
16528935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor  BodyScope.Exit();
1653798d119415323ebcd029ffe1e0fb442a4ca8adbbSebastian Redl
165471c0a951d08dc7a2a057df8c15f22b36f6aa47c7Steve Naroff  return MDecl;
16555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
16565508518a2702b00be3b15a26d772bde968972f54Anders Carlsson
165743bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian RedlParser::OwningStmtResult Parser::ParseObjCAtStatement(SourceLocation AtLoc) {
16589a0c85e640a08174569a303db22981612f05d385Douglas Gregor  if (Tok.is(tok::code_completion)) {
16599a0c85e640a08174569a303db22981612f05d385Douglas Gregor    Actions.CodeCompleteObjCAtStatement(CurScope);
16609a0c85e640a08174569a303db22981612f05d385Douglas Gregor    ConsumeToken();
16619a0c85e640a08174569a303db22981612f05d385Douglas Gregor    return StmtError();
16625d8031687d086701b4dadaab3e0de1def448da9dChris Lattner  }
16635d8031687d086701b4dadaab3e0de1def448da9dChris Lattner
16645d8031687d086701b4dadaab3e0de1def448da9dChris Lattner  if (Tok.isObjCAtKeyword(tok::objc_try))
16656b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner    return ParseObjCTryStmt(AtLoc);
16665d8031687d086701b4dadaab3e0de1def448da9dChris Lattner
16675d8031687d086701b4dadaab3e0de1def448da9dChris Lattner  if (Tok.isObjCAtKeyword(tok::objc_throw))
166864515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff    return ParseObjCThrowStmt(AtLoc);
16695d8031687d086701b4dadaab3e0de1def448da9dChris Lattner
16705d8031687d086701b4dadaab3e0de1def448da9dChris Lattner  if (Tok.isObjCAtKeyword(tok::objc_synchronized))
167164515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff    return ParseObjCSynchronizedStmt(AtLoc);
16725d8031687d086701b4dadaab3e0de1def448da9dChris Lattner
1673d8c4e15138e69a51754cc259c8a592cc47950c8eSebastian Redl  OwningExprResult Res(ParseExpressionWithLeadingAt(AtLoc));
16740e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl  if (Res.isInvalid()) {
167564515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff    // If the expression is invalid, skip ahead to the next semicolon. Not
167664515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff    // doing this opens us up to the possibility of infinite loops if
167764515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff    // ParseExpression does not consume any tokens.
167864515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff    SkipUntil(tok::semi);
167943bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl    return StmtError();
168064515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff  }
16815d8031687d086701b4dadaab3e0de1def448da9dChris Lattner
168264515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff  // Otherwise, eat the semicolon.
168364515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff  ExpectAndConsume(tok::semi, diag::err_expected_semi_after_expr);
16845ee56e95c3905d2e7bc403631b03865cdbdd8a42Anders Carlsson  return Actions.ActOnExprStmt(Actions.MakeFullExpr(Res));
168564515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff}
168664515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff
16871d922960e083906a586609ac6978678147250177Sebastian RedlParser::OwningExprResult Parser::ParseObjCAtExpression(SourceLocation AtLoc) {
16885508518a2702b00be3b15a26d772bde968972f54Anders Carlsson  switch (Tok.getKind()) {
16899a0c85e640a08174569a303db22981612f05d385Douglas Gregor  case tok::code_completion:
16909a0c85e640a08174569a303db22981612f05d385Douglas Gregor    Actions.CodeCompleteObjCAtExpression(CurScope);
16919a0c85e640a08174569a303db22981612f05d385Douglas Gregor    ConsumeToken();
16929a0c85e640a08174569a303db22981612f05d385Douglas Gregor    return ExprError();
16939a0c85e640a08174569a303db22981612f05d385Douglas Gregor
1694b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner  case tok::string_literal:    // primary-expression: string-literal
1695b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner  case tok::wide_string_literal:
16961d922960e083906a586609ac6978678147250177Sebastian Redl    return ParsePostfixExpressionSuffix(ParseObjCStringLiteral(AtLoc));
1697b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner  default:
16984fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner    if (Tok.getIdentifierInfo() == 0)
16991d922960e083906a586609ac6978678147250177Sebastian Redl      return ExprError(Diag(AtLoc, diag::err_unexpected_at));
17002f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl
17014fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner    switch (Tok.getIdentifierInfo()->getObjCKeywordID()) {
17024fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner    case tok::objc_encode:
17031d922960e083906a586609ac6978678147250177Sebastian Redl      return ParsePostfixExpressionSuffix(ParseObjCEncodeExpression(AtLoc));
17044fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner    case tok::objc_protocol:
17051d922960e083906a586609ac6978678147250177Sebastian Redl      return ParsePostfixExpressionSuffix(ParseObjCProtocolExpression(AtLoc));
17064fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner    case tok::objc_selector:
17071d922960e083906a586609ac6978678147250177Sebastian Redl      return ParsePostfixExpressionSuffix(ParseObjCSelectorExpression(AtLoc));
17084fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner    default:
17091d922960e083906a586609ac6978678147250177Sebastian Redl      return ExprError(Diag(AtLoc, diag::err_unexpected_at));
17104fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner    }
17115508518a2702b00be3b15a26d772bde968972f54Anders Carlsson  }
17125508518a2702b00be3b15a26d772bde968972f54Anders Carlsson}
17135508518a2702b00be3b15a26d772bde968972f54Anders Carlsson
17141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///   objc-message-expr:
17150ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///     '[' objc-receiver objc-message-args ']'
17160ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///
17172725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor///   objc-receiver: [C]
1718eb483eb3ee80300f15d6d13573d82493c2194461Chris Lattner///     'super'
17190ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///     expression
17200ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///     class-name
17210ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///     type-name
17221d922960e083906a586609ac6978678147250177Sebastian RedlParser::OwningExprResult Parser::ParseObjCMessageExpression() {
1723699b66138ac307a32e238463e0eff513ff17d337Chris Lattner  assert(Tok.is(tok::l_square) && "'[' expected");
1724699b66138ac307a32e238463e0eff513ff17d337Chris Lattner  SourceLocation LBracLoc = ConsumeBracket(); // consume '['
1725699b66138ac307a32e238463e0eff513ff17d337Chris Lattner
1726eb483eb3ee80300f15d6d13573d82493c2194461Chris Lattner  if (Tok.is(tok::identifier)) {
17271dbca6ea983231b4cab1a8f1edda8f6e13c21f12Douglas Gregor    IdentifierInfo *Name = Tok.getIdentifierInfo();
17281dbca6ea983231b4cab1a8f1edda8f6e13c21f12Douglas Gregor    SourceLocation NameLoc = Tok.getLocation();
17291dbca6ea983231b4cab1a8f1edda8f6e13c21f12Douglas Gregor    switch (Actions.getObjCMessageKind(CurScope, Name, NameLoc,
17301dbca6ea983231b4cab1a8f1edda8f6e13c21f12Douglas Gregor                                       Name == Ident_super,
17311dbca6ea983231b4cab1a8f1edda8f6e13c21f12Douglas Gregor                                       NextToken().is(tok::period))) {
17321dbca6ea983231b4cab1a8f1edda8f6e13c21f12Douglas Gregor    case Action::ObjCSuperMessage:
17332725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor      return ParseObjCMessageExpressionBody(LBracLoc, ConsumeToken(), 0,
1734d2869925b5f10e00b13fbf3f41bbb17e4c9adbe0Fariborz Jahanian                                            ExprArg(Actions));
17352725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor
17362725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor    case Action::ObjCClassMessage: {
17372725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor      // Create the type that corresponds to the identifier (which
17382725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor      // names an Objective-C class).
17392725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor      TypeTy *Type = 0;
17402725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor      if (TypeTy *TyName = Actions.getTypeName(*Name, NameLoc, CurScope)) {
17412725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor        DeclSpec DS;
17422725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor        const char *PrevSpec = 0;
17432725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor        unsigned DiagID = 0;
17442725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor        if (!DS.SetTypeSpecType(DeclSpec::TST_typename, NameLoc, PrevSpec,
17452725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor                                DiagID, TyName)) {
17462725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor          DS.SetRangeEnd(NameLoc);
17472725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor          Declarator DeclaratorInfo(DS, Declarator::TypeNameContext);
17482725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor          TypeResult Ty = Actions.ActOnTypeName(CurScope, DeclaratorInfo);
17492725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor          if (!Ty.isInvalid())
17502725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor            Type = Ty.get();
17512725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor        }
17522725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor      }
17532725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor
17542725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor      ConsumeToken(); // The identifier.
17552725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor      if (!Type) {
17562725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor        SkipUntil(tok::r_square);
17572725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor        return ExprError();
17582725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor      }
17592725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor
17602725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor      return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(), Type,
17612725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor                                            ExprArg(Actions));
17622725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor    }
17631dbca6ea983231b4cab1a8f1edda8f6e13c21f12Douglas Gregor
17641dbca6ea983231b4cab1a8f1edda8f6e13c21f12Douglas Gregor    case Action::ObjCInstanceMessage:
17652725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor      // Fall through to parse an expression.
17661dbca6ea983231b4cab1a8f1edda8f6e13c21f12Douglas Gregor      break;
1767d2869925b5f10e00b13fbf3f41bbb17e4c9adbe0Fariborz Jahanian    }
1768699b66138ac307a32e238463e0eff513ff17d337Chris Lattner  }
1769eb483eb3ee80300f15d6d13573d82493c2194461Chris Lattner
1770eb483eb3ee80300f15d6d13573d82493c2194461Chris Lattner  // Otherwise, an arbitrary expression can be the receiver of a send.
17712f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl  OwningExprResult Res(ParseExpression());
17720e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl  if (Res.isInvalid()) {
17735c749428a9938d5e2e9564b1c9b7a9252c30ee27Chris Lattner    SkipUntil(tok::r_square);
17741d922960e083906a586609ac6978678147250177Sebastian Redl    return move(Res);
1775699b66138ac307a32e238463e0eff513ff17d337Chris Lattner  }
17761d922960e083906a586609ac6978678147250177Sebastian Redl
17772725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor  return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(), 0,
17782725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor                                        move(Res));
1779699b66138ac307a32e238463e0eff513ff17d337Chris Lattner}
17801d922960e083906a586609ac6978678147250177Sebastian Redl
17812725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// \brief Parse the remainder of an Objective-C message following the
17822725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// '[' objc-receiver.
17832725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor///
17842725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// This routine handles sends to super, class messages (sent to a
17852725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// class name), and instance messages (sent to an object), and the
17862725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// target is represented by \p SuperLoc, \p ReceiverType, or \p
17872725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// ReceiverExpr, respectively. Only one of these parameters may have
17882725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// a valid value.
17892725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor///
17902725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// \param LBracLoc The location of the opening '['.
17912725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor///
17922725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// \param SuperLoc If this is a send to 'super', the location of the
17932725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// 'super' keyword that indicates a send to the superclass.
17942725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor///
17952725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// \param ReceiverType If this is a class message, the type of the
17962725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// class we are sending a message to.
17972725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor///
17982725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// \param ReceiverExpr If this is an instance message, the expression
17992725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// used to compute the receiver object.
18001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///
18010ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///   objc-message-args:
18020ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///     objc-selector
18030ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///     objc-keywordarg-list
18040ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///
18050ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///   objc-keywordarg-list:
18060ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///     objc-keywordarg
18070ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///     objc-keywordarg-list objc-keywordarg
18080ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///
18091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///   objc-keywordarg:
18100ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///     selector-name[opt] ':' objc-keywordexpr
18110ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///
18120ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///   objc-keywordexpr:
18130ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///     nonempty-expr-list
18140ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///
18150ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///   nonempty-expr-list:
18160ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///     assignment-expression
18170ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///     nonempty-expr-list , assignment-expression
18181d922960e083906a586609ac6978678147250177Sebastian Redl///
18191d922960e083906a586609ac6978678147250177Sebastian RedlParser::OwningExprResult
1820699b66138ac307a32e238463e0eff513ff17d337Chris LattnerParser::ParseObjCMessageExpressionBody(SourceLocation LBracLoc,
18212725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor                                       SourceLocation SuperLoc,
18222725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor                                       TypeTy *ReceiverType,
18231d922960e083906a586609ac6978678147250177Sebastian Redl                                       ExprArg ReceiverExpr) {
1824c4df6d2c05c647a6a5770ba0c749782b6c023a3aSteve Naroff  if (Tok.is(tok::code_completion)) {
18252725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor    if (SuperLoc.isValid())
18262725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor      Actions.CodeCompleteObjCSuperMessage(CurScope, SuperLoc, 0, 0);
18272725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor    else if (ReceiverType)
18282725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor      Actions.CodeCompleteObjCClassMessage(CurScope, ReceiverType, 0, 0);
1829c4df6d2c05c647a6a5770ba0c749782b6c023a3aSteve Naroff    else
1830d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor      Actions.CodeCompleteObjCInstanceMessage(CurScope, ReceiverExpr.get(),
1831d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor                                              0, 0);
1832c4df6d2c05c647a6a5770ba0c749782b6c023a3aSteve Naroff    ConsumeToken();
1833c4df6d2c05c647a6a5770ba0c749782b6c023a3aSteve Naroff  }
1834d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor
1835a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian  // Parse objc-selector
18364b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian  SourceLocation Loc;
18372fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner  IdentifierInfo *selIdent = ParseObjCSelectorPiece(Loc);
183868d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff
1839ff975cfab9ada27df86038286d1678084aeb3428Anders Carlsson  SourceLocation SelectorLoc = Loc;
18401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
184168d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff  llvm::SmallVector<IdentifierInfo *, 12> KeyIdents;
1842a55e52c0802cae3b7c366a05c461d3d15074c1a3Sebastian Redl  ExprVector KeyExprs(Actions);
184368d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff
1844df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  if (Tok.is(tok::colon)) {
1845a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian    while (1) {
1846a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian      // Each iteration parses a single keyword argument.
184768d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff      KeyIdents.push_back(selIdent);
184837387c932855c6d58d70bdd705cd3a9fdcd2a931Steve Naroff
1849df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner      if (Tok.isNot(tok::colon)) {
1850a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian        Diag(Tok, diag::err_expected_colon);
18514fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner        // We must manually skip to a ']', otherwise the expression skipper will
18524fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner        // stop at the ']' when it skips to the ';'.  We want it to skip beyond
18534fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner        // the enclosing expression.
18544fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner        SkipUntil(tok::r_square);
18551d922960e083906a586609ac6978678147250177Sebastian Redl        return ExprError();
1856a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian      }
18571d922960e083906a586609ac6978678147250177Sebastian Redl
185868d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff      ConsumeToken(); // Eat the ':'.
18591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      ///  Parse the expression after ':'
18602f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl      OwningExprResult Res(ParseAssignmentExpression());
18610e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl      if (Res.isInvalid()) {
18624fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner        // We must manually skip to a ']', otherwise the expression skipper will
18634fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner        // stop at the ']' when it skips to the ';'.  We want it to skip beyond
18644fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner        // the enclosing expression.
18654fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner        SkipUntil(tok::r_square);
18661d922960e083906a586609ac6978678147250177Sebastian Redl        return move(Res);
186737387c932855c6d58d70bdd705cd3a9fdcd2a931Steve Naroff      }
18681d922960e083906a586609ac6978678147250177Sebastian Redl
186937387c932855c6d58d70bdd705cd3a9fdcd2a931Steve Naroff      // We have a valid expression.
1870effa8d1c97b00a3f53e972b0e61d9aade5ea1c57Sebastian Redl      KeyExprs.push_back(Res.release());
18711d922960e083906a586609ac6978678147250177Sebastian Redl
1872d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor      // Code completion after each argument.
1873d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor      if (Tok.is(tok::code_completion)) {
18742725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor        if (SuperLoc.isValid())
18752725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor          Actions.CodeCompleteObjCSuperMessage(CurScope, SuperLoc,
18762725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor                                               KeyIdents.data(),
18772725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor                                               KeyIdents.size());
18782725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor        else if (ReceiverType)
18792725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor          Actions.CodeCompleteObjCClassMessage(CurScope, ReceiverType,
1880d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor                                               KeyIdents.data(),
1881d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor                                               KeyIdents.size());
1882d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor        else
1883d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor          Actions.CodeCompleteObjCInstanceMessage(CurScope, ReceiverExpr.get(),
1884d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor                                                  KeyIdents.data(),
1885d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor                                                  KeyIdents.size());
1886d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor        ConsumeToken();
1887d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor      }
1888d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor
188937387c932855c6d58d70bdd705cd3a9fdcd2a931Steve Naroff      // Check for another keyword selector.
18902fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner      selIdent = ParseObjCSelectorPiece(Loc);
1891df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner      if (!selIdent && Tok.isNot(tok::colon))
1892a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian        break;
1893a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian      // We have a selector or a colon, continue parsing.
1894a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian    }
1895a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian    // Parse the, optional, argument list, comma separated.
1896df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner    while (Tok.is(tok::comma)) {
189749f109c786f99eb7468dac3976db083a65493444Steve Naroff      ConsumeToken(); // Eat the ','.
18981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      ///  Parse the expression after ','
18992f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl      OwningExprResult Res(ParseAssignmentExpression());
19000e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl      if (Res.isInvalid()) {
19014fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner        // We must manually skip to a ']', otherwise the expression skipper will
19024fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner        // stop at the ']' when it skips to the ';'.  We want it to skip beyond
19034fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner        // the enclosing expression.
19044fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner        SkipUntil(tok::r_square);
19051d922960e083906a586609ac6978678147250177Sebastian Redl        return move(Res);
190649f109c786f99eb7468dac3976db083a65493444Steve Naroff      }
19070e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl
190849f109c786f99eb7468dac3976db083a65493444Steve Naroff      // We have a valid expression.
1909effa8d1c97b00a3f53e972b0e61d9aade5ea1c57Sebastian Redl      KeyExprs.push_back(Res.release());
1910a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian    }
1911a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian  } else if (!selIdent) {
1912a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian    Diag(Tok, diag::err_expected_ident); // missing selector name.
19131d922960e083906a586609ac6978678147250177Sebastian Redl
19144fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner    // We must manually skip to a ']', otherwise the expression skipper will
19154fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner    // stop at the ']' when it skips to the ';'.  We want it to skip beyond
19164fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner    // the enclosing expression.
19174fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner    SkipUntil(tok::r_square);
19181d922960e083906a586609ac6978678147250177Sebastian Redl    return ExprError();
1919a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian  }
1920809872eca7f6c024e2ab41ddffbbeeae807bf5dcFariborz Jahanian
1921df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  if (Tok.isNot(tok::r_square)) {
1922809872eca7f6c024e2ab41ddffbbeeae807bf5dcFariborz Jahanian    if (Tok.is(tok::identifier))
1923809872eca7f6c024e2ab41ddffbbeeae807bf5dcFariborz Jahanian      Diag(Tok, diag::err_expected_colon);
1924809872eca7f6c024e2ab41ddffbbeeae807bf5dcFariborz Jahanian    else
1925809872eca7f6c024e2ab41ddffbbeeae807bf5dcFariborz Jahanian      Diag(Tok, diag::err_expected_rsquare);
19264fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner    // We must manually skip to a ']', otherwise the expression skipper will
19274fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner    // stop at the ']' when it skips to the ';'.  We want it to skip beyond
19284fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner    // the enclosing expression.
19294fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner    SkipUntil(tok::r_square);
19301d922960e083906a586609ac6978678147250177Sebastian Redl    return ExprError();
1931a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian  }
19321d922960e083906a586609ac6978678147250177Sebastian Redl
1933699b66138ac307a32e238463e0eff513ff17d337Chris Lattner  SourceLocation RBracLoc = ConsumeBracket(); // consume ']'
19341d922960e083906a586609ac6978678147250177Sebastian Redl
193529238a0bf7cbf5b396efb451a0adb5fe4aa037caSteve Naroff  unsigned nKeys = KeyIdents.size();
1936ff38491c18b060526d754765b952f4a497a89416Chris Lattner  if (nKeys == 0)
1937ff38491c18b060526d754765b952f4a497a89416Chris Lattner    KeyIdents.push_back(selIdent);
1938ff38491c18b060526d754765b952f4a497a89416Chris Lattner  Selector Sel = PP.getSelectorTable().getSelector(nKeys, &KeyIdents[0]);
19391d922960e083906a586609ac6978678147250177Sebastian Redl
19402725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor  if (SuperLoc.isValid())
19412725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor    return Actions.ActOnSuperMessage(CurScope, SuperLoc, Sel,
19422725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor                                     LBracLoc, SelectorLoc, RBracLoc,
19432725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor                                     Action::MultiExprArg(Actions,
19442725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor                                                          KeyExprs.take(),
19452725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor                                                          KeyExprs.size()));
19462725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor  else if (ReceiverType)
19472725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor    return Actions.ActOnClassMessage(CurScope, ReceiverType, Sel,
19482725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor                                     LBracLoc, SelectorLoc, RBracLoc,
19492725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor                                     Action::MultiExprArg(Actions,
19502725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor                                                          KeyExprs.take(),
19512725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor                                                          KeyExprs.size()));
19522725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor  return Actions.ActOnInstanceMessage(CurScope, move(ReceiverExpr), Sel,
19532725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor                                      LBracLoc, SelectorLoc, RBracLoc,
19542725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor                                      Action::MultiExprArg(Actions,
19552725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor                                                           KeyExprs.take(),
19562725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor                                                           KeyExprs.size()));
19570ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian}
19580ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian
19591d922960e083906a586609ac6978678147250177Sebastian RedlParser::OwningExprResult Parser::ParseObjCStringLiteral(SourceLocation AtLoc) {
196020df9b7ab9388b2a488c5b1293cd196b1e073b4eSebastian Redl  OwningExprResult Res(ParseStringLiteralExpression());
19611d922960e083906a586609ac6978678147250177Sebastian Redl  if (Res.isInvalid()) return move(Res);
19621d922960e083906a586609ac6978678147250177Sebastian Redl
1963b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner  // @"foo" @"bar" is a valid concatenated string.  Eat any subsequent string
1964b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner  // expressions.  At this point, we know that the only valid thing that starts
1965b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner  // with '@' is an @"".
1966b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner  llvm::SmallVector<SourceLocation, 4> AtLocs;
1967a55e52c0802cae3b7c366a05c461d3d15074c1a3Sebastian Redl  ExprVector AtStrings(Actions);
1968b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner  AtLocs.push_back(AtLoc);
1969effa8d1c97b00a3f53e972b0e61d9aade5ea1c57Sebastian Redl  AtStrings.push_back(Res.release());
19700e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl
1971b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner  while (Tok.is(tok::at)) {
1972b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner    AtLocs.push_back(ConsumeToken()); // eat the @.
1973b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner
197415faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl    // Invalid unless there is a string literal.
197597cf6eb380016db868866faf27a086cd55a316d4Chris Lattner    if (!isTokenStringLiteral())
197697cf6eb380016db868866faf27a086cd55a316d4Chris Lattner      return ExprError(Diag(Tok, diag::err_objc_concat_string));
1977b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner
197897cf6eb380016db868866faf27a086cd55a316d4Chris Lattner    OwningExprResult Lit(ParseStringLiteralExpression());
19790e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl    if (Lit.isInvalid())
19801d922960e083906a586609ac6978678147250177Sebastian Redl      return move(Lit);
19810e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl
1982effa8d1c97b00a3f53e972b0e61d9aade5ea1c57Sebastian Redl    AtStrings.push_back(Lit.release());
1983b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner  }
19841d922960e083906a586609ac6978678147250177Sebastian Redl
19851d922960e083906a586609ac6978678147250177Sebastian Redl  return Owned(Actions.ParseObjCStringLiteral(&AtLocs[0], AtStrings.take(),
19861d922960e083906a586609ac6978678147250177Sebastian Redl                                              AtStrings.size()));
19875508518a2702b00be3b15a26d772bde968972f54Anders Carlsson}
1988f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson
1989f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson///    objc-encode-expression:
1990f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson///      @encode ( type-name )
19911d922960e083906a586609ac6978678147250177Sebastian RedlParser::OwningExprResult
19921d922960e083906a586609ac6978678147250177Sebastian RedlParser::ParseObjCEncodeExpression(SourceLocation AtLoc) {
1993861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff  assert(Tok.isObjCAtKeyword(tok::objc_encode) && "Not an @encode expression!");
19941d922960e083906a586609ac6978678147250177Sebastian Redl
1995f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson  SourceLocation EncLoc = ConsumeToken();
19961d922960e083906a586609ac6978678147250177Sebastian Redl
19974fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner  if (Tok.isNot(tok::l_paren))
19981d922960e083906a586609ac6978678147250177Sebastian Redl    return ExprError(Diag(Tok, diag::err_expected_lparen_after) << "@encode");
19991d922960e083906a586609ac6978678147250177Sebastian Redl
2000f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson  SourceLocation LParenLoc = ConsumeParen();
20011d922960e083906a586609ac6978678147250177Sebastian Redl
2002809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor  TypeResult Ty = ParseTypeName();
20031d922960e083906a586609ac6978678147250177Sebastian Redl
20044988ae3fda10743c8ed8a98cdcb5a783362587b4Anders Carlsson  SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc);
20051d922960e083906a586609ac6978678147250177Sebastian Redl
2006809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor  if (Ty.isInvalid())
2007809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor    return ExprError();
2008809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor
20091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return Owned(Actions.ParseObjCEncodeExpression(AtLoc, EncLoc, LParenLoc,
2010809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor                                                 Ty.get(), RParenLoc));
2011f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson}
201229b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson
201329b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson///     objc-protocol-expression
201429b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson///       @protocol ( protocol-name )
20151d922960e083906a586609ac6978678147250177Sebastian RedlParser::OwningExprResult
20161d922960e083906a586609ac6978678147250177Sebastian RedlParser::ParseObjCProtocolExpression(SourceLocation AtLoc) {
201729b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson  SourceLocation ProtoLoc = ConsumeToken();
20181d922960e083906a586609ac6978678147250177Sebastian Redl
20194fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner  if (Tok.isNot(tok::l_paren))
20201d922960e083906a586609ac6978678147250177Sebastian Redl    return ExprError(Diag(Tok, diag::err_expected_lparen_after) << "@protocol");
20211d922960e083906a586609ac6978678147250177Sebastian Redl
202229b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson  SourceLocation LParenLoc = ConsumeParen();
20231d922960e083906a586609ac6978678147250177Sebastian Redl
20244fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner  if (Tok.isNot(tok::identifier))
20251d922960e083906a586609ac6978678147250177Sebastian Redl    return ExprError(Diag(Tok, diag::err_expected_ident));
20261d922960e083906a586609ac6978678147250177Sebastian Redl
2027390d50a725497e99247dc104a7d2c2a255d3af14Fariborz Jahanian  IdentifierInfo *protocolId = Tok.getIdentifierInfo();
202829b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson  ConsumeToken();
20291d922960e083906a586609ac6978678147250177Sebastian Redl
20304988ae3fda10743c8ed8a98cdcb5a783362587b4Anders Carlsson  SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc);
203129b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson
20321d922960e083906a586609ac6978678147250177Sebastian Redl  return Owned(Actions.ParseObjCProtocolExpression(protocolId, AtLoc, ProtoLoc,
20331d922960e083906a586609ac6978678147250177Sebastian Redl                                                   LParenLoc, RParenLoc));
203429b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson}
2035a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian
2036a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian///     objc-selector-expression
2037a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian///       @selector '(' objc-keyword-selector ')'
20381d922960e083906a586609ac6978678147250177Sebastian RedlParser::OwningExprResult
20391d922960e083906a586609ac6978678147250177Sebastian RedlParser::ParseObjCSelectorExpression(SourceLocation AtLoc) {
2040a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian  SourceLocation SelectorLoc = ConsumeToken();
20411d922960e083906a586609ac6978678147250177Sebastian Redl
20424fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner  if (Tok.isNot(tok::l_paren))
20431d922960e083906a586609ac6978678147250177Sebastian Redl    return ExprError(Diag(Tok, diag::err_expected_lparen_after) << "@selector");
20441d922960e083906a586609ac6978678147250177Sebastian Redl
2045b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian  llvm::SmallVector<IdentifierInfo *, 12> KeyIdents;
2046a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian  SourceLocation LParenLoc = ConsumeParen();
2047a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian  SourceLocation sLoc;
20482fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner  IdentifierInfo *SelIdent = ParseObjCSelectorPiece(sLoc);
20491d922960e083906a586609ac6978678147250177Sebastian Redl  if (!SelIdent && Tok.isNot(tok::colon)) // missing selector name.
20501d922960e083906a586609ac6978678147250177Sebastian Redl    return ExprError(Diag(Tok, diag::err_expected_ident));
20511d922960e083906a586609ac6978678147250177Sebastian Redl
2052b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian  KeyIdents.push_back(SelIdent);
2053887407e71fd58de452361b77d72970e32b20ebe0Steve Naroff  unsigned nColons = 0;
2054887407e71fd58de452361b77d72970e32b20ebe0Steve Naroff  if (Tok.isNot(tok::r_paren)) {
2055a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian    while (1) {
20564fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner      if (Tok.isNot(tok::colon))
20571d922960e083906a586609ac6978678147250177Sebastian Redl        return ExprError(Diag(Tok, diag::err_expected_colon));
20581d922960e083906a586609ac6978678147250177Sebastian Redl
2059cb53b361bce341c8591333c6997f62e480acc0b4Chris Lattner      nColons++;
2060a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian      ConsumeToken(); // Eat the ':'.
2061a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian      if (Tok.is(tok::r_paren))
2062a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian        break;
2063a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian      // Check for another keyword selector.
2064a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian      SourceLocation Loc;
20652fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner      SelIdent = ParseObjCSelectorPiece(Loc);
2066b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian      KeyIdents.push_back(SelIdent);
2067a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian      if (!SelIdent && Tok.isNot(tok::colon))
2068a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian        break;
2069a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian    }
2070887407e71fd58de452361b77d72970e32b20ebe0Steve Naroff  }
2071a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian  SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc);
2072887407e71fd58de452361b77d72970e32b20ebe0Steve Naroff  Selector Sel = PP.getSelectorTable().getSelector(nColons, &KeyIdents[0]);
20731d922960e083906a586609ac6978678147250177Sebastian Redl  return Owned(Actions.ParseObjCSelectorExpression(Sel, AtLoc, SelectorLoc,
20741d922960e083906a586609ac6978678147250177Sebastian Redl                                                   LParenLoc, RParenLoc));
207558065b2d8038a4e9a91ea4813bd1774c0f6efacbGabor Greif }
2076