ParseObjc.cpp revision 29d9c1adfadf65e2d847d44bec37746844b9e0e3
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
33861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff  switch (Tok.getObjCKeywordID()) {
345ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner  case tok::objc_class:
355ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner    return ParseObjCAtClassDeclaration(AtLoc);
365ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner  case tok::objc_interface:
375ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner    return ParseObjCAtInterfaceDeclaration(AtLoc);
385ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner  case tok::objc_protocol:
395ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner    return ParseObjCAtProtocolDeclaration(AtLoc);
405ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner  case tok::objc_implementation:
415ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner    return ParseObjCAtImplementationDeclaration(AtLoc);
425ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner  case tok::objc_end:
435ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner    return ParseObjCAtEndDeclaration(AtLoc);
445ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner  case tok::objc_compatibility_alias:
455ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner    return ParseObjCAtAliasDeclaration(AtLoc);
465ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner  case tok::objc_synthesize:
475ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner    return ParseObjCPropertySynthesize(AtLoc);
485ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner  case tok::objc_dynamic:
495ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner    return ParseObjCPropertyDynamic(AtLoc);
505ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner  default:
515ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner    Diag(AtLoc, diag::err_unexpected_at);
525ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner    SkipUntil(tok::semi);
53b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner    return DeclPtrTy();
545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// objc-class-declaration:
595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///    '@' 'class' identifier-list ';'
601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///
61b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris LattnerParser::DeclPtrTy Parser::ParseObjCAtClassDeclaration(SourceLocation atLoc) {
625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ConsumeToken(); // the identifier "class"
635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  llvm::SmallVector<IdentifierInfo *, 8> ClassNames;
64c09cba67d0ad01e53e0fed07322e95dd281bcfd9Ted Kremenek  llvm::SmallVector<SourceLocation, 8> ClassLocs;
65c09cba67d0ad01e53e0fed07322e95dd281bcfd9Ted Kremenek
661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  while (1) {
68df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner    if (Tok.isNot(tok::identifier)) {
695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      Diag(Tok, diag::err_expected_ident);
705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      SkipUntil(tok::semi);
71b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner      return DeclPtrTy();
725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    }
735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ClassNames.push_back(Tok.getIdentifierInfo());
74c09cba67d0ad01e53e0fed07322e95dd281bcfd9Ted Kremenek    ClassLocs.push_back(Tok.getLocation());
755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ConsumeToken();
761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
77df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner    if (Tok.isNot(tok::comma))
785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      break;
791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ConsumeToken();
815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // Consume the ';'.
845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  if (ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@class"))
85b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner    return DeclPtrTy();
861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
87c09cba67d0ad01e53e0fed07322e95dd281bcfd9Ted Kremenek  return Actions.ActOnForwardClassDeclaration(atLoc, ClassNames.data(),
88c09cba67d0ad01e53e0fed07322e95dd281bcfd9Ted Kremenek                                              ClassLocs.data(),
89c09cba67d0ad01e53e0fed07322e95dd281bcfd9Ted Kremenek                                              ClassNames.size());
905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
92dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///
93dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///   objc-interface:
94dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     objc-class-interface-attributes[opt] objc-class-interface
95dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     objc-category-interface
96dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///
97dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///   objc-class-interface:
981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///     '@' 'interface' identifier objc-superclass[opt]
99dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///       objc-protocol-refs[opt]
1001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///       objc-class-instance-variables[opt]
101dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///       objc-interface-decl-list
102dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     @end
103dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///
104dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///   objc-category-interface:
1051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///     '@' 'interface' identifier '(' identifier[opt] ')'
106dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///       objc-protocol-refs[opt]
107dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///       objc-interface-decl-list
108dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     @end
109dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///
110dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///   objc-superclass:
111dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     ':' identifier
112dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///
113dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///   objc-class-interface-attributes:
114dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     __attribute__((visibility("default")))
115dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     __attribute__((visibility("hidden")))
116dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     __attribute__((deprecated))
117dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     __attribute__((unavailable))
118dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     __attribute__((objc_exception)) - used by NSException on 64-bit
119dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///
120b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris LattnerParser::DeclPtrTy Parser::ParseObjCAtInterfaceDeclaration(
121dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff  SourceLocation atLoc, AttributeList *attrList) {
122861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff  assert(Tok.isObjCAtKeyword(tok::objc_interface) &&
123dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff         "ParseObjCAtInterfaceDeclaration(): Expected @interface");
124dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff  ConsumeToken(); // the "interface" identifier
1251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1263b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor  // Code completion after '@interface'.
1273b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor  if (Tok.is(tok::code_completion)) {
1283b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor    Actions.CodeCompleteObjCInterfaceDecl(CurScope);
1293b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor    ConsumeToken();
1303b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor  }
1313b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor
132df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  if (Tok.isNot(tok::identifier)) {
133dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff    Diag(Tok, diag::err_expected_ident); // missing class or category name.
134b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner    return DeclPtrTy();
135dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff  }
13663e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian
137dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff  // We have a class or category name - consume it.
1387ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff  IdentifierInfo *nameId = Tok.getIdentifierInfo();
139dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff  SourceLocation nameLoc = ConsumeToken();
1401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
141df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  if (Tok.is(tok::l_paren)) { // we have a category.
142dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff    SourceLocation lparenLoc = ConsumeParen();
143dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff    SourceLocation categoryLoc, rparenLoc;
144dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff    IdentifierInfo *categoryId = 0;
1451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14633ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor    if (Tok.is(tok::code_completion)) {
14733ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor      Actions.CodeCompleteObjCInterfaceCategory(CurScope, nameId);
14833ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor      ConsumeToken();
14933ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor    }
15033ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor
151527fe23f8cbc6a4da1737a547a2517bc92fa88c8Steve Naroff    // For ObjC2, the category name is optional (not an error).
152df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner    if (Tok.is(tok::identifier)) {
153dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff      categoryId = Tok.getIdentifierInfo();
154dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff      categoryLoc = ConsumeToken();
155527fe23f8cbc6a4da1737a547a2517bc92fa88c8Steve Naroff    } else if (!getLang().ObjC2) {
156527fe23f8cbc6a4da1737a547a2517bc92fa88c8Steve Naroff      Diag(Tok, diag::err_expected_ident); // missing category name.
157b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner      return DeclPtrTy();
158dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff    }
159df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner    if (Tok.isNot(tok::r_paren)) {
160dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff      Diag(Tok, diag::err_expected_rparen);
161dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff      SkipUntil(tok::r_paren, false); // don't stop at ';'
162b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner      return DeclPtrTy();
163dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff    }
164dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff    rparenLoc = ConsumeParen();
1651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
166dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff    // Next, we need to check for any protocol references.
16771b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis    SourceLocation LAngleLoc, EndProtoLoc;
168b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner    llvm::SmallVector<DeclPtrTy, 8> ProtocolRefs;
16971b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis    llvm::SmallVector<SourceLocation, 8> ProtocolLocs;
1706bd6d0b9d8944c5e192097bef24f2becb83af172Chris Lattner    if (Tok.is(tok::less) &&
17171b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis        ParseObjCProtocolReferences(ProtocolRefs, ProtocolLocs, true,
17271b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis                                    LAngleLoc, EndProtoLoc))
173b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner      return DeclPtrTy();
1741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
175dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff    if (attrList) // categories don't support attributes.
176dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff      Diag(Tok, diag::err_objc_no_attributes_on_category);
1771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
178beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad    DeclPtrTy CategoryType =
1791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      Actions.ActOnStartCategoryInterface(atLoc,
180beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad                                          nameId, nameLoc,
181beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad                                          categoryId, categoryLoc,
182beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad                                          ProtocolRefs.data(),
183beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad                                          ProtocolRefs.size(),
184beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad                                          EndProtoLoc);
1851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
186fd225cc227143553898f2d3902242d25db9a4902Fariborz Jahanian    ParseObjCInterfaceDeclList(CategoryType, tok::objc_not_keyword);
187bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner    return CategoryType;
188dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff  }
189dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff  // Parse a class interface.
190dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff  IdentifierInfo *superClassId = 0;
191dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff  SourceLocation superClassLoc;
1927ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff
193df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  if (Tok.is(tok::colon)) { // a super class is specified.
194dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff    ConsumeToken();
1953b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor
1963b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor    // Code completion of superclass names.
1973b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor    if (Tok.is(tok::code_completion)) {
1983b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor      Actions.CodeCompleteObjCSuperclass(CurScope, nameId);
1993b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor      ConsumeToken();
2003b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor    }
2013b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor
202df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner    if (Tok.isNot(tok::identifier)) {
203dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff      Diag(Tok, diag::err_expected_ident); // missing super class name.
204b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner      return DeclPtrTy();
205dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff    }
206dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff    superClassId = Tok.getIdentifierInfo();
207dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff    superClassLoc = ConsumeToken();
208dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff  }
209dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff  // Next, we need to check for any protocol references.
210b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner  llvm::SmallVector<Action::DeclPtrTy, 8> ProtocolRefs;
21171b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis  llvm::SmallVector<SourceLocation, 8> ProtocolLocs;
21271b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis  SourceLocation LAngleLoc, EndProtoLoc;
21306036d3709955a53297b4cbe14e20db88f321470Chris Lattner  if (Tok.is(tok::less) &&
21471b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis      ParseObjCProtocolReferences(ProtocolRefs, ProtocolLocs, true,
21571b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis                                  LAngleLoc, EndProtoLoc))
216b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner    return DeclPtrTy();
2171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  DeclPtrTy ClsType =
2191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    Actions.ActOnStartClassInterface(atLoc, nameId, nameLoc,
22006036d3709955a53297b4cbe14e20db88f321470Chris Lattner                                     superClassId, superClassLoc,
221beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad                                     ProtocolRefs.data(), ProtocolRefs.size(),
22206036d3709955a53297b4cbe14e20db88f321470Chris Lattner                                     EndProtoLoc, attrList);
2231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
224df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  if (Tok.is(tok::l_brace))
22560fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff    ParseObjCClassInstanceVariables(ClsType, atLoc);
226dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff
22725e077d59a8e8e43b65882b69610a3d5e2aaf53cFariborz Jahanian  ParseObjCInterfaceDeclList(ClsType, tok::objc_interface);
228bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner  return ClsType;
229dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff}
230dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff
231d0014540005f2a5ab837365db6bd40f479406758John McCall/// The Objective-C property callback.  This should be defined where
232d0014540005f2a5ab837365db6bd40f479406758John McCall/// it's used, but instead it's been lifted to here to support VS2005.
233d0014540005f2a5ab837365db6bd40f479406758John McCallstruct Parser::ObjCPropertyCallback : FieldCallback {
234d0014540005f2a5ab837365db6bd40f479406758John McCall  Parser &P;
235d0014540005f2a5ab837365db6bd40f479406758John McCall  DeclPtrTy IDecl;
236d0014540005f2a5ab837365db6bd40f479406758John McCall  llvm::SmallVectorImpl<DeclPtrTy> &Props;
237d0014540005f2a5ab837365db6bd40f479406758John McCall  ObjCDeclSpec &OCDS;
238d0014540005f2a5ab837365db6bd40f479406758John McCall  SourceLocation AtLoc;
239d0014540005f2a5ab837365db6bd40f479406758John McCall  tok::ObjCKeywordKind MethodImplKind;
240d0014540005f2a5ab837365db6bd40f479406758John McCall
241d0014540005f2a5ab837365db6bd40f479406758John McCall  ObjCPropertyCallback(Parser &P, DeclPtrTy IDecl,
242d0014540005f2a5ab837365db6bd40f479406758John McCall                       llvm::SmallVectorImpl<DeclPtrTy> &Props,
243d0014540005f2a5ab837365db6bd40f479406758John McCall                       ObjCDeclSpec &OCDS, SourceLocation AtLoc,
244d0014540005f2a5ab837365db6bd40f479406758John McCall                       tok::ObjCKeywordKind MethodImplKind) :
245d0014540005f2a5ab837365db6bd40f479406758John McCall    P(P), IDecl(IDecl), Props(Props), OCDS(OCDS), AtLoc(AtLoc),
246d0014540005f2a5ab837365db6bd40f479406758John McCall    MethodImplKind(MethodImplKind) {
247d0014540005f2a5ab837365db6bd40f479406758John McCall  }
248d0014540005f2a5ab837365db6bd40f479406758John McCall
249d0014540005f2a5ab837365db6bd40f479406758John McCall  DeclPtrTy invoke(FieldDeclarator &FD) {
250d0014540005f2a5ab837365db6bd40f479406758John McCall    if (FD.D.getIdentifier() == 0) {
251d0014540005f2a5ab837365db6bd40f479406758John McCall      P.Diag(AtLoc, diag::err_objc_property_requires_field_name)
252d0014540005f2a5ab837365db6bd40f479406758John McCall        << FD.D.getSourceRange();
253d0014540005f2a5ab837365db6bd40f479406758John McCall      return DeclPtrTy();
254d0014540005f2a5ab837365db6bd40f479406758John McCall    }
255d0014540005f2a5ab837365db6bd40f479406758John McCall    if (FD.BitfieldSize) {
256d0014540005f2a5ab837365db6bd40f479406758John McCall      P.Diag(AtLoc, diag::err_objc_property_bitfield)
257d0014540005f2a5ab837365db6bd40f479406758John McCall        << FD.D.getSourceRange();
258d0014540005f2a5ab837365db6bd40f479406758John McCall      return DeclPtrTy();
259d0014540005f2a5ab837365db6bd40f479406758John McCall    }
260d0014540005f2a5ab837365db6bd40f479406758John McCall
261d0014540005f2a5ab837365db6bd40f479406758John McCall    // Install the property declarator into interfaceDecl.
262d0014540005f2a5ab837365db6bd40f479406758John McCall    IdentifierInfo *SelName =
263d0014540005f2a5ab837365db6bd40f479406758John McCall      OCDS.getGetterName() ? OCDS.getGetterName() : FD.D.getIdentifier();
264d0014540005f2a5ab837365db6bd40f479406758John McCall
265d0014540005f2a5ab837365db6bd40f479406758John McCall    Selector GetterSel =
266d0014540005f2a5ab837365db6bd40f479406758John McCall      P.PP.getSelectorTable().getNullarySelector(SelName);
267d0014540005f2a5ab837365db6bd40f479406758John McCall    IdentifierInfo *SetterName = OCDS.getSetterName();
268d0014540005f2a5ab837365db6bd40f479406758John McCall    Selector SetterSel;
269d0014540005f2a5ab837365db6bd40f479406758John McCall    if (SetterName)
270d0014540005f2a5ab837365db6bd40f479406758John McCall      SetterSel = P.PP.getSelectorTable().getSelector(1, &SetterName);
271d0014540005f2a5ab837365db6bd40f479406758John McCall    else
272d0014540005f2a5ab837365db6bd40f479406758John McCall      SetterSel = SelectorTable::constructSetterName(P.PP.getIdentifierTable(),
273d0014540005f2a5ab837365db6bd40f479406758John McCall                                                     P.PP.getSelectorTable(),
274d0014540005f2a5ab837365db6bd40f479406758John McCall                                                     FD.D.getIdentifier());
275d0014540005f2a5ab837365db6bd40f479406758John McCall    bool isOverridingProperty = false;
276d0014540005f2a5ab837365db6bd40f479406758John McCall    DeclPtrTy Property =
277d0014540005f2a5ab837365db6bd40f479406758John McCall      P.Actions.ActOnProperty(P.CurScope, AtLoc, FD, OCDS,
278d0014540005f2a5ab837365db6bd40f479406758John McCall                              GetterSel, SetterSel, IDecl,
279d0014540005f2a5ab837365db6bd40f479406758John McCall                              &isOverridingProperty,
280d0014540005f2a5ab837365db6bd40f479406758John McCall                              MethodImplKind);
281d0014540005f2a5ab837365db6bd40f479406758John McCall    if (!isOverridingProperty)
282d0014540005f2a5ab837365db6bd40f479406758John McCall      Props.push_back(Property);
283d0014540005f2a5ab837365db6bd40f479406758John McCall
284d0014540005f2a5ab837365db6bd40f479406758John McCall    return Property;
285d0014540005f2a5ab837365db6bd40f479406758John McCall  }
286d0014540005f2a5ab837365db6bd40f479406758John McCall};
287d0014540005f2a5ab837365db6bd40f479406758John McCall
288dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///   objc-interface-decl-list:
289dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     empty
290dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     objc-interface-decl-list objc-property-decl [OBJC2]
291294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///     objc-interface-decl-list objc-method-requirement [OBJC2]
2923536b443bc50d58a79f14fca9b6842541a434854Steve Naroff///     objc-interface-decl-list objc-method-proto ';'
293dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     objc-interface-decl-list declaration
294dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     objc-interface-decl-list ';'
295dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///
296294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///   objc-method-requirement: [OBJC2]
297294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///     @required
298294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///     @optional
299294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///
300b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattnervoid Parser::ParseObjCInterfaceDeclList(DeclPtrTy interfaceDecl,
301cb53b361bce341c8591333c6997f62e480acc0b4Chris Lattner                                        tok::ObjCKeywordKind contextKey) {
302b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner  llvm::SmallVector<DeclPtrTy, 32> allMethods;
303b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner  llvm::SmallVector<DeclPtrTy, 16> allProperties;
304682bf92db408a6cbc3d37b5496a99b6ef85041ecChris Lattner  llvm::SmallVector<DeclGroupPtrTy, 8> allTUVariables;
30500933591a2795d09dd1acff12a2d21bce7cb12c5Fariborz Jahanian  tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword;
3061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
307bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner  SourceLocation AtEndLoc;
308bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner
309294494e1cce92043562b4680c613df7fd028c02eSteve Naroff  while (1) {
310e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner    // If this is a method prototype, parse it.
311df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner    if (Tok.is(tok::minus) || Tok.is(tok::plus)) {
3121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      DeclPtrTy methodPrototype =
313df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner        ParseObjCMethodPrototype(interfaceDecl, MethodImplKind);
31425e077d59a8e8e43b65882b69610a3d5e2aaf53cFariborz Jahanian      allMethods.push_back(methodPrototype);
3153536b443bc50d58a79f14fca9b6842541a434854Steve Naroff      // Consume the ';' here, since ParseObjCMethodPrototype() is re-used for
3163536b443bc50d58a79f14fca9b6842541a434854Steve Naroff      // method definitions.
317b6d74a158a9c002e3c0fcbda8ad8d0ccbb2e5088Chris Lattner      ExpectAndConsume(tok::semi, diag::err_expected_semi_after_method_proto,
318b6d74a158a9c002e3c0fcbda8ad8d0ccbb2e5088Chris Lattner                       "", tok::semi);
319294494e1cce92043562b4680c613df7fd028c02eSteve Naroff      continue;
320294494e1cce92043562b4680c613df7fd028c02eSteve Naroff    }
3211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
322e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner    // Ignore excess semicolons.
323e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner    if (Tok.is(tok::semi)) {
324294494e1cce92043562b4680c613df7fd028c02eSteve Naroff      ConsumeToken();
325e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner      continue;
326e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner    }
3271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
328bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner    // If we got to the end of the file, exit the loop.
329e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner    if (Tok.is(tok::eof))
330e3a2ca7e30601cdd31c77a830f4cc487851e8096Fariborz Jahanian      break;
3311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
332e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner    // If we don't have an @ directive, parse it as a function definition.
333e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner    if (Tok.isNot(tok::at)) {
3341fd80116b49782c367ff5d5f50a8b76dd8a5d7f7Chris Lattner      // The code below does not consume '}'s because it is afraid of eating the
3351fd80116b49782c367ff5d5f50a8b76dd8a5d7f7Chris Lattner      // end of a namespace.  Because of the way this code is structured, an
3361fd80116b49782c367ff5d5f50a8b76dd8a5d7f7Chris Lattner      // erroneous r_brace would cause an infinite loop if not handled here.
3371fd80116b49782c367ff5d5f50a8b76dd8a5d7f7Chris Lattner      if (Tok.is(tok::r_brace))
3381fd80116b49782c367ff5d5f50a8b76dd8a5d7f7Chris Lattner        break;
3391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3404985aceceb9b9261b876b515d32726175c13a775Steve Naroff      // FIXME: as the name implies, this rule allows function definitions.
3414985aceceb9b9261b876b515d32726175c13a775Steve Naroff      // We could pass a flag or check for functions during semantic analysis.
342bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt      allTUVariables.push_back(ParseDeclarationOrFunctionDefinition(0));
343e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner      continue;
344e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner    }
3451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
346e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner    // Otherwise, we have an @ directive, eat the @.
347e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner    SourceLocation AtLoc = ConsumeToken(); // the "@"
348a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner    tok::ObjCKeywordKind DirectiveKind = Tok.getObjCKeywordID();
3491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
350a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner    if (DirectiveKind == tok::objc_end) { // @end -> terminate list
351e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner      AtEndLoc = AtLoc;
352e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner      break;
353bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner    }
3541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
355bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner    // Eat the identifier.
356bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner    ConsumeToken();
357bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner
358a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner    switch (DirectiveKind) {
359a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner    default:
360bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner      // FIXME: If someone forgets an @end on a protocol, this loop will
361bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner      // continue to eat up tons of stuff and spew lots of nonsense errors.  It
362bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner      // would probably be better to bail out if we saw an @class or @interface
363bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner      // or something like that.
364f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner      Diag(AtLoc, diag::err_objc_illegal_interface_qual);
365bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner      // Skip until we see an '@' or '}' or ';'.
366a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner      SkipUntil(tok::r_brace, tok::at);
367a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner      break;
3681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
369a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner    case tok::objc_required:
370a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner    case tok::objc_optional:
371a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner      // This is only valid on protocols.
372bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner      // FIXME: Should this check for ObjC2 being enabled?
373e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner      if (contextKey != tok::objc_protocol)
374bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner        Diag(AtLoc, diag::err_objc_directive_only_in_protocol);
375a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner      else
376bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner        MethodImplKind = DirectiveKind;
377a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner      break;
3781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
379a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner    case tok::objc_property:
380f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner      if (!getLang().ObjC2)
381f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner        Diag(AtLoc, diag::err_objc_propertoes_require_objc2);
382f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner
383e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner      ObjCDeclSpec OCDS;
3841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      // Parse property attribute list, if any.
3858ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner      if (Tok.is(tok::l_paren))
3864ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor        ParseObjCPropertyAttribute(OCDS, interfaceDecl,
3874ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor                                   allMethods.data(), allMethods.size());
3881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
389d0014540005f2a5ab837365db6bd40f479406758John McCall      ObjCPropertyCallback Callback(*this, interfaceDecl, allProperties,
390d0014540005f2a5ab837365db6bd40f479406758John McCall                                    OCDS, AtLoc, MethodImplKind);
391bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall
392e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner      // Parse all the comma separated declarators.
393e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner      DeclSpec DS;
394bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall      ParseStructDeclaration(DS, Callback);
3951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
396a1fed7e3beebf9bb1bc85123f283be3eb631c120Chris Lattner      ExpectAndConsume(tok::semi, diag::err_expected_semi_decl_list, "",
397a1fed7e3beebf9bb1bc85123f283be3eb631c120Chris Lattner                       tok::at);
398a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner      break;
399f28b264437053fb0deacc9ba02b18a0966f7290aSteve Naroff    }
400294494e1cce92043562b4680c613df7fd028c02eSteve Naroff  }
401bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner
402bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner  // We break out of the big loop in two cases: when we see @end or when we see
403bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner  // EOF.  In the former case, eat the @end.  In the later case, emit an error.
404bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner  if (Tok.isObjCAtKeyword(tok::objc_end))
405bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner    ConsumeToken(); // the "end" identifier
406bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner  else
407bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner    Diag(Tok, diag::err_objc_missing_end);
4081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
409a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner  // Insert collected methods declarations into the @interface object.
410bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner  // This passes in an invalid SourceLocation for AtEndLoc when EOF is hit.
4118a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek  Actions.ActOnAtEnd(AtEndLoc, interfaceDecl,
4121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                     allMethods.data(), allMethods.size(),
413beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad                     allProperties.data(), allProperties.size(),
414beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad                     allTUVariables.data(), allTUVariables.size());
415294494e1cce92043562b4680c613df7fd028c02eSteve Naroff}
416294494e1cce92043562b4680c613df7fd028c02eSteve Naroff
417d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian///   Parse property attribute declarations.
418d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian///
419d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian///   property-attr-decl: '(' property-attrlist ')'
420d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian///   property-attrlist:
421d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian///     property-attribute
422d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian///     property-attrlist ',' property-attribute
423d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian///   property-attribute:
424d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian///     getter '=' identifier
425d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian///     setter '=' identifier ':'
426d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian///     readonly
427d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian///     readwrite
428d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian///     assign
429d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian///     retain
430d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian///     copy
431d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian///     nonatomic
432d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian///
4334ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregorvoid Parser::ParseObjCPropertyAttribute(ObjCDeclSpec &DS, DeclPtrTy ClassDecl,
4344ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor                                        DeclPtrTy *Methods,
4354ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor                                        unsigned NumMethods) {
4368ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner  assert(Tok.getKind() == tok::l_paren);
437dd5b5f2bb73d037745940431b71eb98393d12d4fChris Lattner  SourceLocation LHSLoc = ConsumeParen(); // consume '('
4381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
439cd9f4b31c4fe5b77b5519cc17b4583fab912bad1Chris Lattner  while (1) {
440ece8e71d12b6f4cb2dc501297afef126dab8ad74Steve Naroff    if (Tok.is(tok::code_completion)) {
441a93b108e025ef2480fa867cc533e7781a40a639bDouglas Gregor      Actions.CodeCompleteObjCPropertyFlags(CurScope, DS);
442ece8e71d12b6f4cb2dc501297afef126dab8ad74Steve Naroff      ConsumeToken();
443ece8e71d12b6f4cb2dc501297afef126dab8ad74Steve Naroff    }
444d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian    const IdentifierInfo *II = Tok.getIdentifierInfo();
4451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
446f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner    // If this is not an identifier at all, bail out early.
447f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner    if (II == 0) {
448f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner      MatchRHSPunctuation(tok::r_paren, LHSLoc);
449f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner      return;
450f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner    }
4511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
452156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner    SourceLocation AttrName = ConsumeToken(); // consume last attribute name
4531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
45492e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner    if (II->isStr("readonly"))
455e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner      DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_readonly);
45692e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner    else if (II->isStr("assign"))
457e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner      DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_assign);
45892e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner    else if (II->isStr("readwrite"))
459e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner      DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_readwrite);
46092e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner    else if (II->isStr("retain"))
461e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner      DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_retain);
46292e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner    else if (II->isStr("copy"))
463e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner      DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_copy);
46492e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner    else if (II->isStr("nonatomic"))
465e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner      DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_nonatomic);
46692e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner    else if (II->isStr("getter") || II->isStr("setter")) {
467e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner      // getter/setter require extra treatment.
468156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner      if (ExpectAndConsume(tok::equal, diag::err_objc_expected_equal, "",
469156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner                           tok::r_paren))
470dd5b5f2bb73d037745940431b71eb98393d12d4fChris Lattner        return;
4711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4724ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor      if (Tok.is(tok::code_completion)) {
4734ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor        if (II->getNameStart()[0] == 's')
4744ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor          Actions.CodeCompleteObjCPropertySetter(CurScope, ClassDecl,
4754ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor                                                 Methods, NumMethods);
4764ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor        else
4774ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor          Actions.CodeCompleteObjCPropertyGetter(CurScope, ClassDecl,
4784ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor                                                 Methods, NumMethods);
4794ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor        ConsumeToken();
4804ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor      }
4814ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor
4828ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner      if (Tok.isNot(tok::identifier)) {
4831ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner        Diag(Tok, diag::err_expected_ident);
4848ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner        SkipUntil(tok::r_paren);
4858ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner        return;
4868ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner      }
4871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
488e013d685c6689ac7ae103ee88acf573422d1ed6aDaniel Dunbar      if (II->getNameStart()[0] == 's') {
4898ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner        DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_setter);
4908ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner        DS.setSetterName(Tok.getIdentifierInfo());
491156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner        ConsumeToken();  // consume method name
4921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
493156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner        if (ExpectAndConsume(tok::colon, diag::err_expected_colon, "",
494156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner                             tok::r_paren))
4958ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner          return;
4968ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner      } else {
4978ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner        DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_getter);
4988ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner        DS.setGetterName(Tok.getIdentifierInfo());
499156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner        ConsumeToken();  // consume method name
5008ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner      }
501e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner    } else {
502a9500f05ba6c09bbd84d342236863833067cd816Chris Lattner      Diag(AttrName, diag::err_objc_expected_property_attr) << II;
503cd9f4b31c4fe5b77b5519cc17b4583fab912bad1Chris Lattner      SkipUntil(tok::r_paren);
504cd9f4b31c4fe5b77b5519cc17b4583fab912bad1Chris Lattner      return;
505cd9f4b31c4fe5b77b5519cc17b4583fab912bad1Chris Lattner    }
5061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
507156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner    if (Tok.isNot(tok::comma))
508156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner      break;
5091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
510156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner    ConsumeToken();
511d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian  }
5121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
513156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner  MatchRHSPunctuation(tok::r_paren, LHSLoc);
514d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian}
515d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian
5163536b443bc50d58a79f14fca9b6842541a434854Steve Naroff///   objc-method-proto:
5171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///     objc-instance-method objc-method-decl objc-method-attributes[opt]
5183536b443bc50d58a79f14fca9b6842541a434854Steve Naroff///     objc-class-method objc-method-decl objc-method-attributes[opt]
519294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///
520294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///   objc-instance-method: '-'
521294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///   objc-class-method: '+'
522294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///
5234985aceceb9b9261b876b515d32726175c13a775Steve Naroff///   objc-method-attributes:         [OBJC2]
5244985aceceb9b9261b876b515d32726175c13a775Steve Naroff///     __attribute__((deprecated))
5254985aceceb9b9261b876b515d32726175c13a775Steve Naroff///
5261eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpParser::DeclPtrTy Parser::ParseObjCMethodPrototype(DeclPtrTy IDecl,
527b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner                                          tok::ObjCKeywordKind MethodImplKind) {
528df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  assert((Tok.is(tok::minus) || Tok.is(tok::plus)) && "expected +/-");
529294494e1cce92043562b4680c613df7fd028c02eSteve Naroff
5301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  tok::TokenKind methodType = Tok.getKind();
531bef1185418705e16012b3dd50cd7c260c8d6b79cSteve Naroff  SourceLocation mLoc = ConsumeToken();
5321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
533b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner  DeclPtrTy MDecl = ParseObjCMethodDecl(mLoc, methodType, IDecl,MethodImplKind);
5343536b443bc50d58a79f14fca9b6842541a434854Steve Naroff  // Since this rule is used for both method declarations and definitions,
5352bd42fadafddc8acf744b57a970bdc96a077c617Steve Naroff  // the caller is (optionally) responsible for consuming the ';'.
536f28b264437053fb0deacc9ba02b18a0966f7290aSteve Naroff  return MDecl;
537294494e1cce92043562b4680c613df7fd028c02eSteve Naroff}
538294494e1cce92043562b4680c613df7fd028c02eSteve Naroff
539294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///   objc-selector:
540294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///     identifier
541294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///     one of
542294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///       enum struct union if else while do for switch case default
543294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///       break continue return goto asm sizeof typeof __alignof
544294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///       unsigned long const short volatile signed restrict _Complex
545294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///       in out inout bycopy byref oneway int char float double void _Bool
546294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///
5472fc5c2428ecb450a3256c8316b93b8655cb76a0fChris LattnerIdentifierInfo *Parser::ParseObjCSelectorPiece(SourceLocation &SelectorLoc) {
548ff38491c18b060526d754765b952f4a497a89416Chris Lattner  switch (Tok.getKind()) {
549ff38491c18b060526d754765b952f4a497a89416Chris Lattner  default:
550ff38491c18b060526d754765b952f4a497a89416Chris Lattner    return 0;
551ff38491c18b060526d754765b952f4a497a89416Chris Lattner  case tok::identifier:
552ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_asm:
553ff38491c18b060526d754765b952f4a497a89416Chris Lattner  case tok::kw_auto:
5549298d9655aed28b2d9f6cc65c81401b209f03fdcChris Lattner  case tok::kw_bool:
555ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_break:
556ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_case:
557ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_catch:
558ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_char:
559ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_class:
560ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_const:
561ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_const_cast:
562ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_continue:
563ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_default:
564ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_delete:
565ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_do:
566ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_double:
567ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_dynamic_cast:
568ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_else:
569ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_enum:
570ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_explicit:
571ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_export:
572ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_extern:
573ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_false:
574ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_float:
575ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_for:
576ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_friend:
577ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_goto:
578ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_if:
579ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_inline:
580ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_int:
581ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_long:
582ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_mutable:
583ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_namespace:
584ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_new:
585ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_operator:
586ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_private:
587ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_protected:
588ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_public:
589ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_register:
590ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_reinterpret_cast:
591ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_restrict:
592ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_return:
593ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_short:
594ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_signed:
595ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_sizeof:
596ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_static:
597ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_static_cast:
598ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_struct:
599ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_switch:
600ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_template:
601ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_this:
602ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_throw:
603ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_true:
604ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_try:
605ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_typedef:
606ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_typeid:
607ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_typename:
608ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_typeof:
609ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_union:
610ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_unsigned:
611ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_using:
612ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_virtual:
613ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_void:
614ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_volatile:
615ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_wchar_t:
616ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_while:
617ff38491c18b060526d754765b952f4a497a89416Chris Lattner  case tok::kw__Bool:
618ff38491c18b060526d754765b952f4a497a89416Chris Lattner  case tok::kw__Complex:
619ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw___alignof:
620ff38491c18b060526d754765b952f4a497a89416Chris Lattner    IdentifierInfo *II = Tok.getIdentifierInfo();
6214b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian    SelectorLoc = ConsumeToken();
622ff38491c18b060526d754765b952f4a497a89416Chris Lattner    return II;
623d064951b0dcc95f8604d0d69ae82d9ecbd38c796Fariborz Jahanian  }
624294494e1cce92043562b4680c613df7fd028c02eSteve Naroff}
625294494e1cce92043562b4680c613df7fd028c02eSteve Naroff
6260196cab54007ff072ec2642da8911c6b7e8d3fb5Fariborz Jahanian///  objc-for-collection-in: 'in'
6270196cab54007ff072ec2642da8911c6b7e8d3fb5Fariborz Jahanian///
628335a2d4122e41343fe11a775889b8bec5b14be60Fariborz Jahanianbool Parser::isTokIdentifier_in() const {
6293ba5a0f90a03d5e13d02cbee9abd2a1ba01b18bcFariborz Jahanian  // FIXME: May have to do additional look-ahead to only allow for
6303ba5a0f90a03d5e13d02cbee9abd2a1ba01b18bcFariborz Jahanian  // valid tokens following an 'in'; such as an identifier, unary operators,
6313ba5a0f90a03d5e13d02cbee9abd2a1ba01b18bcFariborz Jahanian  // '[' etc.
6321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return (getLang().ObjC2 && Tok.is(tok::identifier) &&
6335ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner          Tok.getIdentifierInfo() == ObjCTypeQuals[objc_in]);
6340196cab54007ff072ec2642da8911c6b7e8d3fb5Fariborz Jahanian}
6350196cab54007ff072ec2642da8911c6b7e8d3fb5Fariborz Jahanian
636a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ParseObjCTypeQualifierList - This routine parses the objective-c's type
637e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner/// qualifier list and builds their bitmask representation in the input
638e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner/// argument.
639294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///
640294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///   objc-type-qualifiers:
641294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///     objc-type-qualifier
642294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///     objc-type-qualifiers objc-type-qualifier
643294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///
644a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekvoid Parser::ParseObjCTypeQualifierList(ObjCDeclSpec &DS) {
645e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner  while (1) {
646cb53b361bce341c8591333c6997f62e480acc0b4Chris Lattner    if (Tok.isNot(tok::identifier))
647e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner      return;
6481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
649e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner    const IdentifierInfo *II = Tok.getIdentifierInfo();
650e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner    for (unsigned i = 0; i != objc_NumQuals; ++i) {
651a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek      if (II != ObjCTypeQuals[i])
652e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner        continue;
6531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
654a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek      ObjCDeclSpec::ObjCDeclQualifier Qual;
655e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner      switch (i) {
656e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner      default: assert(0 && "Unknown decl qualifier");
657a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek      case objc_in:     Qual = ObjCDeclSpec::DQ_In; break;
658a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek      case objc_out:    Qual = ObjCDeclSpec::DQ_Out; break;
659a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek      case objc_inout:  Qual = ObjCDeclSpec::DQ_Inout; break;
660a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek      case objc_oneway: Qual = ObjCDeclSpec::DQ_Oneway; break;
661a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek      case objc_bycopy: Qual = ObjCDeclSpec::DQ_Bycopy; break;
662a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek      case objc_byref:  Qual = ObjCDeclSpec::DQ_Byref; break;
663e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner      }
664a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek      DS.setObjCDeclQualifier(Qual);
665e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner      ConsumeToken();
666e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner      II = 0;
667e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner      break;
668e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner    }
6691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
670e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner    // If this wasn't a recognized qualifier, bail out.
671e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner    if (II) return;
672e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner  }
673e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner}
674e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner
675e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner///   objc-type-name:
676e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner///     '(' objc-type-qualifiers[opt] type-name ')'
677e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner///     '(' objc-type-qualifiers[opt] ')'
678e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner///
679a526c5c67e5a0473c340903ee542ce570119665fTed KremenekParser::TypeTy *Parser::ParseObjCTypeName(ObjCDeclSpec &DS) {
680df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  assert(Tok.is(tok::l_paren) && "expected (");
6811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6824a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner  SourceLocation LParenLoc = ConsumeParen();
683e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner  SourceLocation TypeStartLoc = Tok.getLocation();
6841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
68519d74e1494fe399f0e2a94e9419c095f8214851bFariborz Jahanian  // Parse type qualifiers, in, inout, etc.
686a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ParseObjCTypeQualifierList(DS);
6874fa7afd07421e7276d1717e4fdf43a5fdd65a622Steve Naroff
6884a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner  TypeTy *Ty = 0;
689809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor  if (isTypeSpecifierQualifier()) {
690809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor    TypeResult TypeSpec = ParseTypeName();
691809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor    if (!TypeSpec.isInvalid())
692809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor      Ty = TypeSpec.get();
693809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor  }
6941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6954a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner  if (Tok.is(tok::r_paren))
6964a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner    ConsumeParen();
6974a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner  else if (Tok.getLocation() == TypeStartLoc) {
698e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner    // If we didn't eat any tokens, then this isn't a type.
6991ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner    Diag(Tok, diag::err_expected_type);
7004a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner    SkipUntil(tok::r_paren);
7014a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner  } else {
7024a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner    // Otherwise, we found *something*, but didn't get a ')' in the right
7034a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner    // place.  Emit an error then return what we have as the type.
7044a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner    MatchRHSPunctuation(tok::r_paren, LParenLoc);
705294494e1cce92043562b4680c613df7fd028c02eSteve Naroff  }
706f28b264437053fb0deacc9ba02b18a0966f7290aSteve Naroff  return Ty;
707294494e1cce92043562b4680c613df7fd028c02eSteve Naroff}
708294494e1cce92043562b4680c613df7fd028c02eSteve Naroff
709294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///   objc-method-decl:
710294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///     objc-selector
7114985aceceb9b9261b876b515d32726175c13a775Steve Naroff///     objc-keyword-selector objc-parmlist[opt]
712294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///     objc-type-name objc-selector
7134985aceceb9b9261b876b515d32726175c13a775Steve Naroff///     objc-type-name objc-keyword-selector objc-parmlist[opt]
714294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///
715294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///   objc-keyword-selector:
7161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///     objc-keyword-decl
717294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///     objc-keyword-selector objc-keyword-decl
718294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///
719294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///   objc-keyword-decl:
7207ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff///     objc-selector ':' objc-type-name objc-keyword-attributes[opt] identifier
7217ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff///     objc-selector ':' objc-keyword-attributes[opt] identifier
7227ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff///     ':' objc-type-name objc-keyword-attributes[opt] identifier
7237ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff///     ':' objc-keyword-attributes[opt] identifier
724294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///
7254985aceceb9b9261b876b515d32726175c13a775Steve Naroff///   objc-parmlist:
7264985aceceb9b9261b876b515d32726175c13a775Steve Naroff///     objc-parms objc-ellipsis[opt]
727294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///
7284985aceceb9b9261b876b515d32726175c13a775Steve Naroff///   objc-parms:
7294985aceceb9b9261b876b515d32726175c13a775Steve Naroff///     objc-parms , parameter-declaration
730294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///
7314985aceceb9b9261b876b515d32726175c13a775Steve Naroff///   objc-ellipsis:
732294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///     , ...
733294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///
7347ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff///   objc-keyword-attributes:         [OBJC2]
7357ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff///     __attribute__((unused))
7367ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff///
737b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris LattnerParser::DeclPtrTy Parser::ParseObjCMethodDecl(SourceLocation mLoc,
738b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner                                              tok::TokenKind mType,
739b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner                                              DeclPtrTy IDecl,
740b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner                                          tok::ObjCKeywordKind MethodImplKind) {
74154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  ParsingDeclRAIIObject PD(*this);
74254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall
743e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner  // Parse the return type if present.
744ff38491c18b060526d754765b952f4a497a89416Chris Lattner  TypeTy *ReturnType = 0;
745a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCDeclSpec DSRet;
746df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  if (Tok.is(tok::l_paren))
747f1de0ca05e2df6f23bd559028693a12d1ebdaaf6Fariborz Jahanian    ReturnType = ParseObjCTypeName(DSRet);
7481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
749bef1185418705e16012b3dd50cd7c260c8d6b79cSteve Naroff  SourceLocation selLoc;
7502fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner  IdentifierInfo *SelIdent = ParseObjCSelectorPiece(selLoc);
751e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner
75284c431088693e216193094d1dbf327a01173f57fSteve Naroff  // An unnamed colon is valid.
75384c431088693e216193094d1dbf327a01173f57fSteve Naroff  if (!SelIdent && Tok.isNot(tok::colon)) { // missing selector name.
7541ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner    Diag(Tok, diag::err_expected_selector_for_method)
7551ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner      << SourceRange(mLoc, Tok.getLocation());
756e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner    // Skip until we get a ; or {}.
757e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner    SkipUntil(tok::r_brace);
758b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner    return DeclPtrTy();
759e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner  }
7601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
761439c65892cc8629bbf541e0b8bda6b64cbcc4e6bFariborz Jahanian  llvm::SmallVector<Declarator, 8> CargNames;
762df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  if (Tok.isNot(tok::colon)) {
763ff38491c18b060526d754765b952f4a497a89416Chris Lattner    // If attributes exist after the method, parse them.
764ff38491c18b060526d754765b952f4a497a89416Chris Lattner    AttributeList *MethodAttrs = 0;
7651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    if (getLang().ObjC2 && Tok.is(tok::kw___attribute))
766bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt      MethodAttrs = ParseGNUAttributes();
7671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
768ff38491c18b060526d754765b952f4a497a89416Chris Lattner    Selector Sel = PP.getSelectorTable().getNullarySelector(SelIdent);
76954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    DeclPtrTy Result
77054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall         = Actions.ActOnMethodDeclaration(mLoc, Tok.getLocation(),
7711f7b6f88f18d7f6b10265acec5d41c4ed1897487Fariborz Jahanian                                          mType, IDecl, DSRet, ReturnType, Sel,
7721c6a3cc88177c67498fccdf14cfdf09959214e41Ted Kremenek                                          0, CargNames, MethodAttrs,
7731c6a3cc88177c67498fccdf14cfdf09959214e41Ted Kremenek                                          MethodImplKind);
77454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    PD.complete(Result);
77554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    return Result;
776ff38491c18b060526d754765b952f4a497a89416Chris Lattner  }
777f28b264437053fb0deacc9ba02b18a0966f7290aSteve Naroff
77868d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff  llvm::SmallVector<IdentifierInfo *, 12> KeyIdents;
779e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner  llvm::SmallVector<Action::ObjCArgInfo, 12> ArgInfos;
7801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
781ff38491c18b060526d754765b952f4a497a89416Chris Lattner  while (1) {
782e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner    Action::ObjCArgInfo ArgInfo;
7831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
784ff38491c18b060526d754765b952f4a497a89416Chris Lattner    // Each iteration parses a single keyword argument.
785df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner    if (Tok.isNot(tok::colon)) {
786ff38491c18b060526d754765b952f4a497a89416Chris Lattner      Diag(Tok, diag::err_expected_colon);
787ff38491c18b060526d754765b952f4a497a89416Chris Lattner      break;
788ff38491c18b060526d754765b952f4a497a89416Chris Lattner    }
789ff38491c18b060526d754765b952f4a497a89416Chris Lattner    ConsumeToken(); // Eat the ':'.
7901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
791e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner    ArgInfo.Type = 0;
792e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner    if (Tok.is(tok::l_paren)) // Parse the argument type if present.
793e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner      ArgInfo.Type = ParseObjCTypeName(ArgInfo.DeclSpec);
794e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner
795ff38491c18b060526d754765b952f4a497a89416Chris Lattner    // If attributes exist before the argument name, parse them.
796e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner    ArgInfo.ArgAttrs = 0;
797df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner    if (getLang().ObjC2 && Tok.is(tok::kw___attribute))
798bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt      ArgInfo.ArgAttrs = ParseGNUAttributes();
7997ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff
800df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner    if (Tok.isNot(tok::identifier)) {
801ff38491c18b060526d754765b952f4a497a89416Chris Lattner      Diag(Tok, diag::err_expected_ident); // missing argument name.
802ff38491c18b060526d754765b952f4a497a89416Chris Lattner      break;
8034985aceceb9b9261b876b515d32726175c13a775Steve Naroff    }
8041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
805e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner    ArgInfo.Name = Tok.getIdentifierInfo();
806e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner    ArgInfo.NameLoc = Tok.getLocation();
807ff38491c18b060526d754765b952f4a497a89416Chris Lattner    ConsumeToken(); // Eat the identifier.
8081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
809e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner    ArgInfos.push_back(ArgInfo);
810e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner    KeyIdents.push_back(SelIdent);
811e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner
812ff38491c18b060526d754765b952f4a497a89416Chris Lattner    // Check for another keyword selector.
8134b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian    SourceLocation Loc;
8142fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner    SelIdent = ParseObjCSelectorPiece(Loc);
815df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner    if (!SelIdent && Tok.isNot(tok::colon))
816ff38491c18b060526d754765b952f4a497a89416Chris Lattner      break;
817ff38491c18b060526d754765b952f4a497a89416Chris Lattner    // We have a selector or a colon, continue parsing.
818ff38491c18b060526d754765b952f4a497a89416Chris Lattner  }
8191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
820335eafa5be51f6440672a74c73d588af72e96732Steve Naroff  bool isVariadic = false;
8211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
822ff38491c18b060526d754765b952f4a497a89416Chris Lattner  // Parse the (optional) parameter list.
823df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  while (Tok.is(tok::comma)) {
824ff38491c18b060526d754765b952f4a497a89416Chris Lattner    ConsumeToken();
825df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner    if (Tok.is(tok::ellipsis)) {
826335eafa5be51f6440672a74c73d588af72e96732Steve Naroff      isVariadic = true;
8274985aceceb9b9261b876b515d32726175c13a775Steve Naroff      ConsumeToken();
828ff38491c18b060526d754765b952f4a497a89416Chris Lattner      break;
8294985aceceb9b9261b876b515d32726175c13a775Steve Naroff    }
830ff38491c18b060526d754765b952f4a497a89416Chris Lattner    DeclSpec DS;
831ff38491c18b060526d754765b952f4a497a89416Chris Lattner    ParseDeclarationSpecifiers(DS);
8321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    // Parse the declarator.
833ff38491c18b060526d754765b952f4a497a89416Chris Lattner    Declarator ParmDecl(DS, Declarator::PrototypeContext);
834ff38491c18b060526d754765b952f4a497a89416Chris Lattner    ParseDeclarator(ParmDecl);
835439c65892cc8629bbf541e0b8bda6b64cbcc4e6bFariborz Jahanian    CargNames.push_back(ParmDecl);
8364985aceceb9b9261b876b515d32726175c13a775Steve Naroff  }
8371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
838ff38491c18b060526d754765b952f4a497a89416Chris Lattner  // FIXME: Add support for optional parmameter list...
839e3a2ca7e30601cdd31c77a830f4cc487851e8096Fariborz Jahanian  // If attributes exist after the method, parse them.
840ff38491c18b060526d754765b952f4a497a89416Chris Lattner  AttributeList *MethodAttrs = 0;
8411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  if (getLang().ObjC2 && Tok.is(tok::kw___attribute))
842bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt    MethodAttrs = ParseGNUAttributes();
8431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8443688fc679389d67b6755e62406998f9ea84d886aFariborz Jahanian  if (KeyIdents.size() == 0)
8453688fc679389d67b6755e62406998f9ea84d886aFariborz Jahanian    return DeclPtrTy();
846ff38491c18b060526d754765b952f4a497a89416Chris Lattner  Selector Sel = PP.getSelectorTable().getSelector(KeyIdents.size(),
847ff38491c18b060526d754765b952f4a497a89416Chris Lattner                                                   &KeyIdents[0]);
84854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  DeclPtrTy Result
84954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall       = Actions.ActOnMethodDeclaration(mLoc, Tok.getLocation(),
8503688fc679389d67b6755e62406998f9ea84d886aFariborz Jahanian                                        mType, IDecl, DSRet, ReturnType, Sel,
8511c6a3cc88177c67498fccdf14cfdf09959214e41Ted Kremenek                                        &ArgInfos[0], CargNames, MethodAttrs,
852335eafa5be51f6440672a74c73d588af72e96732Steve Naroff                                        MethodImplKind, isVariadic);
85354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  PD.complete(Result);
85454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  return Result;
855294494e1cce92043562b4680c613df7fd028c02eSteve Naroff}
856294494e1cce92043562b4680c613df7fd028c02eSteve Naroff
857dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///   objc-protocol-refs:
858dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     '<' identifier-list '>'
859dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///
8607caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattnerbool Parser::
861b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris LattnerParseObjCProtocolReferences(llvm::SmallVectorImpl<Action::DeclPtrTy> &Protocols,
86271b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis                            llvm::SmallVectorImpl<SourceLocation> &ProtocolLocs,
86371b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis                            bool WarnOnDeclarations,
86471b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis                            SourceLocation &LAngleLoc, SourceLocation &EndLoc) {
865e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner  assert(Tok.is(tok::less) && "expected <");
8661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
86771b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis  LAngleLoc = ConsumeToken(); // the "<"
8681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
869e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner  llvm::SmallVector<IdentifierLocPair, 8> ProtocolIdents;
8701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
871e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner  while (1) {
87255385fe3e723cd675001e45f42d61adde6b7f075Douglas Gregor    if (Tok.is(tok::code_completion)) {
87355385fe3e723cd675001e45f42d61adde6b7f075Douglas Gregor      Actions.CodeCompleteObjCProtocolReferences(ProtocolIdents.data(),
87455385fe3e723cd675001e45f42d61adde6b7f075Douglas Gregor                                                 ProtocolIdents.size());
87555385fe3e723cd675001e45f42d61adde6b7f075Douglas Gregor      ConsumeToken();
87655385fe3e723cd675001e45f42d61adde6b7f075Douglas Gregor    }
87755385fe3e723cd675001e45f42d61adde6b7f075Douglas Gregor
878e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner    if (Tok.isNot(tok::identifier)) {
879e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner      Diag(Tok, diag::err_expected_ident);
880e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner      SkipUntil(tok::greater);
881e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner      return true;
882e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner    }
883e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner    ProtocolIdents.push_back(std::make_pair(Tok.getIdentifierInfo(),
884e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner                                       Tok.getLocation()));
88571b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis    ProtocolLocs.push_back(Tok.getLocation());
886e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner    ConsumeToken();
8871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
888e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner    if (Tok.isNot(tok::comma))
889e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner      break;
890e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner    ConsumeToken();
891e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner  }
8921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
893e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner  // Consume the '>'.
894e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner  if (Tok.isNot(tok::greater)) {
895e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner    Diag(Tok, diag::err_expected_greater);
896e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner    return true;
897e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner  }
8981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
899e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner  EndLoc = ConsumeAnyToken();
9001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
901e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner  // Convert the list of protocols identifiers into a list of protocol decls.
902e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner  Actions.FindProtocolDeclaration(WarnOnDeclarations,
903e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner                                  &ProtocolIdents[0], ProtocolIdents.size(),
904e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner                                  Protocols);
905e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner  return false;
906e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner}
907e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner
908dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///   objc-class-instance-variables:
909dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     '{' objc-instance-variable-decl-list[opt] '}'
910dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///
911dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///   objc-instance-variable-decl-list:
912dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     objc-visibility-spec
913dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     objc-instance-variable-decl ';'
914dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     ';'
915dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     objc-instance-variable-decl-list objc-visibility-spec
916dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     objc-instance-variable-decl-list objc-instance-variable-decl ';'
917dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     objc-instance-variable-decl-list ';'
918dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///
919dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///   objc-visibility-spec:
920dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     @private
921dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     @protected
922dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     @public
923ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff///     @package [OBJC2]
924dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///
925dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///   objc-instance-variable-decl:
9261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///     struct-declaration
927dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///
928b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattnervoid Parser::ParseObjCClassInstanceVariables(DeclPtrTy interfaceDecl,
92960fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff                                             SourceLocation atLoc) {
930df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  assert(Tok.is(tok::l_brace) && "expected {");
931b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner  llvm::SmallVector<DeclPtrTy, 32> AllIvarDecls;
932e13594279a952537ac903325efff57e3edca79d9Chris Lattner
9331a0d31a3d7f14ddc6370ba912c778aece6c12cf0Douglas Gregor  ParseScope ClassScope(this, Scope::DeclScope|Scope::ClassScope);
93472de6676bd30f9081ee4166bbe07b4c270258ce6Douglas Gregor
935ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff  SourceLocation LBraceLoc = ConsumeBrace(); // the "{"
9361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
937aa847fe3c88ee5e8d180e48537c58b805d48d95dFariborz Jahanian  tok::ObjCKeywordKind visibility = tok::objc_protected;
938ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff  // While we still have something to read, read the instance variables.
939df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  while (Tok.isNot(tok::r_brace) && Tok.isNot(tok::eof)) {
940ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff    // Each iteration of this loop reads one objc-instance-variable-decl.
9411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
942ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff    // Check for extraneous top-level semicolon.
943df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner    if (Tok.is(tok::semi)) {
944c2253f5ca170984fcd4f30f8823148e8cb71336bChris Lattner      Diag(Tok, diag::ext_extra_struct_semi)
94529d9c1adfadf65e2d847d44bec37746844b9e0e3Chris Lattner        << CodeModificationHint::CreateRemoval(Tok.getLocation());
946ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff      ConsumeToken();
947ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff      continue;
948ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff    }
9491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
950ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff    // Set the default visibility to private.
951df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner    if (Tok.is(tok::at)) { // parse objc-visibility-spec
952ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff      ConsumeToken(); // eat the @ sign
953861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff      switch (Tok.getObjCKeywordID()) {
954ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff      case tok::objc_private:
955ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff      case tok::objc_public:
956ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff      case tok::objc_protected:
957ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff      case tok::objc_package:
958861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff        visibility = Tok.getObjCKeywordID();
959ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff        ConsumeToken();
9601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump        continue;
961ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff      default:
962ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff        Diag(Tok, diag::err_objc_illegal_visibility_spec);
963ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff        continue;
964ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff      }
965ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff    }
9661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
967bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall    struct ObjCIvarCallback : FieldCallback {
968bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall      Parser &P;
969bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall      DeclPtrTy IDecl;
970bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall      tok::ObjCKeywordKind visibility;
971bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall      llvm::SmallVectorImpl<DeclPtrTy> &AllIvarDecls;
972bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall
973bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall      ObjCIvarCallback(Parser &P, DeclPtrTy IDecl, tok::ObjCKeywordKind V,
974bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall                       llvm::SmallVectorImpl<DeclPtrTy> &AllIvarDecls) :
975bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall        P(P), IDecl(IDecl), visibility(V), AllIvarDecls(AllIvarDecls) {
976bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall      }
977bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall
978bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall      DeclPtrTy invoke(FieldDeclarator &FD) {
979bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall        // Install the declarator into the interface decl.
980bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall        DeclPtrTy Field
981bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall          = P.Actions.ActOnIvar(P.CurScope,
982bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall                                FD.D.getDeclSpec().getSourceRange().getBegin(),
983bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall                                IDecl, FD.D, FD.BitfieldSize, visibility);
984bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall        AllIvarDecls.push_back(Field);
985bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall        return Field;
986bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall      }
987bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall    } Callback(*this, interfaceDecl, visibility, AllIvarDecls);
988bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall
989e13594279a952537ac903325efff57e3edca79d9Chris Lattner    // Parse all the comma separated declarators.
990e13594279a952537ac903325efff57e3edca79d9Chris Lattner    DeclSpec DS;
991bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall    ParseStructDeclaration(DS, Callback);
9921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
993df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner    if (Tok.is(tok::semi)) {
994ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff      ConsumeToken();
995ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff    } else {
996ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff      Diag(Tok, diag::err_expected_semi_decl_list);
997ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff      // Skip to end of block or statement
998ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff      SkipUntil(tok::r_brace, true, true);
999ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff    }
1000ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff  }
100160fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff  SourceLocation RBraceLoc = MatchRHSPunctuation(tok::r_brace, LBraceLoc);
10028749be53f53384e7846502791ceda6c657228d07Steve Naroff  // Call ActOnFields() even if we don't have any decls. This is useful
10038749be53f53384e7846502791ceda6c657228d07Steve Naroff  // for code rewriting tools that need to be aware of the empty list.
10048749be53f53384e7846502791ceda6c657228d07Steve Naroff  Actions.ActOnFields(CurScope, atLoc, interfaceDecl,
1005beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad                      AllIvarDecls.data(), AllIvarDecls.size(),
10061bfe1c2129771c06fb58ae5e8c079ae30e138309Daniel Dunbar                      LBraceLoc, RBraceLoc, 0);
1007ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff  return;
10085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
1009dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff
1010dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///   objc-protocol-declaration:
1011dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     objc-protocol-definition
1012dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     objc-protocol-forward-reference
1013dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///
1014dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///   objc-protocol-definition:
10151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///     @protocol identifier
10161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///       objc-protocol-refs[opt]
10171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///       objc-interface-decl-list
1018dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     @end
1019dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///
1020dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///   objc-protocol-forward-reference:
1021dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     @protocol identifier-list ';'
1022dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///
1023dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///   "@protocol identifier ;" should be resolved as "@protocol
10243536b443bc50d58a79f14fca9b6842541a434854Steve Naroff///   identifier-list ;": objc-interface-decl-list may not start with a
1025dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///   semicolon in the first alternative if objc-protocol-refs are omitted.
1026b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris LattnerParser::DeclPtrTy Parser::ParseObjCAtProtocolDeclaration(SourceLocation AtLoc,
1027b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner                                                      AttributeList *attrList) {
1028861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff  assert(Tok.isObjCAtKeyword(tok::objc_protocol) &&
10297ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff         "ParseObjCAtProtocolDeclaration(): Expected @protocol");
10307ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff  ConsumeToken(); // the "protocol" identifier
10311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1032083128f6b13dfa4fc615a838c49b516d901b1ac0Douglas Gregor  if (Tok.is(tok::code_completion)) {
1033083128f6b13dfa4fc615a838c49b516d901b1ac0Douglas Gregor    Actions.CodeCompleteObjCProtocolDecl(CurScope);
1034083128f6b13dfa4fc615a838c49b516d901b1ac0Douglas Gregor    ConsumeToken();
1035083128f6b13dfa4fc615a838c49b516d901b1ac0Douglas Gregor  }
1036083128f6b13dfa4fc615a838c49b516d901b1ac0Douglas Gregor
1037df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  if (Tok.isNot(tok::identifier)) {
10387ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff    Diag(Tok, diag::err_expected_ident); // missing protocol name.
1039b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner    return DeclPtrTy();
10407ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff  }
10417ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff  // Save the protocol name, then consume it.
10427ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff  IdentifierInfo *protocolName = Tok.getIdentifierInfo();
10437ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff  SourceLocation nameLoc = ConsumeToken();
10441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1045df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  if (Tok.is(tok::semi)) { // forward declaration of one protocol.
10467caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner    IdentifierLocPair ProtoInfo(protocolName, nameLoc);
10477ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff    ConsumeToken();
10481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return Actions.ActOnForwardProtocolDeclaration(AtLoc, &ProtoInfo, 1,
1049bc1c877fe28fb6a825f0b226a0a2da99e713ea03Fariborz Jahanian                                                   attrList);
10507ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff  }
10511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1052df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  if (Tok.is(tok::comma)) { // list of forward declarations.
10537caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner    llvm::SmallVector<IdentifierLocPair, 8> ProtocolRefs;
10547caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner    ProtocolRefs.push_back(std::make_pair(protocolName, nameLoc));
10557caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner
10567ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff    // Parse the list of forward declarations.
10577ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff    while (1) {
10587ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff      ConsumeToken(); // the ','
1059df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner      if (Tok.isNot(tok::identifier)) {
10607ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff        Diag(Tok, diag::err_expected_ident);
10617ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff        SkipUntil(tok::semi);
1062b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner        return DeclPtrTy();
10637ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff      }
10647caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner      ProtocolRefs.push_back(IdentifierLocPair(Tok.getIdentifierInfo(),
10657caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner                                               Tok.getLocation()));
10667ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff      ConsumeToken(); // the identifier
10671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1068df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner      if (Tok.isNot(tok::comma))
10697ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff        break;
10707ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff    }
10717ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff    // Consume the ';'.
10727ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff    if (ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@protocol"))
1073b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner      return DeclPtrTy();
10741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1075e440eb8158e71deb1e4ab11618ae3d680aac6da1Steve Naroff    return Actions.ActOnForwardProtocolDeclaration(AtLoc,
10761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                                   &ProtocolRefs[0],
1077bc1c877fe28fb6a825f0b226a0a2da99e713ea03Fariborz Jahanian                                                   ProtocolRefs.size(),
1078bc1c877fe28fb6a825f0b226a0a2da99e713ea03Fariborz Jahanian                                                   attrList);
10797caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner  }
10801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10817ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff  // Last, and definitely not least, parse a protocol declaration.
108271b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis  SourceLocation LAngleLoc, EndProtoLoc;
10837caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner
1084b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner  llvm::SmallVector<DeclPtrTy, 8> ProtocolRefs;
108571b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis  llvm::SmallVector<SourceLocation, 8> ProtocolLocs;
10867caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner  if (Tok.is(tok::less) &&
108771b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis      ParseObjCProtocolReferences(ProtocolRefs, ProtocolLocs, false,
108871b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis                                  LAngleLoc, EndProtoLoc))
1089b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner    return DeclPtrTy();
10901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1091b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner  DeclPtrTy ProtoType =
1092e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner    Actions.ActOnStartProtocolInterface(AtLoc, protocolName, nameLoc,
1093beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad                                        ProtocolRefs.data(),
1094beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad                                        ProtocolRefs.size(),
1095246e70f69cb8aeb67225c54690f1c6b25abd5a86Daniel Dunbar                                        EndProtoLoc, attrList);
109625e077d59a8e8e43b65882b69610a3d5e2aaf53cFariborz Jahanian  ParseObjCInterfaceDeclList(ProtoType, tok::objc_protocol);
1097bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner  return ProtoType;
1098dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff}
1099dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff
1100dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///   objc-implementation:
1101dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     objc-class-implementation-prologue
1102dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     objc-category-implementation-prologue
1103dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///
1104dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///   objc-class-implementation-prologue:
1105dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     @implementation identifier objc-superclass[opt]
1106dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///       objc-class-instance-variables[opt]
1107dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///
1108dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///   objc-category-implementation-prologue:
1109dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     @implementation identifier ( identifier )
1110b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris LattnerParser::DeclPtrTy Parser::ParseObjCAtImplementationDeclaration(
1111ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian  SourceLocation atLoc) {
1112ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian  assert(Tok.isObjCAtKeyword(tok::objc_implementation) &&
1113ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian         "ParseObjCAtImplementationDeclaration(): Expected @implementation");
1114ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian  ConsumeToken(); // the "implementation" identifier
11151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11163b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor  // Code completion after '@implementation'.
11173b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor  if (Tok.is(tok::code_completion)) {
11183b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor    Actions.CodeCompleteObjCImplementationDecl(CurScope);
11193b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor    ConsumeToken();
11203b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor  }
11213b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor
1122df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  if (Tok.isNot(tok::identifier)) {
1123ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian    Diag(Tok, diag::err_expected_ident); // missing class or category name.
1124b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner    return DeclPtrTy();
1125ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian  }
1126ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian  // We have a class or category name - consume it.
1127ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian  IdentifierInfo *nameId = Tok.getIdentifierInfo();
1128ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian  SourceLocation nameLoc = ConsumeToken(); // consume class or category name
11291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  if (Tok.is(tok::l_paren)) {
1131ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian    // we have a category implementation.
1132ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian    SourceLocation lparenLoc = ConsumeParen();
1133ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian    SourceLocation categoryLoc, rparenLoc;
1134ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian    IdentifierInfo *categoryId = 0;
11351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
113633ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor    if (Tok.is(tok::code_completion)) {
113733ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor      Actions.CodeCompleteObjCImplementationCategory(CurScope, nameId);
113833ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor      ConsumeToken();
113933ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor    }
114033ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor
1141df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner    if (Tok.is(tok::identifier)) {
1142ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian      categoryId = Tok.getIdentifierInfo();
1143ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian      categoryLoc = ConsumeToken();
1144ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian    } else {
1145ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian      Diag(Tok, diag::err_expected_ident); // missing category name.
1146b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner      return DeclPtrTy();
11471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    }
1148df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner    if (Tok.isNot(tok::r_paren)) {
1149ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian      Diag(Tok, diag::err_expected_rparen);
1150ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian      SkipUntil(tok::r_paren, false); // don't stop at ';'
1151b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner      return DeclPtrTy();
1152ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian    }
1153ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian    rparenLoc = ConsumeParen();
1154b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner    DeclPtrTy ImplCatType = Actions.ActOnStartCategoryImplementation(
11551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                    atLoc, nameId, nameLoc, categoryId,
11568f3fde00ad4d4f943321e338b914ae4740711c84Fariborz Jahanian                                    categoryLoc);
1157a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek    ObjCImpDecl = ImplCatType;
115863e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian    PendingObjCImpDecl.push_back(ObjCImpDecl);
1159b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner    return DeclPtrTy();
1160ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian  }
1161ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian  // We have a class implementation
1162ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian  SourceLocation superClassLoc;
1163ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian  IdentifierInfo *superClassId = 0;
1164df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  if (Tok.is(tok::colon)) {
1165ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian    // We have a super class
1166ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian    ConsumeToken();
1167df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner    if (Tok.isNot(tok::identifier)) {
1168ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian      Diag(Tok, diag::err_expected_ident); // missing super class name.
1169b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner      return DeclPtrTy();
1170ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian    }
1171ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian    superClassId = Tok.getIdentifierInfo();
1172ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian    superClassLoc = ConsumeToken(); // Consume super class name
1173ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian  }
1174b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner  DeclPtrTy ImplClsType = Actions.ActOnStartClassImplementation(
1175cb53b361bce341c8591333c6997f62e480acc0b4Chris Lattner                                  atLoc, nameId, nameLoc,
1176ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian                                  superClassId, superClassLoc);
11771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
117860fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff  if (Tok.is(tok::l_brace)) // we have ivars
117960fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff    ParseObjCClassInstanceVariables(ImplClsType/*FIXME*/, atLoc);
1180a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCImpDecl = ImplClsType;
118163e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian  PendingObjCImpDecl.push_back(ObjCImpDecl);
118263e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian
1183b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner  return DeclPtrTy();
11845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
118560fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff
1186b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris LattnerParser::DeclPtrTy Parser::ParseObjCAtEndDeclaration(SourceLocation atLoc) {
1187ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian  assert(Tok.isObjCAtKeyword(tok::objc_end) &&
1188ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian         "ParseObjCAtEndDeclaration(): Expected @end");
1189b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner  DeclPtrTy Result = ObjCImpDecl;
1190ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian  ConsumeToken(); // the "end" identifier
1191a6e3ac514c924879699c6b0b1201028f0091044fFariborz Jahanian  if (ObjCImpDecl) {
1192a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek    Actions.ActOnAtEnd(atLoc, ObjCImpDecl);
1193b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner    ObjCImpDecl = DeclPtrTy();
119463e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian    PendingObjCImpDecl.pop_back();
1195a6e3ac514c924879699c6b0b1201028f0091044fFariborz Jahanian  }
119694cdb25a49bd3716ab56ef6de0ea57d29e686bf2Fariborz Jahanian  else
119794cdb25a49bd3716ab56ef6de0ea57d29e686bf2Fariborz Jahanian    Diag(atLoc, diag::warn_expected_implementation); // missing @implementation
1198a6e3ac514c924879699c6b0b1201028f0091044fFariborz Jahanian  return Result;
11995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
1200e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian
12011ac7104947020a60430ba6f519cd5869af77046fFariborz JahanianParser::DeclGroupPtrTy Parser::RetrievePendingObjCImpDecl() {
120263e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian  if (PendingObjCImpDecl.empty())
120363e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian    return Actions.ConvertDeclToDeclGroup(DeclPtrTy());
120463e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian  DeclPtrTy ImpDecl = PendingObjCImpDecl.pop_back_val();
120563e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian  Actions.ActOnAtEnd(SourceLocation(), ImpDecl);
120663e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian  return Actions.ConvertDeclToDeclGroup(ImpDecl);
120763e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian}
120863e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian
1209e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian///   compatibility-alias-decl:
1210e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian///     @compatibility_alias alias-name  class-name ';'
1211e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian///
1212b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris LattnerParser::DeclPtrTy Parser::ParseObjCAtAliasDeclaration(SourceLocation atLoc) {
1213e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian  assert(Tok.isObjCAtKeyword(tok::objc_compatibility_alias) &&
1214e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian         "ParseObjCAtAliasDeclaration(): Expected @compatibility_alias");
1215e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian  ConsumeToken(); // consume compatibility_alias
1216df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  if (Tok.isNot(tok::identifier)) {
1217e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian    Diag(Tok, diag::err_expected_ident);
1218b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner    return DeclPtrTy();
1219e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian  }
1220243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian  IdentifierInfo *aliasId = Tok.getIdentifierInfo();
1221243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian  SourceLocation aliasLoc = ConsumeToken(); // consume alias-name
1222df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  if (Tok.isNot(tok::identifier)) {
1223e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian    Diag(Tok, diag::err_expected_ident);
1224b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner    return DeclPtrTy();
1225e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian  }
1226243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian  IdentifierInfo *classId = Tok.getIdentifierInfo();
1227243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian  SourceLocation classLoc = ConsumeToken(); // consume class-name;
1228243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian  if (Tok.isNot(tok::semi)) {
12291ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner    Diag(Tok, diag::err_expected_semi_after) << "@compatibility_alias";
1230b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner    return DeclPtrTy();
1231243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian  }
1232b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner  return Actions.ActOnCompatiblityAlias(atLoc, aliasId, aliasLoc,
1233b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner                                        classId, classLoc);
12345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
12355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1236ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian///   property-synthesis:
1237ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian///     @synthesize property-ivar-list ';'
1238ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian///
1239ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian///   property-ivar-list:
1240ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian///     property-ivar
1241ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian///     property-ivar-list ',' property-ivar
1242ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian///
1243ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian///   property-ivar:
1244ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian///     identifier
1245ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian///     identifier '=' identifier
1246ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian///
1247b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris LattnerParser::DeclPtrTy Parser::ParseObjCPropertySynthesize(SourceLocation atLoc) {
1248ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian  assert(Tok.isObjCAtKeyword(tok::objc_synthesize) &&
1249ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian         "ParseObjCPropertyDynamic(): Expected '@synthesize'");
1250f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian  SourceLocation loc = ConsumeToken(); // consume synthesize
12511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1252b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor  while (true) {
1253322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor    if (Tok.is(tok::code_completion)) {
1254424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor      Actions.CodeCompleteObjCPropertyDefinition(CurScope, ObjCImpDecl);
1255322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor      ConsumeToken();
1256322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor    }
1257322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor
1258b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor    if (Tok.isNot(tok::identifier)) {
1259b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor      Diag(Tok, diag::err_synthesized_property_name);
1260b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor      SkipUntil(tok::semi);
1261b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor      return DeclPtrTy();
1262b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor    }
1263b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor
1264f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian    IdentifierInfo *propertyIvar = 0;
1265f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian    IdentifierInfo *propertyId = Tok.getIdentifierInfo();
1266f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian    SourceLocation propertyLoc = ConsumeToken(); // consume property name
1267df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner    if (Tok.is(tok::equal)) {
1268ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian      // property '=' ivar-name
1269ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian      ConsumeToken(); // consume '='
1270322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor
1271322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor      if (Tok.is(tok::code_completion)) {
1272322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor        Actions.CodeCompleteObjCPropertySynthesizeIvar(CurScope, propertyId,
1273322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor                                                       ObjCImpDecl);
1274322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor        ConsumeToken();
1275322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor      }
1276322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor
1277df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner      if (Tok.isNot(tok::identifier)) {
1278ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian        Diag(Tok, diag::err_expected_ident);
1279ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian        break;
1280ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian      }
1281f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian      propertyIvar = Tok.getIdentifierInfo();
1282ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian      ConsumeToken(); // consume ivar-name
1283ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian    }
1284f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian    Actions.ActOnPropertyImplDecl(atLoc, propertyLoc, true, ObjCImpDecl,
1285f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian                                  propertyId, propertyIvar);
1286df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner    if (Tok.isNot(tok::comma))
1287ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian      break;
1288ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian    ConsumeToken(); // consume ','
1289ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian  }
1290b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor  if (Tok.isNot(tok::semi)) {
12911ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner    Diag(Tok, diag::err_expected_semi_after) << "@synthesize";
1292b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor    SkipUntil(tok::semi);
1293b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor  }
1294d3fdcb5a1bf6bd5e54e18579c054ea3c292a0e28Fariborz Jahanian  else
1295d3fdcb5a1bf6bd5e54e18579c054ea3c292a0e28Fariborz Jahanian    ConsumeToken(); // consume ';'
1296b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner  return DeclPtrTy();
1297ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian}
1298ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian
1299ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian///   property-dynamic:
1300ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian///     @dynamic  property-list
1301ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian///
1302ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian///   property-list:
1303ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian///     identifier
1304ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian///     property-list ',' identifier
1305ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian///
1306b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris LattnerParser::DeclPtrTy Parser::ParseObjCPropertyDynamic(SourceLocation atLoc) {
1307ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian  assert(Tok.isObjCAtKeyword(tok::objc_dynamic) &&
1308ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian         "ParseObjCPropertyDynamic(): Expected '@dynamic'");
1309ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian  SourceLocation loc = ConsumeToken(); // consume dynamic
1310424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor  while (true) {
1311424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor    if (Tok.is(tok::code_completion)) {
1312424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor      Actions.CodeCompleteObjCPropertyDefinition(CurScope, ObjCImpDecl);
1313424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor      ConsumeToken();
1314424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor    }
1315424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor
1316424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor    if (Tok.isNot(tok::identifier)) {
1317424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor      Diag(Tok, diag::err_expected_ident);
1318424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor      SkipUntil(tok::semi);
1319424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor      return DeclPtrTy();
1320424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor    }
1321424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor
1322c35b9e4e2efad727538c848cf30d4b0eb1031dc9Fariborz Jahanian    IdentifierInfo *propertyId = Tok.getIdentifierInfo();
1323c35b9e4e2efad727538c848cf30d4b0eb1031dc9Fariborz Jahanian    SourceLocation propertyLoc = ConsumeToken(); // consume property name
1324c35b9e4e2efad727538c848cf30d4b0eb1031dc9Fariborz Jahanian    Actions.ActOnPropertyImplDecl(atLoc, propertyLoc, false, ObjCImpDecl,
1325c35b9e4e2efad727538c848cf30d4b0eb1031dc9Fariborz Jahanian                                  propertyId, 0);
1326c35b9e4e2efad727538c848cf30d4b0eb1031dc9Fariborz Jahanian
1327df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner    if (Tok.isNot(tok::comma))
1328ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian      break;
1329ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian    ConsumeToken(); // consume ','
1330ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian  }
1331df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  if (Tok.isNot(tok::semi))
13321ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner    Diag(Tok, diag::err_expected_semi_after) << "@dynamic";
1333b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner  return DeclPtrTy();
1334ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian}
13351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1336397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian///  objc-throw-statement:
1337397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian///    throw expression[opt];
1338397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian///
133943bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian RedlParser::OwningStmtResult Parser::ParseObjCThrowStmt(SourceLocation atLoc) {
134015faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl  OwningExprResult Res(Actions);
1341397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian  ConsumeToken(); // consume throw
1342df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  if (Tok.isNot(tok::semi)) {
134339f8f159c488a900e5958d5aab3e467af9ec8a2bFariborz Jahanian    Res = ParseExpression();
13440e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl    if (Res.isInvalid()) {
1345397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian      SkipUntil(tok::semi);
134643bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl      return StmtError();
1347397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian    }
1348397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian  }
134939f8f159c488a900e5958d5aab3e467af9ec8a2bFariborz Jahanian  ConsumeToken(); // consume ';'
1350e21dd6ffef4585fa43cd3586ed971217d65bf56cSteve Naroff  return Actions.ActOnObjCAtThrowStmt(atLoc, move(Res), CurScope);
1351397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian}
1352397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian
1353c385c90c68dfa376650e2facfbb444b2ec9bd110Fariborz Jahanian/// objc-synchronized-statement:
135478a677bbb5fa115fa0995b5783adeeefad67167eFariborz Jahanian///   @synchronized '(' expression ')' compound-statement
1355c385c90c68dfa376650e2facfbb444b2ec9bd110Fariborz Jahanian///
135643bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian RedlParser::OwningStmtResult
135743bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian RedlParser::ParseObjCSynchronizedStmt(SourceLocation atLoc) {
1358fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian  ConsumeToken(); // consume synchronized
1359fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian  if (Tok.isNot(tok::l_paren)) {
13601ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner    Diag(Tok, diag::err_expected_lparen_after) << "@synchronized";
136143bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl    return StmtError();
1362fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian  }
1363fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian  ConsumeParen();  // '('
13642f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl  OwningExprResult Res(ParseExpression());
13650e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl  if (Res.isInvalid()) {
1366fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian    SkipUntil(tok::semi);
136743bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl    return StmtError();
1368fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian  }
1369fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian  if (Tok.isNot(tok::r_paren)) {
13701ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner    Diag(Tok, diag::err_expected_lbrace);
137143bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl    return StmtError();
1372fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian  }
1373fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian  ConsumeParen();  // ')'
137478a677bbb5fa115fa0995b5783adeeefad67167eFariborz Jahanian  if (Tok.isNot(tok::l_brace)) {
13751ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner    Diag(Tok, diag::err_expected_lbrace);
137643bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl    return StmtError();
137778a677bbb5fa115fa0995b5783adeeefad67167eFariborz Jahanian  }
13783ac438c383a4a9a73c76a05c76ec5d02f10a3c52Steve Naroff  // Enter a scope to hold everything within the compound stmt.  Compound
13793ac438c383a4a9a73c76a05c76ec5d02f10a3c52Steve Naroff  // statements can always hold declarations.
13808935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor  ParseScope BodyScope(this, Scope::DeclScope);
13813ac438c383a4a9a73c76a05c76ec5d02f10a3c52Steve Naroff
138261364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl  OwningStmtResult SynchBody(ParseCompoundStatementBody());
13830e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl
13848935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor  BodyScope.Exit();
13850e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl  if (SynchBody.isInvalid())
1386fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian    SynchBody = Actions.ActOnNullStmt(Tok.getLocation());
138776ad2e85575722e8a38a2bd4648ab4304d9fcd24Sebastian Redl  return Actions.ActOnObjCAtSynchronizedStmt(atLoc, move(Res), move(SynchBody));
1388c385c90c68dfa376650e2facfbb444b2ec9bd110Fariborz Jahanian}
1389c385c90c68dfa376650e2facfbb444b2ec9bd110Fariborz Jahanian
1390397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian///  objc-try-catch-statement:
1391397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian///    @try compound-statement objc-catch-list[opt]
1392397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian///    @try compound-statement objc-catch-list[opt] @finally compound-statement
1393397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian///
1394397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian///  objc-catch-list:
1395397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian///    @catch ( parameter-declaration ) compound-statement
1396397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian///    objc-catch-list @catch ( catch-parameter-declaration ) compound-statement
1397397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian///  catch-parameter-declaration:
1398397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian///     parameter-declaration
1399397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian///     '...' [OBJC2]
1400397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian///
140143bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian RedlParser::OwningStmtResult Parser::ParseObjCTryStmt(SourceLocation atLoc) {
1402397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian  bool catch_or_finally_seen = false;
140343bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl
1404397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian  ConsumeToken(); // consume try
1405df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  if (Tok.isNot(tok::l_brace)) {
14061ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner    Diag(Tok, diag::err_expected_lbrace);
140743bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl    return StmtError();
1408397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian  }
140915faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl  OwningStmtResult CatchStmts(Actions);
141015faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl  OwningStmtResult FinallyStmt(Actions);
14118935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor  ParseScope TryScope(this, Scope::DeclScope);
141261364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl  OwningStmtResult TryBody(ParseCompoundStatementBody());
14138935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor  TryScope.Exit();
14140e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl  if (TryBody.isInvalid())
1415bd49a647afd9cc534fef13cadf652d4e9c396e2bFariborz Jahanian    TryBody = Actions.ActOnNullStmt(Tok.getLocation());
1416a55e52c0802cae3b7c366a05c461d3d15074c1a3Sebastian Redl
1417df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  while (Tok.is(tok::at)) {
14186b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner    // At this point, we need to lookahead to determine if this @ is the start
14196b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner    // of an @catch or @finally.  We don't want to consume the @ token if this
14206b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner    // is an @try or @encode or something else.
14216b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner    Token AfterAt = GetLookAheadToken(1);
14226b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner    if (!AfterAt.isObjCAtKeyword(tok::objc_catch) &&
14236b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner        !AfterAt.isObjCAtKeyword(tok::objc_finally))
14246b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner      break;
14250e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl
1426161a9c5afaafb4d527b7efba9675a8b2cbbe32e0Fariborz Jahanian    SourceLocation AtCatchFinallyLoc = ConsumeToken();
1427cb53b361bce341c8591333c6997f62e480acc0b4Chris Lattner    if (Tok.isObjCAtKeyword(tok::objc_catch)) {
1428b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner      DeclPtrTy FirstPart;
14293b1191d7eaf2f4984564e01ab84b6713a9d80e70Fariborz Jahanian      ConsumeToken(); // consume catch
1430df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner      if (Tok.is(tok::l_paren)) {
1431397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian        ConsumeParen();
1432e21dd6ffef4585fa43cd3586ed971217d65bf56cSteve Naroff        ParseScope CatchScope(this, Scope::DeclScope|Scope::AtCatchScope);
1433df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner        if (Tok.isNot(tok::ellipsis)) {
1434397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian          DeclSpec DS;
1435397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian          ParseDeclarationSpecifiers(DS);
143643bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl          // For some odd reason, the name of the exception variable is
14371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump          // optional. As a result, we need to use "PrototypeContext", because
14387ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff          // we must accept either 'declarator' or 'abstract-declarator' here.
14397ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff          Declarator ParmDecl(DS, Declarator::PrototypeContext);
14407ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff          ParseDeclarator(ParmDecl);
14417ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff
14427ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff          // Inform the actions module about the parameter declarator, so it
14437ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff          // gets added to the current scope.
14447ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff          FirstPart = Actions.ActOnParamDeclarator(CurScope, ParmDecl);
144564515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff        } else
1446397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian          ConsumeToken(); // consume '...'
14471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
144893a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff        SourceLocation RParenLoc;
14491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
145093a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff        if (Tok.is(tok::r_paren))
145193a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff          RParenLoc = ConsumeParen();
145293a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff        else // Skip over garbage, until we get to ')'.  Eat the ')'.
145393a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff          SkipUntil(tok::r_paren, true, false);
145493a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff
145515faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl        OwningStmtResult CatchBody(Actions, true);
1456c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner        if (Tok.is(tok::l_brace))
1457c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner          CatchBody = ParseCompoundStatementBody();
1458c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner        else
1459c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner          Diag(Tok, diag::err_expected_lbrace);
14600e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl        if (CatchBody.isInvalid())
14613b1191d7eaf2f4984564e01ab84b6713a9d80e70Fariborz Jahanian          CatchBody = Actions.ActOnNullStmt(Tok.getLocation());
14620e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl        CatchStmts = Actions.ActOnObjCAtCatchStmt(AtCatchFinallyLoc,
14637ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff                        RParenLoc, FirstPart, move(CatchBody),
146476ad2e85575722e8a38a2bd4648ab4304d9fcd24Sebastian Redl                        move(CatchStmts));
146564515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff      } else {
14661ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner        Diag(AtCatchFinallyLoc, diag::err_expected_lparen_after)
14671ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner          << "@catch clause";
146843bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl        return StmtError();
1469397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian      }
1470397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian      catch_or_finally_seen = true;
14716b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner    } else {
14726b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner      assert(Tok.isObjCAtKeyword(tok::objc_finally) && "Lookahead confused?");
147364515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff      ConsumeToken(); // consume finally
14748935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor      ParseScope FinallyScope(this, Scope::DeclScope);
14750e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl
147615faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl      OwningStmtResult FinallyBody(Actions, true);
1477c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner      if (Tok.is(tok::l_brace))
1478c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner        FinallyBody = ParseCompoundStatementBody();
1479c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner      else
1480c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner        Diag(Tok, diag::err_expected_lbrace);
14810e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl      if (FinallyBody.isInvalid())
1482161a9c5afaafb4d527b7efba9675a8b2cbbe32e0Fariborz Jahanian        FinallyBody = Actions.ActOnNullStmt(Tok.getLocation());
14830e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl      FinallyStmt = Actions.ActOnObjCAtFinallyStmt(AtCatchFinallyLoc,
148476ad2e85575722e8a38a2bd4648ab4304d9fcd24Sebastian Redl                                                   move(FinallyBody));
1485397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian      catch_or_finally_seen = true;
1486397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian      break;
1487397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian    }
1488397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian  }
1489bd49a647afd9cc534fef13cadf652d4e9c396e2bFariborz Jahanian  if (!catch_or_finally_seen) {
1490397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian    Diag(atLoc, diag::err_missing_catch_finally);
149143bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl    return StmtError();
1492bd49a647afd9cc534fef13cadf652d4e9c396e2bFariborz Jahanian  }
149376ad2e85575722e8a38a2bd4648ab4304d9fcd24Sebastian Redl  return Actions.ActOnObjCAtTryStmt(atLoc, move(TryBody), move(CatchStmts),
149476ad2e85575722e8a38a2bd4648ab4304d9fcd24Sebastian Redl                                    move(FinallyStmt));
1495397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian}
1496ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian
14973536b443bc50d58a79f14fca9b6842541a434854Steve Naroff///   objc-method-def: objc-method-proto ';'[opt] '{' body '}'
1498ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian///
1499b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris LattnerParser::DeclPtrTy Parser::ParseObjCMethodDefinition() {
1500b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner  DeclPtrTy MDecl = ParseObjCMethodPrototype(ObjCImpDecl);
15011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
150249f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner  PrettyStackTraceActionsDecl CrashInfo(MDecl, Tok.getLocation(), Actions,
150349f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner                                        PP.getSourceManager(),
150449f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner                                        "parsing Objective-C method");
15051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1506ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian  // parse optional ';'
1507209a8c2fa23636f6d065d618e7078e164903f5cdFariborz Jahanian  if (Tok.is(tok::semi)) {
1508496e45ef3350fabc312c5a807d308c65c50af4dbTed Kremenek    if (ObjCImpDecl) {
1509496e45ef3350fabc312c5a807d308c65c50af4dbTed Kremenek      Diag(Tok, diag::warn_semicolon_before_method_body)
151029d9c1adfadf65e2d847d44bec37746844b9e0e3Chris Lattner        << CodeModificationHint::CreateRemoval(Tok.getLocation());
1511496e45ef3350fabc312c5a807d308c65c50af4dbTed Kremenek    }
1512ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian    ConsumeToken();
1513209a8c2fa23636f6d065d618e7078e164903f5cdFariborz Jahanian  }
1514ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian
1515409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff  // We should have an opening brace now.
1516df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  if (Tok.isNot(tok::l_brace)) {
1517da323adbb99cee19a203ead852d5d9bfebb23fb7Steve Naroff    Diag(Tok, diag::err_expected_method_body);
15181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1519409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff    // Skip over garbage, until we get to '{'.  Don't eat the '{'.
1520409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff    SkipUntil(tok::l_brace, true, true);
15211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1522409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff    // If we didn't find the '{', bail out.
1523409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff    if (Tok.isNot(tok::l_brace))
1524b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner      return DeclPtrTy();
1525ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian  }
1526409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff  SourceLocation BraceLoc = Tok.getLocation();
15271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1528409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff  // Enter a scope for the method body.
15298935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor  ParseScope BodyScope(this, Scope::FnScope|Scope::DeclScope);
15301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1531409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff  // Tell the actions module that we have entered a method definition with the
1532394f3f483fa4e7b472630cfcd03f7840520958c5Steve Naroff  // specified Declarator for the method.
1533ebf6443a4f493233f7e8d92b3a991848c8b1c00dSteve Naroff  Actions.ActOnStartOfObjCMethodDef(CurScope, MDecl);
153461364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl
153561364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl  OwningStmtResult FnBody(ParseCompoundStatementBody());
153661364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl
1537409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff  // If the function body could not be parsed, make a bogus compoundstmt.
15380e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl  if (FnBody.isInvalid())
1539a60528cdac7deee3991c2b48af4df4f315e49e9dSebastian Redl    FnBody = Actions.ActOnCompoundStmt(BraceLoc, BraceLoc,
1540a60528cdac7deee3991c2b48af4df4f315e49e9dSebastian Redl                                       MultiStmtArg(Actions), false);
1541798d119415323ebcd029ffe1e0fb442a4ca8adbbSebastian Redl
154232ce8376efb7e0d70e5f7e8fcf685130293f412bSteve Naroff  // TODO: Pass argument information.
154332ce8376efb7e0d70e5f7e8fcf685130293f412bSteve Naroff  Actions.ActOnFinishFunctionBody(MDecl, move(FnBody));
15441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1545409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff  // Leave the function body scope.
15468935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor  BodyScope.Exit();
1547798d119415323ebcd029ffe1e0fb442a4ca8adbbSebastian Redl
154871c0a951d08dc7a2a057df8c15f22b36f6aa47c7Steve Naroff  return MDecl;
15495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
15505508518a2702b00be3b15a26d772bde968972f54Anders Carlsson
155143bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian RedlParser::OwningStmtResult Parser::ParseObjCAtStatement(SourceLocation AtLoc) {
155264515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff  if (Tok.isObjCAtKeyword(tok::objc_try)) {
15536b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner    return ParseObjCTryStmt(AtLoc);
155464515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff  } else if (Tok.isObjCAtKeyword(tok::objc_throw))
155564515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff    return ParseObjCThrowStmt(AtLoc);
155664515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff  else if (Tok.isObjCAtKeyword(tok::objc_synchronized))
155764515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff    return ParseObjCSynchronizedStmt(AtLoc);
1558d8c4e15138e69a51754cc259c8a592cc47950c8eSebastian Redl  OwningExprResult Res(ParseExpressionWithLeadingAt(AtLoc));
15590e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl  if (Res.isInvalid()) {
156064515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff    // If the expression is invalid, skip ahead to the next semicolon. Not
156164515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff    // doing this opens us up to the possibility of infinite loops if
156264515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff    // ParseExpression does not consume any tokens.
156364515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff    SkipUntil(tok::semi);
156443bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl    return StmtError();
156564515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff  }
156664515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff  // Otherwise, eat the semicolon.
156764515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff  ExpectAndConsume(tok::semi, diag::err_expected_semi_after_expr);
15686b1d283fe879fb11d7ce7a69feecf66e77b0eaf3Anders Carlsson  return Actions.ActOnExprStmt(Actions.FullExpr(Res));
156964515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff}
157064515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff
15711d922960e083906a586609ac6978678147250177Sebastian RedlParser::OwningExprResult Parser::ParseObjCAtExpression(SourceLocation AtLoc) {
15725508518a2702b00be3b15a26d772bde968972f54Anders Carlsson  switch (Tok.getKind()) {
1573b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner  case tok::string_literal:    // primary-expression: string-literal
1574b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner  case tok::wide_string_literal:
15751d922960e083906a586609ac6978678147250177Sebastian Redl    return ParsePostfixExpressionSuffix(ParseObjCStringLiteral(AtLoc));
1576b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner  default:
15774fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner    if (Tok.getIdentifierInfo() == 0)
15781d922960e083906a586609ac6978678147250177Sebastian Redl      return ExprError(Diag(AtLoc, diag::err_unexpected_at));
15792f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl
15804fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner    switch (Tok.getIdentifierInfo()->getObjCKeywordID()) {
15814fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner    case tok::objc_encode:
15821d922960e083906a586609ac6978678147250177Sebastian Redl      return ParsePostfixExpressionSuffix(ParseObjCEncodeExpression(AtLoc));
15834fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner    case tok::objc_protocol:
15841d922960e083906a586609ac6978678147250177Sebastian Redl      return ParsePostfixExpressionSuffix(ParseObjCProtocolExpression(AtLoc));
15854fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner    case tok::objc_selector:
15861d922960e083906a586609ac6978678147250177Sebastian Redl      return ParsePostfixExpressionSuffix(ParseObjCSelectorExpression(AtLoc));
15874fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner    default:
15881d922960e083906a586609ac6978678147250177Sebastian Redl      return ExprError(Diag(AtLoc, diag::err_unexpected_at));
15894fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner    }
15905508518a2702b00be3b15a26d772bde968972f54Anders Carlsson  }
15915508518a2702b00be3b15a26d772bde968972f54Anders Carlsson}
15925508518a2702b00be3b15a26d772bde968972f54Anders Carlsson
15931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///   objc-message-expr:
15940ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///     '[' objc-receiver objc-message-args ']'
15950ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///
15960ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///   objc-receiver:
15970ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///     expression
15980ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///     class-name
15990ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///     type-name
16001d922960e083906a586609ac6978678147250177Sebastian RedlParser::OwningExprResult Parser::ParseObjCMessageExpression() {
1601699b66138ac307a32e238463e0eff513ff17d337Chris Lattner  assert(Tok.is(tok::l_square) && "'[' expected");
1602699b66138ac307a32e238463e0eff513ff17d337Chris Lattner  SourceLocation LBracLoc = ConsumeBracket(); // consume '['
1603699b66138ac307a32e238463e0eff513ff17d337Chris Lattner
1604699b66138ac307a32e238463e0eff513ff17d337Chris Lattner  // Parse receiver
160514dd98a7952c9559e0d17fff8272bf3be67135afChris Lattner  if (isTokObjCMessageIdentifierReceiver()) {
1606699b66138ac307a32e238463e0eff513ff17d337Chris Lattner    IdentifierInfo *ReceiverName = Tok.getIdentifierInfo();
1607d2869925b5f10e00b13fbf3f41bbb17e4c9adbe0Fariborz Jahanian    if (ReceiverName != Ident_super || GetLookAheadToken(1).isNot(tok::period)) {
1608d2869925b5f10e00b13fbf3f41bbb17e4c9adbe0Fariborz Jahanian      SourceLocation NameLoc = ConsumeToken();
1609d2869925b5f10e00b13fbf3f41bbb17e4c9adbe0Fariborz Jahanian      return ParseObjCMessageExpressionBody(LBracLoc, NameLoc, ReceiverName,
1610d2869925b5f10e00b13fbf3f41bbb17e4c9adbe0Fariborz Jahanian                                            ExprArg(Actions));
1611d2869925b5f10e00b13fbf3f41bbb17e4c9adbe0Fariborz Jahanian    }
1612699b66138ac307a32e238463e0eff513ff17d337Chris Lattner  }
1613699b66138ac307a32e238463e0eff513ff17d337Chris Lattner
16142f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl  OwningExprResult Res(ParseExpression());
16150e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl  if (Res.isInvalid()) {
16165c749428a9938d5e2e9564b1c9b7a9252c30ee27Chris Lattner    SkipUntil(tok::r_square);
16171d922960e083906a586609ac6978678147250177Sebastian Redl    return move(Res);
1618699b66138ac307a32e238463e0eff513ff17d337Chris Lattner  }
16191d922960e083906a586609ac6978678147250177Sebastian Redl
16200e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl  return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(),
162176ad2e85575722e8a38a2bd4648ab4304d9fcd24Sebastian Redl                                        0, move(Res));
1622699b66138ac307a32e238463e0eff513ff17d337Chris Lattner}
16231d922960e083906a586609ac6978678147250177Sebastian Redl
1624699b66138ac307a32e238463e0eff513ff17d337Chris Lattner/// ParseObjCMessageExpressionBody - Having parsed "'[' objc-receiver", parse
1625699b66138ac307a32e238463e0eff513ff17d337Chris Lattner/// the rest of a message expression.
16261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///
16270ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///   objc-message-args:
16280ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///     objc-selector
16290ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///     objc-keywordarg-list
16300ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///
16310ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///   objc-keywordarg-list:
16320ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///     objc-keywordarg
16330ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///     objc-keywordarg-list objc-keywordarg
16340ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///
16351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///   objc-keywordarg:
16360ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///     selector-name[opt] ':' objc-keywordexpr
16370ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///
16380ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///   objc-keywordexpr:
16390ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///     nonempty-expr-list
16400ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///
16410ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///   nonempty-expr-list:
16420ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///     assignment-expression
16430ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///     nonempty-expr-list , assignment-expression
16441d922960e083906a586609ac6978678147250177Sebastian Redl///
16451d922960e083906a586609ac6978678147250177Sebastian RedlParser::OwningExprResult
1646699b66138ac307a32e238463e0eff513ff17d337Chris LattnerParser::ParseObjCMessageExpressionBody(SourceLocation LBracLoc,
16475cb93b8bf009c4b0ae09b71ba85f54b2a7ea8022Steve Naroff                                       SourceLocation NameLoc,
1648699b66138ac307a32e238463e0eff513ff17d337Chris Lattner                                       IdentifierInfo *ReceiverName,
16491d922960e083906a586609ac6978678147250177Sebastian Redl                                       ExprArg ReceiverExpr) {
1650c4df6d2c05c647a6a5770ba0c749782b6c023a3aSteve Naroff  if (Tok.is(tok::code_completion)) {
1651c4df6d2c05c647a6a5770ba0c749782b6c023a3aSteve Naroff    if (ReceiverName)
1652d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor      Actions.CodeCompleteObjCClassMessage(CurScope, ReceiverName, NameLoc,
1653d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor                                           0, 0);
1654c4df6d2c05c647a6a5770ba0c749782b6c023a3aSteve Naroff    else
1655d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor      Actions.CodeCompleteObjCInstanceMessage(CurScope, ReceiverExpr.get(),
1656d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor                                              0, 0);
1657c4df6d2c05c647a6a5770ba0c749782b6c023a3aSteve Naroff    ConsumeToken();
1658c4df6d2c05c647a6a5770ba0c749782b6c023a3aSteve Naroff  }
1659d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor
1660a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian  // Parse objc-selector
16614b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian  SourceLocation Loc;
16622fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner  IdentifierInfo *selIdent = ParseObjCSelectorPiece(Loc);
166368d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff
1664ff975cfab9ada27df86038286d1678084aeb3428Anders Carlsson  SourceLocation SelectorLoc = Loc;
16651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
166668d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff  llvm::SmallVector<IdentifierInfo *, 12> KeyIdents;
1667a55e52c0802cae3b7c366a05c461d3d15074c1a3Sebastian Redl  ExprVector KeyExprs(Actions);
166868d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff
1669df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  if (Tok.is(tok::colon)) {
1670a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian    while (1) {
1671a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian      // Each iteration parses a single keyword argument.
167268d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff      KeyIdents.push_back(selIdent);
167337387c932855c6d58d70bdd705cd3a9fdcd2a931Steve Naroff
1674df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner      if (Tok.isNot(tok::colon)) {
1675a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian        Diag(Tok, diag::err_expected_colon);
16764fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner        // We must manually skip to a ']', otherwise the expression skipper will
16774fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner        // stop at the ']' when it skips to the ';'.  We want it to skip beyond
16784fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner        // the enclosing expression.
16794fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner        SkipUntil(tok::r_square);
16801d922960e083906a586609ac6978678147250177Sebastian Redl        return ExprError();
1681a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian      }
16821d922960e083906a586609ac6978678147250177Sebastian Redl
168368d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff      ConsumeToken(); // Eat the ':'.
16841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      ///  Parse the expression after ':'
16852f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl      OwningExprResult Res(ParseAssignmentExpression());
16860e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl      if (Res.isInvalid()) {
16874fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner        // We must manually skip to a ']', otherwise the expression skipper will
16884fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner        // stop at the ']' when it skips to the ';'.  We want it to skip beyond
16894fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner        // the enclosing expression.
16904fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner        SkipUntil(tok::r_square);
16911d922960e083906a586609ac6978678147250177Sebastian Redl        return move(Res);
169237387c932855c6d58d70bdd705cd3a9fdcd2a931Steve Naroff      }
16931d922960e083906a586609ac6978678147250177Sebastian Redl
169437387c932855c6d58d70bdd705cd3a9fdcd2a931Steve Naroff      // We have a valid expression.
1695effa8d1c97b00a3f53e972b0e61d9aade5ea1c57Sebastian Redl      KeyExprs.push_back(Res.release());
16961d922960e083906a586609ac6978678147250177Sebastian Redl
1697d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor      // Code completion after each argument.
1698d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor      if (Tok.is(tok::code_completion)) {
1699d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor        if (ReceiverName)
1700d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor          Actions.CodeCompleteObjCClassMessage(CurScope, ReceiverName, NameLoc,
1701d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor                                               KeyIdents.data(),
1702d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor                                               KeyIdents.size());
1703d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor        else
1704d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor          Actions.CodeCompleteObjCInstanceMessage(CurScope, ReceiverExpr.get(),
1705d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor                                                  KeyIdents.data(),
1706d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor                                                  KeyIdents.size());
1707d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor        ConsumeToken();
1708d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor      }
1709d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor
171037387c932855c6d58d70bdd705cd3a9fdcd2a931Steve Naroff      // Check for another keyword selector.
17112fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner      selIdent = ParseObjCSelectorPiece(Loc);
1712df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner      if (!selIdent && Tok.isNot(tok::colon))
1713a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian        break;
1714a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian      // We have a selector or a colon, continue parsing.
1715a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian    }
1716a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian    // Parse the, optional, argument list, comma separated.
1717df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner    while (Tok.is(tok::comma)) {
171849f109c786f99eb7468dac3976db083a65493444Steve Naroff      ConsumeToken(); // Eat the ','.
17191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      ///  Parse the expression after ','
17202f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl      OwningExprResult Res(ParseAssignmentExpression());
17210e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl      if (Res.isInvalid()) {
17224fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner        // We must manually skip to a ']', otherwise the expression skipper will
17234fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner        // stop at the ']' when it skips to the ';'.  We want it to skip beyond
17244fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner        // the enclosing expression.
17254fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner        SkipUntil(tok::r_square);
17261d922960e083906a586609ac6978678147250177Sebastian Redl        return move(Res);
172749f109c786f99eb7468dac3976db083a65493444Steve Naroff      }
17280e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl
172949f109c786f99eb7468dac3976db083a65493444Steve Naroff      // We have a valid expression.
1730effa8d1c97b00a3f53e972b0e61d9aade5ea1c57Sebastian Redl      KeyExprs.push_back(Res.release());
1731a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian    }
1732a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian  } else if (!selIdent) {
1733a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian    Diag(Tok, diag::err_expected_ident); // missing selector name.
17341d922960e083906a586609ac6978678147250177Sebastian Redl
17354fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner    // We must manually skip to a ']', otherwise the expression skipper will
17364fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner    // stop at the ']' when it skips to the ';'.  We want it to skip beyond
17374fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner    // the enclosing expression.
17384fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner    SkipUntil(tok::r_square);
17391d922960e083906a586609ac6978678147250177Sebastian Redl    return ExprError();
1740a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian  }
17411d922960e083906a586609ac6978678147250177Sebastian Redl
1742df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  if (Tok.isNot(tok::r_square)) {
1743a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian    Diag(Tok, diag::err_expected_rsquare);
17444fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner    // We must manually skip to a ']', otherwise the expression skipper will
17454fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner    // stop at the ']' when it skips to the ';'.  We want it to skip beyond
17464fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner    // the enclosing expression.
17474fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner    SkipUntil(tok::r_square);
17481d922960e083906a586609ac6978678147250177Sebastian Redl    return ExprError();
1749a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian  }
17501d922960e083906a586609ac6978678147250177Sebastian Redl
1751699b66138ac307a32e238463e0eff513ff17d337Chris Lattner  SourceLocation RBracLoc = ConsumeBracket(); // consume ']'
17521d922960e083906a586609ac6978678147250177Sebastian Redl
175329238a0bf7cbf5b396efb451a0adb5fe4aa037caSteve Naroff  unsigned nKeys = KeyIdents.size();
1754ff38491c18b060526d754765b952f4a497a89416Chris Lattner  if (nKeys == 0)
1755ff38491c18b060526d754765b952f4a497a89416Chris Lattner    KeyIdents.push_back(selIdent);
1756ff38491c18b060526d754765b952f4a497a89416Chris Lattner  Selector Sel = PP.getSelectorTable().getSelector(nKeys, &KeyIdents[0]);
17571d922960e083906a586609ac6978678147250177Sebastian Redl
1758ff38491c18b060526d754765b952f4a497a89416Chris Lattner  // We've just parsed a keyword message.
17591d922960e083906a586609ac6978678147250177Sebastian Redl  if (ReceiverName)
17601d922960e083906a586609ac6978678147250177Sebastian Redl    return Owned(Actions.ActOnClassMessage(CurScope, ReceiverName, Sel,
17611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                           LBracLoc, NameLoc, SelectorLoc,
1762ff975cfab9ada27df86038286d1678084aeb3428Anders Carlsson                                           RBracLoc,
17631d922960e083906a586609ac6978678147250177Sebastian Redl                                           KeyExprs.take(), KeyExprs.size()));
17641d922960e083906a586609ac6978678147250177Sebastian Redl  return Owned(Actions.ActOnInstanceMessage(ReceiverExpr.release(), Sel,
1765ff975cfab9ada27df86038286d1678084aeb3428Anders Carlsson                                            LBracLoc, SelectorLoc, RBracLoc,
17661d922960e083906a586609ac6978678147250177Sebastian Redl                                            KeyExprs.take(), KeyExprs.size()));
17670ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian}
17680ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian
17691d922960e083906a586609ac6978678147250177Sebastian RedlParser::OwningExprResult Parser::ParseObjCStringLiteral(SourceLocation AtLoc) {
177020df9b7ab9388b2a488c5b1293cd196b1e073b4eSebastian Redl  OwningExprResult Res(ParseStringLiteralExpression());
17711d922960e083906a586609ac6978678147250177Sebastian Redl  if (Res.isInvalid()) return move(Res);
17721d922960e083906a586609ac6978678147250177Sebastian Redl
1773b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner  // @"foo" @"bar" is a valid concatenated string.  Eat any subsequent string
1774b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner  // expressions.  At this point, we know that the only valid thing that starts
1775b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner  // with '@' is an @"".
1776b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner  llvm::SmallVector<SourceLocation, 4> AtLocs;
1777a55e52c0802cae3b7c366a05c461d3d15074c1a3Sebastian Redl  ExprVector AtStrings(Actions);
1778b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner  AtLocs.push_back(AtLoc);
1779effa8d1c97b00a3f53e972b0e61d9aade5ea1c57Sebastian Redl  AtStrings.push_back(Res.release());
17800e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl
1781b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner  while (Tok.is(tok::at)) {
1782b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner    AtLocs.push_back(ConsumeToken()); // eat the @.
1783b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner
178415faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl    // Invalid unless there is a string literal.
178597cf6eb380016db868866faf27a086cd55a316d4Chris Lattner    if (!isTokenStringLiteral())
178697cf6eb380016db868866faf27a086cd55a316d4Chris Lattner      return ExprError(Diag(Tok, diag::err_objc_concat_string));
1787b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner
178897cf6eb380016db868866faf27a086cd55a316d4Chris Lattner    OwningExprResult Lit(ParseStringLiteralExpression());
17890e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl    if (Lit.isInvalid())
17901d922960e083906a586609ac6978678147250177Sebastian Redl      return move(Lit);
17910e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl
1792effa8d1c97b00a3f53e972b0e61d9aade5ea1c57Sebastian Redl    AtStrings.push_back(Lit.release());
1793b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner  }
17941d922960e083906a586609ac6978678147250177Sebastian Redl
17951d922960e083906a586609ac6978678147250177Sebastian Redl  return Owned(Actions.ParseObjCStringLiteral(&AtLocs[0], AtStrings.take(),
17961d922960e083906a586609ac6978678147250177Sebastian Redl                                              AtStrings.size()));
17975508518a2702b00be3b15a26d772bde968972f54Anders Carlsson}
1798f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson
1799f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson///    objc-encode-expression:
1800f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson///      @encode ( type-name )
18011d922960e083906a586609ac6978678147250177Sebastian RedlParser::OwningExprResult
18021d922960e083906a586609ac6978678147250177Sebastian RedlParser::ParseObjCEncodeExpression(SourceLocation AtLoc) {
1803861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff  assert(Tok.isObjCAtKeyword(tok::objc_encode) && "Not an @encode expression!");
18041d922960e083906a586609ac6978678147250177Sebastian Redl
1805f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson  SourceLocation EncLoc = ConsumeToken();
18061d922960e083906a586609ac6978678147250177Sebastian Redl
18074fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner  if (Tok.isNot(tok::l_paren))
18081d922960e083906a586609ac6978678147250177Sebastian Redl    return ExprError(Diag(Tok, diag::err_expected_lparen_after) << "@encode");
18091d922960e083906a586609ac6978678147250177Sebastian Redl
1810f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson  SourceLocation LParenLoc = ConsumeParen();
18111d922960e083906a586609ac6978678147250177Sebastian Redl
1812809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor  TypeResult Ty = ParseTypeName();
18131d922960e083906a586609ac6978678147250177Sebastian Redl
18144988ae3fda10743c8ed8a98cdcb5a783362587b4Anders Carlsson  SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc);
18151d922960e083906a586609ac6978678147250177Sebastian Redl
1816809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor  if (Ty.isInvalid())
1817809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor    return ExprError();
1818809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor
18191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return Owned(Actions.ParseObjCEncodeExpression(AtLoc, EncLoc, LParenLoc,
1820809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor                                                 Ty.get(), RParenLoc));
1821f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson}
182229b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson
182329b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson///     objc-protocol-expression
182429b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson///       @protocol ( protocol-name )
18251d922960e083906a586609ac6978678147250177Sebastian RedlParser::OwningExprResult
18261d922960e083906a586609ac6978678147250177Sebastian RedlParser::ParseObjCProtocolExpression(SourceLocation AtLoc) {
182729b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson  SourceLocation ProtoLoc = ConsumeToken();
18281d922960e083906a586609ac6978678147250177Sebastian Redl
18294fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner  if (Tok.isNot(tok::l_paren))
18301d922960e083906a586609ac6978678147250177Sebastian Redl    return ExprError(Diag(Tok, diag::err_expected_lparen_after) << "@protocol");
18311d922960e083906a586609ac6978678147250177Sebastian Redl
183229b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson  SourceLocation LParenLoc = ConsumeParen();
18331d922960e083906a586609ac6978678147250177Sebastian Redl
18344fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner  if (Tok.isNot(tok::identifier))
18351d922960e083906a586609ac6978678147250177Sebastian Redl    return ExprError(Diag(Tok, diag::err_expected_ident));
18361d922960e083906a586609ac6978678147250177Sebastian Redl
1837390d50a725497e99247dc104a7d2c2a255d3af14Fariborz Jahanian  IdentifierInfo *protocolId = Tok.getIdentifierInfo();
183829b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson  ConsumeToken();
18391d922960e083906a586609ac6978678147250177Sebastian Redl
18404988ae3fda10743c8ed8a98cdcb5a783362587b4Anders Carlsson  SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc);
184129b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson
18421d922960e083906a586609ac6978678147250177Sebastian Redl  return Owned(Actions.ParseObjCProtocolExpression(protocolId, AtLoc, ProtoLoc,
18431d922960e083906a586609ac6978678147250177Sebastian Redl                                                   LParenLoc, RParenLoc));
184429b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson}
1845a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian
1846a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian///     objc-selector-expression
1847a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian///       @selector '(' objc-keyword-selector ')'
18481d922960e083906a586609ac6978678147250177Sebastian RedlParser::OwningExprResult
18491d922960e083906a586609ac6978678147250177Sebastian RedlParser::ParseObjCSelectorExpression(SourceLocation AtLoc) {
1850a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian  SourceLocation SelectorLoc = ConsumeToken();
18511d922960e083906a586609ac6978678147250177Sebastian Redl
18524fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner  if (Tok.isNot(tok::l_paren))
18531d922960e083906a586609ac6978678147250177Sebastian Redl    return ExprError(Diag(Tok, diag::err_expected_lparen_after) << "@selector");
18541d922960e083906a586609ac6978678147250177Sebastian Redl
1855b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian  llvm::SmallVector<IdentifierInfo *, 12> KeyIdents;
1856a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian  SourceLocation LParenLoc = ConsumeParen();
1857a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian  SourceLocation sLoc;
18582fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner  IdentifierInfo *SelIdent = ParseObjCSelectorPiece(sLoc);
18591d922960e083906a586609ac6978678147250177Sebastian Redl  if (!SelIdent && Tok.isNot(tok::colon)) // missing selector name.
18601d922960e083906a586609ac6978678147250177Sebastian Redl    return ExprError(Diag(Tok, diag::err_expected_ident));
18611d922960e083906a586609ac6978678147250177Sebastian Redl
1862b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian  KeyIdents.push_back(SelIdent);
1863887407e71fd58de452361b77d72970e32b20ebe0Steve Naroff  unsigned nColons = 0;
1864887407e71fd58de452361b77d72970e32b20ebe0Steve Naroff  if (Tok.isNot(tok::r_paren)) {
1865a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian    while (1) {
18664fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner      if (Tok.isNot(tok::colon))
18671d922960e083906a586609ac6978678147250177Sebastian Redl        return ExprError(Diag(Tok, diag::err_expected_colon));
18681d922960e083906a586609ac6978678147250177Sebastian Redl
1869cb53b361bce341c8591333c6997f62e480acc0b4Chris Lattner      nColons++;
1870a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian      ConsumeToken(); // Eat the ':'.
1871a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian      if (Tok.is(tok::r_paren))
1872a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian        break;
1873a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian      // Check for another keyword selector.
1874a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian      SourceLocation Loc;
18752fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner      SelIdent = ParseObjCSelectorPiece(Loc);
1876b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian      KeyIdents.push_back(SelIdent);
1877a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian      if (!SelIdent && Tok.isNot(tok::colon))
1878a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian        break;
1879a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian    }
1880887407e71fd58de452361b77d72970e32b20ebe0Steve Naroff  }
1881a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian  SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc);
1882887407e71fd58de452361b77d72970e32b20ebe0Steve Naroff  Selector Sel = PP.getSelectorTable().getSelector(nColons, &KeyIdents[0]);
18831d922960e083906a586609ac6978678147250177Sebastian Redl  return Owned(Actions.ParseObjCSelectorExpression(Sel, AtLoc, SelectorLoc,
18841d922960e083906a586609ac6978678147250177Sebastian Redl                                                   LParenLoc, RParenLoc));
188558065b2d8038a4e9a91ea4813bd1774c0f6efacbGabor Greif }
1886