ParseObjc.cpp revision a93b108e025ef2480fa867cc533e7781a40a639b
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
231dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///   objc-interface-decl-list:
232dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     empty
233dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     objc-interface-decl-list objc-property-decl [OBJC2]
234294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///     objc-interface-decl-list objc-method-requirement [OBJC2]
2353536b443bc50d58a79f14fca9b6842541a434854Steve Naroff///     objc-interface-decl-list objc-method-proto ';'
236dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     objc-interface-decl-list declaration
237dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     objc-interface-decl-list ';'
238dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///
239294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///   objc-method-requirement: [OBJC2]
240294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///     @required
241294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///     @optional
242294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///
243b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattnervoid Parser::ParseObjCInterfaceDeclList(DeclPtrTy interfaceDecl,
244cb53b361bce341c8591333c6997f62e480acc0b4Chris Lattner                                        tok::ObjCKeywordKind contextKey) {
245b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner  llvm::SmallVector<DeclPtrTy, 32> allMethods;
246b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner  llvm::SmallVector<DeclPtrTy, 16> allProperties;
247682bf92db408a6cbc3d37b5496a99b6ef85041ecChris Lattner  llvm::SmallVector<DeclGroupPtrTy, 8> allTUVariables;
24800933591a2795d09dd1acff12a2d21bce7cb12c5Fariborz Jahanian  tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword;
2491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
250bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner  SourceLocation AtEndLoc;
251bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner
252294494e1cce92043562b4680c613df7fd028c02eSteve Naroff  while (1) {
253e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner    // If this is a method prototype, parse it.
254df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner    if (Tok.is(tok::minus) || Tok.is(tok::plus)) {
2551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      DeclPtrTy methodPrototype =
256df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner        ParseObjCMethodPrototype(interfaceDecl, MethodImplKind);
25725e077d59a8e8e43b65882b69610a3d5e2aaf53cFariborz Jahanian      allMethods.push_back(methodPrototype);
2583536b443bc50d58a79f14fca9b6842541a434854Steve Naroff      // Consume the ';' here, since ParseObjCMethodPrototype() is re-used for
2593536b443bc50d58a79f14fca9b6842541a434854Steve Naroff      // method definitions.
260b6d74a158a9c002e3c0fcbda8ad8d0ccbb2e5088Chris Lattner      ExpectAndConsume(tok::semi, diag::err_expected_semi_after_method_proto,
261b6d74a158a9c002e3c0fcbda8ad8d0ccbb2e5088Chris Lattner                       "", tok::semi);
262294494e1cce92043562b4680c613df7fd028c02eSteve Naroff      continue;
263294494e1cce92043562b4680c613df7fd028c02eSteve Naroff    }
2641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
265e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner    // Ignore excess semicolons.
266e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner    if (Tok.is(tok::semi)) {
267294494e1cce92043562b4680c613df7fd028c02eSteve Naroff      ConsumeToken();
268e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner      continue;
269e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner    }
2701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
271bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner    // If we got to the end of the file, exit the loop.
272e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner    if (Tok.is(tok::eof))
273e3a2ca7e30601cdd31c77a830f4cc487851e8096Fariborz Jahanian      break;
2741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
275e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner    // If we don't have an @ directive, parse it as a function definition.
276e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner    if (Tok.isNot(tok::at)) {
2771fd80116b49782c367ff5d5f50a8b76dd8a5d7f7Chris Lattner      // The code below does not consume '}'s because it is afraid of eating the
2781fd80116b49782c367ff5d5f50a8b76dd8a5d7f7Chris Lattner      // end of a namespace.  Because of the way this code is structured, an
2791fd80116b49782c367ff5d5f50a8b76dd8a5d7f7Chris Lattner      // erroneous r_brace would cause an infinite loop if not handled here.
2801fd80116b49782c367ff5d5f50a8b76dd8a5d7f7Chris Lattner      if (Tok.is(tok::r_brace))
2811fd80116b49782c367ff5d5f50a8b76dd8a5d7f7Chris Lattner        break;
2821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2834985aceceb9b9261b876b515d32726175c13a775Steve Naroff      // FIXME: as the name implies, this rule allows function definitions.
2844985aceceb9b9261b876b515d32726175c13a775Steve Naroff      // We could pass a flag or check for functions during semantic analysis.
285682bf92db408a6cbc3d37b5496a99b6ef85041ecChris Lattner      allTUVariables.push_back(ParseDeclarationOrFunctionDefinition());
286e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner      continue;
287e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner    }
2881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
289e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner    // Otherwise, we have an @ directive, eat the @.
290e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner    SourceLocation AtLoc = ConsumeToken(); // the "@"
291a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner    tok::ObjCKeywordKind DirectiveKind = Tok.getObjCKeywordID();
2921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
293a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner    if (DirectiveKind == tok::objc_end) { // @end -> terminate list
294e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner      AtEndLoc = AtLoc;
295e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner      break;
296bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner    }
2971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
298bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner    // Eat the identifier.
299bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner    ConsumeToken();
300bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner
301a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner    switch (DirectiveKind) {
302a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner    default:
303bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner      // FIXME: If someone forgets an @end on a protocol, this loop will
304bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner      // continue to eat up tons of stuff and spew lots of nonsense errors.  It
305bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner      // would probably be better to bail out if we saw an @class or @interface
306bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner      // or something like that.
307f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner      Diag(AtLoc, diag::err_objc_illegal_interface_qual);
308bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner      // Skip until we see an '@' or '}' or ';'.
309a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner      SkipUntil(tok::r_brace, tok::at);
310a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner      break;
3111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
312a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner    case tok::objc_required:
313a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner    case tok::objc_optional:
314a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner      // This is only valid on protocols.
315bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner      // FIXME: Should this check for ObjC2 being enabled?
316e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner      if (contextKey != tok::objc_protocol)
317bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner        Diag(AtLoc, diag::err_objc_directive_only_in_protocol);
318a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner      else
319bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner        MethodImplKind = DirectiveKind;
320a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner      break;
3211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
322a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner    case tok::objc_property:
323f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner      if (!getLang().ObjC2)
324f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner        Diag(AtLoc, diag::err_objc_propertoes_require_objc2);
325f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner
326e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner      ObjCDeclSpec OCDS;
3271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      // Parse property attribute list, if any.
3288ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner      if (Tok.is(tok::l_paren))
329e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner        ParseObjCPropertyAttribute(OCDS);
3301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
331bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall      struct ObjCPropertyCallback : FieldCallback {
332bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall        Parser &P;
333bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall        DeclPtrTy IDecl;
334bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall        llvm::SmallVectorImpl<DeclPtrTy> &Props;
335bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall        ObjCDeclSpec &OCDS;
336bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall        SourceLocation AtLoc;
337bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall        tok::ObjCKeywordKind MethodImplKind;
338bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall
339bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall        ObjCPropertyCallback(Parser &P, DeclPtrTy IDecl,
340bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall                             llvm::SmallVectorImpl<DeclPtrTy> &Props,
341bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall                             ObjCDeclSpec &OCDS, SourceLocation AtLoc,
342bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall                             tok::ObjCKeywordKind MethodImplKind) :
343bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall          P(P), IDecl(IDecl), Props(Props), OCDS(OCDS), AtLoc(AtLoc),
344bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall          MethodImplKind(MethodImplKind) {
345bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall        }
346bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall
347bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall        DeclPtrTy invoke(FieldDeclarator &FD) {
348bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall          if (FD.D.getIdentifier() == 0) {
349bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall            P.Diag(AtLoc, diag::err_objc_property_requires_field_name)
350bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall              << FD.D.getSourceRange();
351bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall            return DeclPtrTy();
352bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall          }
353bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall          if (FD.BitfieldSize) {
354bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall            P.Diag(AtLoc, diag::err_objc_property_bitfield)
355bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall              << FD.D.getSourceRange();
356bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall            return DeclPtrTy();
357bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall          }
358bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall
359bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall          // Install the property declarator into interfaceDecl.
360bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall          IdentifierInfo *SelName =
361bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall            OCDS.getGetterName() ? OCDS.getGetterName() : FD.D.getIdentifier();
362bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall
363bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall          Selector GetterSel =
364bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall            P.PP.getSelectorTable().getNullarySelector(SelName);
365bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall          IdentifierInfo *SetterName = OCDS.getSetterName();
366bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall          Selector SetterSel;
367bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall          if (SetterName)
368bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall            SetterSel = P.PP.getSelectorTable().getSelector(1, &SetterName);
369bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall          else
370bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall            SetterSel = SelectorTable::constructSetterName(P.PP.getIdentifierTable(),
371bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall                                                           P.PP.getSelectorTable(),
372bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall                                                           FD.D.getIdentifier());
373bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall          bool isOverridingProperty = false;
374bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall          DeclPtrTy Property =
375bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall            P.Actions.ActOnProperty(P.CurScope, AtLoc, FD, OCDS,
376bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall                                    GetterSel, SetterSel, IDecl,
377bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall                                    &isOverridingProperty,
378bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall                                    MethodImplKind);
379bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall          if (!isOverridingProperty)
380bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall            Props.push_back(Property);
381bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall
382bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall          return Property;
383bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall        }
384bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall      } Callback(*this, interfaceDecl, allProperties,
385bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall                 OCDS, AtLoc, MethodImplKind);
386bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall
387e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner      // Parse all the comma separated declarators.
388e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner      DeclSpec DS;
389bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall      ParseStructDeclaration(DS, Callback);
3901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
391a1fed7e3beebf9bb1bc85123f283be3eb631c120Chris Lattner      ExpectAndConsume(tok::semi, diag::err_expected_semi_decl_list, "",
392a1fed7e3beebf9bb1bc85123f283be3eb631c120Chris Lattner                       tok::at);
393a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner      break;
394f28b264437053fb0deacc9ba02b18a0966f7290aSteve Naroff    }
395294494e1cce92043562b4680c613df7fd028c02eSteve Naroff  }
396bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner
397bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner  // We break out of the big loop in two cases: when we see @end or when we see
398bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner  // EOF.  In the former case, eat the @end.  In the later case, emit an error.
399bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner  if (Tok.isObjCAtKeyword(tok::objc_end))
400bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner    ConsumeToken(); // the "end" identifier
401bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner  else
402bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner    Diag(Tok, diag::err_objc_missing_end);
4031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
404a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner  // Insert collected methods declarations into the @interface object.
405bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner  // This passes in an invalid SourceLocation for AtEndLoc when EOF is hit.
4068a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek  Actions.ActOnAtEnd(AtEndLoc, interfaceDecl,
4071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                     allMethods.data(), allMethods.size(),
408beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad                     allProperties.data(), allProperties.size(),
409beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad                     allTUVariables.data(), allTUVariables.size());
410294494e1cce92043562b4680c613df7fd028c02eSteve Naroff}
411294494e1cce92043562b4680c613df7fd028c02eSteve Naroff
412d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian///   Parse property attribute declarations.
413d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian///
414d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian///   property-attr-decl: '(' property-attrlist ')'
415d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian///   property-attrlist:
416d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian///     property-attribute
417d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian///     property-attrlist ',' property-attribute
418d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian///   property-attribute:
419d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian///     getter '=' identifier
420d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian///     setter '=' identifier ':'
421d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian///     readonly
422d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian///     readwrite
423d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian///     assign
424d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian///     retain
425d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian///     copy
426d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian///     nonatomic
427d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian///
4287caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattnervoid Parser::ParseObjCPropertyAttribute(ObjCDeclSpec &DS) {
4298ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner  assert(Tok.getKind() == tok::l_paren);
430dd5b5f2bb73d037745940431b71eb98393d12d4fChris Lattner  SourceLocation LHSLoc = ConsumeParen(); // consume '('
4311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
432cd9f4b31c4fe5b77b5519cc17b4583fab912bad1Chris Lattner  while (1) {
433ece8e71d12b6f4cb2dc501297afef126dab8ad74Steve Naroff    if (Tok.is(tok::code_completion)) {
434a93b108e025ef2480fa867cc533e7781a40a639bDouglas Gregor      Actions.CodeCompleteObjCPropertyFlags(CurScope, DS);
435ece8e71d12b6f4cb2dc501297afef126dab8ad74Steve Naroff      ConsumeToken();
436ece8e71d12b6f4cb2dc501297afef126dab8ad74Steve Naroff    }
437d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian    const IdentifierInfo *II = Tok.getIdentifierInfo();
4381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
439f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner    // If this is not an identifier at all, bail out early.
440f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner    if (II == 0) {
441f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner      MatchRHSPunctuation(tok::r_paren, LHSLoc);
442f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner      return;
443f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner    }
4441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
445156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner    SourceLocation AttrName = ConsumeToken(); // consume last attribute name
4461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
44792e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner    if (II->isStr("readonly"))
448e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner      DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_readonly);
44992e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner    else if (II->isStr("assign"))
450e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner      DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_assign);
45192e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner    else if (II->isStr("readwrite"))
452e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner      DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_readwrite);
45392e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner    else if (II->isStr("retain"))
454e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner      DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_retain);
45592e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner    else if (II->isStr("copy"))
456e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner      DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_copy);
45792e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner    else if (II->isStr("nonatomic"))
458e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner      DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_nonatomic);
45992e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner    else if (II->isStr("getter") || II->isStr("setter")) {
460e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner      // getter/setter require extra treatment.
461156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner      if (ExpectAndConsume(tok::equal, diag::err_objc_expected_equal, "",
462156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner                           tok::r_paren))
463dd5b5f2bb73d037745940431b71eb98393d12d4fChris Lattner        return;
4641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4658ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner      if (Tok.isNot(tok::identifier)) {
4661ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner        Diag(Tok, diag::err_expected_ident);
4678ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner        SkipUntil(tok::r_paren);
4688ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner        return;
4698ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner      }
4701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
471e013d685c6689ac7ae103ee88acf573422d1ed6aDaniel Dunbar      if (II->getNameStart()[0] == 's') {
4728ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner        DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_setter);
4738ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner        DS.setSetterName(Tok.getIdentifierInfo());
474156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner        ConsumeToken();  // consume method name
4751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
476156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner        if (ExpectAndConsume(tok::colon, diag::err_expected_colon, "",
477156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner                             tok::r_paren))
4788ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner          return;
4798ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner      } else {
4808ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner        DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_getter);
4818ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner        DS.setGetterName(Tok.getIdentifierInfo());
482156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner        ConsumeToken();  // consume method name
4838ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner      }
484e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner    } else {
485a9500f05ba6c09bbd84d342236863833067cd816Chris Lattner      Diag(AttrName, diag::err_objc_expected_property_attr) << II;
486cd9f4b31c4fe5b77b5519cc17b4583fab912bad1Chris Lattner      SkipUntil(tok::r_paren);
487cd9f4b31c4fe5b77b5519cc17b4583fab912bad1Chris Lattner      return;
488cd9f4b31c4fe5b77b5519cc17b4583fab912bad1Chris Lattner    }
4891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
490156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner    if (Tok.isNot(tok::comma))
491156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner      break;
4921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
493156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner    ConsumeToken();
494d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian  }
4951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
496156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner  MatchRHSPunctuation(tok::r_paren, LHSLoc);
497d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian}
498d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian
4993536b443bc50d58a79f14fca9b6842541a434854Steve Naroff///   objc-method-proto:
5001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///     objc-instance-method objc-method-decl objc-method-attributes[opt]
5013536b443bc50d58a79f14fca9b6842541a434854Steve Naroff///     objc-class-method objc-method-decl objc-method-attributes[opt]
502294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///
503294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///   objc-instance-method: '-'
504294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///   objc-class-method: '+'
505294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///
5064985aceceb9b9261b876b515d32726175c13a775Steve Naroff///   objc-method-attributes:         [OBJC2]
5074985aceceb9b9261b876b515d32726175c13a775Steve Naroff///     __attribute__((deprecated))
5084985aceceb9b9261b876b515d32726175c13a775Steve Naroff///
5091eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpParser::DeclPtrTy Parser::ParseObjCMethodPrototype(DeclPtrTy IDecl,
510b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner                                          tok::ObjCKeywordKind MethodImplKind) {
511df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  assert((Tok.is(tok::minus) || Tok.is(tok::plus)) && "expected +/-");
512294494e1cce92043562b4680c613df7fd028c02eSteve Naroff
5131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  tok::TokenKind methodType = Tok.getKind();
514bef1185418705e16012b3dd50cd7c260c8d6b79cSteve Naroff  SourceLocation mLoc = ConsumeToken();
5151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
516b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner  DeclPtrTy MDecl = ParseObjCMethodDecl(mLoc, methodType, IDecl,MethodImplKind);
5173536b443bc50d58a79f14fca9b6842541a434854Steve Naroff  // Since this rule is used for both method declarations and definitions,
5182bd42fadafddc8acf744b57a970bdc96a077c617Steve Naroff  // the caller is (optionally) responsible for consuming the ';'.
519f28b264437053fb0deacc9ba02b18a0966f7290aSteve Naroff  return MDecl;
520294494e1cce92043562b4680c613df7fd028c02eSteve Naroff}
521294494e1cce92043562b4680c613df7fd028c02eSteve Naroff
522294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///   objc-selector:
523294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///     identifier
524294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///     one of
525294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///       enum struct union if else while do for switch case default
526294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///       break continue return goto asm sizeof typeof __alignof
527294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///       unsigned long const short volatile signed restrict _Complex
528294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///       in out inout bycopy byref oneway int char float double void _Bool
529294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///
5302fc5c2428ecb450a3256c8316b93b8655cb76a0fChris LattnerIdentifierInfo *Parser::ParseObjCSelectorPiece(SourceLocation &SelectorLoc) {
531ff38491c18b060526d754765b952f4a497a89416Chris Lattner  switch (Tok.getKind()) {
532ff38491c18b060526d754765b952f4a497a89416Chris Lattner  default:
533ff38491c18b060526d754765b952f4a497a89416Chris Lattner    return 0;
534ff38491c18b060526d754765b952f4a497a89416Chris Lattner  case tok::identifier:
535ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_asm:
536ff38491c18b060526d754765b952f4a497a89416Chris Lattner  case tok::kw_auto:
5379298d9655aed28b2d9f6cc65c81401b209f03fdcChris Lattner  case tok::kw_bool:
538ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_break:
539ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_case:
540ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_catch:
541ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_char:
542ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_class:
543ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_const:
544ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_const_cast:
545ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_continue:
546ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_default:
547ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_delete:
548ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_do:
549ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_double:
550ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_dynamic_cast:
551ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_else:
552ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_enum:
553ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_explicit:
554ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_export:
555ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_extern:
556ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_false:
557ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_float:
558ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_for:
559ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_friend:
560ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_goto:
561ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_if:
562ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_inline:
563ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_int:
564ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_long:
565ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_mutable:
566ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_namespace:
567ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_new:
568ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_operator:
569ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_private:
570ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_protected:
571ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_public:
572ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_register:
573ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_reinterpret_cast:
574ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_restrict:
575ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_return:
576ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_short:
577ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_signed:
578ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_sizeof:
579ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_static:
580ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_static_cast:
581ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_struct:
582ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_switch:
583ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_template:
584ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_this:
585ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_throw:
586ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_true:
587ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_try:
588ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_typedef:
589ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_typeid:
590ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_typename:
591ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_typeof:
592ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_union:
593ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_unsigned:
594ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_using:
595ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_virtual:
596ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_void:
597ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_volatile:
598ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_wchar_t:
599ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_while:
600ff38491c18b060526d754765b952f4a497a89416Chris Lattner  case tok::kw__Bool:
601ff38491c18b060526d754765b952f4a497a89416Chris Lattner  case tok::kw__Complex:
602ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw___alignof:
603ff38491c18b060526d754765b952f4a497a89416Chris Lattner    IdentifierInfo *II = Tok.getIdentifierInfo();
6044b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian    SelectorLoc = ConsumeToken();
605ff38491c18b060526d754765b952f4a497a89416Chris Lattner    return II;
606d064951b0dcc95f8604d0d69ae82d9ecbd38c796Fariborz Jahanian  }
607294494e1cce92043562b4680c613df7fd028c02eSteve Naroff}
608294494e1cce92043562b4680c613df7fd028c02eSteve Naroff
6090196cab54007ff072ec2642da8911c6b7e8d3fb5Fariborz Jahanian///  objc-for-collection-in: 'in'
6100196cab54007ff072ec2642da8911c6b7e8d3fb5Fariborz Jahanian///
611335a2d4122e41343fe11a775889b8bec5b14be60Fariborz Jahanianbool Parser::isTokIdentifier_in() const {
6123ba5a0f90a03d5e13d02cbee9abd2a1ba01b18bcFariborz Jahanian  // FIXME: May have to do additional look-ahead to only allow for
6133ba5a0f90a03d5e13d02cbee9abd2a1ba01b18bcFariborz Jahanian  // valid tokens following an 'in'; such as an identifier, unary operators,
6143ba5a0f90a03d5e13d02cbee9abd2a1ba01b18bcFariborz Jahanian  // '[' etc.
6151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return (getLang().ObjC2 && Tok.is(tok::identifier) &&
6165ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner          Tok.getIdentifierInfo() == ObjCTypeQuals[objc_in]);
6170196cab54007ff072ec2642da8911c6b7e8d3fb5Fariborz Jahanian}
6180196cab54007ff072ec2642da8911c6b7e8d3fb5Fariborz Jahanian
619a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ParseObjCTypeQualifierList - This routine parses the objective-c's type
620e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner/// qualifier list and builds their bitmask representation in the input
621e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner/// argument.
622294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///
623294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///   objc-type-qualifiers:
624294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///     objc-type-qualifier
625294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///     objc-type-qualifiers objc-type-qualifier
626294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///
627a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekvoid Parser::ParseObjCTypeQualifierList(ObjCDeclSpec &DS) {
628e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner  while (1) {
629cb53b361bce341c8591333c6997f62e480acc0b4Chris Lattner    if (Tok.isNot(tok::identifier))
630e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner      return;
6311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
632e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner    const IdentifierInfo *II = Tok.getIdentifierInfo();
633e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner    for (unsigned i = 0; i != objc_NumQuals; ++i) {
634a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek      if (II != ObjCTypeQuals[i])
635e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner        continue;
6361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
637a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek      ObjCDeclSpec::ObjCDeclQualifier Qual;
638e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner      switch (i) {
639e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner      default: assert(0 && "Unknown decl qualifier");
640a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek      case objc_in:     Qual = ObjCDeclSpec::DQ_In; break;
641a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek      case objc_out:    Qual = ObjCDeclSpec::DQ_Out; break;
642a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek      case objc_inout:  Qual = ObjCDeclSpec::DQ_Inout; break;
643a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek      case objc_oneway: Qual = ObjCDeclSpec::DQ_Oneway; break;
644a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek      case objc_bycopy: Qual = ObjCDeclSpec::DQ_Bycopy; break;
645a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek      case objc_byref:  Qual = ObjCDeclSpec::DQ_Byref; break;
646e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner      }
647a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek      DS.setObjCDeclQualifier(Qual);
648e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner      ConsumeToken();
649e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner      II = 0;
650e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner      break;
651e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner    }
6521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
653e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner    // If this wasn't a recognized qualifier, bail out.
654e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner    if (II) return;
655e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner  }
656e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner}
657e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner
658e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner///   objc-type-name:
659e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner///     '(' objc-type-qualifiers[opt] type-name ')'
660e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner///     '(' objc-type-qualifiers[opt] ')'
661e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner///
662a526c5c67e5a0473c340903ee542ce570119665fTed KremenekParser::TypeTy *Parser::ParseObjCTypeName(ObjCDeclSpec &DS) {
663df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  assert(Tok.is(tok::l_paren) && "expected (");
6641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6654a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner  SourceLocation LParenLoc = ConsumeParen();
666e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner  SourceLocation TypeStartLoc = Tok.getLocation();
6671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
66819d74e1494fe399f0e2a94e9419c095f8214851bFariborz Jahanian  // Parse type qualifiers, in, inout, etc.
669a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ParseObjCTypeQualifierList(DS);
6704fa7afd07421e7276d1717e4fdf43a5fdd65a622Steve Naroff
6714a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner  TypeTy *Ty = 0;
672809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor  if (isTypeSpecifierQualifier()) {
673809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor    TypeResult TypeSpec = ParseTypeName();
674809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor    if (!TypeSpec.isInvalid())
675809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor      Ty = TypeSpec.get();
676809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor  }
6771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6784a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner  if (Tok.is(tok::r_paren))
6794a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner    ConsumeParen();
6804a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner  else if (Tok.getLocation() == TypeStartLoc) {
681e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner    // If we didn't eat any tokens, then this isn't a type.
6821ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner    Diag(Tok, diag::err_expected_type);
6834a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner    SkipUntil(tok::r_paren);
6844a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner  } else {
6854a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner    // Otherwise, we found *something*, but didn't get a ')' in the right
6864a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner    // place.  Emit an error then return what we have as the type.
6874a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner    MatchRHSPunctuation(tok::r_paren, LParenLoc);
688294494e1cce92043562b4680c613df7fd028c02eSteve Naroff  }
689f28b264437053fb0deacc9ba02b18a0966f7290aSteve Naroff  return Ty;
690294494e1cce92043562b4680c613df7fd028c02eSteve Naroff}
691294494e1cce92043562b4680c613df7fd028c02eSteve Naroff
692294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///   objc-method-decl:
693294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///     objc-selector
6944985aceceb9b9261b876b515d32726175c13a775Steve Naroff///     objc-keyword-selector objc-parmlist[opt]
695294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///     objc-type-name objc-selector
6964985aceceb9b9261b876b515d32726175c13a775Steve Naroff///     objc-type-name objc-keyword-selector objc-parmlist[opt]
697294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///
698294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///   objc-keyword-selector:
6991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///     objc-keyword-decl
700294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///     objc-keyword-selector objc-keyword-decl
701294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///
702294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///   objc-keyword-decl:
7037ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff///     objc-selector ':' objc-type-name objc-keyword-attributes[opt] identifier
7047ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff///     objc-selector ':' objc-keyword-attributes[opt] identifier
7057ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff///     ':' objc-type-name objc-keyword-attributes[opt] identifier
7067ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff///     ':' objc-keyword-attributes[opt] identifier
707294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///
7084985aceceb9b9261b876b515d32726175c13a775Steve Naroff///   objc-parmlist:
7094985aceceb9b9261b876b515d32726175c13a775Steve Naroff///     objc-parms objc-ellipsis[opt]
710294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///
7114985aceceb9b9261b876b515d32726175c13a775Steve Naroff///   objc-parms:
7124985aceceb9b9261b876b515d32726175c13a775Steve Naroff///     objc-parms , parameter-declaration
713294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///
7144985aceceb9b9261b876b515d32726175c13a775Steve Naroff///   objc-ellipsis:
715294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///     , ...
716294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///
7177ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff///   objc-keyword-attributes:         [OBJC2]
7187ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff///     __attribute__((unused))
7197ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff///
720b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris LattnerParser::DeclPtrTy Parser::ParseObjCMethodDecl(SourceLocation mLoc,
721b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner                                              tok::TokenKind mType,
722b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner                                              DeclPtrTy IDecl,
723b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner                                          tok::ObjCKeywordKind MethodImplKind) {
72454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  ParsingDeclRAIIObject PD(*this);
72554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall
726e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner  // Parse the return type if present.
727ff38491c18b060526d754765b952f4a497a89416Chris Lattner  TypeTy *ReturnType = 0;
728a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCDeclSpec DSRet;
729df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  if (Tok.is(tok::l_paren))
730f1de0ca05e2df6f23bd559028693a12d1ebdaaf6Fariborz Jahanian    ReturnType = ParseObjCTypeName(DSRet);
7311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
732bef1185418705e16012b3dd50cd7c260c8d6b79cSteve Naroff  SourceLocation selLoc;
7332fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner  IdentifierInfo *SelIdent = ParseObjCSelectorPiece(selLoc);
734e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner
73584c431088693e216193094d1dbf327a01173f57fSteve Naroff  // An unnamed colon is valid.
73684c431088693e216193094d1dbf327a01173f57fSteve Naroff  if (!SelIdent && Tok.isNot(tok::colon)) { // missing selector name.
7371ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner    Diag(Tok, diag::err_expected_selector_for_method)
7381ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner      << SourceRange(mLoc, Tok.getLocation());
739e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner    // Skip until we get a ; or {}.
740e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner    SkipUntil(tok::r_brace);
741b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner    return DeclPtrTy();
742e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner  }
7431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
744439c65892cc8629bbf541e0b8bda6b64cbcc4e6bFariborz Jahanian  llvm::SmallVector<Declarator, 8> CargNames;
745df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  if (Tok.isNot(tok::colon)) {
746ff38491c18b060526d754765b952f4a497a89416Chris Lattner    // If attributes exist after the method, parse them.
747ff38491c18b060526d754765b952f4a497a89416Chris Lattner    AttributeList *MethodAttrs = 0;
7481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    if (getLang().ObjC2 && Tok.is(tok::kw___attribute))
749ff38491c18b060526d754765b952f4a497a89416Chris Lattner      MethodAttrs = ParseAttributes();
7501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
751ff38491c18b060526d754765b952f4a497a89416Chris Lattner    Selector Sel = PP.getSelectorTable().getNullarySelector(SelIdent);
75254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    DeclPtrTy Result
75354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall         = Actions.ActOnMethodDeclaration(mLoc, Tok.getLocation(),
7541f7b6f88f18d7f6b10265acec5d41c4ed1897487Fariborz Jahanian                                          mType, IDecl, DSRet, ReturnType, Sel,
7551c6a3cc88177c67498fccdf14cfdf09959214e41Ted Kremenek                                          0, CargNames, MethodAttrs,
7561c6a3cc88177c67498fccdf14cfdf09959214e41Ted Kremenek                                          MethodImplKind);
75754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    PD.complete(Result);
75854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    return Result;
759ff38491c18b060526d754765b952f4a497a89416Chris Lattner  }
760f28b264437053fb0deacc9ba02b18a0966f7290aSteve Naroff
76168d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff  llvm::SmallVector<IdentifierInfo *, 12> KeyIdents;
762e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner  llvm::SmallVector<Action::ObjCArgInfo, 12> ArgInfos;
7631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
764ff38491c18b060526d754765b952f4a497a89416Chris Lattner  while (1) {
765e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner    Action::ObjCArgInfo ArgInfo;
7661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
767ff38491c18b060526d754765b952f4a497a89416Chris Lattner    // Each iteration parses a single keyword argument.
768df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner    if (Tok.isNot(tok::colon)) {
769ff38491c18b060526d754765b952f4a497a89416Chris Lattner      Diag(Tok, diag::err_expected_colon);
770ff38491c18b060526d754765b952f4a497a89416Chris Lattner      break;
771ff38491c18b060526d754765b952f4a497a89416Chris Lattner    }
772ff38491c18b060526d754765b952f4a497a89416Chris Lattner    ConsumeToken(); // Eat the ':'.
7731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
774e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner    ArgInfo.Type = 0;
775e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner    if (Tok.is(tok::l_paren)) // Parse the argument type if present.
776e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner      ArgInfo.Type = ParseObjCTypeName(ArgInfo.DeclSpec);
777e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner
778ff38491c18b060526d754765b952f4a497a89416Chris Lattner    // If attributes exist before the argument name, parse them.
779e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner    ArgInfo.ArgAttrs = 0;
780df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner    if (getLang().ObjC2 && Tok.is(tok::kw___attribute))
781e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner      ArgInfo.ArgAttrs = ParseAttributes();
7827ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff
783df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner    if (Tok.isNot(tok::identifier)) {
784ff38491c18b060526d754765b952f4a497a89416Chris Lattner      Diag(Tok, diag::err_expected_ident); // missing argument name.
785ff38491c18b060526d754765b952f4a497a89416Chris Lattner      break;
7864985aceceb9b9261b876b515d32726175c13a775Steve Naroff    }
7871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
788e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner    ArgInfo.Name = Tok.getIdentifierInfo();
789e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner    ArgInfo.NameLoc = Tok.getLocation();
790ff38491c18b060526d754765b952f4a497a89416Chris Lattner    ConsumeToken(); // Eat the identifier.
7911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
792e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner    ArgInfos.push_back(ArgInfo);
793e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner    KeyIdents.push_back(SelIdent);
794e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner
795ff38491c18b060526d754765b952f4a497a89416Chris Lattner    // Check for another keyword selector.
7964b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian    SourceLocation Loc;
7972fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner    SelIdent = ParseObjCSelectorPiece(Loc);
798df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner    if (!SelIdent && Tok.isNot(tok::colon))
799ff38491c18b060526d754765b952f4a497a89416Chris Lattner      break;
800ff38491c18b060526d754765b952f4a497a89416Chris Lattner    // We have a selector or a colon, continue parsing.
801ff38491c18b060526d754765b952f4a497a89416Chris Lattner  }
8021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
803335eafa5be51f6440672a74c73d588af72e96732Steve Naroff  bool isVariadic = false;
8041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
805ff38491c18b060526d754765b952f4a497a89416Chris Lattner  // Parse the (optional) parameter list.
806df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  while (Tok.is(tok::comma)) {
807ff38491c18b060526d754765b952f4a497a89416Chris Lattner    ConsumeToken();
808df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner    if (Tok.is(tok::ellipsis)) {
809335eafa5be51f6440672a74c73d588af72e96732Steve Naroff      isVariadic = true;
8104985aceceb9b9261b876b515d32726175c13a775Steve Naroff      ConsumeToken();
811ff38491c18b060526d754765b952f4a497a89416Chris Lattner      break;
8124985aceceb9b9261b876b515d32726175c13a775Steve Naroff    }
813ff38491c18b060526d754765b952f4a497a89416Chris Lattner    DeclSpec DS;
814ff38491c18b060526d754765b952f4a497a89416Chris Lattner    ParseDeclarationSpecifiers(DS);
8151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    // Parse the declarator.
816ff38491c18b060526d754765b952f4a497a89416Chris Lattner    Declarator ParmDecl(DS, Declarator::PrototypeContext);
817ff38491c18b060526d754765b952f4a497a89416Chris Lattner    ParseDeclarator(ParmDecl);
818439c65892cc8629bbf541e0b8bda6b64cbcc4e6bFariborz Jahanian    CargNames.push_back(ParmDecl);
8194985aceceb9b9261b876b515d32726175c13a775Steve Naroff  }
8201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
821ff38491c18b060526d754765b952f4a497a89416Chris Lattner  // FIXME: Add support for optional parmameter list...
822e3a2ca7e30601cdd31c77a830f4cc487851e8096Fariborz Jahanian  // If attributes exist after the method, parse them.
823ff38491c18b060526d754765b952f4a497a89416Chris Lattner  AttributeList *MethodAttrs = 0;
8241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  if (getLang().ObjC2 && Tok.is(tok::kw___attribute))
825ff38491c18b060526d754765b952f4a497a89416Chris Lattner    MethodAttrs = ParseAttributes();
8261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8273688fc679389d67b6755e62406998f9ea84d886aFariborz Jahanian  if (KeyIdents.size() == 0)
8283688fc679389d67b6755e62406998f9ea84d886aFariborz Jahanian    return DeclPtrTy();
829ff38491c18b060526d754765b952f4a497a89416Chris Lattner  Selector Sel = PP.getSelectorTable().getSelector(KeyIdents.size(),
830ff38491c18b060526d754765b952f4a497a89416Chris Lattner                                                   &KeyIdents[0]);
83154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  DeclPtrTy Result
83254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall       = Actions.ActOnMethodDeclaration(mLoc, Tok.getLocation(),
8333688fc679389d67b6755e62406998f9ea84d886aFariborz Jahanian                                        mType, IDecl, DSRet, ReturnType, Sel,
8341c6a3cc88177c67498fccdf14cfdf09959214e41Ted Kremenek                                        &ArgInfos[0], CargNames, MethodAttrs,
835335eafa5be51f6440672a74c73d588af72e96732Steve Naroff                                        MethodImplKind, isVariadic);
83654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  PD.complete(Result);
83754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  return Result;
838294494e1cce92043562b4680c613df7fd028c02eSteve Naroff}
839294494e1cce92043562b4680c613df7fd028c02eSteve Naroff
840dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///   objc-protocol-refs:
841dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     '<' identifier-list '>'
842dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///
8437caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattnerbool Parser::
844b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris LattnerParseObjCProtocolReferences(llvm::SmallVectorImpl<Action::DeclPtrTy> &Protocols,
84571b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis                            llvm::SmallVectorImpl<SourceLocation> &ProtocolLocs,
84671b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis                            bool WarnOnDeclarations,
84771b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis                            SourceLocation &LAngleLoc, SourceLocation &EndLoc) {
848e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner  assert(Tok.is(tok::less) && "expected <");
8491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
85071b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis  LAngleLoc = ConsumeToken(); // the "<"
8511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
852e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner  llvm::SmallVector<IdentifierLocPair, 8> ProtocolIdents;
8531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
854e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner  while (1) {
85555385fe3e723cd675001e45f42d61adde6b7f075Douglas Gregor    if (Tok.is(tok::code_completion)) {
85655385fe3e723cd675001e45f42d61adde6b7f075Douglas Gregor      Actions.CodeCompleteObjCProtocolReferences(ProtocolIdents.data(),
85755385fe3e723cd675001e45f42d61adde6b7f075Douglas Gregor                                                 ProtocolIdents.size());
85855385fe3e723cd675001e45f42d61adde6b7f075Douglas Gregor      ConsumeToken();
85955385fe3e723cd675001e45f42d61adde6b7f075Douglas Gregor    }
86055385fe3e723cd675001e45f42d61adde6b7f075Douglas Gregor
861e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner    if (Tok.isNot(tok::identifier)) {
862e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner      Diag(Tok, diag::err_expected_ident);
863e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner      SkipUntil(tok::greater);
864e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner      return true;
865e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner    }
866e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner    ProtocolIdents.push_back(std::make_pair(Tok.getIdentifierInfo(),
867e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner                                       Tok.getLocation()));
86871b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis    ProtocolLocs.push_back(Tok.getLocation());
869e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner    ConsumeToken();
8701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
871e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner    if (Tok.isNot(tok::comma))
872e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner      break;
873e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner    ConsumeToken();
874e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner  }
8751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
876e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner  // Consume the '>'.
877e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner  if (Tok.isNot(tok::greater)) {
878e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner    Diag(Tok, diag::err_expected_greater);
879e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner    return true;
880e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner  }
8811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
882e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner  EndLoc = ConsumeAnyToken();
8831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
884e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner  // Convert the list of protocols identifiers into a list of protocol decls.
885e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner  Actions.FindProtocolDeclaration(WarnOnDeclarations,
886e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner                                  &ProtocolIdents[0], ProtocolIdents.size(),
887e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner                                  Protocols);
888e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner  return false;
889e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner}
890e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner
891dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///   objc-class-instance-variables:
892dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     '{' objc-instance-variable-decl-list[opt] '}'
893dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///
894dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///   objc-instance-variable-decl-list:
895dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     objc-visibility-spec
896dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     objc-instance-variable-decl ';'
897dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     ';'
898dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     objc-instance-variable-decl-list objc-visibility-spec
899dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     objc-instance-variable-decl-list objc-instance-variable-decl ';'
900dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     objc-instance-variable-decl-list ';'
901dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///
902dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///   objc-visibility-spec:
903dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     @private
904dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     @protected
905dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     @public
906ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff///     @package [OBJC2]
907dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///
908dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///   objc-instance-variable-decl:
9091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///     struct-declaration
910dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///
911b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattnervoid Parser::ParseObjCClassInstanceVariables(DeclPtrTy interfaceDecl,
91260fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff                                             SourceLocation atLoc) {
913df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  assert(Tok.is(tok::l_brace) && "expected {");
914b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner  llvm::SmallVector<DeclPtrTy, 32> AllIvarDecls;
915e13594279a952537ac903325efff57e3edca79d9Chris Lattner
9161a0d31a3d7f14ddc6370ba912c778aece6c12cf0Douglas Gregor  ParseScope ClassScope(this, Scope::DeclScope|Scope::ClassScope);
91772de6676bd30f9081ee4166bbe07b4c270258ce6Douglas Gregor
918ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff  SourceLocation LBraceLoc = ConsumeBrace(); // the "{"
9191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
920aa847fe3c88ee5e8d180e48537c58b805d48d95dFariborz Jahanian  tok::ObjCKeywordKind visibility = tok::objc_protected;
921ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff  // While we still have something to read, read the instance variables.
922df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  while (Tok.isNot(tok::r_brace) && Tok.isNot(tok::eof)) {
923ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff    // Each iteration of this loop reads one objc-instance-variable-decl.
9241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
925ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff    // Check for extraneous top-level semicolon.
926df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner    if (Tok.is(tok::semi)) {
927c2253f5ca170984fcd4f30f8823148e8cb71336bChris Lattner      Diag(Tok, diag::ext_extra_struct_semi)
928c2253f5ca170984fcd4f30f8823148e8cb71336bChris Lattner        << CodeModificationHint::CreateRemoval(SourceRange(Tok.getLocation()));
929ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff      ConsumeToken();
930ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff      continue;
931ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff    }
9321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
933ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff    // Set the default visibility to private.
934df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner    if (Tok.is(tok::at)) { // parse objc-visibility-spec
935ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff      ConsumeToken(); // eat the @ sign
936861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff      switch (Tok.getObjCKeywordID()) {
937ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff      case tok::objc_private:
938ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff      case tok::objc_public:
939ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff      case tok::objc_protected:
940ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff      case tok::objc_package:
941861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff        visibility = Tok.getObjCKeywordID();
942ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff        ConsumeToken();
9431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump        continue;
944ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff      default:
945ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff        Diag(Tok, diag::err_objc_illegal_visibility_spec);
946ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff        continue;
947ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff      }
948ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff    }
9491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
950bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall    struct ObjCIvarCallback : FieldCallback {
951bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall      Parser &P;
952bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall      DeclPtrTy IDecl;
953bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall      tok::ObjCKeywordKind visibility;
954bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall      llvm::SmallVectorImpl<DeclPtrTy> &AllIvarDecls;
955bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall
956bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall      ObjCIvarCallback(Parser &P, DeclPtrTy IDecl, tok::ObjCKeywordKind V,
957bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall                       llvm::SmallVectorImpl<DeclPtrTy> &AllIvarDecls) :
958bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall        P(P), IDecl(IDecl), visibility(V), AllIvarDecls(AllIvarDecls) {
959bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall      }
960bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall
961bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall      DeclPtrTy invoke(FieldDeclarator &FD) {
962bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall        // Install the declarator into the interface decl.
963bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall        DeclPtrTy Field
964bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall          = P.Actions.ActOnIvar(P.CurScope,
965bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall                                FD.D.getDeclSpec().getSourceRange().getBegin(),
966bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall                                IDecl, FD.D, FD.BitfieldSize, visibility);
967bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall        AllIvarDecls.push_back(Field);
968bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall        return Field;
969bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall      }
970bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall    } Callback(*this, interfaceDecl, visibility, AllIvarDecls);
971bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall
972e13594279a952537ac903325efff57e3edca79d9Chris Lattner    // Parse all the comma separated declarators.
973e13594279a952537ac903325efff57e3edca79d9Chris Lattner    DeclSpec DS;
974bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall    ParseStructDeclaration(DS, Callback);
9751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
976df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner    if (Tok.is(tok::semi)) {
977ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff      ConsumeToken();
978ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff    } else {
979ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff      Diag(Tok, diag::err_expected_semi_decl_list);
980ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff      // Skip to end of block or statement
981ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff      SkipUntil(tok::r_brace, true, true);
982ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff    }
983ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff  }
98460fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff  SourceLocation RBraceLoc = MatchRHSPunctuation(tok::r_brace, LBraceLoc);
9858749be53f53384e7846502791ceda6c657228d07Steve Naroff  // Call ActOnFields() even if we don't have any decls. This is useful
9868749be53f53384e7846502791ceda6c657228d07Steve Naroff  // for code rewriting tools that need to be aware of the empty list.
9878749be53f53384e7846502791ceda6c657228d07Steve Naroff  Actions.ActOnFields(CurScope, atLoc, interfaceDecl,
988beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad                      AllIvarDecls.data(), AllIvarDecls.size(),
9891bfe1c2129771c06fb58ae5e8c079ae30e138309Daniel Dunbar                      LBraceLoc, RBraceLoc, 0);
990ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff  return;
9915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
992dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff
993dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///   objc-protocol-declaration:
994dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     objc-protocol-definition
995dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     objc-protocol-forward-reference
996dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///
997dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///   objc-protocol-definition:
9981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///     @protocol identifier
9991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///       objc-protocol-refs[opt]
10001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///       objc-interface-decl-list
1001dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     @end
1002dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///
1003dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///   objc-protocol-forward-reference:
1004dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     @protocol identifier-list ';'
1005dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///
1006dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///   "@protocol identifier ;" should be resolved as "@protocol
10073536b443bc50d58a79f14fca9b6842541a434854Steve Naroff///   identifier-list ;": objc-interface-decl-list may not start with a
1008dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///   semicolon in the first alternative if objc-protocol-refs are omitted.
1009b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris LattnerParser::DeclPtrTy Parser::ParseObjCAtProtocolDeclaration(SourceLocation AtLoc,
1010b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner                                                      AttributeList *attrList) {
1011861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff  assert(Tok.isObjCAtKeyword(tok::objc_protocol) &&
10127ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff         "ParseObjCAtProtocolDeclaration(): Expected @protocol");
10137ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff  ConsumeToken(); // the "protocol" identifier
10141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1015083128f6b13dfa4fc615a838c49b516d901b1ac0Douglas Gregor  if (Tok.is(tok::code_completion)) {
1016083128f6b13dfa4fc615a838c49b516d901b1ac0Douglas Gregor    Actions.CodeCompleteObjCProtocolDecl(CurScope);
1017083128f6b13dfa4fc615a838c49b516d901b1ac0Douglas Gregor    ConsumeToken();
1018083128f6b13dfa4fc615a838c49b516d901b1ac0Douglas Gregor  }
1019083128f6b13dfa4fc615a838c49b516d901b1ac0Douglas Gregor
1020df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  if (Tok.isNot(tok::identifier)) {
10217ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff    Diag(Tok, diag::err_expected_ident); // missing protocol name.
1022b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner    return DeclPtrTy();
10237ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff  }
10247ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff  // Save the protocol name, then consume it.
10257ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff  IdentifierInfo *protocolName = Tok.getIdentifierInfo();
10267ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff  SourceLocation nameLoc = ConsumeToken();
10271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1028df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  if (Tok.is(tok::semi)) { // forward declaration of one protocol.
10297caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner    IdentifierLocPair ProtoInfo(protocolName, nameLoc);
10307ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff    ConsumeToken();
10311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return Actions.ActOnForwardProtocolDeclaration(AtLoc, &ProtoInfo, 1,
1032bc1c877fe28fb6a825f0b226a0a2da99e713ea03Fariborz Jahanian                                                   attrList);
10337ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff  }
10341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1035df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  if (Tok.is(tok::comma)) { // list of forward declarations.
10367caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner    llvm::SmallVector<IdentifierLocPair, 8> ProtocolRefs;
10377caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner    ProtocolRefs.push_back(std::make_pair(protocolName, nameLoc));
10387caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner
10397ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff    // Parse the list of forward declarations.
10407ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff    while (1) {
10417ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff      ConsumeToken(); // the ','
1042df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner      if (Tok.isNot(tok::identifier)) {
10437ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff        Diag(Tok, diag::err_expected_ident);
10447ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff        SkipUntil(tok::semi);
1045b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner        return DeclPtrTy();
10467ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff      }
10477caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner      ProtocolRefs.push_back(IdentifierLocPair(Tok.getIdentifierInfo(),
10487caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner                                               Tok.getLocation()));
10497ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff      ConsumeToken(); // the identifier
10501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1051df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner      if (Tok.isNot(tok::comma))
10527ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff        break;
10537ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff    }
10547ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff    // Consume the ';'.
10557ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff    if (ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@protocol"))
1056b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner      return DeclPtrTy();
10571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1058e440eb8158e71deb1e4ab11618ae3d680aac6da1Steve Naroff    return Actions.ActOnForwardProtocolDeclaration(AtLoc,
10591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                                   &ProtocolRefs[0],
1060bc1c877fe28fb6a825f0b226a0a2da99e713ea03Fariborz Jahanian                                                   ProtocolRefs.size(),
1061bc1c877fe28fb6a825f0b226a0a2da99e713ea03Fariborz Jahanian                                                   attrList);
10627caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner  }
10631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10647ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff  // Last, and definitely not least, parse a protocol declaration.
106571b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis  SourceLocation LAngleLoc, EndProtoLoc;
10667caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner
1067b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner  llvm::SmallVector<DeclPtrTy, 8> ProtocolRefs;
106871b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis  llvm::SmallVector<SourceLocation, 8> ProtocolLocs;
10697caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner  if (Tok.is(tok::less) &&
107071b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis      ParseObjCProtocolReferences(ProtocolRefs, ProtocolLocs, false,
107171b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis                                  LAngleLoc, EndProtoLoc))
1072b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner    return DeclPtrTy();
10731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1074b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner  DeclPtrTy ProtoType =
1075e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner    Actions.ActOnStartProtocolInterface(AtLoc, protocolName, nameLoc,
1076beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad                                        ProtocolRefs.data(),
1077beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad                                        ProtocolRefs.size(),
1078246e70f69cb8aeb67225c54690f1c6b25abd5a86Daniel Dunbar                                        EndProtoLoc, attrList);
107925e077d59a8e8e43b65882b69610a3d5e2aaf53cFariborz Jahanian  ParseObjCInterfaceDeclList(ProtoType, tok::objc_protocol);
1080bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner  return ProtoType;
1081dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff}
1082dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff
1083dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///   objc-implementation:
1084dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     objc-class-implementation-prologue
1085dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     objc-category-implementation-prologue
1086dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///
1087dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///   objc-class-implementation-prologue:
1088dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     @implementation identifier objc-superclass[opt]
1089dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///       objc-class-instance-variables[opt]
1090dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///
1091dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///   objc-category-implementation-prologue:
1092dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     @implementation identifier ( identifier )
1093b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris LattnerParser::DeclPtrTy Parser::ParseObjCAtImplementationDeclaration(
1094ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian  SourceLocation atLoc) {
1095ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian  assert(Tok.isObjCAtKeyword(tok::objc_implementation) &&
1096ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian         "ParseObjCAtImplementationDeclaration(): Expected @implementation");
1097ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian  ConsumeToken(); // the "implementation" identifier
10981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10993b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor  // Code completion after '@implementation'.
11003b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor  if (Tok.is(tok::code_completion)) {
11013b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor    Actions.CodeCompleteObjCImplementationDecl(CurScope);
11023b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor    ConsumeToken();
11033b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor  }
11043b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor
1105df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  if (Tok.isNot(tok::identifier)) {
1106ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian    Diag(Tok, diag::err_expected_ident); // missing class or category name.
1107b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner    return DeclPtrTy();
1108ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian  }
1109ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian  // We have a class or category name - consume it.
1110ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian  IdentifierInfo *nameId = Tok.getIdentifierInfo();
1111ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian  SourceLocation nameLoc = ConsumeToken(); // consume class or category name
11121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  if (Tok.is(tok::l_paren)) {
1114ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian    // we have a category implementation.
1115ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian    SourceLocation lparenLoc = ConsumeParen();
1116ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian    SourceLocation categoryLoc, rparenLoc;
1117ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian    IdentifierInfo *categoryId = 0;
11181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
111933ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor    if (Tok.is(tok::code_completion)) {
112033ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor      Actions.CodeCompleteObjCImplementationCategory(CurScope, nameId);
112133ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor      ConsumeToken();
112233ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor    }
112333ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor
1124df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner    if (Tok.is(tok::identifier)) {
1125ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian      categoryId = Tok.getIdentifierInfo();
1126ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian      categoryLoc = ConsumeToken();
1127ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian    } else {
1128ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian      Diag(Tok, diag::err_expected_ident); // missing category name.
1129b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner      return DeclPtrTy();
11301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    }
1131df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner    if (Tok.isNot(tok::r_paren)) {
1132ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian      Diag(Tok, diag::err_expected_rparen);
1133ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian      SkipUntil(tok::r_paren, false); // don't stop at ';'
1134b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner      return DeclPtrTy();
1135ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian    }
1136ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian    rparenLoc = ConsumeParen();
1137b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner    DeclPtrTy ImplCatType = Actions.ActOnStartCategoryImplementation(
11381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                    atLoc, nameId, nameLoc, categoryId,
11398f3fde00ad4d4f943321e338b914ae4740711c84Fariborz Jahanian                                    categoryLoc);
1140a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek    ObjCImpDecl = ImplCatType;
114163e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian    PendingObjCImpDecl.push_back(ObjCImpDecl);
1142b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner    return DeclPtrTy();
1143ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian  }
1144ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian  // We have a class implementation
1145ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian  SourceLocation superClassLoc;
1146ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian  IdentifierInfo *superClassId = 0;
1147df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  if (Tok.is(tok::colon)) {
1148ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian    // We have a super class
1149ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian    ConsumeToken();
1150df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner    if (Tok.isNot(tok::identifier)) {
1151ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian      Diag(Tok, diag::err_expected_ident); // missing super class name.
1152b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner      return DeclPtrTy();
1153ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian    }
1154ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian    superClassId = Tok.getIdentifierInfo();
1155ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian    superClassLoc = ConsumeToken(); // Consume super class name
1156ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian  }
1157b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner  DeclPtrTy ImplClsType = Actions.ActOnStartClassImplementation(
1158cb53b361bce341c8591333c6997f62e480acc0b4Chris Lattner                                  atLoc, nameId, nameLoc,
1159ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian                                  superClassId, superClassLoc);
11601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
116160fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff  if (Tok.is(tok::l_brace)) // we have ivars
116260fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff    ParseObjCClassInstanceVariables(ImplClsType/*FIXME*/, atLoc);
1163a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCImpDecl = ImplClsType;
116463e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian  PendingObjCImpDecl.push_back(ObjCImpDecl);
116563e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian
1166b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner  return DeclPtrTy();
11675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
116860fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff
1169b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris LattnerParser::DeclPtrTy Parser::ParseObjCAtEndDeclaration(SourceLocation atLoc) {
1170ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian  assert(Tok.isObjCAtKeyword(tok::objc_end) &&
1171ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian         "ParseObjCAtEndDeclaration(): Expected @end");
1172b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner  DeclPtrTy Result = ObjCImpDecl;
1173ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian  ConsumeToken(); // the "end" identifier
1174a6e3ac514c924879699c6b0b1201028f0091044fFariborz Jahanian  if (ObjCImpDecl) {
1175a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek    Actions.ActOnAtEnd(atLoc, ObjCImpDecl);
1176b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner    ObjCImpDecl = DeclPtrTy();
117763e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian    PendingObjCImpDecl.pop_back();
1178a6e3ac514c924879699c6b0b1201028f0091044fFariborz Jahanian  }
117994cdb25a49bd3716ab56ef6de0ea57d29e686bf2Fariborz Jahanian  else
118094cdb25a49bd3716ab56ef6de0ea57d29e686bf2Fariborz Jahanian    Diag(atLoc, diag::warn_expected_implementation); // missing @implementation
1181a6e3ac514c924879699c6b0b1201028f0091044fFariborz Jahanian  return Result;
11825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
1183e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian
11841ac7104947020a60430ba6f519cd5869af77046fFariborz JahanianParser::DeclGroupPtrTy Parser::RetrievePendingObjCImpDecl() {
118563e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian  if (PendingObjCImpDecl.empty())
118663e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian    return Actions.ConvertDeclToDeclGroup(DeclPtrTy());
118763e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian  DeclPtrTy ImpDecl = PendingObjCImpDecl.pop_back_val();
118863e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian  Actions.ActOnAtEnd(SourceLocation(), ImpDecl);
118963e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian  return Actions.ConvertDeclToDeclGroup(ImpDecl);
119063e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian}
119163e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian
1192e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian///   compatibility-alias-decl:
1193e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian///     @compatibility_alias alias-name  class-name ';'
1194e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian///
1195b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris LattnerParser::DeclPtrTy Parser::ParseObjCAtAliasDeclaration(SourceLocation atLoc) {
1196e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian  assert(Tok.isObjCAtKeyword(tok::objc_compatibility_alias) &&
1197e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian         "ParseObjCAtAliasDeclaration(): Expected @compatibility_alias");
1198e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian  ConsumeToken(); // consume compatibility_alias
1199df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  if (Tok.isNot(tok::identifier)) {
1200e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian    Diag(Tok, diag::err_expected_ident);
1201b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner    return DeclPtrTy();
1202e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian  }
1203243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian  IdentifierInfo *aliasId = Tok.getIdentifierInfo();
1204243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian  SourceLocation aliasLoc = ConsumeToken(); // consume alias-name
1205df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  if (Tok.isNot(tok::identifier)) {
1206e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian    Diag(Tok, diag::err_expected_ident);
1207b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner    return DeclPtrTy();
1208e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian  }
1209243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian  IdentifierInfo *classId = Tok.getIdentifierInfo();
1210243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian  SourceLocation classLoc = ConsumeToken(); // consume class-name;
1211243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian  if (Tok.isNot(tok::semi)) {
12121ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner    Diag(Tok, diag::err_expected_semi_after) << "@compatibility_alias";
1213b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner    return DeclPtrTy();
1214243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian  }
1215b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner  return Actions.ActOnCompatiblityAlias(atLoc, aliasId, aliasLoc,
1216b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner                                        classId, classLoc);
12175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
12185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1219ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian///   property-synthesis:
1220ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian///     @synthesize property-ivar-list ';'
1221ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian///
1222ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian///   property-ivar-list:
1223ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian///     property-ivar
1224ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian///     property-ivar-list ',' property-ivar
1225ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian///
1226ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian///   property-ivar:
1227ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian///     identifier
1228ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian///     identifier '=' identifier
1229ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian///
1230b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris LattnerParser::DeclPtrTy Parser::ParseObjCPropertySynthesize(SourceLocation atLoc) {
1231ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian  assert(Tok.isObjCAtKeyword(tok::objc_synthesize) &&
1232ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian         "ParseObjCPropertyDynamic(): Expected '@synthesize'");
1233f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian  SourceLocation loc = ConsumeToken(); // consume synthesize
12341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1235b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor  while (true) {
1236322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor    if (Tok.is(tok::code_completion)) {
1237424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor      Actions.CodeCompleteObjCPropertyDefinition(CurScope, ObjCImpDecl);
1238322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor      ConsumeToken();
1239322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor    }
1240322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor
1241b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor    if (Tok.isNot(tok::identifier)) {
1242b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor      Diag(Tok, diag::err_synthesized_property_name);
1243b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor      SkipUntil(tok::semi);
1244b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor      return DeclPtrTy();
1245b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor    }
1246b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor
1247f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian    IdentifierInfo *propertyIvar = 0;
1248f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian    IdentifierInfo *propertyId = Tok.getIdentifierInfo();
1249f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian    SourceLocation propertyLoc = ConsumeToken(); // consume property name
1250df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner    if (Tok.is(tok::equal)) {
1251ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian      // property '=' ivar-name
1252ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian      ConsumeToken(); // consume '='
1253322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor
1254322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor      if (Tok.is(tok::code_completion)) {
1255322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor        Actions.CodeCompleteObjCPropertySynthesizeIvar(CurScope, propertyId,
1256322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor                                                       ObjCImpDecl);
1257322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor        ConsumeToken();
1258322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor      }
1259322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor
1260df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner      if (Tok.isNot(tok::identifier)) {
1261ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian        Diag(Tok, diag::err_expected_ident);
1262ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian        break;
1263ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian      }
1264f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian      propertyIvar = Tok.getIdentifierInfo();
1265ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian      ConsumeToken(); // consume ivar-name
1266ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian    }
1267f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian    Actions.ActOnPropertyImplDecl(atLoc, propertyLoc, true, ObjCImpDecl,
1268f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian                                  propertyId, propertyIvar);
1269df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner    if (Tok.isNot(tok::comma))
1270ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian      break;
1271ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian    ConsumeToken(); // consume ','
1272ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian  }
1273b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor  if (Tok.isNot(tok::semi)) {
12741ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner    Diag(Tok, diag::err_expected_semi_after) << "@synthesize";
1275b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor    SkipUntil(tok::semi);
1276b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor  }
1277d3fdcb5a1bf6bd5e54e18579c054ea3c292a0e28Fariborz Jahanian  else
1278d3fdcb5a1bf6bd5e54e18579c054ea3c292a0e28Fariborz Jahanian    ConsumeToken(); // consume ';'
1279b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner  return DeclPtrTy();
1280ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian}
1281ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian
1282ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian///   property-dynamic:
1283ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian///     @dynamic  property-list
1284ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian///
1285ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian///   property-list:
1286ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian///     identifier
1287ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian///     property-list ',' identifier
1288ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian///
1289b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris LattnerParser::DeclPtrTy Parser::ParseObjCPropertyDynamic(SourceLocation atLoc) {
1290ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian  assert(Tok.isObjCAtKeyword(tok::objc_dynamic) &&
1291ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian         "ParseObjCPropertyDynamic(): Expected '@dynamic'");
1292ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian  SourceLocation loc = ConsumeToken(); // consume dynamic
1293424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor  while (true) {
1294424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor    if (Tok.is(tok::code_completion)) {
1295424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor      Actions.CodeCompleteObjCPropertyDefinition(CurScope, ObjCImpDecl);
1296424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor      ConsumeToken();
1297424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor    }
1298424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor
1299424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor    if (Tok.isNot(tok::identifier)) {
1300424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor      Diag(Tok, diag::err_expected_ident);
1301424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor      SkipUntil(tok::semi);
1302424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor      return DeclPtrTy();
1303424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor    }
1304424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor
1305c35b9e4e2efad727538c848cf30d4b0eb1031dc9Fariborz Jahanian    IdentifierInfo *propertyId = Tok.getIdentifierInfo();
1306c35b9e4e2efad727538c848cf30d4b0eb1031dc9Fariborz Jahanian    SourceLocation propertyLoc = ConsumeToken(); // consume property name
1307c35b9e4e2efad727538c848cf30d4b0eb1031dc9Fariborz Jahanian    Actions.ActOnPropertyImplDecl(atLoc, propertyLoc, false, ObjCImpDecl,
1308c35b9e4e2efad727538c848cf30d4b0eb1031dc9Fariborz Jahanian                                  propertyId, 0);
1309c35b9e4e2efad727538c848cf30d4b0eb1031dc9Fariborz Jahanian
1310df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner    if (Tok.isNot(tok::comma))
1311ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian      break;
1312ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian    ConsumeToken(); // consume ','
1313ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian  }
1314df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  if (Tok.isNot(tok::semi))
13151ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner    Diag(Tok, diag::err_expected_semi_after) << "@dynamic";
1316b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner  return DeclPtrTy();
1317ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian}
13181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1319397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian///  objc-throw-statement:
1320397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian///    throw expression[opt];
1321397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian///
132243bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian RedlParser::OwningStmtResult Parser::ParseObjCThrowStmt(SourceLocation atLoc) {
132315faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl  OwningExprResult Res(Actions);
1324397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian  ConsumeToken(); // consume throw
1325df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  if (Tok.isNot(tok::semi)) {
132639f8f159c488a900e5958d5aab3e467af9ec8a2bFariborz Jahanian    Res = ParseExpression();
13270e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl    if (Res.isInvalid()) {
1328397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian      SkipUntil(tok::semi);
132943bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl      return StmtError();
1330397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian    }
1331397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian  }
133239f8f159c488a900e5958d5aab3e467af9ec8a2bFariborz Jahanian  ConsumeToken(); // consume ';'
1333e21dd6ffef4585fa43cd3586ed971217d65bf56cSteve Naroff  return Actions.ActOnObjCAtThrowStmt(atLoc, move(Res), CurScope);
1334397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian}
1335397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian
1336c385c90c68dfa376650e2facfbb444b2ec9bd110Fariborz Jahanian/// objc-synchronized-statement:
133778a677bbb5fa115fa0995b5783adeeefad67167eFariborz Jahanian///   @synchronized '(' expression ')' compound-statement
1338c385c90c68dfa376650e2facfbb444b2ec9bd110Fariborz Jahanian///
133943bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian RedlParser::OwningStmtResult
134043bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian RedlParser::ParseObjCSynchronizedStmt(SourceLocation atLoc) {
1341fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian  ConsumeToken(); // consume synchronized
1342fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian  if (Tok.isNot(tok::l_paren)) {
13431ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner    Diag(Tok, diag::err_expected_lparen_after) << "@synchronized";
134443bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl    return StmtError();
1345fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian  }
1346fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian  ConsumeParen();  // '('
13472f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl  OwningExprResult Res(ParseExpression());
13480e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl  if (Res.isInvalid()) {
1349fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian    SkipUntil(tok::semi);
135043bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl    return StmtError();
1351fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian  }
1352fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian  if (Tok.isNot(tok::r_paren)) {
13531ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner    Diag(Tok, diag::err_expected_lbrace);
135443bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl    return StmtError();
1355fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian  }
1356fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian  ConsumeParen();  // ')'
135778a677bbb5fa115fa0995b5783adeeefad67167eFariborz Jahanian  if (Tok.isNot(tok::l_brace)) {
13581ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner    Diag(Tok, diag::err_expected_lbrace);
135943bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl    return StmtError();
136078a677bbb5fa115fa0995b5783adeeefad67167eFariborz Jahanian  }
13613ac438c383a4a9a73c76a05c76ec5d02f10a3c52Steve Naroff  // Enter a scope to hold everything within the compound stmt.  Compound
13623ac438c383a4a9a73c76a05c76ec5d02f10a3c52Steve Naroff  // statements can always hold declarations.
13638935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor  ParseScope BodyScope(this, Scope::DeclScope);
13643ac438c383a4a9a73c76a05c76ec5d02f10a3c52Steve Naroff
136561364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl  OwningStmtResult SynchBody(ParseCompoundStatementBody());
13660e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl
13678935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor  BodyScope.Exit();
13680e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl  if (SynchBody.isInvalid())
1369fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian    SynchBody = Actions.ActOnNullStmt(Tok.getLocation());
137076ad2e85575722e8a38a2bd4648ab4304d9fcd24Sebastian Redl  return Actions.ActOnObjCAtSynchronizedStmt(atLoc, move(Res), move(SynchBody));
1371c385c90c68dfa376650e2facfbb444b2ec9bd110Fariborz Jahanian}
1372c385c90c68dfa376650e2facfbb444b2ec9bd110Fariborz Jahanian
1373397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian///  objc-try-catch-statement:
1374397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian///    @try compound-statement objc-catch-list[opt]
1375397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian///    @try compound-statement objc-catch-list[opt] @finally compound-statement
1376397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian///
1377397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian///  objc-catch-list:
1378397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian///    @catch ( parameter-declaration ) compound-statement
1379397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian///    objc-catch-list @catch ( catch-parameter-declaration ) compound-statement
1380397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian///  catch-parameter-declaration:
1381397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian///     parameter-declaration
1382397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian///     '...' [OBJC2]
1383397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian///
138443bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian RedlParser::OwningStmtResult Parser::ParseObjCTryStmt(SourceLocation atLoc) {
1385397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian  bool catch_or_finally_seen = false;
138643bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl
1387397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian  ConsumeToken(); // consume try
1388df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  if (Tok.isNot(tok::l_brace)) {
13891ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner    Diag(Tok, diag::err_expected_lbrace);
139043bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl    return StmtError();
1391397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian  }
139215faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl  OwningStmtResult CatchStmts(Actions);
139315faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl  OwningStmtResult FinallyStmt(Actions);
13948935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor  ParseScope TryScope(this, Scope::DeclScope);
139561364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl  OwningStmtResult TryBody(ParseCompoundStatementBody());
13968935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor  TryScope.Exit();
13970e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl  if (TryBody.isInvalid())
1398bd49a647afd9cc534fef13cadf652d4e9c396e2bFariborz Jahanian    TryBody = Actions.ActOnNullStmt(Tok.getLocation());
1399a55e52c0802cae3b7c366a05c461d3d15074c1a3Sebastian Redl
1400df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  while (Tok.is(tok::at)) {
14016b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner    // At this point, we need to lookahead to determine if this @ is the start
14026b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner    // of an @catch or @finally.  We don't want to consume the @ token if this
14036b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner    // is an @try or @encode or something else.
14046b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner    Token AfterAt = GetLookAheadToken(1);
14056b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner    if (!AfterAt.isObjCAtKeyword(tok::objc_catch) &&
14066b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner        !AfterAt.isObjCAtKeyword(tok::objc_finally))
14076b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner      break;
14080e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl
1409161a9c5afaafb4d527b7efba9675a8b2cbbe32e0Fariborz Jahanian    SourceLocation AtCatchFinallyLoc = ConsumeToken();
1410cb53b361bce341c8591333c6997f62e480acc0b4Chris Lattner    if (Tok.isObjCAtKeyword(tok::objc_catch)) {
1411b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner      DeclPtrTy FirstPart;
14123b1191d7eaf2f4984564e01ab84b6713a9d80e70Fariborz Jahanian      ConsumeToken(); // consume catch
1413df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner      if (Tok.is(tok::l_paren)) {
1414397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian        ConsumeParen();
1415e21dd6ffef4585fa43cd3586ed971217d65bf56cSteve Naroff        ParseScope CatchScope(this, Scope::DeclScope|Scope::AtCatchScope);
1416df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner        if (Tok.isNot(tok::ellipsis)) {
1417397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian          DeclSpec DS;
1418397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian          ParseDeclarationSpecifiers(DS);
141943bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl          // For some odd reason, the name of the exception variable is
14201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump          // optional. As a result, we need to use "PrototypeContext", because
14217ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff          // we must accept either 'declarator' or 'abstract-declarator' here.
14227ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff          Declarator ParmDecl(DS, Declarator::PrototypeContext);
14237ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff          ParseDeclarator(ParmDecl);
14247ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff
14257ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff          // Inform the actions module about the parameter declarator, so it
14267ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff          // gets added to the current scope.
14277ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff          FirstPart = Actions.ActOnParamDeclarator(CurScope, ParmDecl);
142864515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff        } else
1429397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian          ConsumeToken(); // consume '...'
14301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
143193a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff        SourceLocation RParenLoc;
14321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
143393a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff        if (Tok.is(tok::r_paren))
143493a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff          RParenLoc = ConsumeParen();
143593a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff        else // Skip over garbage, until we get to ')'.  Eat the ')'.
143693a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff          SkipUntil(tok::r_paren, true, false);
143793a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff
143815faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl        OwningStmtResult CatchBody(Actions, true);
1439c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner        if (Tok.is(tok::l_brace))
1440c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner          CatchBody = ParseCompoundStatementBody();
1441c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner        else
1442c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner          Diag(Tok, diag::err_expected_lbrace);
14430e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl        if (CatchBody.isInvalid())
14443b1191d7eaf2f4984564e01ab84b6713a9d80e70Fariborz Jahanian          CatchBody = Actions.ActOnNullStmt(Tok.getLocation());
14450e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl        CatchStmts = Actions.ActOnObjCAtCatchStmt(AtCatchFinallyLoc,
14467ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff                        RParenLoc, FirstPart, move(CatchBody),
144776ad2e85575722e8a38a2bd4648ab4304d9fcd24Sebastian Redl                        move(CatchStmts));
144864515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff      } else {
14491ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner        Diag(AtCatchFinallyLoc, diag::err_expected_lparen_after)
14501ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner          << "@catch clause";
145143bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl        return StmtError();
1452397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian      }
1453397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian      catch_or_finally_seen = true;
14546b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner    } else {
14556b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner      assert(Tok.isObjCAtKeyword(tok::objc_finally) && "Lookahead confused?");
145664515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff      ConsumeToken(); // consume finally
14578935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor      ParseScope FinallyScope(this, Scope::DeclScope);
14580e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl
145915faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl      OwningStmtResult FinallyBody(Actions, true);
1460c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner      if (Tok.is(tok::l_brace))
1461c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner        FinallyBody = ParseCompoundStatementBody();
1462c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner      else
1463c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner        Diag(Tok, diag::err_expected_lbrace);
14640e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl      if (FinallyBody.isInvalid())
1465161a9c5afaafb4d527b7efba9675a8b2cbbe32e0Fariborz Jahanian        FinallyBody = Actions.ActOnNullStmt(Tok.getLocation());
14660e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl      FinallyStmt = Actions.ActOnObjCAtFinallyStmt(AtCatchFinallyLoc,
146776ad2e85575722e8a38a2bd4648ab4304d9fcd24Sebastian Redl                                                   move(FinallyBody));
1468397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian      catch_or_finally_seen = true;
1469397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian      break;
1470397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian    }
1471397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian  }
1472bd49a647afd9cc534fef13cadf652d4e9c396e2bFariborz Jahanian  if (!catch_or_finally_seen) {
1473397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian    Diag(atLoc, diag::err_missing_catch_finally);
147443bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl    return StmtError();
1475bd49a647afd9cc534fef13cadf652d4e9c396e2bFariborz Jahanian  }
147676ad2e85575722e8a38a2bd4648ab4304d9fcd24Sebastian Redl  return Actions.ActOnObjCAtTryStmt(atLoc, move(TryBody), move(CatchStmts),
147776ad2e85575722e8a38a2bd4648ab4304d9fcd24Sebastian Redl                                    move(FinallyStmt));
1478397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian}
1479ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian
14803536b443bc50d58a79f14fca9b6842541a434854Steve Naroff///   objc-method-def: objc-method-proto ';'[opt] '{' body '}'
1481ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian///
1482b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris LattnerParser::DeclPtrTy Parser::ParseObjCMethodDefinition() {
1483b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner  DeclPtrTy MDecl = ParseObjCMethodPrototype(ObjCImpDecl);
14841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
148549f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner  PrettyStackTraceActionsDecl CrashInfo(MDecl, Tok.getLocation(), Actions,
148649f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner                                        PP.getSourceManager(),
148749f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner                                        "parsing Objective-C method");
14881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1489ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian  // parse optional ';'
1490209a8c2fa23636f6d065d618e7078e164903f5cdFariborz Jahanian  if (Tok.is(tok::semi)) {
1491496e45ef3350fabc312c5a807d308c65c50af4dbTed Kremenek    if (ObjCImpDecl) {
1492496e45ef3350fabc312c5a807d308c65c50af4dbTed Kremenek      Diag(Tok, diag::warn_semicolon_before_method_body)
1493496e45ef3350fabc312c5a807d308c65c50af4dbTed Kremenek        << CodeModificationHint::CreateRemoval(SourceRange(Tok.getLocation()));
1494496e45ef3350fabc312c5a807d308c65c50af4dbTed Kremenek    }
1495ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian    ConsumeToken();
1496209a8c2fa23636f6d065d618e7078e164903f5cdFariborz Jahanian  }
1497ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian
1498409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff  // We should have an opening brace now.
1499df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  if (Tok.isNot(tok::l_brace)) {
1500da323adbb99cee19a203ead852d5d9bfebb23fb7Steve Naroff    Diag(Tok, diag::err_expected_method_body);
15011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1502409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff    // Skip over garbage, until we get to '{'.  Don't eat the '{'.
1503409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff    SkipUntil(tok::l_brace, true, true);
15041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1505409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff    // If we didn't find the '{', bail out.
1506409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff    if (Tok.isNot(tok::l_brace))
1507b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner      return DeclPtrTy();
1508ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian  }
1509409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff  SourceLocation BraceLoc = Tok.getLocation();
15101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1511409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff  // Enter a scope for the method body.
15128935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor  ParseScope BodyScope(this, Scope::FnScope|Scope::DeclScope);
15131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1514409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff  // Tell the actions module that we have entered a method definition with the
1515394f3f483fa4e7b472630cfcd03f7840520958c5Steve Naroff  // specified Declarator for the method.
1516ebf6443a4f493233f7e8d92b3a991848c8b1c00dSteve Naroff  Actions.ActOnStartOfObjCMethodDef(CurScope, MDecl);
151761364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl
151861364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl  OwningStmtResult FnBody(ParseCompoundStatementBody());
151961364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl
1520409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff  // If the function body could not be parsed, make a bogus compoundstmt.
15210e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl  if (FnBody.isInvalid())
1522a60528cdac7deee3991c2b48af4df4f315e49e9dSebastian Redl    FnBody = Actions.ActOnCompoundStmt(BraceLoc, BraceLoc,
1523a60528cdac7deee3991c2b48af4df4f315e49e9dSebastian Redl                                       MultiStmtArg(Actions), false);
1524798d119415323ebcd029ffe1e0fb442a4ca8adbbSebastian Redl
152532ce8376efb7e0d70e5f7e8fcf685130293f412bSteve Naroff  // TODO: Pass argument information.
152632ce8376efb7e0d70e5f7e8fcf685130293f412bSteve Naroff  Actions.ActOnFinishFunctionBody(MDecl, move(FnBody));
15271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1528409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff  // Leave the function body scope.
15298935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor  BodyScope.Exit();
1530798d119415323ebcd029ffe1e0fb442a4ca8adbbSebastian Redl
153171c0a951d08dc7a2a057df8c15f22b36f6aa47c7Steve Naroff  return MDecl;
15325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
15335508518a2702b00be3b15a26d772bde968972f54Anders Carlsson
153443bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian RedlParser::OwningStmtResult Parser::ParseObjCAtStatement(SourceLocation AtLoc) {
153564515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff  if (Tok.isObjCAtKeyword(tok::objc_try)) {
15366b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner    return ParseObjCTryStmt(AtLoc);
153764515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff  } else if (Tok.isObjCAtKeyword(tok::objc_throw))
153864515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff    return ParseObjCThrowStmt(AtLoc);
153964515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff  else if (Tok.isObjCAtKeyword(tok::objc_synchronized))
154064515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff    return ParseObjCSynchronizedStmt(AtLoc);
1541d8c4e15138e69a51754cc259c8a592cc47950c8eSebastian Redl  OwningExprResult Res(ParseExpressionWithLeadingAt(AtLoc));
15420e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl  if (Res.isInvalid()) {
154364515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff    // If the expression is invalid, skip ahead to the next semicolon. Not
154464515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff    // doing this opens us up to the possibility of infinite loops if
154564515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff    // ParseExpression does not consume any tokens.
154664515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff    SkipUntil(tok::semi);
154743bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl    return StmtError();
154864515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff  }
154964515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff  // Otherwise, eat the semicolon.
155064515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff  ExpectAndConsume(tok::semi, diag::err_expected_semi_after_expr);
15516b1d283fe879fb11d7ce7a69feecf66e77b0eaf3Anders Carlsson  return Actions.ActOnExprStmt(Actions.FullExpr(Res));
155264515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff}
155364515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff
15541d922960e083906a586609ac6978678147250177Sebastian RedlParser::OwningExprResult Parser::ParseObjCAtExpression(SourceLocation AtLoc) {
15555508518a2702b00be3b15a26d772bde968972f54Anders Carlsson  switch (Tok.getKind()) {
1556b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner  case tok::string_literal:    // primary-expression: string-literal
1557b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner  case tok::wide_string_literal:
15581d922960e083906a586609ac6978678147250177Sebastian Redl    return ParsePostfixExpressionSuffix(ParseObjCStringLiteral(AtLoc));
1559b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner  default:
15604fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner    if (Tok.getIdentifierInfo() == 0)
15611d922960e083906a586609ac6978678147250177Sebastian Redl      return ExprError(Diag(AtLoc, diag::err_unexpected_at));
15622f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl
15634fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner    switch (Tok.getIdentifierInfo()->getObjCKeywordID()) {
15644fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner    case tok::objc_encode:
15651d922960e083906a586609ac6978678147250177Sebastian Redl      return ParsePostfixExpressionSuffix(ParseObjCEncodeExpression(AtLoc));
15664fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner    case tok::objc_protocol:
15671d922960e083906a586609ac6978678147250177Sebastian Redl      return ParsePostfixExpressionSuffix(ParseObjCProtocolExpression(AtLoc));
15684fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner    case tok::objc_selector:
15691d922960e083906a586609ac6978678147250177Sebastian Redl      return ParsePostfixExpressionSuffix(ParseObjCSelectorExpression(AtLoc));
15704fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner    default:
15711d922960e083906a586609ac6978678147250177Sebastian Redl      return ExprError(Diag(AtLoc, diag::err_unexpected_at));
15724fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner    }
15735508518a2702b00be3b15a26d772bde968972f54Anders Carlsson  }
15745508518a2702b00be3b15a26d772bde968972f54Anders Carlsson}
15755508518a2702b00be3b15a26d772bde968972f54Anders Carlsson
15761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///   objc-message-expr:
15770ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///     '[' objc-receiver objc-message-args ']'
15780ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///
15790ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///   objc-receiver:
15800ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///     expression
15810ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///     class-name
15820ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///     type-name
15831d922960e083906a586609ac6978678147250177Sebastian RedlParser::OwningExprResult Parser::ParseObjCMessageExpression() {
1584699b66138ac307a32e238463e0eff513ff17d337Chris Lattner  assert(Tok.is(tok::l_square) && "'[' expected");
1585699b66138ac307a32e238463e0eff513ff17d337Chris Lattner  SourceLocation LBracLoc = ConsumeBracket(); // consume '['
1586699b66138ac307a32e238463e0eff513ff17d337Chris Lattner
1587699b66138ac307a32e238463e0eff513ff17d337Chris Lattner  // Parse receiver
158814dd98a7952c9559e0d17fff8272bf3be67135afChris Lattner  if (isTokObjCMessageIdentifierReceiver()) {
1589699b66138ac307a32e238463e0eff513ff17d337Chris Lattner    IdentifierInfo *ReceiverName = Tok.getIdentifierInfo();
1590d2869925b5f10e00b13fbf3f41bbb17e4c9adbe0Fariborz Jahanian    if (ReceiverName != Ident_super || GetLookAheadToken(1).isNot(tok::period)) {
1591d2869925b5f10e00b13fbf3f41bbb17e4c9adbe0Fariborz Jahanian      SourceLocation NameLoc = ConsumeToken();
1592d2869925b5f10e00b13fbf3f41bbb17e4c9adbe0Fariborz Jahanian      return ParseObjCMessageExpressionBody(LBracLoc, NameLoc, ReceiverName,
1593d2869925b5f10e00b13fbf3f41bbb17e4c9adbe0Fariborz Jahanian                                            ExprArg(Actions));
1594d2869925b5f10e00b13fbf3f41bbb17e4c9adbe0Fariborz Jahanian    }
1595699b66138ac307a32e238463e0eff513ff17d337Chris Lattner  }
1596699b66138ac307a32e238463e0eff513ff17d337Chris Lattner
15972f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl  OwningExprResult Res(ParseExpression());
15980e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl  if (Res.isInvalid()) {
15995c749428a9938d5e2e9564b1c9b7a9252c30ee27Chris Lattner    SkipUntil(tok::r_square);
16001d922960e083906a586609ac6978678147250177Sebastian Redl    return move(Res);
1601699b66138ac307a32e238463e0eff513ff17d337Chris Lattner  }
16021d922960e083906a586609ac6978678147250177Sebastian Redl
16030e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl  return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(),
160476ad2e85575722e8a38a2bd4648ab4304d9fcd24Sebastian Redl                                        0, move(Res));
1605699b66138ac307a32e238463e0eff513ff17d337Chris Lattner}
16061d922960e083906a586609ac6978678147250177Sebastian Redl
1607699b66138ac307a32e238463e0eff513ff17d337Chris Lattner/// ParseObjCMessageExpressionBody - Having parsed "'[' objc-receiver", parse
1608699b66138ac307a32e238463e0eff513ff17d337Chris Lattner/// the rest of a message expression.
16091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///
16100ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///   objc-message-args:
16110ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///     objc-selector
16120ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///     objc-keywordarg-list
16130ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///
16140ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///   objc-keywordarg-list:
16150ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///     objc-keywordarg
16160ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///     objc-keywordarg-list objc-keywordarg
16170ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///
16181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///   objc-keywordarg:
16190ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///     selector-name[opt] ':' objc-keywordexpr
16200ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///
16210ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///   objc-keywordexpr:
16220ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///     nonempty-expr-list
16230ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///
16240ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///   nonempty-expr-list:
16250ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///     assignment-expression
16260ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///     nonempty-expr-list , assignment-expression
16271d922960e083906a586609ac6978678147250177Sebastian Redl///
16281d922960e083906a586609ac6978678147250177Sebastian RedlParser::OwningExprResult
1629699b66138ac307a32e238463e0eff513ff17d337Chris LattnerParser::ParseObjCMessageExpressionBody(SourceLocation LBracLoc,
16305cb93b8bf009c4b0ae09b71ba85f54b2a7ea8022Steve Naroff                                       SourceLocation NameLoc,
1631699b66138ac307a32e238463e0eff513ff17d337Chris Lattner                                       IdentifierInfo *ReceiverName,
16321d922960e083906a586609ac6978678147250177Sebastian Redl                                       ExprArg ReceiverExpr) {
1633c4df6d2c05c647a6a5770ba0c749782b6c023a3aSteve Naroff  if (Tok.is(tok::code_completion)) {
1634c4df6d2c05c647a6a5770ba0c749782b6c023a3aSteve Naroff    if (ReceiverName)
163560b01cc44855d62979f76dc4cdffa4277f321049Douglas Gregor      Actions.CodeCompleteObjCClassMessage(CurScope, ReceiverName, NameLoc);
1636c4df6d2c05c647a6a5770ba0c749782b6c023a3aSteve Naroff    else
163760b01cc44855d62979f76dc4cdffa4277f321049Douglas Gregor      Actions.CodeCompleteObjCInstanceMessage(CurScope, ReceiverExpr.get());
1638c4df6d2c05c647a6a5770ba0c749782b6c023a3aSteve Naroff    ConsumeToken();
1639c4df6d2c05c647a6a5770ba0c749782b6c023a3aSteve Naroff  }
1640a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian  // Parse objc-selector
16414b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian  SourceLocation Loc;
16422fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner  IdentifierInfo *selIdent = ParseObjCSelectorPiece(Loc);
164368d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff
1644ff975cfab9ada27df86038286d1678084aeb3428Anders Carlsson  SourceLocation SelectorLoc = Loc;
16451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
164668d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff  llvm::SmallVector<IdentifierInfo *, 12> KeyIdents;
1647a55e52c0802cae3b7c366a05c461d3d15074c1a3Sebastian Redl  ExprVector KeyExprs(Actions);
164868d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff
1649df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  if (Tok.is(tok::colon)) {
1650a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian    while (1) {
1651a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian      // Each iteration parses a single keyword argument.
165268d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff      KeyIdents.push_back(selIdent);
165337387c932855c6d58d70bdd705cd3a9fdcd2a931Steve Naroff
1654df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner      if (Tok.isNot(tok::colon)) {
1655a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian        Diag(Tok, diag::err_expected_colon);
16564fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner        // We must manually skip to a ']', otherwise the expression skipper will
16574fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner        // stop at the ']' when it skips to the ';'.  We want it to skip beyond
16584fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner        // the enclosing expression.
16594fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner        SkipUntil(tok::r_square);
16601d922960e083906a586609ac6978678147250177Sebastian Redl        return ExprError();
1661a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian      }
16621d922960e083906a586609ac6978678147250177Sebastian Redl
166368d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff      ConsumeToken(); // Eat the ':'.
16641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      ///  Parse the expression after ':'
16652f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl      OwningExprResult Res(ParseAssignmentExpression());
16660e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl      if (Res.isInvalid()) {
16674fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner        // We must manually skip to a ']', otherwise the expression skipper will
16684fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner        // stop at the ']' when it skips to the ';'.  We want it to skip beyond
16694fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner        // the enclosing expression.
16704fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner        SkipUntil(tok::r_square);
16711d922960e083906a586609ac6978678147250177Sebastian Redl        return move(Res);
167237387c932855c6d58d70bdd705cd3a9fdcd2a931Steve Naroff      }
16731d922960e083906a586609ac6978678147250177Sebastian Redl
167437387c932855c6d58d70bdd705cd3a9fdcd2a931Steve Naroff      // We have a valid expression.
1675effa8d1c97b00a3f53e972b0e61d9aade5ea1c57Sebastian Redl      KeyExprs.push_back(Res.release());
16761d922960e083906a586609ac6978678147250177Sebastian Redl
167737387c932855c6d58d70bdd705cd3a9fdcd2a931Steve Naroff      // Check for another keyword selector.
16782fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner      selIdent = ParseObjCSelectorPiece(Loc);
1679df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner      if (!selIdent && Tok.isNot(tok::colon))
1680a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian        break;
1681a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian      // We have a selector or a colon, continue parsing.
1682a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian    }
1683a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian    // Parse the, optional, argument list, comma separated.
1684df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner    while (Tok.is(tok::comma)) {
168549f109c786f99eb7468dac3976db083a65493444Steve Naroff      ConsumeToken(); // Eat the ','.
16861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      ///  Parse the expression after ','
16872f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl      OwningExprResult Res(ParseAssignmentExpression());
16880e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl      if (Res.isInvalid()) {
16894fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner        // We must manually skip to a ']', otherwise the expression skipper will
16904fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner        // stop at the ']' when it skips to the ';'.  We want it to skip beyond
16914fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner        // the enclosing expression.
16924fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner        SkipUntil(tok::r_square);
16931d922960e083906a586609ac6978678147250177Sebastian Redl        return move(Res);
169449f109c786f99eb7468dac3976db083a65493444Steve Naroff      }
16950e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl
169649f109c786f99eb7468dac3976db083a65493444Steve Naroff      // We have a valid expression.
1697effa8d1c97b00a3f53e972b0e61d9aade5ea1c57Sebastian Redl      KeyExprs.push_back(Res.release());
1698a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian    }
1699a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian  } else if (!selIdent) {
1700a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian    Diag(Tok, diag::err_expected_ident); // missing selector name.
17011d922960e083906a586609ac6978678147250177Sebastian Redl
17024fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner    // We must manually skip to a ']', otherwise the expression skipper will
17034fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner    // stop at the ']' when it skips to the ';'.  We want it to skip beyond
17044fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner    // the enclosing expression.
17054fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner    SkipUntil(tok::r_square);
17061d922960e083906a586609ac6978678147250177Sebastian Redl    return ExprError();
1707a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian  }
17081d922960e083906a586609ac6978678147250177Sebastian Redl
1709df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  if (Tok.isNot(tok::r_square)) {
1710a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian    Diag(Tok, diag::err_expected_rsquare);
17114fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner    // We must manually skip to a ']', otherwise the expression skipper will
17124fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner    // stop at the ']' when it skips to the ';'.  We want it to skip beyond
17134fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner    // the enclosing expression.
17144fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner    SkipUntil(tok::r_square);
17151d922960e083906a586609ac6978678147250177Sebastian Redl    return ExprError();
1716a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian  }
17171d922960e083906a586609ac6978678147250177Sebastian Redl
1718699b66138ac307a32e238463e0eff513ff17d337Chris Lattner  SourceLocation RBracLoc = ConsumeBracket(); // consume ']'
17191d922960e083906a586609ac6978678147250177Sebastian Redl
172029238a0bf7cbf5b396efb451a0adb5fe4aa037caSteve Naroff  unsigned nKeys = KeyIdents.size();
1721ff38491c18b060526d754765b952f4a497a89416Chris Lattner  if (nKeys == 0)
1722ff38491c18b060526d754765b952f4a497a89416Chris Lattner    KeyIdents.push_back(selIdent);
1723ff38491c18b060526d754765b952f4a497a89416Chris Lattner  Selector Sel = PP.getSelectorTable().getSelector(nKeys, &KeyIdents[0]);
17241d922960e083906a586609ac6978678147250177Sebastian Redl
1725ff38491c18b060526d754765b952f4a497a89416Chris Lattner  // We've just parsed a keyword message.
17261d922960e083906a586609ac6978678147250177Sebastian Redl  if (ReceiverName)
17271d922960e083906a586609ac6978678147250177Sebastian Redl    return Owned(Actions.ActOnClassMessage(CurScope, ReceiverName, Sel,
17281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                           LBracLoc, NameLoc, SelectorLoc,
1729ff975cfab9ada27df86038286d1678084aeb3428Anders Carlsson                                           RBracLoc,
17301d922960e083906a586609ac6978678147250177Sebastian Redl                                           KeyExprs.take(), KeyExprs.size()));
17311d922960e083906a586609ac6978678147250177Sebastian Redl  return Owned(Actions.ActOnInstanceMessage(ReceiverExpr.release(), Sel,
1732ff975cfab9ada27df86038286d1678084aeb3428Anders Carlsson                                            LBracLoc, SelectorLoc, RBracLoc,
17331d922960e083906a586609ac6978678147250177Sebastian Redl                                            KeyExprs.take(), KeyExprs.size()));
17340ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian}
17350ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian
17361d922960e083906a586609ac6978678147250177Sebastian RedlParser::OwningExprResult Parser::ParseObjCStringLiteral(SourceLocation AtLoc) {
173720df9b7ab9388b2a488c5b1293cd196b1e073b4eSebastian Redl  OwningExprResult Res(ParseStringLiteralExpression());
17381d922960e083906a586609ac6978678147250177Sebastian Redl  if (Res.isInvalid()) return move(Res);
17391d922960e083906a586609ac6978678147250177Sebastian Redl
1740b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner  // @"foo" @"bar" is a valid concatenated string.  Eat any subsequent string
1741b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner  // expressions.  At this point, we know that the only valid thing that starts
1742b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner  // with '@' is an @"".
1743b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner  llvm::SmallVector<SourceLocation, 4> AtLocs;
1744a55e52c0802cae3b7c366a05c461d3d15074c1a3Sebastian Redl  ExprVector AtStrings(Actions);
1745b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner  AtLocs.push_back(AtLoc);
1746effa8d1c97b00a3f53e972b0e61d9aade5ea1c57Sebastian Redl  AtStrings.push_back(Res.release());
17470e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl
1748b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner  while (Tok.is(tok::at)) {
1749b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner    AtLocs.push_back(ConsumeToken()); // eat the @.
1750b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner
175115faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl    // Invalid unless there is a string literal.
175297cf6eb380016db868866faf27a086cd55a316d4Chris Lattner    if (!isTokenStringLiteral())
175397cf6eb380016db868866faf27a086cd55a316d4Chris Lattner      return ExprError(Diag(Tok, diag::err_objc_concat_string));
1754b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner
175597cf6eb380016db868866faf27a086cd55a316d4Chris Lattner    OwningExprResult Lit(ParseStringLiteralExpression());
17560e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl    if (Lit.isInvalid())
17571d922960e083906a586609ac6978678147250177Sebastian Redl      return move(Lit);
17580e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl
1759effa8d1c97b00a3f53e972b0e61d9aade5ea1c57Sebastian Redl    AtStrings.push_back(Lit.release());
1760b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner  }
17611d922960e083906a586609ac6978678147250177Sebastian Redl
17621d922960e083906a586609ac6978678147250177Sebastian Redl  return Owned(Actions.ParseObjCStringLiteral(&AtLocs[0], AtStrings.take(),
17631d922960e083906a586609ac6978678147250177Sebastian Redl                                              AtStrings.size()));
17645508518a2702b00be3b15a26d772bde968972f54Anders Carlsson}
1765f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson
1766f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson///    objc-encode-expression:
1767f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson///      @encode ( type-name )
17681d922960e083906a586609ac6978678147250177Sebastian RedlParser::OwningExprResult
17691d922960e083906a586609ac6978678147250177Sebastian RedlParser::ParseObjCEncodeExpression(SourceLocation AtLoc) {
1770861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff  assert(Tok.isObjCAtKeyword(tok::objc_encode) && "Not an @encode expression!");
17711d922960e083906a586609ac6978678147250177Sebastian Redl
1772f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson  SourceLocation EncLoc = ConsumeToken();
17731d922960e083906a586609ac6978678147250177Sebastian Redl
17744fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner  if (Tok.isNot(tok::l_paren))
17751d922960e083906a586609ac6978678147250177Sebastian Redl    return ExprError(Diag(Tok, diag::err_expected_lparen_after) << "@encode");
17761d922960e083906a586609ac6978678147250177Sebastian Redl
1777f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson  SourceLocation LParenLoc = ConsumeParen();
17781d922960e083906a586609ac6978678147250177Sebastian Redl
1779809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor  TypeResult Ty = ParseTypeName();
17801d922960e083906a586609ac6978678147250177Sebastian Redl
17814988ae3fda10743c8ed8a98cdcb5a783362587b4Anders Carlsson  SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc);
17821d922960e083906a586609ac6978678147250177Sebastian Redl
1783809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor  if (Ty.isInvalid())
1784809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor    return ExprError();
1785809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor
17861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return Owned(Actions.ParseObjCEncodeExpression(AtLoc, EncLoc, LParenLoc,
1787809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor                                                 Ty.get(), RParenLoc));
1788f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson}
178929b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson
179029b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson///     objc-protocol-expression
179129b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson///       @protocol ( protocol-name )
17921d922960e083906a586609ac6978678147250177Sebastian RedlParser::OwningExprResult
17931d922960e083906a586609ac6978678147250177Sebastian RedlParser::ParseObjCProtocolExpression(SourceLocation AtLoc) {
179429b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson  SourceLocation ProtoLoc = ConsumeToken();
17951d922960e083906a586609ac6978678147250177Sebastian Redl
17964fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner  if (Tok.isNot(tok::l_paren))
17971d922960e083906a586609ac6978678147250177Sebastian Redl    return ExprError(Diag(Tok, diag::err_expected_lparen_after) << "@protocol");
17981d922960e083906a586609ac6978678147250177Sebastian Redl
179929b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson  SourceLocation LParenLoc = ConsumeParen();
18001d922960e083906a586609ac6978678147250177Sebastian Redl
18014fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner  if (Tok.isNot(tok::identifier))
18021d922960e083906a586609ac6978678147250177Sebastian Redl    return ExprError(Diag(Tok, diag::err_expected_ident));
18031d922960e083906a586609ac6978678147250177Sebastian Redl
1804390d50a725497e99247dc104a7d2c2a255d3af14Fariborz Jahanian  IdentifierInfo *protocolId = Tok.getIdentifierInfo();
180529b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson  ConsumeToken();
18061d922960e083906a586609ac6978678147250177Sebastian Redl
18074988ae3fda10743c8ed8a98cdcb5a783362587b4Anders Carlsson  SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc);
180829b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson
18091d922960e083906a586609ac6978678147250177Sebastian Redl  return Owned(Actions.ParseObjCProtocolExpression(protocolId, AtLoc, ProtoLoc,
18101d922960e083906a586609ac6978678147250177Sebastian Redl                                                   LParenLoc, RParenLoc));
181129b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson}
1812a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian
1813a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian///     objc-selector-expression
1814a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian///       @selector '(' objc-keyword-selector ')'
18151d922960e083906a586609ac6978678147250177Sebastian RedlParser::OwningExprResult
18161d922960e083906a586609ac6978678147250177Sebastian RedlParser::ParseObjCSelectorExpression(SourceLocation AtLoc) {
1817a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian  SourceLocation SelectorLoc = ConsumeToken();
18181d922960e083906a586609ac6978678147250177Sebastian Redl
18194fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner  if (Tok.isNot(tok::l_paren))
18201d922960e083906a586609ac6978678147250177Sebastian Redl    return ExprError(Diag(Tok, diag::err_expected_lparen_after) << "@selector");
18211d922960e083906a586609ac6978678147250177Sebastian Redl
1822b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian  llvm::SmallVector<IdentifierInfo *, 12> KeyIdents;
1823a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian  SourceLocation LParenLoc = ConsumeParen();
1824a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian  SourceLocation sLoc;
18252fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner  IdentifierInfo *SelIdent = ParseObjCSelectorPiece(sLoc);
18261d922960e083906a586609ac6978678147250177Sebastian Redl  if (!SelIdent && Tok.isNot(tok::colon)) // missing selector name.
18271d922960e083906a586609ac6978678147250177Sebastian Redl    return ExprError(Diag(Tok, diag::err_expected_ident));
18281d922960e083906a586609ac6978678147250177Sebastian Redl
1829b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian  KeyIdents.push_back(SelIdent);
1830887407e71fd58de452361b77d72970e32b20ebe0Steve Naroff  unsigned nColons = 0;
1831887407e71fd58de452361b77d72970e32b20ebe0Steve Naroff  if (Tok.isNot(tok::r_paren)) {
1832a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian    while (1) {
18334fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner      if (Tok.isNot(tok::colon))
18341d922960e083906a586609ac6978678147250177Sebastian Redl        return ExprError(Diag(Tok, diag::err_expected_colon));
18351d922960e083906a586609ac6978678147250177Sebastian Redl
1836cb53b361bce341c8591333c6997f62e480acc0b4Chris Lattner      nColons++;
1837a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian      ConsumeToken(); // Eat the ':'.
1838a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian      if (Tok.is(tok::r_paren))
1839a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian        break;
1840a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian      // Check for another keyword selector.
1841a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian      SourceLocation Loc;
18422fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner      SelIdent = ParseObjCSelectorPiece(Loc);
1843b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian      KeyIdents.push_back(SelIdent);
1844a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian      if (!SelIdent && Tok.isNot(tok::colon))
1845a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian        break;
1846a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian    }
1847887407e71fd58de452361b77d72970e32b20ebe0Steve Naroff  }
1848a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian  SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc);
1849887407e71fd58de452361b77d72970e32b20ebe0Steve Naroff  Selector Sel = PP.getSelectorTable().getSelector(nColons, &KeyIdents[0]);
18501d922960e083906a586609ac6978678147250177Sebastian Redl  return Owned(Actions.ParseObjCSelectorExpression(Sel, AtLoc, SelectorLoc,
18511d922960e083906a586609ac6978678147250177Sebastian Redl                                                   LParenLoc, RParenLoc));
185258065b2d8038a4e9a91ea4813bd1774c0f6efacbGabor Greif }
1853