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
14500d3297d2a21edeac4d46cbcbe21bc2352c2a28Chris Lattner#include "clang/Parse/ParseDiagnostic.h"
1519510856727e0e14a3696b2a72c35163bff2a71fJohn McCall#include "clang/Parse/Parser.h"
160fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor#include "RAIIObjectsForParser.h"
1719510856727e0e14a3696b2a72c35163bff2a71fJohn McCall#include "clang/Sema/DeclSpec.h"
18f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall#include "clang/Sema/PrettyDeclStackTrace.h"
1919510856727e0e14a3696b2a72c35163bff2a71fJohn McCall#include "clang/Sema/Scope.h"
205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "llvm/ADT/SmallVector.h"
215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing namespace clang;
225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
24891dca671a80c865c6def7259f170ba785e4faaaChris Lattner/// ParseObjCAtDirectives - Handle parts of the external-declaration production:
255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///       external-declaration: [C99 6.9]
265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// [OBJC]  objc-class-definition
2791fa0b7759b575045142abd6ee48c076297ad77bSteve Naroff/// [OBJC]  objc-class-declaration
2891fa0b7759b575045142abd6ee48c076297ad77bSteve Naroff/// [OBJC]  objc-alias-declaration
2991fa0b7759b575045142abd6ee48c076297ad77bSteve Naroff/// [OBJC]  objc-protocol-definition
3091fa0b7759b575045142abd6ee48c076297ad77bSteve Naroff/// [OBJC]  objc-method-definition
3191fa0b7759b575045142abd6ee48c076297ad77bSteve Naroff/// [OBJC]  '@' 'end'
3295ed7784a335aca53b0c6e952cf31a4cfb633360Fariborz JahanianParser::DeclGroupPtrTy Parser::ParseObjCAtDirectives() {
335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation AtLoc = ConsumeToken(); // the "@"
341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
35c464ae8444edb6d07ea49b7a0eae1674c0fa1bb8Douglas Gregor  if (Tok.is(tok::code_completion)) {
36a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian    Actions.CodeCompleteObjCAtDirective(getCurScope());
377d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis    cutOffParsing();
387d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis    return DeclGroupPtrTy();
39c464ae8444edb6d07ea49b7a0eae1674c0fa1bb8Douglas Gregor  }
4095ed7784a335aca53b0c6e952cf31a4cfb633360Fariborz Jahanian
4195ed7784a335aca53b0c6e952cf31a4cfb633360Fariborz Jahanian  Decl *SingleDecl = 0;
42861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff  switch (Tok.getObjCKeywordID()) {
435ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner  case tok::objc_class:
445ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner    return ParseObjCAtClassDeclaration(AtLoc);
457f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  case tok::objc_interface: {
460b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall    ParsedAttributes attrs(AttrFactory);
4795ed7784a335aca53b0c6e952cf31a4cfb633360Fariborz Jahanian    SingleDecl = ParseObjCAtInterfaceDeclaration(AtLoc, attrs);
4895ed7784a335aca53b0c6e952cf31a4cfb633360Fariborz Jahanian    break;
497f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  }
507f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  case tok::objc_protocol: {
510b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall    ParsedAttributes attrs(AttrFactory);
52bd9482d859a74bf2c45ef8b8aedec61c0e1c8374Douglas Gregor    return ParseObjCAtProtocolDeclaration(AtLoc, attrs);
537f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  }
545ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner  case tok::objc_implementation:
55849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis    return ParseObjCAtImplementationDeclaration(AtLoc);
565ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner  case tok::objc_end:
57140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian    return ParseObjCAtEndDeclaration(AtLoc);
585ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner  case tok::objc_compatibility_alias:
5995ed7784a335aca53b0c6e952cf31a4cfb633360Fariborz Jahanian    SingleDecl = ParseObjCAtAliasDeclaration(AtLoc);
6095ed7784a335aca53b0c6e952cf31a4cfb633360Fariborz Jahanian    break;
615ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner  case tok::objc_synthesize:
6295ed7784a335aca53b0c6e952cf31a4cfb633360Fariborz Jahanian    SingleDecl = ParseObjCPropertySynthesize(AtLoc);
6395ed7784a335aca53b0c6e952cf31a4cfb633360Fariborz Jahanian    break;
645ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner  case tok::objc_dynamic:
6595ed7784a335aca53b0c6e952cf31a4cfb633360Fariborz Jahanian    SingleDecl = ParseObjCPropertyDynamic(AtLoc);
6695ed7784a335aca53b0c6e952cf31a4cfb633360Fariborz Jahanian    break;
6732ad2ee2618745ce3da51c2ae066ed5f21157c07Ted Kremenek  case tok::objc___experimental_modules_import:
684e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie    if (getLangOpts().Modules)
6994ad28b31433058445a27db722f60402ee820beaDouglas Gregor      return ParseModuleImport(AtLoc);
7094ad28b31433058445a27db722f60402ee820beaDouglas Gregor
7194ad28b31433058445a27db722f60402ee820beaDouglas Gregor    // Fall through
7294ad28b31433058445a27db722f60402ee820beaDouglas Gregor
735ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner  default:
745ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner    Diag(AtLoc, diag::err_unexpected_at);
755ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner    SkipUntil(tok::semi);
7695ed7784a335aca53b0c6e952cf31a4cfb633360Fariborz Jahanian    SingleDecl = 0;
7795ed7784a335aca53b0c6e952cf31a4cfb633360Fariborz Jahanian    break;
785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
7995ed7784a335aca53b0c6e952cf31a4cfb633360Fariborz Jahanian  return Actions.ConvertDeclToDeclGroup(SingleDecl);
805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// objc-class-declaration:
845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///    '@' 'class' identifier-list ';'
851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///
8695ed7784a335aca53b0c6e952cf31a4cfb633360Fariborz JahanianParser::DeclGroupPtrTy
8795ed7784a335aca53b0c6e952cf31a4cfb633360Fariborz JahanianParser::ParseObjCAtClassDeclaration(SourceLocation atLoc) {
885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ConsumeToken(); // the identifier "class"
895f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner  SmallVector<IdentifierInfo *, 8> ClassNames;
905f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner  SmallVector<SourceLocation, 8> ClassLocs;
91c09cba67d0ad01e53e0fed07322e95dd281bcfd9Ted Kremenek
921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  while (1) {
94df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner    if (Tok.isNot(tok::identifier)) {
955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      Diag(Tok, diag::err_expected_ident);
965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      SkipUntil(tok::semi);
9795ed7784a335aca53b0c6e952cf31a4cfb633360Fariborz Jahanian      return Actions.ConvertDeclToDeclGroup(0);
985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    }
995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ClassNames.push_back(Tok.getIdentifierInfo());
100c09cba67d0ad01e53e0fed07322e95dd281bcfd9Ted Kremenek    ClassLocs.push_back(Tok.getLocation());
1015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ConsumeToken();
1021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
103df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner    if (Tok.isNot(tok::comma))
1045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      break;
1051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ConsumeToken();
1075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
1081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // Consume the ';'.
1105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  if (ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@class"))
11195ed7784a335aca53b0c6e952cf31a4cfb633360Fariborz Jahanian    return Actions.ConvertDeclToDeclGroup(0);
1121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
113c09cba67d0ad01e53e0fed07322e95dd281bcfd9Ted Kremenek  return Actions.ActOnForwardClassDeclaration(atLoc, ClassNames.data(),
114c09cba67d0ad01e53e0fed07322e95dd281bcfd9Ted Kremenek                                              ClassLocs.data(),
115c09cba67d0ad01e53e0fed07322e95dd281bcfd9Ted Kremenek                                              ClassNames.size());
1165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
1175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
118d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggenvoid Parser::CheckNestedObjCContexts(SourceLocation AtLoc)
119d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen{
120d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen  Sema::ObjCContainerKind ock = Actions.getObjCContainerKind();
121d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen  if (ock == Sema::OCK_None)
122d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen    return;
123d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen
124849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis  Decl *Decl = Actions.getObjCDeclContext();
125849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis  if (CurParsedObjCImpl) {
126849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis    CurParsedObjCImpl->finish(AtLoc);
127849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis  } else {
128849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis    Actions.ActOnAtEnd(getCurScope(), AtLoc);
129849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis  }
130d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen  Diag(AtLoc, diag::err_objc_missing_end)
131d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen      << FixItHint::CreateInsertion(AtLoc, "@end\n");
132d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen  if (Decl)
133d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen    Diag(Decl->getLocStart(), diag::note_objc_container_start)
134d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen        << (int) ock;
135d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen}
136d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen
137dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///
138dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///   objc-interface:
139dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     objc-class-interface-attributes[opt] objc-class-interface
140dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     objc-category-interface
141dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///
142dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///   objc-class-interface:
1431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///     '@' 'interface' identifier objc-superclass[opt]
144dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///       objc-protocol-refs[opt]
1451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///       objc-class-instance-variables[opt]
146dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///       objc-interface-decl-list
147dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     @end
148dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///
149dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///   objc-category-interface:
1501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///     '@' 'interface' identifier '(' identifier[opt] ')'
151dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///       objc-protocol-refs[opt]
152dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///       objc-interface-decl-list
153dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     @end
154dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///
155dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///   objc-superclass:
156dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     ':' identifier
157dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///
158dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///   objc-class-interface-attributes:
159dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     __attribute__((visibility("default")))
160dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     __attribute__((visibility("hidden")))
161dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     __attribute__((deprecated))
162dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     __attribute__((unavailable))
163dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     __attribute__((objc_exception)) - used by NSException on 64-bit
164b2f6820773aabff3c5c9e0dbb1cbbbda0d80c41fPatrick Beard///     __attribute__((objc_root_class))
165dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///
166d64251fd56577dd5c78903454632361e094c6dc1Erik VerbruggenDecl *Parser::ParseObjCAtInterfaceDeclaration(SourceLocation AtLoc,
1677f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall                                              ParsedAttributes &attrs) {
168861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff  assert(Tok.isObjCAtKeyword(tok::objc_interface) &&
169dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff         "ParseObjCAtInterfaceDeclaration(): Expected @interface");
170d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen  CheckNestedObjCContexts(AtLoc);
171dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff  ConsumeToken(); // the "interface" identifier
1721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1733b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor  // Code completion after '@interface'.
1743b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor  if (Tok.is(tok::code_completion)) {
17523c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor    Actions.CodeCompleteObjCInterfaceDecl(getCurScope());
1767d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis    cutOffParsing();
1777d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis    return 0;
1783b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor  }
1793b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor
180df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  if (Tok.isNot(tok::identifier)) {
181dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff    Diag(Tok, diag::err_expected_ident); // missing class or category name.
182d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall    return 0;
183dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff  }
18463e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian
185dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff  // We have a class or category name - consume it.
1867ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff  IdentifierInfo *nameId = Tok.getIdentifierInfo();
187dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff  SourceLocation nameLoc = ConsumeToken();
1885512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian  if (Tok.is(tok::l_paren) &&
1895512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian      !isKnownToBeTypeSpecifier(GetLookAheadToken(1))) { // we have a category.
1904a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor
1914a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor    BalancedDelimiterTracker T(*this, tok::l_paren);
1924a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor    T.consumeOpen();
1934a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor
1944a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor    SourceLocation categoryLoc;
195dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff    IdentifierInfo *categoryId = 0;
19633ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor    if (Tok.is(tok::code_completion)) {
19723c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor      Actions.CodeCompleteObjCInterfaceCategory(getCurScope(), nameId, nameLoc);
1987d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis      cutOffParsing();
1997d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis      return 0;
20033ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor    }
20133ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor
202527fe23f8cbc6a4da1737a547a2517bc92fa88c8Steve Naroff    // For ObjC2, the category name is optional (not an error).
203df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner    if (Tok.is(tok::identifier)) {
204dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff      categoryId = Tok.getIdentifierInfo();
205dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff      categoryLoc = ConsumeToken();
20605511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian    }
2074e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie    else if (!getLangOpts().ObjC2) {
208527fe23f8cbc6a4da1737a547a2517bc92fa88c8Steve Naroff      Diag(Tok, diag::err_expected_ident); // missing category name.
209d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall      return 0;
210dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff    }
2114a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor
2124a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor    T.consumeClose();
2134a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor    if (T.getCloseLocation().isInvalid())
214d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall      return 0;
21513d05ac08974ccb41f7da7595d769c158f58fbd6Douglas Gregor
21613d05ac08974ccb41f7da7595d769c158f58fbd6Douglas Gregor    if (!attrs.empty()) { // categories don't support attributes.
21713d05ac08974ccb41f7da7595d769c158f58fbd6Douglas Gregor      Diag(nameLoc, diag::err_objc_no_attributes_on_category);
21813d05ac08974ccb41f7da7595d769c158f58fbd6Douglas Gregor      attrs.clear();
219dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff    }
22013d05ac08974ccb41f7da7595d769c158f58fbd6Douglas Gregor
2215512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian    // Next, we need to check for any protocol references.
2225512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian    SourceLocation LAngleLoc, EndProtoLoc;
2235f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner    SmallVector<Decl *, 8> ProtocolRefs;
2245f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner    SmallVector<SourceLocation, 8> ProtocolLocs;
2255512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian    if (Tok.is(tok::less) &&
2265512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian        ParseObjCProtocolReferences(ProtocolRefs, ProtocolLocs, true,
22771b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis                                    LAngleLoc, EndProtoLoc))
228d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall      return 0;
22905511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian
230d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall    Decl *CategoryType =
231d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen    Actions.ActOnStartCategoryInterface(AtLoc,
2325512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian                                        nameId, nameLoc,
2335512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian                                        categoryId, categoryLoc,
2345512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian                                        ProtocolRefs.data(),
2355512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian                                        ProtocolRefs.size(),
2365512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian                                        ProtocolLocs.data(),
2375512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian                                        EndProtoLoc);
238e6f07f538fd0eddd6c087fcc01d4e4ff19129c71Fariborz Jahanian
239a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian    if (Tok.is(tok::l_brace))
240d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen      ParseObjCClassInstanceVariables(CategoryType, tok::objc_private, AtLoc);
241a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian
2422f64cfe19e8bf6b6ba1660e38da8c421440457feFariborz Jahanian    ParseObjCInterfaceDeclList(tok::objc_not_keyword, CategoryType);
2435512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian    return CategoryType;
244dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff  }
245dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff  // Parse a class interface.
246dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff  IdentifierInfo *superClassId = 0;
247dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff  SourceLocation superClassLoc;
2487ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff
249df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  if (Tok.is(tok::colon)) { // a super class is specified.
250dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff    ConsumeToken();
2513b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor
2523b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor    // Code completion of superclass names.
2533b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor    if (Tok.is(tok::code_completion)) {
25423c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor      Actions.CodeCompleteObjCSuperclass(getCurScope(), nameId, nameLoc);
2557d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis      cutOffParsing();
2567d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis      return 0;
2573b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor    }
2583b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor
259df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner    if (Tok.isNot(tok::identifier)) {
260dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff      Diag(Tok, diag::err_expected_ident); // missing super class name.
261d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall      return 0;
262dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff    }
263dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff    superClassId = Tok.getIdentifierInfo();
264dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff    superClassLoc = ConsumeToken();
265dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff  }
266dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff  // Next, we need to check for any protocol references.
2675f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner  SmallVector<Decl *, 8> ProtocolRefs;
2685f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner  SmallVector<SourceLocation, 8> ProtocolLocs;
26971b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis  SourceLocation LAngleLoc, EndProtoLoc;
27006036d3709955a53297b4cbe14e20db88f321470Chris Lattner  if (Tok.is(tok::less) &&
27171b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis      ParseObjCProtocolReferences(ProtocolRefs, ProtocolLocs, true,
27271b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis                                  LAngleLoc, EndProtoLoc))
273d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall    return 0;
2741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
275d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  Decl *ClsType =
276d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen    Actions.ActOnStartClassInterface(AtLoc, nameId, nameLoc,
27706036d3709955a53297b4cbe14e20db88f321470Chris Lattner                                     superClassId, superClassLoc,
278beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad                                     ProtocolRefs.data(), ProtocolRefs.size(),
27918df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor                                     ProtocolLocs.data(),
2807f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall                                     EndProtoLoc, attrs.getList());
2811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
282df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  if (Tok.is(tok::l_brace))
283d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen    ParseObjCClassInstanceVariables(ClsType, tok::objc_protected, AtLoc);
284dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff
2852f64cfe19e8bf6b6ba1660e38da8c421440457feFariborz Jahanian  ParseObjCInterfaceDeclList(tok::objc_interface, ClsType);
2865512ba538f3f6b0576623f680fa7d930fa085ccdFariborz Jahanian  return ClsType;
287dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff}
288dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff
289d0014540005f2a5ab837365db6bd40f479406758John McCall/// The Objective-C property callback.  This should be defined where
290d0014540005f2a5ab837365db6bd40f479406758John McCall/// it's used, but instead it's been lifted to here to support VS2005.
291d0014540005f2a5ab837365db6bd40f479406758John McCallstruct Parser::ObjCPropertyCallback : FieldCallback {
29299ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikieprivate:
29399ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie  virtual void anchor();
29499ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikiepublic:
295d0014540005f2a5ab837365db6bd40f479406758John McCall  Parser &P;
2965f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner  SmallVectorImpl<Decl *> &Props;
297d0014540005f2a5ab837365db6bd40f479406758John McCall  ObjCDeclSpec &OCDS;
298d0014540005f2a5ab837365db6bd40f479406758John McCall  SourceLocation AtLoc;
29977bfb8b43ec3f7dee3a71f6e854b03ad29dab84fFariborz Jahanian  SourceLocation LParenLoc;
300d0014540005f2a5ab837365db6bd40f479406758John McCall  tok::ObjCKeywordKind MethodImplKind;
301d0014540005f2a5ab837365db6bd40f479406758John McCall
302a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian  ObjCPropertyCallback(Parser &P,
3035f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner                       SmallVectorImpl<Decl *> &Props,
304d0014540005f2a5ab837365db6bd40f479406758John McCall                       ObjCDeclSpec &OCDS, SourceLocation AtLoc,
30577bfb8b43ec3f7dee3a71f6e854b03ad29dab84fFariborz Jahanian                       SourceLocation LParenLoc,
306d0014540005f2a5ab837365db6bd40f479406758John McCall                       tok::ObjCKeywordKind MethodImplKind) :
30777bfb8b43ec3f7dee3a71f6e854b03ad29dab84fFariborz Jahanian    P(P), Props(Props), OCDS(OCDS), AtLoc(AtLoc), LParenLoc(LParenLoc),
308d0014540005f2a5ab837365db6bd40f479406758John McCall    MethodImplKind(MethodImplKind) {
309d0014540005f2a5ab837365db6bd40f479406758John McCall  }
310d0014540005f2a5ab837365db6bd40f479406758John McCall
311d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  Decl *invoke(FieldDeclarator &FD) {
312d0014540005f2a5ab837365db6bd40f479406758John McCall    if (FD.D.getIdentifier() == 0) {
313d0014540005f2a5ab837365db6bd40f479406758John McCall      P.Diag(AtLoc, diag::err_objc_property_requires_field_name)
314d0014540005f2a5ab837365db6bd40f479406758John McCall        << FD.D.getSourceRange();
315d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall      return 0;
316d0014540005f2a5ab837365db6bd40f479406758John McCall    }
317d0014540005f2a5ab837365db6bd40f479406758John McCall    if (FD.BitfieldSize) {
318d0014540005f2a5ab837365db6bd40f479406758John McCall      P.Diag(AtLoc, diag::err_objc_property_bitfield)
319d0014540005f2a5ab837365db6bd40f479406758John McCall        << FD.D.getSourceRange();
320d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall      return 0;
321d0014540005f2a5ab837365db6bd40f479406758John McCall    }
322d0014540005f2a5ab837365db6bd40f479406758John McCall
323d0014540005f2a5ab837365db6bd40f479406758John McCall    // Install the property declarator into interfaceDecl.
324d0014540005f2a5ab837365db6bd40f479406758John McCall    IdentifierInfo *SelName =
325d0014540005f2a5ab837365db6bd40f479406758John McCall      OCDS.getGetterName() ? OCDS.getGetterName() : FD.D.getIdentifier();
326d0014540005f2a5ab837365db6bd40f479406758John McCall
327d0014540005f2a5ab837365db6bd40f479406758John McCall    Selector GetterSel =
328d0014540005f2a5ab837365db6bd40f479406758John McCall      P.PP.getSelectorTable().getNullarySelector(SelName);
329d0014540005f2a5ab837365db6bd40f479406758John McCall    IdentifierInfo *SetterName = OCDS.getSetterName();
330d0014540005f2a5ab837365db6bd40f479406758John McCall    Selector SetterSel;
331d0014540005f2a5ab837365db6bd40f479406758John McCall    if (SetterName)
332d0014540005f2a5ab837365db6bd40f479406758John McCall      SetterSel = P.PP.getSelectorTable().getSelector(1, &SetterName);
333d0014540005f2a5ab837365db6bd40f479406758John McCall    else
334d0014540005f2a5ab837365db6bd40f479406758John McCall      SetterSel = SelectorTable::constructSetterName(P.PP.getIdentifierTable(),
335d0014540005f2a5ab837365db6bd40f479406758John McCall                                                     P.PP.getSelectorTable(),
336d0014540005f2a5ab837365db6bd40f479406758John McCall                                                     FD.D.getIdentifier());
337d0014540005f2a5ab837365db6bd40f479406758John McCall    bool isOverridingProperty = false;
338d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall    Decl *Property =
33977bfb8b43ec3f7dee3a71f6e854b03ad29dab84fFariborz Jahanian      P.Actions.ActOnProperty(P.getCurScope(), AtLoc, LParenLoc,
34077bfb8b43ec3f7dee3a71f6e854b03ad29dab84fFariborz Jahanian                              FD, OCDS,
341a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian                              GetterSel, SetterSel,
342d0014540005f2a5ab837365db6bd40f479406758John McCall                              &isOverridingProperty,
343d0014540005f2a5ab837365db6bd40f479406758John McCall                              MethodImplKind);
344d0014540005f2a5ab837365db6bd40f479406758John McCall    if (!isOverridingProperty)
345d0014540005f2a5ab837365db6bd40f479406758John McCall      Props.push_back(Property);
346d0014540005f2a5ab837365db6bd40f479406758John McCall
347d0014540005f2a5ab837365db6bd40f479406758John McCall    return Property;
348d0014540005f2a5ab837365db6bd40f479406758John McCall  }
349d0014540005f2a5ab837365db6bd40f479406758John McCall};
350d0014540005f2a5ab837365db6bd40f479406758John McCall
35199ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikievoid Parser::ObjCPropertyCallback::anchor() {
35299ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie}
35399ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie
354dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///   objc-interface-decl-list:
355dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     empty
356dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     objc-interface-decl-list objc-property-decl [OBJC2]
357294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///     objc-interface-decl-list objc-method-requirement [OBJC2]
3583536b443bc50d58a79f14fca9b6842541a434854Steve Naroff///     objc-interface-decl-list objc-method-proto ';'
359dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     objc-interface-decl-list declaration
360dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     objc-interface-decl-list ';'
361dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///
362294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///   objc-method-requirement: [OBJC2]
363294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///     @required
364294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///     @optional
365294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///
3662f64cfe19e8bf6b6ba1660e38da8c421440457feFariborz Jahanianvoid Parser::ParseObjCInterfaceDeclList(tok::ObjCKeywordKind contextKey,
3672f64cfe19e8bf6b6ba1660e38da8c421440457feFariborz Jahanian                                        Decl *CDecl) {
3685f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner  SmallVector<Decl *, 32> allMethods;
3695f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner  SmallVector<Decl *, 16> allProperties;
3705f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner  SmallVector<DeclGroupPtrTy, 8> allTUVariables;
37100933591a2795d09dd1acff12a2d21bce7cb12c5Fariborz Jahanian  tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword;
3721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
373782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek  SourceRange AtEnd;
3742f64cfe19e8bf6b6ba1660e38da8c421440457feFariborz Jahanian
375294494e1cce92043562b4680c613df7fd028c02eSteve Naroff  while (1) {
376e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner    // If this is a method prototype, parse it.
377df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner    if (Tok.is(tok::minus) || Tok.is(tok::plus)) {
378d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall      Decl *methodPrototype =
379a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian        ParseObjCMethodPrototype(MethodImplKind, false);
38025e077d59a8e8e43b65882b69610a3d5e2aaf53cFariborz Jahanian      allMethods.push_back(methodPrototype);
3813536b443bc50d58a79f14fca9b6842541a434854Steve Naroff      // Consume the ';' here, since ParseObjCMethodPrototype() is re-used for
3823536b443bc50d58a79f14fca9b6842541a434854Steve Naroff      // method definitions.
3830db9f4dad563a335641f5b9d4a42504d638b6c85Argyrios Kyrtzidis      if (ExpectAndConsumeSemi(diag::err_expected_semi_after_method_proto)) {
3840db9f4dad563a335641f5b9d4a42504d638b6c85Argyrios Kyrtzidis        // We didn't find a semi and we error'ed out. Skip until a ';' or '@'.
3850db9f4dad563a335641f5b9d4a42504d638b6c85Argyrios Kyrtzidis        SkipUntil(tok::at, /*StopAtSemi=*/true, /*DontConsume=*/true);
3860db9f4dad563a335641f5b9d4a42504d638b6c85Argyrios Kyrtzidis        if (Tok.is(tok::semi))
3870db9f4dad563a335641f5b9d4a42504d638b6c85Argyrios Kyrtzidis          ConsumeToken();
3880db9f4dad563a335641f5b9d4a42504d638b6c85Argyrios Kyrtzidis      }
389294494e1cce92043562b4680c613df7fd028c02eSteve Naroff      continue;
390294494e1cce92043562b4680c613df7fd028c02eSteve Naroff    }
39105511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian    if (Tok.is(tok::l_paren)) {
39205511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian      Diag(Tok, diag::err_expected_minus_or_plus);
393d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall      ParseObjCMethodDecl(Tok.getLocation(),
394d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall                          tok::minus,
39590ba78c64d0c24cfbc1bf88728db9775d44d7f9fFariborz Jahanian                          MethodImplKind, false);
39605511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian      continue;
39705511fa6349ef0820a778f8c840d0b64e05e9aeeFariborz Jahanian    }
398e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner    // Ignore excess semicolons.
399e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner    if (Tok.is(tok::semi)) {
400294494e1cce92043562b4680c613df7fd028c02eSteve Naroff      ConsumeToken();
401e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner      continue;
402e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner    }
4031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
404bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner    // If we got to the end of the file, exit the loop.
405e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner    if (Tok.is(tok::eof))
406e3a2ca7e30601cdd31c77a830f4cc487851e8096Fariborz Jahanian      break;
4071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
408b6ac2451bfed36206c5cec7217372c4299f67f2bDouglas Gregor    // Code completion within an Objective-C interface.
409b6ac2451bfed36206c5cec7217372c4299f67f2bDouglas Gregor    if (Tok.is(tok::code_completion)) {
41023c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor      Actions.CodeCompleteOrdinaryName(getCurScope(),
411849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis                            CurParsedObjCImpl? Sema::PCC_ObjCImplementation
412f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                             : Sema::PCC_ObjCInterface);
4137d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis      return cutOffParsing();
414b6ac2451bfed36206c5cec7217372c4299f67f2bDouglas Gregor    }
415b6ac2451bfed36206c5cec7217372c4299f67f2bDouglas Gregor
416e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner    // If we don't have an @ directive, parse it as a function definition.
417e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner    if (Tok.isNot(tok::at)) {
4181fd80116b49782c367ff5d5f50a8b76dd8a5d7f7Chris Lattner      // The code below does not consume '}'s because it is afraid of eating the
4191fd80116b49782c367ff5d5f50a8b76dd8a5d7f7Chris Lattner      // end of a namespace.  Because of the way this code is structured, an
4201fd80116b49782c367ff5d5f50a8b76dd8a5d7f7Chris Lattner      // erroneous r_brace would cause an infinite loop if not handled here.
4211fd80116b49782c367ff5d5f50a8b76dd8a5d7f7Chris Lattner      if (Tok.is(tok::r_brace))
4221fd80116b49782c367ff5d5f50a8b76dd8a5d7f7Chris Lattner        break;
4230b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall      ParsedAttributes attrs(AttrFactory);
4247f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall      allTUVariables.push_back(ParseDeclarationOrFunctionDefinition(attrs));
425e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner      continue;
426e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner    }
4271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
428e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner    // Otherwise, we have an @ directive, eat the @.
429e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner    SourceLocation AtLoc = ConsumeToken(); // the "@"
430c464ae8444edb6d07ea49b7a0eae1674c0fa1bb8Douglas Gregor    if (Tok.is(tok::code_completion)) {
431a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian      Actions.CodeCompleteObjCAtDirective(getCurScope());
4327d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis      return cutOffParsing();
433c464ae8444edb6d07ea49b7a0eae1674c0fa1bb8Douglas Gregor    }
434c464ae8444edb6d07ea49b7a0eae1674c0fa1bb8Douglas Gregor
435a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner    tok::ObjCKeywordKind DirectiveKind = Tok.getObjCKeywordID();
4361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
437a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner    if (DirectiveKind == tok::objc_end) { // @end -> terminate list
438782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek      AtEnd.setBegin(AtLoc);
439782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek      AtEnd.setEnd(Tok.getLocation());
440e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner      break;
441c3d43b783dfb1a1502aa8b31ab1985cf237b1f77Douglas Gregor    } else if (DirectiveKind == tok::objc_not_keyword) {
442c3d43b783dfb1a1502aa8b31ab1985cf237b1f77Douglas Gregor      Diag(Tok, diag::err_objc_unknown_at);
443c3d43b783dfb1a1502aa8b31ab1985cf237b1f77Douglas Gregor      SkipUntil(tok::semi);
444c3d43b783dfb1a1502aa8b31ab1985cf237b1f77Douglas Gregor      continue;
445bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner    }
4461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
447bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner    // Eat the identifier.
448bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner    ConsumeToken();
449bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner
450a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner    switch (DirectiveKind) {
451a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner    default:
452bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner      // FIXME: If someone forgets an @end on a protocol, this loop will
453bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner      // continue to eat up tons of stuff and spew lots of nonsense errors.  It
454bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner      // would probably be better to bail out if we saw an @class or @interface
455bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner      // or something like that.
456f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner      Diag(AtLoc, diag::err_objc_illegal_interface_qual);
457bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner      // Skip until we see an '@' or '}' or ';'.
458a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner      SkipUntil(tok::r_brace, tok::at);
459a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner      break;
46046d545e355a4fea2a201652c3c8bbf22a13187a6Fariborz Jahanian
46146d545e355a4fea2a201652c3c8bbf22a13187a6Fariborz Jahanian    case tok::objc_implementation:
462df81c2c6ce37f4ae3c45dd01093b6274fa0b6692Fariborz Jahanian    case tok::objc_interface:
463d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen      Diag(AtLoc, diag::err_objc_missing_end)
464d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen          << FixItHint::CreateInsertion(AtLoc, "@end\n");
465d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen      Diag(CDecl->getLocStart(), diag::note_objc_container_start)
466d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen          << (int) Actions.getObjCContainerKind();
46746d545e355a4fea2a201652c3c8bbf22a13187a6Fariborz Jahanian      ConsumeToken();
46846d545e355a4fea2a201652c3c8bbf22a13187a6Fariborz Jahanian      break;
46946d545e355a4fea2a201652c3c8bbf22a13187a6Fariborz Jahanian
470a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner    case tok::objc_required:
471a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner    case tok::objc_optional:
472a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner      // This is only valid on protocols.
473bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner      // FIXME: Should this check for ObjC2 being enabled?
474e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner      if (contextKey != tok::objc_protocol)
475bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner        Diag(AtLoc, diag::err_objc_directive_only_in_protocol);
476a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner      else
477bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner        MethodImplKind = DirectiveKind;
478a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner      break;
4791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
480a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner    case tok::objc_property:
4814e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie      if (!getLangOpts().ObjC2)
482b321c0c0ba957d78475e72cebde4028fdaa00f8fChris Lattner        Diag(AtLoc, diag::err_objc_properties_require_objc2);
483f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner
484e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner      ObjCDeclSpec OCDS;
48577bfb8b43ec3f7dee3a71f6e854b03ad29dab84fFariborz Jahanian      SourceLocation LParenLoc;
4861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      // Parse property attribute list, if any.
48777bfb8b43ec3f7dee3a71f6e854b03ad29dab84fFariborz Jahanian      if (Tok.is(tok::l_paren)) {
48877bfb8b43ec3f7dee3a71f6e854b03ad29dab84fFariborz Jahanian        LParenLoc = Tok.getLocation();
489a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian        ParseObjCPropertyAttribute(OCDS);
49077bfb8b43ec3f7dee3a71f6e854b03ad29dab84fFariborz Jahanian      }
4911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
492a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian      ObjCPropertyCallback Callback(*this, allProperties,
49377bfb8b43ec3f7dee3a71f6e854b03ad29dab84fFariborz Jahanian                                    OCDS, AtLoc, LParenLoc, MethodImplKind);
494bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall
495e82a10fbba9e33b253119c7c1e0a9801caef486dChris Lattner      // Parse all the comma separated declarators.
4960b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall      DeclSpec DS(AttrFactory);
497bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall      ParseStructDeclaration(DS, Callback);
4981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4997da19ea50d4161fcda40d135735bcf450cabeb50John McCall      ExpectAndConsume(tok::semi, diag::err_expected_semi_decl_list);
500a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner      break;
501f28b264437053fb0deacc9ba02b18a0966f7290aSteve Naroff    }
502294494e1cce92043562b4680c613df7fd028c02eSteve Naroff  }
503bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner
504bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner  // We break out of the big loop in two cases: when we see @end or when we see
505bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner  // EOF.  In the former case, eat the @end.  In the later case, emit an error.
506c464ae8444edb6d07ea49b7a0eae1674c0fa1bb8Douglas Gregor  if (Tok.is(tok::code_completion)) {
507a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian    Actions.CodeCompleteObjCAtDirective(getCurScope());
5087d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis    return cutOffParsing();
509d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen  } else if (Tok.isObjCAtKeyword(tok::objc_end)) {
510bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner    ConsumeToken(); // the "end" identifier
511d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen  } else {
512d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen    Diag(Tok, diag::err_objc_missing_end)
513d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen        << FixItHint::CreateInsertion(Tok.getLocation(), "\n@end\n");
514d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen    Diag(CDecl->getLocStart(), diag::note_objc_container_start)
515d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen        << (int) Actions.getObjCContainerKind();
516d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen    AtEnd.setBegin(Tok.getLocation());
517d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen    AtEnd.setEnd(Tok.getLocation());
518d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen  }
5191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
520a2449b2bf739545494241e189b59587d5ca5c2c1Chris Lattner  // Insert collected methods declarations into the @interface object.
521bc662afa1cb9b61cb1e7808bb1463dd6291b8095Chris Lattner  // This passes in an invalid SourceLocation for AtEndLoc when EOF is hit.
522a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian  Actions.ActOnAtEnd(getCurScope(), AtEnd,
5231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                     allMethods.data(), allMethods.size(),
524beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad                     allProperties.data(), allProperties.size(),
525beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad                     allTUVariables.data(), allTUVariables.size());
526294494e1cce92043562b4680c613df7fd028c02eSteve Naroff}
527294494e1cce92043562b4680c613df7fd028c02eSteve Naroff
528d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian///   Parse property attribute declarations.
529d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian///
530d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian///   property-attr-decl: '(' property-attrlist ')'
531d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian///   property-attrlist:
532d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian///     property-attribute
533d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian///     property-attrlist ',' property-attribute
534d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian///   property-attribute:
535d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian///     getter '=' identifier
536d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian///     setter '=' identifier ':'
537d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian///     readonly
538d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian///     readwrite
539d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian///     assign
540d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian///     retain
541d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian///     copy
542d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian///     nonatomic
543f85e193739c953358c865005855253af4f68a497John McCall///     atomic
544f85e193739c953358c865005855253af4f68a497John McCall///     strong
545f85e193739c953358c865005855253af4f68a497John McCall///     weak
546f85e193739c953358c865005855253af4f68a497John McCall///     unsafe_unretained
547d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian///
548a28948f34817476d02412fa204cae038e228c827Fariborz Jahanianvoid Parser::ParseObjCPropertyAttribute(ObjCDeclSpec &DS) {
5498ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner  assert(Tok.getKind() == tok::l_paren);
5504a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor  BalancedDelimiterTracker T(*this, tok::l_paren);
5514a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor  T.consumeOpen();
5521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
553cd9f4b31c4fe5b77b5519cc17b4583fab912bad1Chris Lattner  while (1) {
554ece8e71d12b6f4cb2dc501297afef126dab8ad74Steve Naroff    if (Tok.is(tok::code_completion)) {
55523c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor      Actions.CodeCompleteObjCPropertyFlags(getCurScope(), DS);
5567d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis      return cutOffParsing();
557ece8e71d12b6f4cb2dc501297afef126dab8ad74Steve Naroff    }
558d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian    const IdentifierInfo *II = Tok.getIdentifierInfo();
5591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
560f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner    // If this is not an identifier at all, bail out early.
561f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner    if (II == 0) {
5624a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor      T.consumeClose();
563f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner      return;
564f6ed85533583dae18a44ddc4be6cfc4d68749e36Chris Lattner    }
5651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
566156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner    SourceLocation AttrName = ConsumeToken(); // consume last attribute name
5671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
56892e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner    if (II->isStr("readonly"))
569e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner      DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_readonly);
57092e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner    else if (II->isStr("assign"))
571e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner      DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_assign);
572f85e193739c953358c865005855253af4f68a497John McCall    else if (II->isStr("unsafe_unretained"))
573f85e193739c953358c865005855253af4f68a497John McCall      DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_unsafe_unretained);
57492e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner    else if (II->isStr("readwrite"))
575e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner      DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_readwrite);
57692e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner    else if (II->isStr("retain"))
577e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner      DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_retain);
578f85e193739c953358c865005855253af4f68a497John McCall    else if (II->isStr("strong"))
579f85e193739c953358c865005855253af4f68a497John McCall      DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_strong);
58092e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner    else if (II->isStr("copy"))
581e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner      DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_copy);
58292e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner    else if (II->isStr("nonatomic"))
583e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner      DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_nonatomic);
58445937ae10a0f70f74508165aab4f2b63e18ea747Fariborz Jahanian    else if (II->isStr("atomic"))
58545937ae10a0f70f74508165aab4f2b63e18ea747Fariborz Jahanian      DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_atomic);
586f85e193739c953358c865005855253af4f68a497John McCall    else if (II->isStr("weak"))
587f85e193739c953358c865005855253af4f68a497John McCall      DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_weak);
58892e62b02226410bcad8584541b8f1ff4d35ebab9Chris Lattner    else if (II->isStr("getter") || II->isStr("setter")) {
58942499be29b620d2eae34beb0f4d0f9da5a9584daAnders Carlsson      bool IsSetter = II->getNameStart()[0] == 's';
59042499be29b620d2eae34beb0f4d0f9da5a9584daAnders Carlsson
591e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner      // getter/setter require extra treatment.
59242499be29b620d2eae34beb0f4d0f9da5a9584daAnders Carlsson      unsigned DiagID = IsSetter ? diag::err_objc_expected_equal_for_setter :
59342499be29b620d2eae34beb0f4d0f9da5a9584daAnders Carlsson        diag::err_objc_expected_equal_for_getter;
59442499be29b620d2eae34beb0f4d0f9da5a9584daAnders Carlsson
59542499be29b620d2eae34beb0f4d0f9da5a9584daAnders Carlsson      if (ExpectAndConsume(tok::equal, DiagID, "", tok::r_paren))
596dd5b5f2bb73d037745940431b71eb98393d12d4fChris Lattner        return;
5971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5984ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor      if (Tok.is(tok::code_completion)) {
59942499be29b620d2eae34beb0f4d0f9da5a9584daAnders Carlsson        if (IsSetter)
600a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian          Actions.CodeCompleteObjCPropertySetter(getCurScope());
6014ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor        else
602a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian          Actions.CodeCompleteObjCPropertyGetter(getCurScope());
6037d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis        return cutOffParsing();
6044ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor      }
6054ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor
60642499be29b620d2eae34beb0f4d0f9da5a9584daAnders Carlsson
60742499be29b620d2eae34beb0f4d0f9da5a9584daAnders Carlsson      SourceLocation SelLoc;
60842499be29b620d2eae34beb0f4d0f9da5a9584daAnders Carlsson      IdentifierInfo *SelIdent = ParseObjCSelectorPiece(SelLoc);
60942499be29b620d2eae34beb0f4d0f9da5a9584daAnders Carlsson
61042499be29b620d2eae34beb0f4d0f9da5a9584daAnders Carlsson      if (!SelIdent) {
61142499be29b620d2eae34beb0f4d0f9da5a9584daAnders Carlsson        Diag(Tok, diag::err_objc_expected_selector_for_getter_setter)
61242499be29b620d2eae34beb0f4d0f9da5a9584daAnders Carlsson          << IsSetter;
6138ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner        SkipUntil(tok::r_paren);
6148ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner        return;
6158ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner      }
6161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
61742499be29b620d2eae34beb0f4d0f9da5a9584daAnders Carlsson      if (IsSetter) {
6188ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner        DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_setter);
61942499be29b620d2eae34beb0f4d0f9da5a9584daAnders Carlsson        DS.setSetterName(SelIdent);
6201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
621e0097db2848c463a534c18c235c6d3e53f2f1b87Fariborz Jahanian        if (ExpectAndConsume(tok::colon,
622e0097db2848c463a534c18c235c6d3e53f2f1b87Fariborz Jahanian                             diag::err_expected_colon_after_setter_name, "",
623156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner                             tok::r_paren))
6248ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner          return;
6258ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner      } else {
6268ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner        DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_getter);
62742499be29b620d2eae34beb0f4d0f9da5a9584daAnders Carlsson        DS.setGetterName(SelIdent);
6288ca329c00e72f301cbaaa42229b20a2f5bc793e5Chris Lattner      }
629e00da7c2f47d4a3d9615c1056a8a65e459113de3Chris Lattner    } else {
630a9500f05ba6c09bbd84d342236863833067cd816Chris Lattner      Diag(AttrName, diag::err_objc_expected_property_attr) << II;
631cd9f4b31c4fe5b77b5519cc17b4583fab912bad1Chris Lattner      SkipUntil(tok::r_paren);
632cd9f4b31c4fe5b77b5519cc17b4583fab912bad1Chris Lattner      return;
633cd9f4b31c4fe5b77b5519cc17b4583fab912bad1Chris Lattner    }
6341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
635156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner    if (Tok.isNot(tok::comma))
636156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner      break;
6371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
638156b061e4918a5e7ecd8eb317975de0e6be2688bChris Lattner    ConsumeToken();
639d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian  }
6401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6414a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor  T.consumeClose();
642d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian}
643d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian
6443536b443bc50d58a79f14fca9b6842541a434854Steve Naroff///   objc-method-proto:
6451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///     objc-instance-method objc-method-decl objc-method-attributes[opt]
6463536b443bc50d58a79f14fca9b6842541a434854Steve Naroff///     objc-class-method objc-method-decl objc-method-attributes[opt]
647294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///
648294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///   objc-instance-method: '-'
649294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///   objc-class-method: '+'
650294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///
6514985aceceb9b9261b876b515d32726175c13a775Steve Naroff///   objc-method-attributes:         [OBJC2]
6524985aceceb9b9261b876b515d32726175c13a775Steve Naroff///     __attribute__((deprecated))
6534985aceceb9b9261b876b515d32726175c13a775Steve Naroff///
654a28948f34817476d02412fa204cae038e228c827Fariborz JahanianDecl *Parser::ParseObjCMethodPrototype(tok::ObjCKeywordKind MethodImplKind,
65590ba78c64d0c24cfbc1bf88728db9775d44d7f9fFariborz Jahanian                                       bool MethodDefinition) {
656df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  assert((Tok.is(tok::minus) || Tok.is(tok::plus)) && "expected +/-");
657294494e1cce92043562b4680c613df7fd028c02eSteve Naroff
6581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  tok::TokenKind methodType = Tok.getKind();
659bef1185418705e16012b3dd50cd7c260c8d6b79cSteve Naroff  SourceLocation mLoc = ConsumeToken();
660a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian  Decl *MDecl = ParseObjCMethodDecl(mLoc, methodType, MethodImplKind,
66190ba78c64d0c24cfbc1bf88728db9775d44d7f9fFariborz Jahanian                                    MethodDefinition);
6623536b443bc50d58a79f14fca9b6842541a434854Steve Naroff  // Since this rule is used for both method declarations and definitions,
6632bd42fadafddc8acf744b57a970bdc96a077c617Steve Naroff  // the caller is (optionally) responsible for consuming the ';'.
664f28b264437053fb0deacc9ba02b18a0966f7290aSteve Naroff  return MDecl;
665294494e1cce92043562b4680c613df7fd028c02eSteve Naroff}
666294494e1cce92043562b4680c613df7fd028c02eSteve Naroff
667294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///   objc-selector:
668294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///     identifier
669294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///     one of
670294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///       enum struct union if else while do for switch case default
671294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///       break continue return goto asm sizeof typeof __alignof
672294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///       unsigned long const short volatile signed restrict _Complex
673294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///       in out inout bycopy byref oneway int char float double void _Bool
674294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///
6752fc5c2428ecb450a3256c8316b93b8655cb76a0fChris LattnerIdentifierInfo *Parser::ParseObjCSelectorPiece(SourceLocation &SelectorLoc) {
676be74740cc246ce08d42804a684385a42eb814edbFariborz Jahanian
677ff38491c18b060526d754765b952f4a497a89416Chris Lattner  switch (Tok.getKind()) {
678ff38491c18b060526d754765b952f4a497a89416Chris Lattner  default:
679ff38491c18b060526d754765b952f4a497a89416Chris Lattner    return 0;
680afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian  case tok::ampamp:
681afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian  case tok::ampequal:
682afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian  case tok::amp:
683afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian  case tok::pipe:
684afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian  case tok::tilde:
685afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian  case tok::exclaim:
686afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian  case tok::exclaimequal:
687afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian  case tok::pipepipe:
688afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian  case tok::pipeequal:
689afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian  case tok::caret:
690afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian  case tok::caretequal: {
6913846ca29a8cc1d376a4b695194c29952dbbfb544Fariborz Jahanian    std::string ThisTok(PP.getSpelling(Tok));
692afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian    if (isalpha(ThisTok[0])) {
693afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian      IdentifierInfo *II = &PP.getIdentifierTable().get(ThisTok.data());
694afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian      Tok.setKind(tok::identifier);
695afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian      SelectorLoc = ConsumeToken();
696afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian      return II;
697afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian    }
698afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian    return 0;
699afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian  }
700afbc68177cc11b8bfa47464b20e15d5f8fb21d4eFariborz Jahanian
701ff38491c18b060526d754765b952f4a497a89416Chris Lattner  case tok::identifier:
702ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_asm:
703ff38491c18b060526d754765b952f4a497a89416Chris Lattner  case tok::kw_auto:
7049298d9655aed28b2d9f6cc65c81401b209f03fdcChris Lattner  case tok::kw_bool:
705ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_break:
706ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_case:
707ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_catch:
708ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_char:
709ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_class:
710ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_const:
711ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_const_cast:
712ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_continue:
713ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_default:
714ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_delete:
715ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_do:
716ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_double:
717ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_dynamic_cast:
718ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_else:
719ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_enum:
720ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_explicit:
721ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_export:
722ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_extern:
723ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_false:
724ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_float:
725ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_for:
726ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_friend:
727ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_goto:
728ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_if:
729ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_inline:
730ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_int:
731ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_long:
732ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_mutable:
733ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_namespace:
734ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_new:
735ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_operator:
736ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_private:
737ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_protected:
738ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_public:
739ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_register:
740ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_reinterpret_cast:
741ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_restrict:
742ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_return:
743ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_short:
744ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_signed:
745ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_sizeof:
746ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_static:
747ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_static_cast:
748ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_struct:
749ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_switch:
750ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_template:
751ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_this:
752ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_throw:
753ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_true:
754ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_try:
755ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_typedef:
756ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_typeid:
757ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_typename:
758ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_typeof:
759ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_union:
760ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_unsigned:
761ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_using:
762ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_virtual:
763ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_void:
764ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_volatile:
765ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_wchar_t:
766ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw_while:
767ff38491c18b060526d754765b952f4a497a89416Chris Lattner  case tok::kw__Bool:
768ff38491c18b060526d754765b952f4a497a89416Chris Lattner  case tok::kw__Complex:
769ef048ef393960728bdc82cd5c45035bde7013b6aAnders Carlsson  case tok::kw___alignof:
770ff38491c18b060526d754765b952f4a497a89416Chris Lattner    IdentifierInfo *II = Tok.getIdentifierInfo();
7714b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian    SelectorLoc = ConsumeToken();
772ff38491c18b060526d754765b952f4a497a89416Chris Lattner    return II;
773d064951b0dcc95f8604d0d69ae82d9ecbd38c796Fariborz Jahanian  }
774294494e1cce92043562b4680c613df7fd028c02eSteve Naroff}
775294494e1cce92043562b4680c613df7fd028c02eSteve Naroff
7760196cab54007ff072ec2642da8911c6b7e8d3fb5Fariborz Jahanian///  objc-for-collection-in: 'in'
7770196cab54007ff072ec2642da8911c6b7e8d3fb5Fariborz Jahanian///
778335a2d4122e41343fe11a775889b8bec5b14be60Fariborz Jahanianbool Parser::isTokIdentifier_in() const {
7793ba5a0f90a03d5e13d02cbee9abd2a1ba01b18bcFariborz Jahanian  // FIXME: May have to do additional look-ahead to only allow for
7803ba5a0f90a03d5e13d02cbee9abd2a1ba01b18bcFariborz Jahanian  // valid tokens following an 'in'; such as an identifier, unary operators,
7813ba5a0f90a03d5e13d02cbee9abd2a1ba01b18bcFariborz Jahanian  // '[' etc.
7824e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie  return (getLangOpts().ObjC2 && Tok.is(tok::identifier) &&
7835ffb14b7e88e587cd2f78dcc3a966a64108920f0Chris Lattner          Tok.getIdentifierInfo() == ObjCTypeQuals[objc_in]);
7840196cab54007ff072ec2642da8911c6b7e8d3fb5Fariborz Jahanian}
7850196cab54007ff072ec2642da8911c6b7e8d3fb5Fariborz Jahanian
786a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ParseObjCTypeQualifierList - This routine parses the objective-c's type
787e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner/// qualifier list and builds their bitmask representation in the input
788e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner/// argument.
789294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///
790294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///   objc-type-qualifiers:
791294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///     objc-type-qualifier
792294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///     objc-type-qualifiers objc-type-qualifier
793294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///
794b77cab97f17f946744c920629ca17271308d8ebfDouglas Gregorvoid Parser::ParseObjCTypeQualifierList(ObjCDeclSpec &DS,
795cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall                                        Declarator::TheContext Context) {
796cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall  assert(Context == Declarator::ObjCParameterContext ||
797cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall         Context == Declarator::ObjCResultContext);
798cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall
799e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner  while (1) {
800d32b0225e29fcafb2b2b2a4b1c51dcb1518af9c6Douglas Gregor    if (Tok.is(tok::code_completion)) {
801b77cab97f17f946744c920629ca17271308d8ebfDouglas Gregor      Actions.CodeCompleteObjCPassingType(getCurScope(), DS,
802cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall                          Context == Declarator::ObjCParameterContext);
8037d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis      return cutOffParsing();
804d32b0225e29fcafb2b2b2a4b1c51dcb1518af9c6Douglas Gregor    }
805d32b0225e29fcafb2b2b2a4b1c51dcb1518af9c6Douglas Gregor
806cb53b361bce341c8591333c6997f62e480acc0b4Chris Lattner    if (Tok.isNot(tok::identifier))
807e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner      return;
8081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
809e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner    const IdentifierInfo *II = Tok.getIdentifierInfo();
810e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner    for (unsigned i = 0; i != objc_NumQuals; ++i) {
811a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek      if (II != ObjCTypeQuals[i])
812e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner        continue;
8131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
814a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek      ObjCDeclSpec::ObjCDeclQualifier Qual;
815e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner      switch (i) {
816b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie      default: llvm_unreachable("Unknown decl qualifier");
817a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek      case objc_in:     Qual = ObjCDeclSpec::DQ_In; break;
818a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek      case objc_out:    Qual = ObjCDeclSpec::DQ_Out; break;
819a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek      case objc_inout:  Qual = ObjCDeclSpec::DQ_Inout; break;
820a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek      case objc_oneway: Qual = ObjCDeclSpec::DQ_Oneway; break;
821a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek      case objc_bycopy: Qual = ObjCDeclSpec::DQ_Bycopy; break;
822a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek      case objc_byref:  Qual = ObjCDeclSpec::DQ_Byref; break;
823e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner      }
824a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek      DS.setObjCDeclQualifier(Qual);
825e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner      ConsumeToken();
826e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner      II = 0;
827e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner      break;
828e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner    }
8291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
830e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner    // If this wasn't a recognized qualifier, bail out.
831e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner    if (II) return;
832e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner  }
833e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner}
834e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner
835cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall/// Take all the decl attributes out of the given list and add
836cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall/// them to the given attribute set.
837cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCallstatic void takeDeclAttributes(ParsedAttributes &attrs,
838cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall                               AttributeList *list) {
839cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall  while (list) {
840cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall    AttributeList *cur = list;
841cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall    list = cur->getNext();
842cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall
843cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall    if (!cur->isUsedAsTypeAttr()) {
844cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall      // Clear out the next pointer.  We're really completely
845cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall      // destroying the internal invariants of the declarator here,
846cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall      // but it doesn't matter because we're done with it.
847cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall      cur->setNext(0);
848cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall      attrs.add(cur);
849cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall    }
850cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall  }
851cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall}
852cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall
853cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall/// takeDeclAttributes - Take all the decl attributes from the given
854cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall/// declarator and add them to the given list.
855cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCallstatic void takeDeclAttributes(ParsedAttributes &attrs,
856cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall                               Declarator &D) {
857cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall  // First, take ownership of all attributes.
858cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall  attrs.getPool().takeAllFrom(D.getAttributePool());
859cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall  attrs.getPool().takeAllFrom(D.getDeclSpec().getAttributePool());
860cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall
861cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall  // Now actually move the attributes over.
862cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall  takeDeclAttributes(attrs, D.getDeclSpec().getAttributes().getList());
863cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall  takeDeclAttributes(attrs, D.getAttributes());
864cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall  for (unsigned i = 0, e = D.getNumTypeObjects(); i != e; ++i)
865cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall    takeDeclAttributes(attrs,
866cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall                  const_cast<AttributeList*>(D.getTypeObject(i).getAttrs()));
867cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall}
868cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall
869e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner///   objc-type-name:
870e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner///     '(' objc-type-qualifiers[opt] type-name ')'
871e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner///     '(' objc-type-qualifiers[opt] ')'
872e8b724d481c9547de2ee6f442be594b38ada452dChris Lattner///
873b77cab97f17f946744c920629ca17271308d8ebfDouglas GregorParsedType Parser::ParseObjCTypeName(ObjCDeclSpec &DS,
874cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall                                     Declarator::TheContext context,
875cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall                                     ParsedAttributes *paramAttrs) {
876cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall  assert(context == Declarator::ObjCParameterContext ||
877cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall         context == Declarator::ObjCResultContext);
878cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall  assert((paramAttrs != 0) == (context == Declarator::ObjCParameterContext));
879cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall
880df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  assert(Tok.is(tok::l_paren) && "expected (");
8811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8824a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor  BalancedDelimiterTracker T(*this, tok::l_paren);
8834a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor  T.consumeOpen();
8844a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor
885e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner  SourceLocation TypeStartLoc = Tok.getLocation();
8869735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian  ObjCDeclContextSwitch ObjCDC(*this);
8879735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian
88819d74e1494fe399f0e2a94e9419c095f8214851bFariborz Jahanian  // Parse type qualifiers, in, inout, etc.
889cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall  ParseObjCTypeQualifierList(DS, context);
8904fa7afd07421e7276d1717e4fdf43a5fdd65a622Steve Naroff
891b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  ParsedType Ty;
892809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor  if (isTypeSpecifierQualifier()) {
893cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall    // Parse an abstract declarator.
894cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall    DeclSpec declSpec(AttrFactory);
895cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall    declSpec.setObjCQualifiers(&DS);
896cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall    ParseSpecifierQualifierList(declSpec);
897cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall    Declarator declarator(declSpec, context);
898cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall    ParseDeclarator(declarator);
899cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall
900cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall    // If that's not invalid, extract a type.
901cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall    if (!declarator.isInvalidType()) {
902cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall      TypeResult type = Actions.ActOnTypeName(getCurScope(), declarator);
903cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall      if (!type.isInvalid())
904cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall        Ty = type.get();
905cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall
906cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall      // If we're parsing a parameter, steal all the decl attributes
907cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall      // and add them to the decl spec.
908cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall      if (context == Declarator::ObjCParameterContext)
909cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall        takeDeclAttributes(*paramAttrs, declarator);
910cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall    }
911cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall  } else if (context == Declarator::ObjCResultContext &&
912cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall             Tok.is(tok::identifier)) {
913e97179c675b341927807c718be215c8d1aab8acbDouglas Gregor    if (!Ident_instancetype)
914e97179c675b341927807c718be215c8d1aab8acbDouglas Gregor      Ident_instancetype = PP.getIdentifierInfo("instancetype");
915e97179c675b341927807c718be215c8d1aab8acbDouglas Gregor
916e97179c675b341927807c718be215c8d1aab8acbDouglas Gregor    if (Tok.getIdentifierInfo() == Ident_instancetype) {
917e97179c675b341927807c718be215c8d1aab8acbDouglas Gregor      Ty = Actions.ActOnObjCInstanceType(Tok.getLocation());
918e97179c675b341927807c718be215c8d1aab8acbDouglas Gregor      ConsumeToken();
919e97179c675b341927807c718be215c8d1aab8acbDouglas Gregor    }
920809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor  }
921e97179c675b341927807c718be215c8d1aab8acbDouglas Gregor
9224a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner  if (Tok.is(tok::r_paren))
9234a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor    T.consumeClose();
9244a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner  else if (Tok.getLocation() == TypeStartLoc) {
925e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner    // If we didn't eat any tokens, then this isn't a type.
9261ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner    Diag(Tok, diag::err_expected_type);
9274a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner    SkipUntil(tok::r_paren);
9284a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner  } else {
9294a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner    // Otherwise, we found *something*, but didn't get a ')' in the right
9304a76b292c9c3f60a257636e21d76b6ce1c12f8c4Chris Lattner    // place.  Emit an error then return what we have as the type.
9314a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor    T.consumeClose();
932294494e1cce92043562b4680c613df7fd028c02eSteve Naroff  }
933f28b264437053fb0deacc9ba02b18a0966f7290aSteve Naroff  return Ty;
934294494e1cce92043562b4680c613df7fd028c02eSteve Naroff}
935294494e1cce92043562b4680c613df7fd028c02eSteve Naroff
936294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///   objc-method-decl:
937294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///     objc-selector
9384985aceceb9b9261b876b515d32726175c13a775Steve Naroff///     objc-keyword-selector objc-parmlist[opt]
939294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///     objc-type-name objc-selector
9404985aceceb9b9261b876b515d32726175c13a775Steve Naroff///     objc-type-name objc-keyword-selector objc-parmlist[opt]
941294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///
942294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///   objc-keyword-selector:
9431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///     objc-keyword-decl
944294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///     objc-keyword-selector objc-keyword-decl
945294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///
946294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///   objc-keyword-decl:
9477ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff///     objc-selector ':' objc-type-name objc-keyword-attributes[opt] identifier
9487ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff///     objc-selector ':' objc-keyword-attributes[opt] identifier
9497ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff///     ':' objc-type-name objc-keyword-attributes[opt] identifier
9507ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff///     ':' objc-keyword-attributes[opt] identifier
951294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///
9524985aceceb9b9261b876b515d32726175c13a775Steve Naroff///   objc-parmlist:
9534985aceceb9b9261b876b515d32726175c13a775Steve Naroff///     objc-parms objc-ellipsis[opt]
954294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///
9554985aceceb9b9261b876b515d32726175c13a775Steve Naroff///   objc-parms:
9564985aceceb9b9261b876b515d32726175c13a775Steve Naroff///     objc-parms , parameter-declaration
957294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///
9584985aceceb9b9261b876b515d32726175c13a775Steve Naroff///   objc-ellipsis:
959294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///     , ...
960294494e1cce92043562b4680c613df7fd028c02eSteve Naroff///
9617ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff///   objc-keyword-attributes:         [OBJC2]
9627ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff///     __attribute__((unused))
9637ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff///
964d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseObjCMethodDecl(SourceLocation mLoc,
9652ccccb3ff40c64927817a7e1ddf1da8c188ed224Douglas Gregor                                  tok::TokenKind mType,
96690ba78c64d0c24cfbc1bf88728db9775d44d7f9fFariborz Jahanian                                  tok::ObjCKeywordKind MethodImplKind,
96790ba78c64d0c24cfbc1bf88728db9775d44d7f9fFariborz Jahanian                                  bool MethodDefinition) {
96854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  ParsingDeclRAIIObject PD(*this);
96954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall
970e8f5a1710a7738deff40e10efcd05b1bd6af184fDouglas Gregor  if (Tok.is(tok::code_completion)) {
97123c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor    Actions.CodeCompleteObjCMethodDecl(getCurScope(), mType == tok::minus,
972a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian                                       /*ReturnType=*/ ParsedType());
9737d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis    cutOffParsing();
9747d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis    return 0;
975e8f5a1710a7738deff40e10efcd05b1bd6af184fDouglas Gregor  }
976e8f5a1710a7738deff40e10efcd05b1bd6af184fDouglas Gregor
977e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner  // Parse the return type if present.
978b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  ParsedType ReturnType;
979a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCDeclSpec DSRet;
980df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  if (Tok.is(tok::l_paren))
981cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall    ReturnType = ParseObjCTypeName(DSRet, Declarator::ObjCResultContext, 0);
9821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
9839e0493576af77dba1c48858c03e31a2897d0681eTed Kremenek  // If attributes exist before the method, parse them.
9840b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall  ParsedAttributes methodAttrs(AttrFactory);
9854e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie  if (getLangOpts().ObjC2)
9860b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall    MaybeParseGNUAttributes(methodAttrs);
9879e0493576af77dba1c48858c03e31a2897d0681eTed Kremenek
988e8f5a1710a7738deff40e10efcd05b1bd6af184fDouglas Gregor  if (Tok.is(tok::code_completion)) {
98923c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor    Actions.CodeCompleteObjCMethodDecl(getCurScope(), mType == tok::minus,
990a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian                                       ReturnType);
9917d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis    cutOffParsing();
9927d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis    return 0;
993e8f5a1710a7738deff40e10efcd05b1bd6af184fDouglas Gregor  }
994e8f5a1710a7738deff40e10efcd05b1bd6af184fDouglas Gregor
9959e0493576af77dba1c48858c03e31a2897d0681eTed Kremenek  // Now parse the selector.
996bef1185418705e16012b3dd50cd7c260c8d6b79cSteve Naroff  SourceLocation selLoc;
9972fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner  IdentifierInfo *SelIdent = ParseObjCSelectorPiece(selLoc);
998e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner
99984c431088693e216193094d1dbf327a01173f57fSteve Naroff  // An unnamed colon is valid.
100084c431088693e216193094d1dbf327a01173f57fSteve Naroff  if (!SelIdent && Tok.isNot(tok::colon)) { // missing selector name.
10011ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner    Diag(Tok, diag::err_expected_selector_for_method)
10021ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner      << SourceRange(mLoc, Tok.getLocation());
1003e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner    // Skip until we get a ; or {}.
1004e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner    SkipUntil(tok::r_brace);
1005d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall    return 0;
1006e8904e992ca5e821b199c4577e8b5e5b17a33b1dChris Lattner  }
10071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10085f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner  SmallVector<DeclaratorChunk::ParamInfo, 8> CParamInfo;
1009df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  if (Tok.isNot(tok::colon)) {
1010ff38491c18b060526d754765b952f4a497a89416Chris Lattner    // If attributes exist after the method, parse them.
10114e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie    if (getLangOpts().ObjC2)
10120b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall      MaybeParseGNUAttributes(methodAttrs);
10131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1014ff38491c18b060526d754765b952f4a497a89416Chris Lattner    Selector Sel = PP.getSelectorTable().getNullarySelector(SelIdent);
1015d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall    Decl *Result
10167f53253223b29d77f1e9c5c0ce93a19932761b77Fariborz Jahanian         = Actions.ActOnMethodDeclaration(getCurScope(), mLoc, Tok.getLocation(),
1017a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian                                          mType, DSRet, ReturnType,
1018926df6cfabf3eaa4afc990c097fa4619b76a9b57Douglas Gregor                                          selLoc, Sel, 0,
10194f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian                                          CParamInfo.data(), CParamInfo.size(),
10200b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall                                          methodAttrs.getList(), MethodImplKind,
10210b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall                                          false, MethodDefinition);
102254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    PD.complete(Result);
102354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    return Result;
1024ff38491c18b060526d754765b952f4a497a89416Chris Lattner  }
1025f28b264437053fb0deacc9ba02b18a0966f7290aSteve Naroff
10265f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner  SmallVector<IdentifierInfo *, 12> KeyIdents;
102711d77169555480ee0a04c6e5bc390d8fde41175dArgyrios Kyrtzidis  SmallVector<SourceLocation, 12> KeyLocs;
10285f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner  SmallVector<Sema::ObjCArgInfo, 12> ArgInfos;
10297f53253223b29d77f1e9c5c0ce93a19932761b77Fariborz Jahanian  ParseScope PrototypeScope(this,
10307f53253223b29d77f1e9c5c0ce93a19932761b77Fariborz Jahanian                            Scope::FunctionPrototypeScope|Scope::DeclScope);
10310b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall
10320b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall  AttributePool allParamAttrs(AttrFactory);
10337f53253223b29d77f1e9c5c0ce93a19932761b77Fariborz Jahanian
1034ff38491c18b060526d754765b952f4a497a89416Chris Lattner  while (1) {
10350b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall    ParsedAttributes paramAttrs(AttrFactory);
1036f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    Sema::ObjCArgInfo ArgInfo;
10371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1038ff38491c18b060526d754765b952f4a497a89416Chris Lattner    // Each iteration parses a single keyword argument.
1039df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner    if (Tok.isNot(tok::colon)) {
1040ff38491c18b060526d754765b952f4a497a89416Chris Lattner      Diag(Tok, diag::err_expected_colon);
1041ff38491c18b060526d754765b952f4a497a89416Chris Lattner      break;
1042ff38491c18b060526d754765b952f4a497a89416Chris Lattner    }
1043ff38491c18b060526d754765b952f4a497a89416Chris Lattner    ConsumeToken(); // Eat the ':'.
10441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1045b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    ArgInfo.Type = ParsedType();
1046e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner    if (Tok.is(tok::l_paren)) // Parse the argument type if present.
1047cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall      ArgInfo.Type = ParseObjCTypeName(ArgInfo.DeclSpec,
1048cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall                                       Declarator::ObjCParameterContext,
1049cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall                                       &paramAttrs);
1050e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner
1051ff38491c18b060526d754765b952f4a497a89416Chris Lattner    // If attributes exist before the argument name, parse them.
1052cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall    // Regardless, collect all the attributes we've parsed so far.
1053e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner    ArgInfo.ArgAttrs = 0;
10544e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie    if (getLangOpts().ObjC2) {
10550b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall      MaybeParseGNUAttributes(paramAttrs);
10560b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall      ArgInfo.ArgAttrs = paramAttrs.getList();
10577f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall    }
10587ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff
105940ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor    // Code completion for the next piece of the selector.
106040ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor    if (Tok.is(tok::code_completion)) {
106140ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor      KeyIdents.push_back(SelIdent);
106240ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor      Actions.CodeCompleteObjCMethodDeclSelector(getCurScope(),
106340ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor                                                 mType == tok::minus,
106440ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor                                                 /*AtParameterName=*/true,
106540ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor                                                 ReturnType,
106640ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor                                                 KeyIdents.data(),
106740ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor                                                 KeyIdents.size());
10687d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis      cutOffParsing();
10697d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis      return 0;
107040ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor    }
107140ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor
1072df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner    if (Tok.isNot(tok::identifier)) {
1073ff38491c18b060526d754765b952f4a497a89416Chris Lattner      Diag(Tok, diag::err_expected_ident); // missing argument name.
1074ff38491c18b060526d754765b952f4a497a89416Chris Lattner      break;
10754985aceceb9b9261b876b515d32726175c13a775Steve Naroff    }
10761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1077e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner    ArgInfo.Name = Tok.getIdentifierInfo();
1078e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner    ArgInfo.NameLoc = Tok.getLocation();
1079ff38491c18b060526d754765b952f4a497a89416Chris Lattner    ConsumeToken(); // Eat the identifier.
10801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1081e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner    ArgInfos.push_back(ArgInfo);
1082e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner    KeyIdents.push_back(SelIdent);
108311d77169555480ee0a04c6e5bc390d8fde41175dArgyrios Kyrtzidis    KeyLocs.push_back(selLoc);
1084e294d3fbaffcbc0cf5f16067ab31d2b2763d25e9Chris Lattner
10850b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall    // Make sure the attributes persist.
10860b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall    allParamAttrs.takeAllFrom(paramAttrs.getPool());
10870b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall
10881f5537aaac1e775aff1d523f2cc59a9a3bd6c946Douglas Gregor    // Code completion for the next piece of the selector.
10891f5537aaac1e775aff1d523f2cc59a9a3bd6c946Douglas Gregor    if (Tok.is(tok::code_completion)) {
10901f5537aaac1e775aff1d523f2cc59a9a3bd6c946Douglas Gregor      Actions.CodeCompleteObjCMethodDeclSelector(getCurScope(),
10911f5537aaac1e775aff1d523f2cc59a9a3bd6c946Douglas Gregor                                                 mType == tok::minus,
109240ed9a13f5b67b2941f5a9521616e57e9e31ba97Douglas Gregor                                                 /*AtParameterName=*/false,
10931f5537aaac1e775aff1d523f2cc59a9a3bd6c946Douglas Gregor                                                 ReturnType,
10941f5537aaac1e775aff1d523f2cc59a9a3bd6c946Douglas Gregor                                                 KeyIdents.data(),
10951f5537aaac1e775aff1d523f2cc59a9a3bd6c946Douglas Gregor                                                 KeyIdents.size());
10967d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis      cutOffParsing();
10977d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis      return 0;
10981f5537aaac1e775aff1d523f2cc59a9a3bd6c946Douglas Gregor    }
10991f5537aaac1e775aff1d523f2cc59a9a3bd6c946Douglas Gregor
1100ff38491c18b060526d754765b952f4a497a89416Chris Lattner    // Check for another keyword selector.
110111d77169555480ee0a04c6e5bc390d8fde41175dArgyrios Kyrtzidis    SelIdent = ParseObjCSelectorPiece(selLoc);
1102df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner    if (!SelIdent && Tok.isNot(tok::colon))
1103ff38491c18b060526d754765b952f4a497a89416Chris Lattner      break;
1104ff38491c18b060526d754765b952f4a497a89416Chris Lattner    // We have a selector or a colon, continue parsing.
1105ff38491c18b060526d754765b952f4a497a89416Chris Lattner  }
11061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1107335eafa5be51f6440672a74c73d588af72e96732Steve Naroff  bool isVariadic = false;
11081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1109ff38491c18b060526d754765b952f4a497a89416Chris Lattner  // Parse the (optional) parameter list.
1110df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  while (Tok.is(tok::comma)) {
1111ff38491c18b060526d754765b952f4a497a89416Chris Lattner    ConsumeToken();
1112df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner    if (Tok.is(tok::ellipsis)) {
1113335eafa5be51f6440672a74c73d588af72e96732Steve Naroff      isVariadic = true;
11144985aceceb9b9261b876b515d32726175c13a775Steve Naroff      ConsumeToken();
1115ff38491c18b060526d754765b952f4a497a89416Chris Lattner      break;
11164985aceceb9b9261b876b515d32726175c13a775Steve Naroff    }
11170b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall    DeclSpec DS(AttrFactory);
1118ff38491c18b060526d754765b952f4a497a89416Chris Lattner    ParseDeclarationSpecifiers(DS);
11191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    // Parse the declarator.
1120ff38491c18b060526d754765b952f4a497a89416Chris Lattner    Declarator ParmDecl(DS, Declarator::PrototypeContext);
1121ff38491c18b060526d754765b952f4a497a89416Chris Lattner    ParseDeclarator(ParmDecl);
11224f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian    IdentifierInfo *ParmII = ParmDecl.getIdentifier();
1123d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall    Decl *Param = Actions.ActOnParamDeclarator(getCurScope(), ParmDecl);
11244f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian    CParamInfo.push_back(DeclaratorChunk::ParamInfo(ParmII,
11254f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian                                                    ParmDecl.getIdentifierLoc(),
11264f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian                                                    Param,
11274f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian                                                   0));
11284f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian
11294985aceceb9b9261b876b515d32726175c13a775Steve Naroff  }
11301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11319c4bb2c08989265411925a04252fd4f93c26e3b1Cameron Esfahani  // FIXME: Add support for optional parameter list...
1132e3a2ca7e30601cdd31c77a830f4cc487851e8096Fariborz Jahanian  // If attributes exist after the method, parse them.
11334e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie  if (getLangOpts().ObjC2)
11340b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall    MaybeParseGNUAttributes(methodAttrs);
11357f53253223b29d77f1e9c5c0ce93a19932761b77Fariborz Jahanian
1136a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian  if (KeyIdents.size() == 0)
1137d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall    return 0;
11387f53253223b29d77f1e9c5c0ce93a19932761b77Fariborz Jahanian
1139ff38491c18b060526d754765b952f4a497a89416Chris Lattner  Selector Sel = PP.getSelectorTable().getSelector(KeyIdents.size(),
1140ff38491c18b060526d754765b952f4a497a89416Chris Lattner                                                   &KeyIdents[0]);
1141d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  Decl *Result
11427f53253223b29d77f1e9c5c0ce93a19932761b77Fariborz Jahanian       = Actions.ActOnMethodDeclaration(getCurScope(), mLoc, Tok.getLocation(),
1143a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian                                        mType, DSRet, ReturnType,
114411d77169555480ee0a04c6e5bc390d8fde41175dArgyrios Kyrtzidis                                        KeyLocs, Sel, &ArgInfos[0],
11454f4fd92c6c64ecbc65507f63ddd09211f732622cFariborz Jahanian                                        CParamInfo.data(), CParamInfo.size(),
11460b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall                                        methodAttrs.getList(),
114790ba78c64d0c24cfbc1bf88728db9775d44d7f9fFariborz Jahanian                                        MethodImplKind, isVariadic, MethodDefinition);
11487f53253223b29d77f1e9c5c0ce93a19932761b77Fariborz Jahanian
114954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  PD.complete(Result);
115054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  return Result;
1151294494e1cce92043562b4680c613df7fd028c02eSteve Naroff}
1152294494e1cce92043562b4680c613df7fd028c02eSteve Naroff
1153dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///   objc-protocol-refs:
1154dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     '<' identifier-list '>'
1155dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///
11567caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattnerbool Parser::
11575f9e272e632e951b1efe824cd16acb4d96077930Chris LattnerParseObjCProtocolReferences(SmallVectorImpl<Decl *> &Protocols,
11585f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner                            SmallVectorImpl<SourceLocation> &ProtocolLocs,
115971b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis                            bool WarnOnDeclarations,
116071b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis                            SourceLocation &LAngleLoc, SourceLocation &EndLoc) {
1161e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner  assert(Tok.is(tok::less) && "expected <");
11621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
116371b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis  LAngleLoc = ConsumeToken(); // the "<"
11641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11655f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner  SmallVector<IdentifierLocPair, 8> ProtocolIdents;
11661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1167e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner  while (1) {
116855385fe3e723cd675001e45f42d61adde6b7f075Douglas Gregor    if (Tok.is(tok::code_completion)) {
116955385fe3e723cd675001e45f42d61adde6b7f075Douglas Gregor      Actions.CodeCompleteObjCProtocolReferences(ProtocolIdents.data(),
117055385fe3e723cd675001e45f42d61adde6b7f075Douglas Gregor                                                 ProtocolIdents.size());
11717d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis      cutOffParsing();
11727d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis      return true;
117355385fe3e723cd675001e45f42d61adde6b7f075Douglas Gregor    }
117455385fe3e723cd675001e45f42d61adde6b7f075Douglas Gregor
1175e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner    if (Tok.isNot(tok::identifier)) {
1176e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner      Diag(Tok, diag::err_expected_ident);
1177e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner      SkipUntil(tok::greater);
1178e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner      return true;
1179e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner    }
1180e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner    ProtocolIdents.push_back(std::make_pair(Tok.getIdentifierInfo(),
1181e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner                                       Tok.getLocation()));
118271b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis    ProtocolLocs.push_back(Tok.getLocation());
1183e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner    ConsumeToken();
11841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1185e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner    if (Tok.isNot(tok::comma))
1186e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner      break;
1187e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner    ConsumeToken();
1188e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner  }
11891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1190e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner  // Consume the '>'.
1191e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner  if (Tok.isNot(tok::greater)) {
1192e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner    Diag(Tok, diag::err_expected_greater);
1193e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner    return true;
1194e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner  }
11951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1196d78ef5b941ce2937228b010e8443f92025f9d683Douglas Gregor  EndLoc = ConsumeToken();
11971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1198e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner  // Convert the list of protocols identifiers into a list of protocol decls.
1199e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner  Actions.FindProtocolDeclaration(WarnOnDeclarations,
1200e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner                                  &ProtocolIdents[0], ProtocolIdents.size(),
1201e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner                                  Protocols);
1202e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner  return false;
1203e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner}
1204e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner
12059bd1d8d174a9d15ae343246c8322299248b9e92aDouglas Gregor/// \brief Parse the Objective-C protocol qualifiers that follow a typename
12069bd1d8d174a9d15ae343246c8322299248b9e92aDouglas Gregor/// in a decl-specifier-seq, starting at the '<'.
120746f936e055d763437accd1e5a1bc49e7e5dbc0a3Douglas Gregorbool Parser::ParseObjCProtocolQualifiers(DeclSpec &DS) {
12089bd1d8d174a9d15ae343246c8322299248b9e92aDouglas Gregor  assert(Tok.is(tok::less) && "Protocol qualifiers start with '<'");
12094e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie  assert(getLangOpts().ObjC1 && "Protocol qualifiers only exist in Objective-C");
12109bd1d8d174a9d15ae343246c8322299248b9e92aDouglas Gregor  SourceLocation LAngleLoc, EndProtoLoc;
12115f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner  SmallVector<Decl *, 8> ProtocolDecl;
12125f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner  SmallVector<SourceLocation, 8> ProtocolLocs;
121346f936e055d763437accd1e5a1bc49e7e5dbc0a3Douglas Gregor  bool Result = ParseObjCProtocolReferences(ProtocolDecl, ProtocolLocs, false,
121446f936e055d763437accd1e5a1bc49e7e5dbc0a3Douglas Gregor                                            LAngleLoc, EndProtoLoc);
12159bd1d8d174a9d15ae343246c8322299248b9e92aDouglas Gregor  DS.setProtocolQualifiers(ProtocolDecl.data(), ProtocolDecl.size(),
12169bd1d8d174a9d15ae343246c8322299248b9e92aDouglas Gregor                           ProtocolLocs.data(), LAngleLoc);
12179bd1d8d174a9d15ae343246c8322299248b9e92aDouglas Gregor  if (EndProtoLoc.isValid())
12189bd1d8d174a9d15ae343246c8322299248b9e92aDouglas Gregor    DS.SetRangeEnd(EndProtoLoc);
121946f936e055d763437accd1e5a1bc49e7e5dbc0a3Douglas Gregor  return Result;
12209bd1d8d174a9d15ae343246c8322299248b9e92aDouglas Gregor}
12219bd1d8d174a9d15ae343246c8322299248b9e92aDouglas Gregor
12229bd1d8d174a9d15ae343246c8322299248b9e92aDouglas Gregor
1223dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///   objc-class-instance-variables:
1224dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     '{' objc-instance-variable-decl-list[opt] '}'
1225dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///
1226dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///   objc-instance-variable-decl-list:
1227dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     objc-visibility-spec
1228dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     objc-instance-variable-decl ';'
1229dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     ';'
1230dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     objc-instance-variable-decl-list objc-visibility-spec
1231dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     objc-instance-variable-decl-list objc-instance-variable-decl ';'
1232dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     objc-instance-variable-decl-list ';'
1233dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///
1234dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///   objc-visibility-spec:
1235dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     @private
1236dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     @protected
1237dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     @public
1238ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff///     @package [OBJC2]
1239dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///
1240dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///   objc-instance-variable-decl:
12411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///     struct-declaration
1242dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///
1243d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallvoid Parser::ParseObjCClassInstanceVariables(Decl *interfaceDecl,
124483c481ade785a919ba21a33f9a8b1b21c1212fb3Fariborz Jahanian                                             tok::ObjCKeywordKind visibility,
124560fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff                                             SourceLocation atLoc) {
1246df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  assert(Tok.is(tok::l_brace) && "expected {");
12475f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner  SmallVector<Decl *, 32> AllIvarDecls;
1248a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian
12491a0d31a3d7f14ddc6370ba912c778aece6c12cf0Douglas Gregor  ParseScope ClassScope(this, Scope::DeclScope|Scope::ClassScope);
12503a387441ae339363ee5b254658f295e97bd9e913Argyrios Kyrtzidis  ObjCDeclContextSwitch ObjCDC(*this);
125172de6676bd30f9081ee4166bbe07b4c270258ce6Douglas Gregor
12524a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor  BalancedDelimiterTracker T(*this, tok::l_brace);
12534a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor  T.consumeOpen();
12541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1255ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff  // While we still have something to read, read the instance variables.
1256df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  while (Tok.isNot(tok::r_brace) && Tok.isNot(tok::eof)) {
1257ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff    // Each iteration of this loop reads one objc-instance-variable-decl.
12581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1259ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff    // Check for extraneous top-level semicolon.
1260df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner    if (Tok.is(tok::semi)) {
1261f13ca06e57ac094ed05ea08c26a499af1ba0ce88Douglas Gregor      Diag(Tok, diag::ext_extra_ivar_semi)
1262849b243d4065f56742a4677d6dc8277609a151f8Douglas Gregor        << FixItHint::CreateRemoval(Tok.getLocation());
1263ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff      ConsumeToken();
1264ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff      continue;
1265ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff    }
12661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1267ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff    // Set the default visibility to private.
1268df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner    if (Tok.is(tok::at)) { // parse objc-visibility-spec
1269ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff      ConsumeToken(); // eat the @ sign
1270c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor
1271c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor      if (Tok.is(tok::code_completion)) {
127223c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor        Actions.CodeCompleteObjCAtVisibility(getCurScope());
12737d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis        return cutOffParsing();
1274c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor      }
1275c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor
1276861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff      switch (Tok.getObjCKeywordID()) {
1277ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff      case tok::objc_private:
1278ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff      case tok::objc_public:
1279ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff      case tok::objc_protected:
1280ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff      case tok::objc_package:
1281861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff        visibility = Tok.getObjCKeywordID();
1282ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff        ConsumeToken();
12831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump        continue;
1284ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff      default:
1285ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff        Diag(Tok, diag::err_objc_illegal_visibility_spec);
1286ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff        continue;
1287ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff      }
1288ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff    }
12891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1290c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor    if (Tok.is(tok::code_completion)) {
129123c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor      Actions.CodeCompleteOrdinaryName(getCurScope(),
1292f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                       Sema::PCC_ObjCInstanceVariableList);
12937d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis      return cutOffParsing();
1294c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor    }
1295c38c3e1e726630458154534227d74eda833d26a0Douglas Gregor
1296bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall    struct ObjCIvarCallback : FieldCallback {
1297bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall      Parser &P;
1298d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall      Decl *IDecl;
1299bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall      tok::ObjCKeywordKind visibility;
13005f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner      SmallVectorImpl<Decl *> &AllIvarDecls;
1301bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall
1302d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall      ObjCIvarCallback(Parser &P, Decl *IDecl, tok::ObjCKeywordKind V,
13035f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner                       SmallVectorImpl<Decl *> &AllIvarDecls) :
1304bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall        P(P), IDecl(IDecl), visibility(V), AllIvarDecls(AllIvarDecls) {
1305bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall      }
1306bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall
1307d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall      Decl *invoke(FieldDeclarator &FD) {
1308a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian        P.Actions.ActOnObjCContainerStartDefinition(IDecl);
1309bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall        // Install the declarator into the interface decl.
1310d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall        Decl *Field
131123c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor          = P.Actions.ActOnIvar(P.getCurScope(),
1312bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall                                FD.D.getDeclSpec().getSourceRange().getBegin(),
1313a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian                                FD.D, FD.BitfieldSize, visibility);
131410af87932fe4bffad539b24d512a33a1803daeaeFariborz Jahanian        P.Actions.ActOnObjCContainerFinishDefinition();
13150bd04596e4645ff145a046dfb3475f39674060d9Fariborz Jahanian        if (Field)
13160bd04596e4645ff145a046dfb3475f39674060d9Fariborz Jahanian          AllIvarDecls.push_back(Field);
1317bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall        return Field;
1318bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall      }
1319bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall    } Callback(*this, interfaceDecl, visibility, AllIvarDecls);
1320d097be8f81fbf4ed96ac10bae18562dd8202666bFariborz Jahanian
1321e13594279a952537ac903325efff57e3edca79d9Chris Lattner    // Parse all the comma separated declarators.
13220b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall    DeclSpec DS(AttrFactory);
1323bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall    ParseStructDeclaration(DS, Callback);
13241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1325df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner    if (Tok.is(tok::semi)) {
1326ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff      ConsumeToken();
1327ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff    } else {
1328ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff      Diag(Tok, diag::err_expected_semi_decl_list);
1329ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff      // Skip to end of block or statement
1330ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff      SkipUntil(tok::r_brace, true, true);
1331ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff    }
1332ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff  }
13334a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor  T.consumeClose();
13344a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor
1335a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian  Actions.ActOnObjCContainerStartDefinition(interfaceDecl);
13364a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor  Actions.ActOnLastBitfield(T.getCloseLocation(), AllIvarDecls);
133710af87932fe4bffad539b24d512a33a1803daeaeFariborz Jahanian  Actions.ActOnObjCContainerFinishDefinition();
13388749be53f53384e7846502791ceda6c657228d07Steve Naroff  // Call ActOnFields() even if we don't have any decls. This is useful
13398749be53f53384e7846502791ceda6c657228d07Steve Naroff  // for code rewriting tools that need to be aware of the empty list.
134023c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor  Actions.ActOnFields(getCurScope(), atLoc, interfaceDecl,
134177b6de07be9186063c12928d2e9785a5d4eecbf6David Blaikie                      AllIvarDecls,
13424a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor                      T.getOpenLocation(), T.getCloseLocation(), 0);
1343ddbff78fb719a645b04bd27099fa6ec8c4693b3cSteve Naroff  return;
13445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
1345dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff
1346dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///   objc-protocol-declaration:
1347dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     objc-protocol-definition
1348dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     objc-protocol-forward-reference
1349dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///
1350dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///   objc-protocol-definition:
13511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///     @protocol identifier
13521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///       objc-protocol-refs[opt]
13531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///       objc-interface-decl-list
1354dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     @end
1355dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///
1356dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///   objc-protocol-forward-reference:
1357dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     @protocol identifier-list ';'
1358dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///
1359dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///   "@protocol identifier ;" should be resolved as "@protocol
13603536b443bc50d58a79f14fca9b6842541a434854Steve Naroff///   identifier-list ;": objc-interface-decl-list may not start with a
1361dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///   semicolon in the first alternative if objc-protocol-refs are omitted.
1362bd9482d859a74bf2c45ef8b8aedec61c0e1c8374Douglas GregorParser::DeclGroupPtrTy
1363bd9482d859a74bf2c45ef8b8aedec61c0e1c8374Douglas GregorParser::ParseObjCAtProtocolDeclaration(SourceLocation AtLoc,
1364bd9482d859a74bf2c45ef8b8aedec61c0e1c8374Douglas Gregor                                       ParsedAttributes &attrs) {
1365861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff  assert(Tok.isObjCAtKeyword(tok::objc_protocol) &&
13667ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff         "ParseObjCAtProtocolDeclaration(): Expected @protocol");
13677ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff  ConsumeToken(); // the "protocol" identifier
13681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1369083128f6b13dfa4fc615a838c49b516d901b1ac0Douglas Gregor  if (Tok.is(tok::code_completion)) {
137023c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor    Actions.CodeCompleteObjCProtocolDecl(getCurScope());
13717d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis    cutOffParsing();
1372bd9482d859a74bf2c45ef8b8aedec61c0e1c8374Douglas Gregor    return DeclGroupPtrTy();
1373083128f6b13dfa4fc615a838c49b516d901b1ac0Douglas Gregor  }
1374083128f6b13dfa4fc615a838c49b516d901b1ac0Douglas Gregor
1375df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  if (Tok.isNot(tok::identifier)) {
13767ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff    Diag(Tok, diag::err_expected_ident); // missing protocol name.
1377bd9482d859a74bf2c45ef8b8aedec61c0e1c8374Douglas Gregor    return DeclGroupPtrTy();
13787ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff  }
13797ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff  // Save the protocol name, then consume it.
13807ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff  IdentifierInfo *protocolName = Tok.getIdentifierInfo();
13817ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff  SourceLocation nameLoc = ConsumeToken();
13821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1383df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  if (Tok.is(tok::semi)) { // forward declaration of one protocol.
13847caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner    IdentifierLocPair ProtoInfo(protocolName, nameLoc);
13857ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff    ConsumeToken();
13861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return Actions.ActOnForwardProtocolDeclaration(AtLoc, &ProtoInfo, 1,
13877f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall                                                   attrs.getList());
13887ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff  }
13891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
139090ec96f3026480fa41057b05d58f338aed585f62Erik Verbruggen  CheckNestedObjCContexts(AtLoc);
139190ec96f3026480fa41057b05d58f338aed585f62Erik Verbruggen
1392df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  if (Tok.is(tok::comma)) { // list of forward declarations.
13935f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner    SmallVector<IdentifierLocPair, 8> ProtocolRefs;
13947caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner    ProtocolRefs.push_back(std::make_pair(protocolName, nameLoc));
13957caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner
13967ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff    // Parse the list of forward declarations.
13977ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff    while (1) {
13987ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff      ConsumeToken(); // the ','
1399df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner      if (Tok.isNot(tok::identifier)) {
14007ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff        Diag(Tok, diag::err_expected_ident);
14017ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff        SkipUntil(tok::semi);
1402bd9482d859a74bf2c45ef8b8aedec61c0e1c8374Douglas Gregor        return DeclGroupPtrTy();
14037ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff      }
14047caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner      ProtocolRefs.push_back(IdentifierLocPair(Tok.getIdentifierInfo(),
14057caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner                                               Tok.getLocation()));
14067ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff      ConsumeToken(); // the identifier
14071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1408df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner      if (Tok.isNot(tok::comma))
14097ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff        break;
14107ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff    }
14117ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff    // Consume the ';'.
14127ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff    if (ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@protocol"))
1413bd9482d859a74bf2c45ef8b8aedec61c0e1c8374Douglas Gregor      return DeclGroupPtrTy();
14141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1415e440eb8158e71deb1e4ab11618ae3d680aac6da1Steve Naroff    return Actions.ActOnForwardProtocolDeclaration(AtLoc,
14161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                                   &ProtocolRefs[0],
1417bc1c877fe28fb6a825f0b226a0a2da99e713ea03Fariborz Jahanian                                                   ProtocolRefs.size(),
14187f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall                                                   attrs.getList());
14197caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner  }
14201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14217ef58fdbefddf693910e6403a71b3d367444c897Steve Naroff  // Last, and definitely not least, parse a protocol declaration.
142271b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis  SourceLocation LAngleLoc, EndProtoLoc;
14237caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner
14245f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner  SmallVector<Decl *, 8> ProtocolRefs;
14255f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner  SmallVector<SourceLocation, 8> ProtocolLocs;
14267caeabd868d46cf4e68478c6e9136dae4e735d21Chris Lattner  if (Tok.is(tok::less) &&
142771b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis      ParseObjCProtocolReferences(ProtocolRefs, ProtocolLocs, false,
142871b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis                                  LAngleLoc, EndProtoLoc))
1429bd9482d859a74bf2c45ef8b8aedec61c0e1c8374Douglas Gregor    return DeclGroupPtrTy();
14301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1431d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  Decl *ProtoType =
1432e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner    Actions.ActOnStartProtocolInterface(AtLoc, protocolName, nameLoc,
1433beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad                                        ProtocolRefs.data(),
1434beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad                                        ProtocolRefs.size(),
143518df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor                                        ProtocolLocs.data(),
14367f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall                                        EndProtoLoc, attrs.getList());
1437a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian
14382f64cfe19e8bf6b6ba1660e38da8c421440457feFariborz Jahanian  ParseObjCInterfaceDeclList(tok::objc_protocol, ProtoType);
1439bd9482d859a74bf2c45ef8b8aedec61c0e1c8374Douglas Gregor  return Actions.ConvertDeclToDeclGroup(ProtoType);
1440dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff}
1441dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff
1442dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///   objc-implementation:
1443dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     objc-class-implementation-prologue
1444dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     objc-category-implementation-prologue
1445dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///
1446dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///   objc-class-implementation-prologue:
1447dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     @implementation identifier objc-superclass[opt]
1448dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///       objc-class-instance-variables[opt]
1449dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///
1450dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///   objc-category-implementation-prologue:
1451dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff///     @implementation identifier ( identifier )
1452849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios KyrtzidisParser::DeclGroupPtrTy
1453849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios KyrtzidisParser::ParseObjCAtImplementationDeclaration(SourceLocation AtLoc) {
1454ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian  assert(Tok.isObjCAtKeyword(tok::objc_implementation) &&
1455ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian         "ParseObjCAtImplementationDeclaration(): Expected @implementation");
1456d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen  CheckNestedObjCContexts(AtLoc);
1457ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian  ConsumeToken(); // the "implementation" identifier
14581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14593b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor  // Code completion after '@implementation'.
14603b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor  if (Tok.is(tok::code_completion)) {
146123c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor    Actions.CodeCompleteObjCImplementationDecl(getCurScope());
14627d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis    cutOffParsing();
1463849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis    return DeclGroupPtrTy();
14643b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor  }
14653b49aca913dc0c1838321b9bb2dc9a4cb4681922Douglas Gregor
1466df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  if (Tok.isNot(tok::identifier)) {
1467ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian    Diag(Tok, diag::err_expected_ident); // missing class or category name.
1468849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis    return DeclGroupPtrTy();
1469ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian  }
1470ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian  // We have a class or category name - consume it.
1471ccb4f314248fb2202637d3290f2b17af5646da08Fariborz Jahanian  IdentifierInfo *nameId = Tok.getIdentifierInfo();
1472ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian  SourceLocation nameLoc = ConsumeToken(); // consume class or category name
1473849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis  Decl *ObjCImpDecl = 0;
14741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  if (Tok.is(tok::l_paren)) {
1476ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian    // we have a category implementation.
1477dec0984fce504a39a7f085774fb67cfd9957be58Jeffrey Yasskin    ConsumeParen();
1478ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian    SourceLocation categoryLoc, rparenLoc;
1479ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian    IdentifierInfo *categoryId = 0;
14801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
148133ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor    if (Tok.is(tok::code_completion)) {
148223c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor      Actions.CodeCompleteObjCImplementationCategory(getCurScope(), nameId, nameLoc);
14837d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis      cutOffParsing();
1484849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis      return DeclGroupPtrTy();
148533ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor    }
148633ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor
1487df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner    if (Tok.is(tok::identifier)) {
1488ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian      categoryId = Tok.getIdentifierInfo();
1489ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian      categoryLoc = ConsumeToken();
1490ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian    } else {
1491ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian      Diag(Tok, diag::err_expected_ident); // missing category name.
1492849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis      return DeclGroupPtrTy();
14931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    }
1494df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner    if (Tok.isNot(tok::r_paren)) {
1495ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian      Diag(Tok, diag::err_expected_rparen);
1496ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian      SkipUntil(tok::r_paren, false); // don't stop at ';'
1497849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis      return DeclGroupPtrTy();
1498ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian    }
1499ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian    rparenLoc = ConsumeParen();
1500849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis    ObjCImpDecl = Actions.ActOnStartCategoryImplementation(
1501d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen                                    AtLoc, nameId, nameLoc, categoryId,
15028f3fde00ad4d4f943321e338b914ae4740711c84Fariborz Jahanian                                    categoryLoc);
1503a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian
1504849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis  } else {
1505849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis    // We have a class implementation
1506849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis    SourceLocation superClassLoc;
1507849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis    IdentifierInfo *superClassId = 0;
1508849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis    if (Tok.is(tok::colon)) {
1509849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis      // We have a super class
1510849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis      ConsumeToken();
1511849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis      if (Tok.isNot(tok::identifier)) {
1512849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis        Diag(Tok, diag::err_expected_ident); // missing super class name.
1513849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis        return DeclGroupPtrTy();
1514849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis      }
1515849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis      superClassId = Tok.getIdentifierInfo();
1516849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis      superClassLoc = ConsumeToken(); // Consume super class name
1517ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian    }
1518849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis    ObjCImpDecl = Actions.ActOnStartClassImplementation(
1519849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis                                    AtLoc, nameId, nameLoc,
1520849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis                                    superClassId, superClassLoc);
1521849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis
1522849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis    if (Tok.is(tok::l_brace)) // we have ivars
1523849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis      ParseObjCClassInstanceVariables(ObjCImpDecl, tok::objc_private, AtLoc);
1524ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian  }
1525849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis  assert(ObjCImpDecl);
15261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1527849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis  SmallVector<Decl *, 8> DeclsInGroup;
1528a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian
1529849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis  {
1530849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis    ObjCImplParsingDataRAII ObjCImplParsing(*this, ObjCImpDecl);
1531849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis    while (!ObjCImplParsing.isFinished() && Tok.isNot(tok::eof)) {
1532849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis      ParsedAttributesWithRange attrs(AttrFactory);
1533849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis      MaybeParseCXX0XAttributes(attrs);
1534849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis      MaybeParseMicrosoftAttributes(attrs);
1535849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis      if (DeclGroupPtrTy DGP = ParseExternalDeclaration(attrs)) {
1536849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis        DeclGroupRef DG = DGP.get();
1537849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis        DeclsInGroup.append(DG.begin(), DG.end());
1538849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis      }
1539849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis    }
1540849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis  }
1541849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis
1542644af7b50bd0541468b45c197f5b637e934d48a0Argyrios Kyrtzidis  return Actions.ActOnFinishObjCImplementation(ObjCImpDecl, DeclsInGroup);
15435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
154460fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff
1545140ab234c23f392d5422691c5de1ee3c15026defFariborz JahanianParser::DeclGroupPtrTy
1546140ab234c23f392d5422691c5de1ee3c15026defFariborz JahanianParser::ParseObjCAtEndDeclaration(SourceRange atEnd) {
1547ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian  assert(Tok.isObjCAtKeyword(tok::objc_end) &&
1548ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian         "ParseObjCAtEndDeclaration(): Expected @end");
1549ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian  ConsumeToken(); // the "end" identifier
1550849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis  if (CurParsedObjCImpl)
1551849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis    CurParsedObjCImpl->finish(atEnd);
15528697d308c1bdd50e5c45757ac11be701c26e9e97Fariborz Jahanian  else
1553782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek    // missing @implementation
1554d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen    Diag(atEnd.getBegin(), diag::err_expected_objc_container);
1555849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis  return DeclGroupPtrTy();
15565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
1557e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian
1558849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios KyrtzidisParser::ObjCImplParsingDataRAII::~ObjCImplParsingDataRAII() {
1559849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis  if (!Finished) {
1560849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis    finish(P.Tok.getLocation());
1561849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis    if (P.Tok.is(tok::eof)) {
1562849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis      P.Diag(P.Tok, diag::err_objc_missing_end)
1563849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis          << FixItHint::CreateInsertion(P.Tok.getLocation(), "\n@end\n");
1564849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis      P.Diag(Dcl->getLocStart(), diag::note_objc_container_start)
1565849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis          << Sema::OCK_Implementation;
1566849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis    }
1567849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis  }
1568849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis  P.CurParsedObjCImpl = 0;
1569849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis  assert(LateParsedObjCMethods.empty());
1570849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis}
1571d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen
1572849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidisvoid Parser::ObjCImplParsingDataRAII::finish(SourceRange AtEnd) {
1573849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis  assert(!Finished);
1574849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis  P.Actions.DefaultSynthesizeProperties(P.getCurScope(), Dcl);
1575849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis  for (size_t i = 0; i < LateParsedObjCMethods.size(); ++i)
1576849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis    P.ParseLexedObjCMethodDefs(*LateParsedObjCMethods[i]);
1577d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen
1578849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis  P.Actions.ActOnAtEnd(P.getCurScope(), AtEnd);
157963e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian
1580849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis  /// \brief Clear and free the cached objc methods.
15812fea2242fe7e7c37df1e96316616febeaf4e29ebArgyrios Kyrtzidis  for (LateParsedObjCMethodContainer::iterator
15822fea2242fe7e7c37df1e96316616febeaf4e29ebArgyrios Kyrtzidis         I = LateParsedObjCMethods.begin(),
15832fea2242fe7e7c37df1e96316616febeaf4e29ebArgyrios Kyrtzidis         E = LateParsedObjCMethods.end(); I != E; ++I)
15842fea2242fe7e7c37df1e96316616febeaf4e29ebArgyrios Kyrtzidis    delete *I;
15852fea2242fe7e7c37df1e96316616febeaf4e29ebArgyrios Kyrtzidis  LateParsedObjCMethods.clear();
1586849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis
1587849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis  Finished = true;
15882fea2242fe7e7c37df1e96316616febeaf4e29ebArgyrios Kyrtzidis}
15892fea2242fe7e7c37df1e96316616febeaf4e29ebArgyrios Kyrtzidis
1590e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian///   compatibility-alias-decl:
1591e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian///     @compatibility_alias alias-name  class-name ';'
1592e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian///
1593d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseObjCAtAliasDeclaration(SourceLocation atLoc) {
1594e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian  assert(Tok.isObjCAtKeyword(tok::objc_compatibility_alias) &&
1595e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian         "ParseObjCAtAliasDeclaration(): Expected @compatibility_alias");
1596e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian  ConsumeToken(); // consume compatibility_alias
1597df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  if (Tok.isNot(tok::identifier)) {
1598e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian    Diag(Tok, diag::err_expected_ident);
1599d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall    return 0;
1600e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian  }
1601243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian  IdentifierInfo *aliasId = Tok.getIdentifierInfo();
1602243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian  SourceLocation aliasLoc = ConsumeToken(); // consume alias-name
1603df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  if (Tok.isNot(tok::identifier)) {
1604e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian    Diag(Tok, diag::err_expected_ident);
1605d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall    return 0;
1606e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian  }
1607243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian  IdentifierInfo *classId = Tok.getIdentifierInfo();
1608243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian  SourceLocation classLoc = ConsumeToken(); // consume class-name;
1609e6bf90aec0044342ffccd13201b8a3a31a985a4bDouglas Gregor  ExpectAndConsume(tok::semi, diag::err_expected_semi_after,
1610e6bf90aec0044342ffccd13201b8a3a31a985a4bDouglas Gregor                   "@compatibility_alias");
1611b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner  return Actions.ActOnCompatiblityAlias(atLoc, aliasId, aliasLoc,
1612b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner                                        classId, classLoc);
16135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
16145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1615ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian///   property-synthesis:
1616ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian///     @synthesize property-ivar-list ';'
1617ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian///
1618ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian///   property-ivar-list:
1619ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian///     property-ivar
1620ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian///     property-ivar-list ',' property-ivar
1621ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian///
1622ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian///   property-ivar:
1623ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian///     identifier
1624ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian///     identifier '=' identifier
1625ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian///
1626d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseObjCPropertySynthesize(SourceLocation atLoc) {
1627ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian  assert(Tok.isObjCAtKeyword(tok::objc_synthesize) &&
1628ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian         "ParseObjCPropertyDynamic(): Expected '@synthesize'");
1629dec0984fce504a39a7f085774fb67cfd9957be58Jeffrey Yasskin  ConsumeToken(); // consume synthesize
16301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1631b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor  while (true) {
1632322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor    if (Tok.is(tok::code_completion)) {
1633a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian      Actions.CodeCompleteObjCPropertyDefinition(getCurScope());
16347d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis      cutOffParsing();
16357d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis      return 0;
1636322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor    }
1637322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor
1638b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor    if (Tok.isNot(tok::identifier)) {
1639b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor      Diag(Tok, diag::err_synthesized_property_name);
1640b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor      SkipUntil(tok::semi);
1641d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall      return 0;
1642b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor    }
1643b328c4251a9d2db704b3bd46ec04884dc8e56332Douglas Gregor
1644f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian    IdentifierInfo *propertyIvar = 0;
1645f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian    IdentifierInfo *propertyId = Tok.getIdentifierInfo();
1646f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian    SourceLocation propertyLoc = ConsumeToken(); // consume property name
1647a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor    SourceLocation propertyIvarLoc;
1648df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner    if (Tok.is(tok::equal)) {
1649ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian      // property '=' ivar-name
1650ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian      ConsumeToken(); // consume '='
1651322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor
1652322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor      if (Tok.is(tok::code_completion)) {
1653a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian        Actions.CodeCompleteObjCPropertySynthesizeIvar(getCurScope(), propertyId);
16547d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis        cutOffParsing();
16557d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis        return 0;
1656322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor      }
1657322328b8a65ad2e45829eb06d245addb64037f6fDouglas Gregor
1658df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner      if (Tok.isNot(tok::identifier)) {
1659ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian        Diag(Tok, diag::err_expected_ident);
1660ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian        break;
1661ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian      }
1662f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian      propertyIvar = Tok.getIdentifierInfo();
1663a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor      propertyIvarLoc = ConsumeToken(); // consume ivar-name
1664ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian    }
1665a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian    Actions.ActOnPropertyImplDecl(getCurScope(), atLoc, propertyLoc, true,
1666a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor                                  propertyId, propertyIvar, propertyIvarLoc);
1667df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner    if (Tok.isNot(tok::comma))
1668ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian      break;
1669ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian    ConsumeToken(); // consume ','
1670ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian  }
1671e6bf90aec0044342ffccd13201b8a3a31a985a4bDouglas Gregor  ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@synthesize");
1672d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  return 0;
1673ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian}
1674ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian
1675ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian///   property-dynamic:
1676ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian///     @dynamic  property-list
1677ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian///
1678ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian///   property-list:
1679ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian///     identifier
1680ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian///     property-list ',' identifier
1681ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian///
1682d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseObjCPropertyDynamic(SourceLocation atLoc) {
1683ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian  assert(Tok.isObjCAtKeyword(tok::objc_dynamic) &&
1684ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian         "ParseObjCPropertyDynamic(): Expected '@dynamic'");
1685dec0984fce504a39a7f085774fb67cfd9957be58Jeffrey Yasskin  ConsumeToken(); // consume dynamic
1686424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor  while (true) {
1687424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor    if (Tok.is(tok::code_completion)) {
1688a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian      Actions.CodeCompleteObjCPropertyDefinition(getCurScope());
16897d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis      cutOffParsing();
16907d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis      return 0;
1691424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor    }
1692424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor
1693424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor    if (Tok.isNot(tok::identifier)) {
1694424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor      Diag(Tok, diag::err_expected_ident);
1695424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor      SkipUntil(tok::semi);
1696d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall      return 0;
1697424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor    }
1698424b2a546dbd09cf70d43087771c7fff851ca158Douglas Gregor
1699c35b9e4e2efad727538c848cf30d4b0eb1031dc9Fariborz Jahanian    IdentifierInfo *propertyId = Tok.getIdentifierInfo();
1700c35b9e4e2efad727538c848cf30d4b0eb1031dc9Fariborz Jahanian    SourceLocation propertyLoc = ConsumeToken(); // consume property name
1701a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian    Actions.ActOnPropertyImplDecl(getCurScope(), atLoc, propertyLoc, false,
1702a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor                                  propertyId, 0, SourceLocation());
1703c35b9e4e2efad727538c848cf30d4b0eb1031dc9Fariborz Jahanian
1704df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner    if (Tok.isNot(tok::comma))
1705ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian      break;
1706ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian    ConsumeToken(); // consume ','
1707ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian  }
1708e6bf90aec0044342ffccd13201b8a3a31a985a4bDouglas Gregor  ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@dynamic");
1709d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  return 0;
1710ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian}
17111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1712397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian///  objc-throw-statement:
1713397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian///    throw expression[opt];
1714397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian///
171560d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult Parser::ParseObjCThrowStmt(SourceLocation atLoc) {
171660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Res;
1717397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian  ConsumeToken(); // consume throw
1718df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  if (Tok.isNot(tok::semi)) {
171939f8f159c488a900e5958d5aab3e467af9ec8a2bFariborz Jahanian    Res = ParseExpression();
17200e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl    if (Res.isInvalid()) {
1721397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian      SkipUntil(tok::semi);
172243bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl      return StmtError();
1723397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian    }
1724397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian  }
172502418c7f0cb8bb83f1a1a1fad9bf6104efa83e0eTed Kremenek  // consume ';'
172602418c7f0cb8bb83f1a1a1fad9bf6104efa83e0eTed Kremenek  ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@throw");
17279ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return Actions.ActOnObjCAtThrowStmt(atLoc, Res.take(), getCurScope());
1728397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian}
1729397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian
1730c385c90c68dfa376650e2facfbb444b2ec9bd110Fariborz Jahanian/// objc-synchronized-statement:
173178a677bbb5fa115fa0995b5783adeeefad67167eFariborz Jahanian///   @synchronized '(' expression ')' compound-statement
1732c385c90c68dfa376650e2facfbb444b2ec9bd110Fariborz Jahanian///
173360d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
173443bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian RedlParser::ParseObjCSynchronizedStmt(SourceLocation atLoc) {
1735fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian  ConsumeToken(); // consume synchronized
1736fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian  if (Tok.isNot(tok::l_paren)) {
17371ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner    Diag(Tok, diag::err_expected_lparen_after) << "@synchronized";
173843bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl    return StmtError();
1739fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian  }
174007524039dce5c820f111a1b3f772b4261f004b4aJohn McCall
174107524039dce5c820f111a1b3f772b4261f004b4aJohn McCall  // The operand is surrounded with parentheses.
1742fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian  ConsumeParen();  // '('
174307524039dce5c820f111a1b3f772b4261f004b4aJohn McCall  ExprResult operand(ParseExpression());
174407524039dce5c820f111a1b3f772b4261f004b4aJohn McCall
174507524039dce5c820f111a1b3f772b4261f004b4aJohn McCall  if (Tok.is(tok::r_paren)) {
174607524039dce5c820f111a1b3f772b4261f004b4aJohn McCall    ConsumeParen();  // ')'
174707524039dce5c820f111a1b3f772b4261f004b4aJohn McCall  } else {
174807524039dce5c820f111a1b3f772b4261f004b4aJohn McCall    if (!operand.isInvalid())
174907524039dce5c820f111a1b3f772b4261f004b4aJohn McCall      Diag(Tok, diag::err_expected_rparen);
175007524039dce5c820f111a1b3f772b4261f004b4aJohn McCall
175107524039dce5c820f111a1b3f772b4261f004b4aJohn McCall    // Skip forward until we see a left brace, but don't consume it.
175207524039dce5c820f111a1b3f772b4261f004b4aJohn McCall    SkipUntil(tok::l_brace, true, true);
1753fa3ee8e6776634caf064ba5928ca7699d317a280Fariborz Jahanian  }
175407524039dce5c820f111a1b3f772b4261f004b4aJohn McCall
175507524039dce5c820f111a1b3f772b4261f004b4aJohn McCall  // Require a compound statement.
175678a677bbb5fa115fa0995b5783adeeefad67167eFariborz Jahanian  if (Tok.isNot(tok::l_brace)) {
175707524039dce5c820f111a1b3f772b4261f004b4aJohn McCall    if (!operand.isInvalid())
175807524039dce5c820f111a1b3f772b4261f004b4aJohn McCall      Diag(Tok, diag::err_expected_lbrace);
175943bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl    return StmtError();
176078a677bbb5fa115fa0995b5783adeeefad67167eFariborz Jahanian  }
17613ac438c383a4a9a73c76a05c76ec5d02f10a3c52Steve Naroff
176207524039dce5c820f111a1b3f772b4261f004b4aJohn McCall  // Check the @synchronized operand now.
176307524039dce5c820f111a1b3f772b4261f004b4aJohn McCall  if (!operand.isInvalid())
176407524039dce5c820f111a1b3f772b4261f004b4aJohn McCall    operand = Actions.ActOnObjCAtSynchronizedOperand(atLoc, operand.take());
176507524039dce5c820f111a1b3f772b4261f004b4aJohn McCall
176607524039dce5c820f111a1b3f772b4261f004b4aJohn McCall  // Parse the compound statement within a new scope.
176707524039dce5c820f111a1b3f772b4261f004b4aJohn McCall  ParseScope bodyScope(this, Scope::DeclScope);
176807524039dce5c820f111a1b3f772b4261f004b4aJohn McCall  StmtResult body(ParseCompoundStatementBody());
176907524039dce5c820f111a1b3f772b4261f004b4aJohn McCall  bodyScope.Exit();
177007524039dce5c820f111a1b3f772b4261f004b4aJohn McCall
177107524039dce5c820f111a1b3f772b4261f004b4aJohn McCall  // If there was a semantic or parse error earlier with the
177207524039dce5c820f111a1b3f772b4261f004b4aJohn McCall  // operand, fail now.
177307524039dce5c820f111a1b3f772b4261f004b4aJohn McCall  if (operand.isInvalid())
177407524039dce5c820f111a1b3f772b4261f004b4aJohn McCall    return StmtError();
177507524039dce5c820f111a1b3f772b4261f004b4aJohn McCall
177607524039dce5c820f111a1b3f772b4261f004b4aJohn McCall  if (body.isInvalid())
177707524039dce5c820f111a1b3f772b4261f004b4aJohn McCall    body = Actions.ActOnNullStmt(Tok.getLocation());
17780e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl
177907524039dce5c820f111a1b3f772b4261f004b4aJohn McCall  return Actions.ActOnObjCAtSynchronizedStmt(atLoc, operand.get(), body.get());
1780c385c90c68dfa376650e2facfbb444b2ec9bd110Fariborz Jahanian}
1781c385c90c68dfa376650e2facfbb444b2ec9bd110Fariborz Jahanian
1782397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian///  objc-try-catch-statement:
1783397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian///    @try compound-statement objc-catch-list[opt]
1784397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian///    @try compound-statement objc-catch-list[opt] @finally compound-statement
1785397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian///
1786397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian///  objc-catch-list:
1787397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian///    @catch ( parameter-declaration ) compound-statement
1788397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian///    objc-catch-list @catch ( catch-parameter-declaration ) compound-statement
1789397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian///  catch-parameter-declaration:
1790397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian///     parameter-declaration
1791397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian///     '...' [OBJC2]
1792397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian///
179360d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult Parser::ParseObjCTryStmt(SourceLocation atLoc) {
1794397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian  bool catch_or_finally_seen = false;
179543bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl
1796397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian  ConsumeToken(); // consume try
1797df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  if (Tok.isNot(tok::l_brace)) {
17981ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner    Diag(Tok, diag::err_expected_lbrace);
179943bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl    return StmtError();
1800397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian  }
18018f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor  StmtVector CatchStmts(Actions);
180260d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult FinallyStmt;
18038935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor  ParseScope TryScope(this, Scope::DeclScope);
180460d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult TryBody(ParseCompoundStatementBody());
18058935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor  TryScope.Exit();
18060e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl  if (TryBody.isInvalid())
1807bd49a647afd9cc534fef13cadf652d4e9c396e2bFariborz Jahanian    TryBody = Actions.ActOnNullStmt(Tok.getLocation());
1808a55e52c0802cae3b7c366a05c461d3d15074c1a3Sebastian Redl
1809df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  while (Tok.is(tok::at)) {
18106b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner    // At this point, we need to lookahead to determine if this @ is the start
18116b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner    // of an @catch or @finally.  We don't want to consume the @ token if this
18126b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner    // is an @try or @encode or something else.
18136b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner    Token AfterAt = GetLookAheadToken(1);
18146b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner    if (!AfterAt.isObjCAtKeyword(tok::objc_catch) &&
18156b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner        !AfterAt.isObjCAtKeyword(tok::objc_finally))
18166b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner      break;
18170e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl
1818161a9c5afaafb4d527b7efba9675a8b2cbbe32e0Fariborz Jahanian    SourceLocation AtCatchFinallyLoc = ConsumeToken();
1819cb53b361bce341c8591333c6997f62e480acc0b4Chris Lattner    if (Tok.isObjCAtKeyword(tok::objc_catch)) {
1820d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall      Decl *FirstPart = 0;
18213b1191d7eaf2f4984564e01ab84b6713a9d80e70Fariborz Jahanian      ConsumeToken(); // consume catch
1822df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner      if (Tok.is(tok::l_paren)) {
1823397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian        ConsumeParen();
1824e21dd6ffef4585fa43cd3586ed971217d65bf56cSteve Naroff        ParseScope CatchScope(this, Scope::DeclScope|Scope::AtCatchScope);
1825df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner        if (Tok.isNot(tok::ellipsis)) {
18260b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall          DeclSpec DS(AttrFactory);
1827397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian          ParseDeclarationSpecifiers(DS);
182817b6399f8461c5b7e1c6f367b0a0dde49f921240Argyrios Kyrtzidis          Declarator ParmDecl(DS, Declarator::ObjCCatchContext);
18297ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff          ParseDeclarator(ParmDecl);
18307ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff
18314e6c0d19b7c072758922cf80525a81aeefc6e64bDouglas Gregor          // Inform the actions module about the declarator, so it
18327ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff          // gets added to the current scope.
183323c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor          FirstPart = Actions.ActOnObjCExceptionDecl(getCurScope(), ParmDecl);
183464515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff        } else
1835397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian          ConsumeToken(); // consume '...'
18361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
183793a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff        SourceLocation RParenLoc;
18381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
183993a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff        if (Tok.is(tok::r_paren))
184093a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff          RParenLoc = ConsumeParen();
184193a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff        else // Skip over garbage, until we get to ')'.  Eat the ')'.
184293a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff          SkipUntil(tok::r_paren, true, false);
184393a259500186fa7270f66cb460c5f5728e5680aeSteve Naroff
184460d7b3a319d84d688752be3870615ac0f111fb16John McCall        StmtResult CatchBody(true);
1845c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner        if (Tok.is(tok::l_brace))
1846c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner          CatchBody = ParseCompoundStatementBody();
1847c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner        else
1848c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner          Diag(Tok, diag::err_expected_lbrace);
18490e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl        if (CatchBody.isInvalid())
18503b1191d7eaf2f4984564e01ab84b6713a9d80e70Fariborz Jahanian          CatchBody = Actions.ActOnNullStmt(Tok.getLocation());
18518f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor
185260d7b3a319d84d688752be3870615ac0f111fb16John McCall        StmtResult Catch = Actions.ActOnObjCAtCatchStmt(AtCatchFinallyLoc,
18538f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor                                                              RParenLoc,
18548f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor                                                              FirstPart,
18559ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                              CatchBody.take());
18568f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor        if (!Catch.isInvalid())
18578f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor          CatchStmts.push_back(Catch.release());
18588f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor
185964515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff      } else {
18601ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner        Diag(AtCatchFinallyLoc, diag::err_expected_lparen_after)
18611ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner          << "@catch clause";
186243bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl        return StmtError();
1863397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian      }
1864397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian      catch_or_finally_seen = true;
18656b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner    } else {
18666b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner      assert(Tok.isObjCAtKeyword(tok::objc_finally) && "Lookahead confused?");
186764515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff      ConsumeToken(); // consume finally
18688935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor      ParseScope FinallyScope(this, Scope::DeclScope);
18690e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl
187060d7b3a319d84d688752be3870615ac0f111fb16John McCall      StmtResult FinallyBody(true);
1871c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner      if (Tok.is(tok::l_brace))
1872c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner        FinallyBody = ParseCompoundStatementBody();
1873c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner      else
1874c1b3ba5ae08316fe43e541c4fb02921fc3e80b21Chris Lattner        Diag(Tok, diag::err_expected_lbrace);
18750e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl      if (FinallyBody.isInvalid())
1876161a9c5afaafb4d527b7efba9675a8b2cbbe32e0Fariborz Jahanian        FinallyBody = Actions.ActOnNullStmt(Tok.getLocation());
18770e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl      FinallyStmt = Actions.ActOnObjCAtFinallyStmt(AtCatchFinallyLoc,
18789ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   FinallyBody.take());
1879397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian      catch_or_finally_seen = true;
1880397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian      break;
1881397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian    }
1882397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian  }
1883bd49a647afd9cc534fef13cadf652d4e9c396e2bFariborz Jahanian  if (!catch_or_finally_seen) {
1884397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian    Diag(atLoc, diag::err_missing_catch_finally);
188543bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl    return StmtError();
1886bd49a647afd9cc534fef13cadf652d4e9c396e2bFariborz Jahanian  }
18878f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor
18889ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return Actions.ActOnObjCAtTryStmt(atLoc, TryBody.take(),
18898f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor                                    move_arg(CatchStmts),
18909ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                    FinallyStmt.take());
1891397fcc117e5631db53879fbfcca66966088f3f07Fariborz Jahanian}
1892ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian
1893f85e193739c953358c865005855253af4f68a497John McCall/// objc-autoreleasepool-statement:
1894f85e193739c953358c865005855253af4f68a497John McCall///   @autoreleasepool compound-statement
1895f85e193739c953358c865005855253af4f68a497John McCall///
1896f85e193739c953358c865005855253af4f68a497John McCallStmtResult
1897f85e193739c953358c865005855253af4f68a497John McCallParser::ParseObjCAutoreleasePoolStmt(SourceLocation atLoc) {
1898f85e193739c953358c865005855253af4f68a497John McCall  ConsumeToken(); // consume autoreleasepool
1899f85e193739c953358c865005855253af4f68a497John McCall  if (Tok.isNot(tok::l_brace)) {
1900f85e193739c953358c865005855253af4f68a497John McCall    Diag(Tok, diag::err_expected_lbrace);
1901f85e193739c953358c865005855253af4f68a497John McCall    return StmtError();
1902f85e193739c953358c865005855253af4f68a497John McCall  }
1903f85e193739c953358c865005855253af4f68a497John McCall  // Enter a scope to hold everything within the compound stmt.  Compound
1904f85e193739c953358c865005855253af4f68a497John McCall  // statements can always hold declarations.
1905f85e193739c953358c865005855253af4f68a497John McCall  ParseScope BodyScope(this, Scope::DeclScope);
1906f85e193739c953358c865005855253af4f68a497John McCall
1907f85e193739c953358c865005855253af4f68a497John McCall  StmtResult AutoreleasePoolBody(ParseCompoundStatementBody());
1908f85e193739c953358c865005855253af4f68a497John McCall
1909f85e193739c953358c865005855253af4f68a497John McCall  BodyScope.Exit();
1910f85e193739c953358c865005855253af4f68a497John McCall  if (AutoreleasePoolBody.isInvalid())
1911f85e193739c953358c865005855253af4f68a497John McCall    AutoreleasePoolBody = Actions.ActOnNullStmt(Tok.getLocation());
1912f85e193739c953358c865005855253af4f68a497John McCall  return Actions.ActOnObjCAutoreleasePoolStmt(atLoc,
1913f85e193739c953358c865005855253af4f68a497John McCall                                                AutoreleasePoolBody.take());
1914f85e193739c953358c865005855253af4f68a497John McCall}
1915f85e193739c953358c865005855253af4f68a497John McCall
19163536b443bc50d58a79f14fca9b6842541a434854Steve Naroff///   objc-method-def: objc-method-proto ';'[opt] '{' body '}'
1917ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian///
1918d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseObjCMethodDefinition() {
1919a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian  Decl *MDecl = ParseObjCMethodPrototype();
19201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1921f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall  PrettyDeclStackTraceEntry CrashInfo(Actions, MDecl, Tok.getLocation(),
1922f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                      "parsing Objective-C method");
19231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1924ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian  // parse optional ';'
1925209a8c2fa23636f6d065d618e7078e164903f5cdFariborz Jahanian  if (Tok.is(tok::semi)) {
1926849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis    if (CurParsedObjCImpl) {
1927496e45ef3350fabc312c5a807d308c65c50af4dbTed Kremenek      Diag(Tok, diag::warn_semicolon_before_method_body)
1928849b243d4065f56742a4677d6dc8277609a151f8Douglas Gregor        << FixItHint::CreateRemoval(Tok.getLocation());
1929496e45ef3350fabc312c5a807d308c65c50af4dbTed Kremenek    }
1930ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian    ConsumeToken();
1931209a8c2fa23636f6d065d618e7078e164903f5cdFariborz Jahanian  }
1932ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian
1933409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff  // We should have an opening brace now.
1934df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  if (Tok.isNot(tok::l_brace)) {
1935da323adbb99cee19a203ead852d5d9bfebb23fb7Steve Naroff    Diag(Tok, diag::err_expected_method_body);
19361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1937409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff    // Skip over garbage, until we get to '{'.  Don't eat the '{'.
1938409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff    SkipUntil(tok::l_brace, true, true);
19391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1940409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff    // If we didn't find the '{', bail out.
1941409be835b68344e0de56f99ef9a1e12760bc69eeSteve Naroff    if (Tok.isNot(tok::l_brace))
1942d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall      return 0;
1943ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian  }
1944849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis
1945849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis  if (!MDecl) {
1946849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis    ConsumeBrace();
1947849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis    SkipUntil(tok::r_brace, /*StopAtSemi=*/false);
1948849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis    return 0;
1949849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis  }
1950849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis
1951140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian  // Allow the rest of sema to find private method decl implementations.
1952849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis  Actions.AddAnyMethodToGlobalPool(MDecl);
1953849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis
1954849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis  if (CurParsedObjCImpl) {
1955849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis    // Consume the tokens and store them for later parsing.
1956849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis    LexedMethod* LM = new LexedMethod(this, MDecl);
1957849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis    CurParsedObjCImpl->LateParsedObjCMethods.push_back(LM);
1958849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis    CachedTokens &Toks = LM->Toks;
1959849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis    // Begin by storing the '{' token.
1960849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis    Toks.push_back(Tok);
1961849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis    ConsumeBrace();
1962849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis    // Consume everything up to (and including) the matching right brace.
1963849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis    ConsumeAndStoreUntil(tok::r_brace, Toks, /*StopAtSemi=*/false);
1964849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis
1965849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis  } else {
1966849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis    ConsumeBrace();
1967849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis    SkipUntil(tok::r_brace, /*StopAtSemi=*/false);
1968849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis  }
1969849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis
197071c0a951d08dc7a2a057df8c15f22b36f6aa47c7Steve Naroff  return MDecl;
19715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
19725508518a2702b00be3b15a26d772bde968972f54Anders Carlsson
197360d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult Parser::ParseObjCAtStatement(SourceLocation AtLoc) {
19749a0c85e640a08174569a303db22981612f05d385Douglas Gregor  if (Tok.is(tok::code_completion)) {
197523c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor    Actions.CodeCompleteObjCAtStatement(getCurScope());
19767d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis    cutOffParsing();
19779a0c85e640a08174569a303db22981612f05d385Douglas Gregor    return StmtError();
19785d8031687d086701b4dadaab3e0de1def448da9dChris Lattner  }
19795d8031687d086701b4dadaab3e0de1def448da9dChris Lattner
19805d8031687d086701b4dadaab3e0de1def448da9dChris Lattner  if (Tok.isObjCAtKeyword(tok::objc_try))
19816b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner    return ParseObjCTryStmt(AtLoc);
19825d8031687d086701b4dadaab3e0de1def448da9dChris Lattner
19835d8031687d086701b4dadaab3e0de1def448da9dChris Lattner  if (Tok.isObjCAtKeyword(tok::objc_throw))
198464515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff    return ParseObjCThrowStmt(AtLoc);
19855d8031687d086701b4dadaab3e0de1def448da9dChris Lattner
19865d8031687d086701b4dadaab3e0de1def448da9dChris Lattner  if (Tok.isObjCAtKeyword(tok::objc_synchronized))
198764515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff    return ParseObjCSynchronizedStmt(AtLoc);
1988f85e193739c953358c865005855253af4f68a497John McCall
1989f85e193739c953358c865005855253af4f68a497John McCall  if (Tok.isObjCAtKeyword(tok::objc_autoreleasepool))
1990f85e193739c953358c865005855253af4f68a497John McCall    return ParseObjCAutoreleasePoolStmt(AtLoc);
19915d8031687d086701b4dadaab3e0de1def448da9dChris Lattner
199260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Res(ParseExpressionWithLeadingAt(AtLoc));
19930e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl  if (Res.isInvalid()) {
199464515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff    // If the expression is invalid, skip ahead to the next semicolon. Not
199564515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff    // doing this opens us up to the possibility of infinite loops if
199664515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff    // ParseExpression does not consume any tokens.
199764515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff    SkipUntil(tok::semi);
199843bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl    return StmtError();
199964515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff  }
20005d8031687d086701b4dadaab3e0de1def448da9dChris Lattner
200164515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff  // Otherwise, eat the semicolon.
20029ba23b4ceacd77cd264501690a7a9e94184ef71bDouglas Gregor  ExpectAndConsumeSemi(diag::err_expected_semi_after_expr);
20039ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return Actions.ActOnExprStmt(Actions.MakeFullExpr(Res.take()));
200464515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff}
200564515f31850024a263e8f55f81e9ea4b39925cfaSteve Naroff
200660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult Parser::ParseObjCAtExpression(SourceLocation AtLoc) {
20075508518a2702b00be3b15a26d772bde968972f54Anders Carlsson  switch (Tok.getKind()) {
20089a0c85e640a08174569a303db22981612f05d385Douglas Gregor  case tok::code_completion:
200923c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor    Actions.CodeCompleteObjCAtExpression(getCurScope());
20107d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis    cutOffParsing();
20119a0c85e640a08174569a303db22981612f05d385Douglas Gregor    return ExprError();
20129a0c85e640a08174569a303db22981612f05d385Douglas Gregor
2013ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  case tok::minus:
2014ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  case tok::plus: {
2015ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    tok::TokenKind Kind = Tok.getKind();
2016ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    SourceLocation OpLoc = ConsumeToken();
2017ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek
2018ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    if (!Tok.is(tok::numeric_constant)) {
2019ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek      const char *Symbol = 0;
2020ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek      switch (Kind) {
2021ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek      case tok::minus: Symbol = "-"; break;
2022ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek      case tok::plus: Symbol = "+"; break;
2023ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek      default: llvm_unreachable("missing unary operator case");
2024ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek      }
2025ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek      Diag(Tok, diag::err_nsnumber_nonliteral_unary)
2026ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek        << Symbol;
2027ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek      return ExprError();
2028ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    }
2029ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek
2030ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    ExprResult Lit(Actions.ActOnNumericConstant(Tok));
2031ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    if (Lit.isInvalid()) {
2032ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek      return move(Lit);
2033ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    }
20348b8d9534f185743fb72c59d4e735794e6e0f4335Benjamin Kramer    ConsumeToken(); // Consume the literal token.
2035ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek
2036ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    Lit = Actions.ActOnUnaryOp(getCurScope(), OpLoc, Kind, Lit.take());
2037ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    if (Lit.isInvalid())
2038ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek      return move(Lit);
2039ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek
2040ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    return ParsePostfixExpressionSuffix(
2041ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek             Actions.BuildObjCNumericLiteral(AtLoc, Lit.take()));
2042ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  }
2043ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek
2044b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner  case tok::string_literal:    // primary-expression: string-literal
2045b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner  case tok::wide_string_literal:
20461d922960e083906a586609ac6978678147250177Sebastian Redl    return ParsePostfixExpressionSuffix(ParseObjCStringLiteral(AtLoc));
2047ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek
2048ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  case tok::char_constant:
2049ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    return ParsePostfixExpressionSuffix(ParseObjCCharacterLiteral(AtLoc));
2050ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek
2051ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  case tok::numeric_constant:
2052ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    return ParsePostfixExpressionSuffix(ParseObjCNumericLiteral(AtLoc));
2053ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek
2054ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  case tok::kw_true:  // Objective-C++, etc.
2055ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  case tok::kw___objc_yes: // c/c++/objc/objc++ __objc_yes
2056ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    return ParsePostfixExpressionSuffix(ParseObjCBooleanLiteral(AtLoc, true));
2057ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  case tok::kw_false: // Objective-C++, etc.
2058ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  case tok::kw___objc_no: // c/c++/objc/objc++ __objc_no
2059ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    return ParsePostfixExpressionSuffix(ParseObjCBooleanLiteral(AtLoc, false));
2060ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek
2061ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  case tok::l_square:
2062ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    // Objective-C array literal
2063ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    return ParsePostfixExpressionSuffix(ParseObjCArrayLiteral(AtLoc));
2064ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek
2065ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  case tok::l_brace:
2066ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    // Objective-C dictionary literal
2067ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    return ParsePostfixExpressionSuffix(ParseObjCDictionaryLiteral(AtLoc));
2068ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek
2069eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard  case tok::l_paren:
2070eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard    // Objective-C boxed expression
2071eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard    return ParsePostfixExpressionSuffix(ParseObjCBoxedExpr(AtLoc));
2072eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard
2073b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner  default:
20744fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner    if (Tok.getIdentifierInfo() == 0)
20751d922960e083906a586609ac6978678147250177Sebastian Redl      return ExprError(Diag(AtLoc, diag::err_unexpected_at));
20762f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl
20774fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner    switch (Tok.getIdentifierInfo()->getObjCKeywordID()) {
20784fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner    case tok::objc_encode:
20791d922960e083906a586609ac6978678147250177Sebastian Redl      return ParsePostfixExpressionSuffix(ParseObjCEncodeExpression(AtLoc));
20804fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner    case tok::objc_protocol:
20811d922960e083906a586609ac6978678147250177Sebastian Redl      return ParsePostfixExpressionSuffix(ParseObjCProtocolExpression(AtLoc));
20824fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner    case tok::objc_selector:
20831d922960e083906a586609ac6978678147250177Sebastian Redl      return ParsePostfixExpressionSuffix(ParseObjCSelectorExpression(AtLoc));
20844fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner    default:
20851d922960e083906a586609ac6978678147250177Sebastian Redl      return ExprError(Diag(AtLoc, diag::err_unexpected_at));
20864fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner    }
20875508518a2702b00be3b15a26d772bde968972f54Anders Carlsson  }
20885508518a2702b00be3b15a26d772bde968972f54Anders Carlsson}
20895508518a2702b00be3b15a26d772bde968972f54Anders Carlsson
20906aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// \brirg Parse the receiver of an Objective-C++ message send.
20916aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor///
20926aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// This routine parses the receiver of a message send in
20936aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// Objective-C++ either as a type or as an expression. Note that this
20946aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// routine must not be called to parse a send to 'super', since it
20956aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// has no way to return such a result.
20966aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor///
20976aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// \param IsExpr Whether the receiver was parsed as an expression.
20986aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor///
20996aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// \param TypeOrExpr If the receiver was parsed as an expression (\c
21006aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// IsExpr is true), the parsed expression. If the receiver was parsed
21016aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// as a type (\c IsExpr is false), the parsed type.
21026aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor///
21036aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// \returns True if an error occurred during parsing or semantic
21046aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// analysis, in which case the arguments do not have valid
21056aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// values. Otherwise, returns false for a successful parse.
21066aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor///
21076aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor///   objc-receiver: [C++]
21086aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor///     'super' [not parsed here]
21096aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor///     expression
21106aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor///     simple-type-specifier
21116aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor///     typename-specifier
21126aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregorbool Parser::ParseObjCXXMessageReceiver(bool &IsExpr, void *&TypeOrExpr) {
21130fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor  InMessageExpressionRAIIObject InMessage(*this, true);
21140fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor
21156aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor  if (Tok.is(tok::identifier) || Tok.is(tok::coloncolon) ||
21166aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor      Tok.is(tok::kw_typename) || Tok.is(tok::annot_cxxscope))
21176aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor    TryAnnotateTypeOrScopeToken();
21186aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor
21196aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor  if (!isCXXSimpleTypeSpecifier()) {
21206aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor    //   objc-receiver:
21216aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor    //     expression
212260d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Receiver = ParseExpression();
21236aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor    if (Receiver.isInvalid())
21246aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor      return true;
21256aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor
21266aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor    IsExpr = true;
21276aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor    TypeOrExpr = Receiver.take();
21286aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor    return false;
21296aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor  }
21306aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor
21316aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor  // objc-receiver:
21326aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor  //   typename-specifier
21336aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor  //   simple-type-specifier
21346aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor  //   expression (that starts with one of the above)
21350b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall  DeclSpec DS(AttrFactory);
21366aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor  ParseCXXSimpleTypeSpecifier(DS);
21376aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor
21386aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor  if (Tok.is(tok::l_paren)) {
21396aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor    // If we see an opening parentheses at this point, we are
21406aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor    // actually parsing an expression that starts with a
21416aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor    // function-style cast, e.g.,
21426aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor    //
21436aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor    //   postfix-expression:
21446aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor    //     simple-type-specifier ( expression-list [opt] )
21456aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor    //     typename-specifier ( expression-list [opt] )
21466aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor    //
21476aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor    // Parse the remainder of this case, then the (optional)
21486aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor    // postfix-expression suffix, followed by the (optional)
21496aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor    // right-hand side of the binary expression. We have an
21506aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor    // instance method.
215160d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Receiver = ParseCXXTypeConstructExpression(DS);
21526aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor    if (!Receiver.isInvalid())
21539ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      Receiver = ParsePostfixExpressionSuffix(Receiver.take());
21546aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor    if (!Receiver.isInvalid())
21559ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      Receiver = ParseRHSOfBinaryExpression(Receiver.take(), prec::Comma);
21566aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor    if (Receiver.isInvalid())
21576aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor      return true;
21586aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor
21596aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor    IsExpr = true;
21606aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor    TypeOrExpr = Receiver.take();
21616aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor    return false;
21626aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor  }
21636aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor
21646aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor  // We have a class message. Turn the simple-type-specifier or
21656aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor  // typename-specifier we parsed into a type and parse the
21666aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor  // remainder of the class message.
21676aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor  Declarator DeclaratorInfo(DS, Declarator::TypeNameContext);
216823c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor  TypeResult Type = Actions.ActOnTypeName(getCurScope(), DeclaratorInfo);
21696aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor  if (Type.isInvalid())
21706aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor    return true;
21716aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor
21726aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor  IsExpr = false;
2173b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  TypeOrExpr = Type.get().getAsOpaquePtr();
21746aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor  return false;
21756aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor}
21766aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor
21771b730e847ded503f2e615154035c083c4f94a067Douglas Gregor/// \brief Determine whether the parser is currently referring to a an
21781b730e847ded503f2e615154035c083c4f94a067Douglas Gregor/// Objective-C message send, using a simplified heuristic to avoid overhead.
21791b730e847ded503f2e615154035c083c4f94a067Douglas Gregor///
21801b730e847ded503f2e615154035c083c4f94a067Douglas Gregor/// This routine will only return true for a subset of valid message-send
21811b730e847ded503f2e615154035c083c4f94a067Douglas Gregor/// expressions.
21821b730e847ded503f2e615154035c083c4f94a067Douglas Gregorbool Parser::isSimpleObjCMessageExpression() {
21834e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie  assert(Tok.is(tok::l_square) && getLangOpts().ObjC1 &&
21841b730e847ded503f2e615154035c083c4f94a067Douglas Gregor         "Incorrect start for isSimpleObjCMessageExpression");
21851b730e847ded503f2e615154035c083c4f94a067Douglas Gregor  return GetLookAheadToken(1).is(tok::identifier) &&
21861b730e847ded503f2e615154035c083c4f94a067Douglas Gregor         GetLookAheadToken(2).is(tok::identifier);
21871b730e847ded503f2e615154035c083c4f94a067Douglas Gregor}
21881b730e847ded503f2e615154035c083c4f94a067Douglas Gregor
21899497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregorbool Parser::isStartOfObjCClassMessageMissingOpenBracket() {
21904e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie  if (!getLangOpts().ObjC1 || !NextToken().is(tok::identifier) ||
21919497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor      InMessageExpression)
21929497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor    return false;
21939497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor
21949497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor
21959497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor  ParsedType Type;
21969497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor
21979497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor  if (Tok.is(tok::annot_typename))
21989497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor    Type = getTypeAnnotation(Tok);
21999497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor  else if (Tok.is(tok::identifier))
22009497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor    Type = Actions.getTypeName(*Tok.getIdentifierInfo(), Tok.getLocation(),
22019497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor                               getCurScope());
22029497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor  else
22039497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor    return false;
22049497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor
22059497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor  if (!Type.get().isNull() && Type.get()->isObjCObjectOrInterfaceType()) {
22069497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor    const Token &AfterNext = GetLookAheadToken(2);
22079497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor    if (AfterNext.is(tok::colon) || AfterNext.is(tok::r_square)) {
22089497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor      if (Tok.is(tok::identifier))
22099497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor        TryAnnotateTypeOrScopeToken();
22109497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor
22119497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor      return Tok.is(tok::annot_typename);
22129497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor    }
22139497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor  }
22149497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor
22159497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor  return false;
22169497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor}
22179497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor
22181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///   objc-message-expr:
22190ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///     '[' objc-receiver objc-message-args ']'
22200ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///
22212725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor///   objc-receiver: [C]
2222eb483eb3ee80300f15d6d13573d82493c2194461Chris Lattner///     'super'
22230ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///     expression
22240ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///     class-name
22250ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///     type-name
22266aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor///
222760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult Parser::ParseObjCMessageExpression() {
2228699b66138ac307a32e238463e0eff513ff17d337Chris Lattner  assert(Tok.is(tok::l_square) && "'[' expected");
2229699b66138ac307a32e238463e0eff513ff17d337Chris Lattner  SourceLocation LBracLoc = ConsumeBracket(); // consume '['
2230699b66138ac307a32e238463e0eff513ff17d337Chris Lattner
22318e254cfe5a6ab4202c7fcc4b64bdd1ca0fe071acDouglas Gregor  if (Tok.is(tok::code_completion)) {
223223c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor    Actions.CodeCompleteObjCMessageReceiver(getCurScope());
22337d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis    cutOffParsing();
22348e254cfe5a6ab4202c7fcc4b64bdd1ca0fe071acDouglas Gregor    return ExprError();
22358e254cfe5a6ab4202c7fcc4b64bdd1ca0fe071acDouglas Gregor  }
22368e254cfe5a6ab4202c7fcc4b64bdd1ca0fe071acDouglas Gregor
22370fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor  InMessageExpressionRAIIObject InMessage(*this, true);
22380fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor
22394e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie  if (getLangOpts().CPlusPlus) {
22406aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor    // We completely separate the C and C++ cases because C++ requires
22416aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor    // more complicated (read: slower) parsing.
22426aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor
22436aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor    // Handle send to super.
22446aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor    // FIXME: This doesn't benefit from the same typo-correction we
22456aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor    // get in Objective-C.
22466aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor    if (Tok.is(tok::identifier) && Tok.getIdentifierInfo() == Ident_super &&
224723c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor        NextToken().isNot(tok::period) && getCurScope()->isInObjcMethodScope())
2248b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall      return ParseObjCMessageExpressionBody(LBracLoc, ConsumeToken(),
2249b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                                            ParsedType(), 0);
22506aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor
22516aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor    // Parse the receiver, which is either a type or an expression.
22526aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor    bool IsExpr;
2253304b752a450c0fc5968c20ba25446d0bb7c6f68dNick Lewycky    void *TypeOrExpr = NULL;
22546aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor    if (ParseObjCXXMessageReceiver(IsExpr, TypeOrExpr)) {
22556aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor      SkipUntil(tok::r_square);
22566aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor      return ExprError();
22576aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor    }
22586aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor
22596aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor    if (IsExpr)
2260b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall      return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(),
2261b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                                            ParsedType(),
22629ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                            static_cast<Expr*>(TypeOrExpr));
22636aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor
22646aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor    return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(),
2265b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                              ParsedType::getFromOpaquePtr(TypeOrExpr),
2266b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                                          0);
2267c59cb38810c63a806270385f79ea84e0203754eaChris Lattner  }
2268c59cb38810c63a806270385f79ea84e0203754eaChris Lattner
2269c59cb38810c63a806270385f79ea84e0203754eaChris Lattner  if (Tok.is(tok::identifier)) {
22701dbca6ea983231b4cab1a8f1edda8f6e13c21f12Douglas Gregor    IdentifierInfo *Name = Tok.getIdentifierInfo();
22711dbca6ea983231b4cab1a8f1edda8f6e13c21f12Douglas Gregor    SourceLocation NameLoc = Tok.getLocation();
2272b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    ParsedType ReceiverType;
227323c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor    switch (Actions.getObjCMessageKind(getCurScope(), Name, NameLoc,
22741dbca6ea983231b4cab1a8f1edda8f6e13c21f12Douglas Gregor                                       Name == Ident_super,
22751569f95831a8c99e9f664137bf8f40e47ee3d90fDouglas Gregor                                       NextToken().is(tok::period),
22761569f95831a8c99e9f664137bf8f40e47ee3d90fDouglas Gregor                                       ReceiverType)) {
2277f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    case Sema::ObjCSuperMessage:
2278b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall      return ParseObjCMessageExpressionBody(LBracLoc, ConsumeToken(),
2279b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                                            ParsedType(), 0);
22802725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor
2281f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    case Sema::ObjCClassMessage:
22821569f95831a8c99e9f664137bf8f40e47ee3d90fDouglas Gregor      if (!ReceiverType) {
22832725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor        SkipUntil(tok::r_square);
22842725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor        return ExprError();
22852725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor      }
22862725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor
22871569f95831a8c99e9f664137bf8f40e47ee3d90fDouglas Gregor      ConsumeToken(); // the type name
22881569f95831a8c99e9f664137bf8f40e47ee3d90fDouglas Gregor
22891569f95831a8c99e9f664137bf8f40e47ee3d90fDouglas Gregor      return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(),
22909ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                            ReceiverType, 0);
22911dbca6ea983231b4cab1a8f1edda8f6e13c21f12Douglas Gregor
2292f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    case Sema::ObjCInstanceMessage:
22932725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor      // Fall through to parse an expression.
22941dbca6ea983231b4cab1a8f1edda8f6e13c21f12Douglas Gregor      break;
2295d2869925b5f10e00b13fbf3f41bbb17e4c9adbe0Fariborz Jahanian    }
2296699b66138ac307a32e238463e0eff513ff17d337Chris Lattner  }
2297eb483eb3ee80300f15d6d13573d82493c2194461Chris Lattner
2298eb483eb3ee80300f15d6d13573d82493c2194461Chris Lattner  // Otherwise, an arbitrary expression can be the receiver of a send.
229960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Res(ParseExpression());
23000e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl  if (Res.isInvalid()) {
23015c749428a9938d5e2e9564b1c9b7a9252c30ee27Chris Lattner    SkipUntil(tok::r_square);
23021d922960e083906a586609ac6978678147250177Sebastian Redl    return move(Res);
2303699b66138ac307a32e238463e0eff513ff17d337Chris Lattner  }
23041d922960e083906a586609ac6978678147250177Sebastian Redl
2305b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(),
2306b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                                        ParsedType(), Res.take());
2307699b66138ac307a32e238463e0eff513ff17d337Chris Lattner}
23081d922960e083906a586609ac6978678147250177Sebastian Redl
23092725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// \brief Parse the remainder of an Objective-C message following the
23102725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// '[' objc-receiver.
23112725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor///
23122725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// This routine handles sends to super, class messages (sent to a
23132725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// class name), and instance messages (sent to an object), and the
23142725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// target is represented by \p SuperLoc, \p ReceiverType, or \p
23152725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// ReceiverExpr, respectively. Only one of these parameters may have
23162725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// a valid value.
23172725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor///
23182725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// \param LBracLoc The location of the opening '['.
23192725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor///
23202725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// \param SuperLoc If this is a send to 'super', the location of the
23212725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// 'super' keyword that indicates a send to the superclass.
23222725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor///
23232725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// \param ReceiverType If this is a class message, the type of the
23242725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// class we are sending a message to.
23252725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor///
23262725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// \param ReceiverExpr If this is an instance message, the expression
23272725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// used to compute the receiver object.
23281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///
23290ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///   objc-message-args:
23300ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///     objc-selector
23310ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///     objc-keywordarg-list
23320ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///
23330ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///   objc-keywordarg-list:
23340ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///     objc-keywordarg
23350ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///     objc-keywordarg-list objc-keywordarg
23360ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///
23371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///   objc-keywordarg:
23380ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///     selector-name[opt] ':' objc-keywordexpr
23390ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///
23400ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///   objc-keywordexpr:
23410ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///     nonempty-expr-list
23420ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///
23430ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///   nonempty-expr-list:
23440ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///     assignment-expression
23450ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian///     nonempty-expr-list , assignment-expression
23461d922960e083906a586609ac6978678147250177Sebastian Redl///
234760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
2348699b66138ac307a32e238463e0eff513ff17d337Chris LattnerParser::ParseObjCMessageExpressionBody(SourceLocation LBracLoc,
23492725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor                                       SourceLocation SuperLoc,
2350b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                                       ParsedType ReceiverType,
23511d922960e083906a586609ac6978678147250177Sebastian Redl                                       ExprArg ReceiverExpr) {
23520fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor  InMessageExpressionRAIIObject InMessage(*this, true);
23530fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor
2354c4df6d2c05c647a6a5770ba0c749782b6c023a3aSteve Naroff  if (Tok.is(tok::code_completion)) {
23552725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor    if (SuperLoc.isValid())
235670c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor      Actions.CodeCompleteObjCSuperMessage(getCurScope(), SuperLoc, 0, 0,
235770c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor                                           false);
23582725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor    else if (ReceiverType)
235970c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor      Actions.CodeCompleteObjCClassMessage(getCurScope(), ReceiverType, 0, 0,
236070c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor                                           false);
2361c4df6d2c05c647a6a5770ba0c749782b6c023a3aSteve Naroff    else
23629ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      Actions.CodeCompleteObjCInstanceMessage(getCurScope(), ReceiverExpr,
236370c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor                                              0, 0, false);
23647d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis    cutOffParsing();
23657d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis    return ExprError();
2366c4df6d2c05c647a6a5770ba0c749782b6c023a3aSteve Naroff  }
2367d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor
2368a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian  // Parse objc-selector
23694b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian  SourceLocation Loc;
23702fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner  IdentifierInfo *selIdent = ParseObjCSelectorPiece(Loc);
237168d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff
23725f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner  SmallVector<IdentifierInfo *, 12> KeyIdents;
2373951376242c076c3f62dd78bf672909fc011991dbArgyrios Kyrtzidis  SmallVector<SourceLocation, 12> KeyLocs;
2374a55e52c0802cae3b7c366a05c461d3d15074c1a3Sebastian Redl  ExprVector KeyExprs(Actions);
237568d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff
2376df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  if (Tok.is(tok::colon)) {
2377a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian    while (1) {
2378a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian      // Each iteration parses a single keyword argument.
237968d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff      KeyIdents.push_back(selIdent);
2380951376242c076c3f62dd78bf672909fc011991dbArgyrios Kyrtzidis      KeyLocs.push_back(Loc);
238137387c932855c6d58d70bdd705cd3a9fdcd2a931Steve Naroff
2382df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner      if (Tok.isNot(tok::colon)) {
2383a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian        Diag(Tok, diag::err_expected_colon);
23844fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner        // We must manually skip to a ']', otherwise the expression skipper will
23854fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner        // stop at the ']' when it skips to the ';'.  We want it to skip beyond
23864fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner        // the enclosing expression.
23874fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner        SkipUntil(tok::r_square);
23881d922960e083906a586609ac6978678147250177Sebastian Redl        return ExprError();
2389a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian      }
23901d922960e083906a586609ac6978678147250177Sebastian Redl
239168d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff      ConsumeToken(); // Eat the ':'.
23921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      ///  Parse the expression after ':'
239370c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor
239470c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor      if (Tok.is(tok::code_completion)) {
239570c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor        if (SuperLoc.isValid())
239670c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor          Actions.CodeCompleteObjCSuperMessage(getCurScope(), SuperLoc,
239770c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor                                               KeyIdents.data(),
239870c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor                                               KeyIdents.size(),
239970c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor                                               /*AtArgumentEpression=*/true);
240070c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor        else if (ReceiverType)
240170c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor          Actions.CodeCompleteObjCClassMessage(getCurScope(), ReceiverType,
240270c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor                                               KeyIdents.data(),
240370c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor                                               KeyIdents.size(),
240470c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor                                               /*AtArgumentEpression=*/true);
240570c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor        else
240670c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor          Actions.CodeCompleteObjCInstanceMessage(getCurScope(), ReceiverExpr,
240770c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor                                                  KeyIdents.data(),
240870c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor                                                  KeyIdents.size(),
240970c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor                                                  /*AtArgumentEpression=*/true);
241070c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor
24117d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis        cutOffParsing();
241270c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor        return ExprError();
241370c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor      }
241470c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor
241560d7b3a319d84d688752be3870615ac0f111fb16John McCall      ExprResult Res(ParseAssignmentExpression());
24160e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl      if (Res.isInvalid()) {
24174fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner        // We must manually skip to a ']', otherwise the expression skipper will
24184fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner        // stop at the ']' when it skips to the ';'.  We want it to skip beyond
24194fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner        // the enclosing expression.
24204fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner        SkipUntil(tok::r_square);
24211d922960e083906a586609ac6978678147250177Sebastian Redl        return move(Res);
242237387c932855c6d58d70bdd705cd3a9fdcd2a931Steve Naroff      }
24231d922960e083906a586609ac6978678147250177Sebastian Redl
242437387c932855c6d58d70bdd705cd3a9fdcd2a931Steve Naroff      // We have a valid expression.
2425effa8d1c97b00a3f53e972b0e61d9aade5ea1c57Sebastian Redl      KeyExprs.push_back(Res.release());
24261d922960e083906a586609ac6978678147250177Sebastian Redl
2427d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor      // Code completion after each argument.
2428d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor      if (Tok.is(tok::code_completion)) {
24292725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor        if (SuperLoc.isValid())
243023c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor          Actions.CodeCompleteObjCSuperMessage(getCurScope(), SuperLoc,
24312725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor                                               KeyIdents.data(),
243270c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor                                               KeyIdents.size(),
243370c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor                                               /*AtArgumentEpression=*/false);
24342725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor        else if (ReceiverType)
243523c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor          Actions.CodeCompleteObjCClassMessage(getCurScope(), ReceiverType,
2436d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor                                               KeyIdents.data(),
243770c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor                                               KeyIdents.size(),
243870c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor                                               /*AtArgumentEpression=*/false);
2439d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor        else
24409ae2f076ca5ab1feb3ba95629099ec2319833701John McCall          Actions.CodeCompleteObjCInstanceMessage(getCurScope(), ReceiverExpr,
2441d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor                                                  KeyIdents.data(),
244270c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor                                                  KeyIdents.size(),
244370c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor                                                /*AtArgumentEpression=*/false);
24447d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis        cutOffParsing();
244570c5ac70ace21b011dc2d4001bae26cdcf62ff8dDouglas Gregor        return ExprError();
2446d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor      }
2447d3c6854153fd6bc6a412a29e4491dbd0a47bdb14Douglas Gregor
244837387c932855c6d58d70bdd705cd3a9fdcd2a931Steve Naroff      // Check for another keyword selector.
24492fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner      selIdent = ParseObjCSelectorPiece(Loc);
2450df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner      if (!selIdent && Tok.isNot(tok::colon))
2451a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian        break;
2452a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian      // We have a selector or a colon, continue parsing.
2453a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian    }
2454a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian    // Parse the, optional, argument list, comma separated.
2455df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner    while (Tok.is(tok::comma)) {
245649f109c786f99eb7468dac3976db083a65493444Steve Naroff      ConsumeToken(); // Eat the ','.
24571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      ///  Parse the expression after ','
245860d7b3a319d84d688752be3870615ac0f111fb16John McCall      ExprResult Res(ParseAssignmentExpression());
24590e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl      if (Res.isInvalid()) {
24604fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner        // We must manually skip to a ']', otherwise the expression skipper will
24614fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner        // stop at the ']' when it skips to the ';'.  We want it to skip beyond
24624fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner        // the enclosing expression.
24634fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner        SkipUntil(tok::r_square);
24641d922960e083906a586609ac6978678147250177Sebastian Redl        return move(Res);
246549f109c786f99eb7468dac3976db083a65493444Steve Naroff      }
24660e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl
246749f109c786f99eb7468dac3976db083a65493444Steve Naroff      // We have a valid expression.
2468effa8d1c97b00a3f53e972b0e61d9aade5ea1c57Sebastian Redl      KeyExprs.push_back(Res.release());
2469a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian    }
2470a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian  } else if (!selIdent) {
2471a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian    Diag(Tok, diag::err_expected_ident); // missing selector name.
24721d922960e083906a586609ac6978678147250177Sebastian Redl
24734fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner    // We must manually skip to a ']', otherwise the expression skipper will
24744fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner    // stop at the ']' when it skips to the ';'.  We want it to skip beyond
24754fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner    // the enclosing expression.
24764fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner    SkipUntil(tok::r_square);
24771d922960e083906a586609ac6978678147250177Sebastian Redl    return ExprError();
2478a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian  }
2479809872eca7f6c024e2ab41ddffbbeeae807bf5dcFariborz Jahanian
2480df19526177bc6d0a3ea4d1ae97497869f60563dbChris Lattner  if (Tok.isNot(tok::r_square)) {
2481809872eca7f6c024e2ab41ddffbbeeae807bf5dcFariborz Jahanian    if (Tok.is(tok::identifier))
2482809872eca7f6c024e2ab41ddffbbeeae807bf5dcFariborz Jahanian      Diag(Tok, diag::err_expected_colon);
2483809872eca7f6c024e2ab41ddffbbeeae807bf5dcFariborz Jahanian    else
2484809872eca7f6c024e2ab41ddffbbeeae807bf5dcFariborz Jahanian      Diag(Tok, diag::err_expected_rsquare);
24854fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner    // We must manually skip to a ']', otherwise the expression skipper will
24864fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner    // stop at the ']' when it skips to the ';'.  We want it to skip beyond
24874fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner    // the enclosing expression.
24884fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner    SkipUntil(tok::r_square);
24891d922960e083906a586609ac6978678147250177Sebastian Redl    return ExprError();
2490a65ff6c81f5b278000839988bb532114fd8c6797Fariborz Jahanian  }
24911d922960e083906a586609ac6978678147250177Sebastian Redl
2492699b66138ac307a32e238463e0eff513ff17d337Chris Lattner  SourceLocation RBracLoc = ConsumeBracket(); // consume ']'
24931d922960e083906a586609ac6978678147250177Sebastian Redl
249429238a0bf7cbf5b396efb451a0adb5fe4aa037caSteve Naroff  unsigned nKeys = KeyIdents.size();
2495951376242c076c3f62dd78bf672909fc011991dbArgyrios Kyrtzidis  if (nKeys == 0) {
2496ff38491c18b060526d754765b952f4a497a89416Chris Lattner    KeyIdents.push_back(selIdent);
2497951376242c076c3f62dd78bf672909fc011991dbArgyrios Kyrtzidis    KeyLocs.push_back(Loc);
2498951376242c076c3f62dd78bf672909fc011991dbArgyrios Kyrtzidis  }
2499ff38491c18b060526d754765b952f4a497a89416Chris Lattner  Selector Sel = PP.getSelectorTable().getSelector(nKeys, &KeyIdents[0]);
25001d922960e083906a586609ac6978678147250177Sebastian Redl
25012725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor  if (SuperLoc.isValid())
250223c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor    return Actions.ActOnSuperMessage(getCurScope(), SuperLoc, Sel,
2503951376242c076c3f62dd78bf672909fc011991dbArgyrios Kyrtzidis                                     LBracLoc, KeyLocs, RBracLoc,
2504f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                     MultiExprArg(Actions,
2505f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                                  KeyExprs.take(),
2506f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                                  KeyExprs.size()));
25072725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor  else if (ReceiverType)
250823c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor    return Actions.ActOnClassMessage(getCurScope(), ReceiverType, Sel,
2509951376242c076c3f62dd78bf672909fc011991dbArgyrios Kyrtzidis                                     LBracLoc, KeyLocs, RBracLoc,
2510f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                     MultiExprArg(Actions,
2511f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                                  KeyExprs.take(),
2512f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                                  KeyExprs.size()));
25139ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return Actions.ActOnInstanceMessage(getCurScope(), ReceiverExpr, Sel,
2514951376242c076c3f62dd78bf672909fc011991dbArgyrios Kyrtzidis                                      LBracLoc, KeyLocs, RBracLoc,
2515f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                      MultiExprArg(Actions,
2516f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                                   KeyExprs.take(),
2517f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                                   KeyExprs.size()));
25180ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian}
25190ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian
252060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult Parser::ParseObjCStringLiteral(SourceLocation AtLoc) {
252160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Res(ParseStringLiteralExpression());
25221d922960e083906a586609ac6978678147250177Sebastian Redl  if (Res.isInvalid()) return move(Res);
25231d922960e083906a586609ac6978678147250177Sebastian Redl
2524b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner  // @"foo" @"bar" is a valid concatenated string.  Eat any subsequent string
2525b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner  // expressions.  At this point, we know that the only valid thing that starts
2526b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner  // with '@' is an @"".
25275f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner  SmallVector<SourceLocation, 4> AtLocs;
2528a55e52c0802cae3b7c366a05c461d3d15074c1a3Sebastian Redl  ExprVector AtStrings(Actions);
2529b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner  AtLocs.push_back(AtLoc);
2530effa8d1c97b00a3f53e972b0e61d9aade5ea1c57Sebastian Redl  AtStrings.push_back(Res.release());
25310e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl
2532b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner  while (Tok.is(tok::at)) {
2533b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner    AtLocs.push_back(ConsumeToken()); // eat the @.
2534b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner
253515faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl    // Invalid unless there is a string literal.
253697cf6eb380016db868866faf27a086cd55a316d4Chris Lattner    if (!isTokenStringLiteral())
253797cf6eb380016db868866faf27a086cd55a316d4Chris Lattner      return ExprError(Diag(Tok, diag::err_objc_concat_string));
2538b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner
253960d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Lit(ParseStringLiteralExpression());
25400e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl    if (Lit.isInvalid())
25411d922960e083906a586609ac6978678147250177Sebastian Redl      return move(Lit);
25420e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl
2543effa8d1c97b00a3f53e972b0e61d9aade5ea1c57Sebastian Redl    AtStrings.push_back(Lit.release());
2544b3a99cd5bcaeff0c5ff6a60788b5eb68e52a3953Chris Lattner  }
25451d922960e083906a586609ac6978678147250177Sebastian Redl
25461d922960e083906a586609ac6978678147250177Sebastian Redl  return Owned(Actions.ParseObjCStringLiteral(&AtLocs[0], AtStrings.take(),
25471d922960e083906a586609ac6978678147250177Sebastian Redl                                              AtStrings.size()));
25485508518a2702b00be3b15a26d772bde968972f54Anders Carlsson}
2549f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson
2550ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek/// ParseObjCBooleanLiteral -
2551ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek/// objc-scalar-literal : '@' boolean-keyword
2552ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek///                        ;
2553ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek/// boolean-keyword: 'true' | 'false' | '__objc_yes' | '__objc_no'
2554ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek///                        ;
2555ebcb57a8d298862c65043e88b2429591ab3c58d3Ted KremenekExprResult Parser::ParseObjCBooleanLiteral(SourceLocation AtLoc,
2556ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek                                           bool ArgValue) {
2557ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  SourceLocation EndLoc = ConsumeToken();             // consume the keyword.
2558ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  return Actions.ActOnObjCBoolLiteral(AtLoc, EndLoc, ArgValue);
2559ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek}
2560ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek
2561ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek/// ParseObjCCharacterLiteral -
2562ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek/// objc-scalar-literal : '@' character-literal
2563ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek///                        ;
2564ebcb57a8d298862c65043e88b2429591ab3c58d3Ted KremenekExprResult Parser::ParseObjCCharacterLiteral(SourceLocation AtLoc) {
2565ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  ExprResult Lit(Actions.ActOnCharacterConstant(Tok));
2566ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  if (Lit.isInvalid()) {
2567ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    return move(Lit);
2568ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  }
25698b8d9534f185743fb72c59d4e735794e6e0f4335Benjamin Kramer  ConsumeToken(); // Consume the literal token.
2570ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  return Owned(Actions.BuildObjCNumericLiteral(AtLoc, Lit.take()));
2571ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek}
2572ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek
2573ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek/// ParseObjCNumericLiteral -
2574ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek/// objc-scalar-literal : '@' scalar-literal
2575ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek///                        ;
2576ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek/// scalar-literal : | numeric-constant			/* any numeric constant. */
2577ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek///                    ;
2578ebcb57a8d298862c65043e88b2429591ab3c58d3Ted KremenekExprResult Parser::ParseObjCNumericLiteral(SourceLocation AtLoc) {
2579ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  ExprResult Lit(Actions.ActOnNumericConstant(Tok));
2580ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  if (Lit.isInvalid()) {
2581ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    return move(Lit);
2582ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  }
25838b8d9534f185743fb72c59d4e735794e6e0f4335Benjamin Kramer  ConsumeToken(); // Consume the literal token.
2584ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  return Owned(Actions.BuildObjCNumericLiteral(AtLoc, Lit.take()));
2585ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek}
2586ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek
2587eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard/// ParseObjCBoxedExpr -
2588eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard/// objc-box-expression:
2589eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard///       @( assignment-expression )
2590eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick BeardExprResult
2591eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick BeardParser::ParseObjCBoxedExpr(SourceLocation AtLoc) {
2592eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard  if (Tok.isNot(tok::l_paren))
2593eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard    return ExprError(Diag(Tok, diag::err_expected_lparen_after) << "@");
2594eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard
2595eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard  BalancedDelimiterTracker T(*this, tok::l_paren);
2596eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard  T.consumeOpen();
2597eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard  ExprResult ValueExpr(ParseAssignmentExpression());
2598eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard  if (T.consumeClose())
2599eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard    return ExprError();
2600eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard
2601eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard  // Wrap the sub-expression in a parenthesized expression, to distinguish
2602eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard  // a boxed expression from a literal.
2603eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard  SourceLocation LPLoc = T.getOpenLocation(), RPLoc = T.getCloseLocation();
2604eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard  ValueExpr = Actions.ActOnParenExpr(LPLoc, RPLoc, ValueExpr.take());
2605eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard  return Owned(Actions.BuildObjCBoxedExpr(SourceRange(AtLoc, RPLoc),
2606eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard                                          ValueExpr.take()));
2607eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard}
2608eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard
2609ebcb57a8d298862c65043e88b2429591ab3c58d3Ted KremenekExprResult Parser::ParseObjCArrayLiteral(SourceLocation AtLoc) {
2610ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  ExprVector ElementExprs(Actions);                   // array elements.
2611ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  ConsumeBracket(); // consume the l_square.
2612ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek
2613ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  while (Tok.isNot(tok::r_square)) {
2614ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    // Parse list of array element expressions (all must be id types).
2615ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    ExprResult Res(ParseAssignmentExpression());
2616ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    if (Res.isInvalid()) {
2617ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek      // We must manually skip to a ']', otherwise the expression skipper will
2618ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek      // stop at the ']' when it skips to the ';'.  We want it to skip beyond
2619ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek      // the enclosing expression.
2620ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek      SkipUntil(tok::r_square);
2621ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek      return move(Res);
2622ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    }
2623ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek
2624ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    // Parse the ellipsis that indicates a pack expansion.
2625ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    if (Tok.is(tok::ellipsis))
2626ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek      Res = Actions.ActOnPackExpansion(Res.get(), ConsumeToken());
2627ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    if (Res.isInvalid())
2628ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek      return true;
2629ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek
2630ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    ElementExprs.push_back(Res.release());
2631ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek
2632ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    if (Tok.is(tok::comma))
2633ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek      ConsumeToken(); // Eat the ','.
2634ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    else if (Tok.isNot(tok::r_square))
2635ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek     return ExprError(Diag(Tok, diag::err_expected_rsquare_or_comma));
2636ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  }
2637ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  SourceLocation EndLoc = ConsumeBracket(); // location of ']'
2638ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  MultiExprArg Args(Actions, ElementExprs.take(), ElementExprs.size());
2639ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  return Owned(Actions.BuildObjCArrayLiteral(SourceRange(AtLoc, EndLoc), Args));
2640ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek}
2641ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek
2642ebcb57a8d298862c65043e88b2429591ab3c58d3Ted KremenekExprResult Parser::ParseObjCDictionaryLiteral(SourceLocation AtLoc) {
2643ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  SmallVector<ObjCDictionaryElement, 4> Elements; // dictionary elements.
2644ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  ConsumeBrace(); // consume the l_square.
2645ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  while (Tok.isNot(tok::r_brace)) {
2646ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    // Parse the comma separated key : value expressions.
2647ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    ExprResult KeyExpr;
2648ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    {
2649ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek      ColonProtectionRAIIObject X(*this);
2650ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek      KeyExpr = ParseAssignmentExpression();
2651ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek      if (KeyExpr.isInvalid()) {
2652ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek        // We must manually skip to a '}', otherwise the expression skipper will
2653ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek        // stop at the '}' when it skips to the ';'.  We want it to skip beyond
2654ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek        // the enclosing expression.
2655ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek        SkipUntil(tok::r_brace);
2656ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek        return move(KeyExpr);
2657ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek      }
2658ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    }
2659ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek
2660ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    if (Tok.is(tok::colon)) {
2661ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek      ConsumeToken();
2662ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    } else {
2663ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek      return ExprError(Diag(Tok, diag::err_expected_colon));
2664ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    }
2665ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek
2666ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    ExprResult ValueExpr(ParseAssignmentExpression());
2667ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    if (ValueExpr.isInvalid()) {
2668ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek      // We must manually skip to a '}', otherwise the expression skipper will
2669ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek      // stop at the '}' when it skips to the ';'.  We want it to skip beyond
2670ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek      // the enclosing expression.
2671ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek      SkipUntil(tok::r_brace);
2672ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek      return move(ValueExpr);
2673ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    }
2674ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek
2675ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    // Parse the ellipsis that designates this as a pack expansion.
2676ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    SourceLocation EllipsisLoc;
26774e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie    if (Tok.is(tok::ellipsis) && getLangOpts().CPlusPlus)
2678ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek      EllipsisLoc = ConsumeToken();
2679ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek
2680ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    // We have a valid expression. Collect it in a vector so we can
2681ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    // build the argument list.
2682ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    ObjCDictionaryElement Element = {
2683ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek      KeyExpr.get(), ValueExpr.get(), EllipsisLoc, llvm::Optional<unsigned>()
2684ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    };
2685ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    Elements.push_back(Element);
2686ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek
2687ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    if (Tok.is(tok::comma))
2688ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek      ConsumeToken(); // Eat the ','.
2689ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    else if (Tok.isNot(tok::r_brace))
2690ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek      return ExprError(Diag(Tok, diag::err_expected_rbrace_or_comma));
2691ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  }
2692ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  SourceLocation EndLoc = ConsumeBrace();
2693ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek
2694ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  // Create the ObjCDictionaryLiteral.
2695ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  return Owned(Actions.BuildObjCDictionaryLiteral(SourceRange(AtLoc, EndLoc),
2696ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek                                                  Elements.data(),
2697ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek                                                  Elements.size()));
2698ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek}
2699ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek
2700f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson///    objc-encode-expression:
2701f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson///      @encode ( type-name )
270260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
27031d922960e083906a586609ac6978678147250177Sebastian RedlParser::ParseObjCEncodeExpression(SourceLocation AtLoc) {
2704861cf3effdc0fbc97d401539bc3050da76b2476fSteve Naroff  assert(Tok.isObjCAtKeyword(tok::objc_encode) && "Not an @encode expression!");
27051d922960e083906a586609ac6978678147250177Sebastian Redl
2706f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson  SourceLocation EncLoc = ConsumeToken();
27071d922960e083906a586609ac6978678147250177Sebastian Redl
27084fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner  if (Tok.isNot(tok::l_paren))
27091d922960e083906a586609ac6978678147250177Sebastian Redl    return ExprError(Diag(Tok, diag::err_expected_lparen_after) << "@encode");
27101d922960e083906a586609ac6978678147250177Sebastian Redl
27114a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor  BalancedDelimiterTracker T(*this, tok::l_paren);
27124a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor  T.consumeOpen();
27131d922960e083906a586609ac6978678147250177Sebastian Redl
2714809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor  TypeResult Ty = ParseTypeName();
27151d922960e083906a586609ac6978678147250177Sebastian Redl
27164a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor  T.consumeClose();
27171d922960e083906a586609ac6978678147250177Sebastian Redl
2718809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor  if (Ty.isInvalid())
2719809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor    return ExprError();
2720809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor
27214a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor  return Owned(Actions.ParseObjCEncodeExpression(AtLoc, EncLoc,
27224a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor                                                 T.getOpenLocation(), Ty.get(),
27234a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor                                                 T.getCloseLocation()));
2724f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson}
272529b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson
272629b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson///     objc-protocol-expression
272729b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson///       @protocol ( protocol-name )
272860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
27291d922960e083906a586609ac6978678147250177Sebastian RedlParser::ParseObjCProtocolExpression(SourceLocation AtLoc) {
273029b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson  SourceLocation ProtoLoc = ConsumeToken();
27311d922960e083906a586609ac6978678147250177Sebastian Redl
27324fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner  if (Tok.isNot(tok::l_paren))
27331d922960e083906a586609ac6978678147250177Sebastian Redl    return ExprError(Diag(Tok, diag::err_expected_lparen_after) << "@protocol");
27341d922960e083906a586609ac6978678147250177Sebastian Redl
27354a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor  BalancedDelimiterTracker T(*this, tok::l_paren);
27364a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor  T.consumeOpen();
27371d922960e083906a586609ac6978678147250177Sebastian Redl
27384fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner  if (Tok.isNot(tok::identifier))
27391d922960e083906a586609ac6978678147250177Sebastian Redl    return ExprError(Diag(Tok, diag::err_expected_ident));
27401d922960e083906a586609ac6978678147250177Sebastian Redl
2741390d50a725497e99247dc104a7d2c2a255d3af14Fariborz Jahanian  IdentifierInfo *protocolId = Tok.getIdentifierInfo();
274229b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson  ConsumeToken();
27431d922960e083906a586609ac6978678147250177Sebastian Redl
27444a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor  T.consumeClose();
274529b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson
27461d922960e083906a586609ac6978678147250177Sebastian Redl  return Owned(Actions.ParseObjCProtocolExpression(protocolId, AtLoc, ProtoLoc,
27474a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor                                                   T.getOpenLocation(),
27484a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor                                                   T.getCloseLocation()));
274929b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3cAnders Carlsson}
2750a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian
2751a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian///     objc-selector-expression
2752a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian///       @selector '(' objc-keyword-selector ')'
275360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult Parser::ParseObjCSelectorExpression(SourceLocation AtLoc) {
2754a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian  SourceLocation SelectorLoc = ConsumeToken();
27551d922960e083906a586609ac6978678147250177Sebastian Redl
27564fef81d718ca1b91ce2adef52db91a35f86e9bbdChris Lattner  if (Tok.isNot(tok::l_paren))
27571d922960e083906a586609ac6978678147250177Sebastian Redl    return ExprError(Diag(Tok, diag::err_expected_lparen_after) << "@selector");
27581d922960e083906a586609ac6978678147250177Sebastian Redl
27595f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner  SmallVector<IdentifierInfo *, 12> KeyIdents;
2760a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian  SourceLocation sLoc;
2761458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor
27624a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor  BalancedDelimiterTracker T(*this, tok::l_paren);
27634a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor  T.consumeOpen();
27644a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor
2765458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor  if (Tok.is(tok::code_completion)) {
2766458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor    Actions.CodeCompleteObjCSelector(getCurScope(), KeyIdents.data(),
2767458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor                                     KeyIdents.size());
27687d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis    cutOffParsing();
2769458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor    return ExprError();
2770458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor  }
2771458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor
27722fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner  IdentifierInfo *SelIdent = ParseObjCSelectorPiece(sLoc);
27735add7541726348b9d1c8e96ac5031b87c41acff0Chris Lattner  if (!SelIdent &&  // missing selector name.
27745add7541726348b9d1c8e96ac5031b87c41acff0Chris Lattner      Tok.isNot(tok::colon) && Tok.isNot(tok::coloncolon))
27751d922960e083906a586609ac6978678147250177Sebastian Redl    return ExprError(Diag(Tok, diag::err_expected_ident));
27761d922960e083906a586609ac6978678147250177Sebastian Redl
2777b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian  KeyIdents.push_back(SelIdent);
2778887407e71fd58de452361b77d72970e32b20ebe0Steve Naroff  unsigned nColons = 0;
2779887407e71fd58de452361b77d72970e32b20ebe0Steve Naroff  if (Tok.isNot(tok::r_paren)) {
2780a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian    while (1) {
27815add7541726348b9d1c8e96ac5031b87c41acff0Chris Lattner      if (Tok.is(tok::coloncolon)) { // Handle :: in C++.
27825add7541726348b9d1c8e96ac5031b87c41acff0Chris Lattner        ++nColons;
27835add7541726348b9d1c8e96ac5031b87c41acff0Chris Lattner        KeyIdents.push_back(0);
27845add7541726348b9d1c8e96ac5031b87c41acff0Chris Lattner      } else if (Tok.isNot(tok::colon))
27851d922960e083906a586609ac6978678147250177Sebastian Redl        return ExprError(Diag(Tok, diag::err_expected_colon));
27861d922960e083906a586609ac6978678147250177Sebastian Redl
27875add7541726348b9d1c8e96ac5031b87c41acff0Chris Lattner      ++nColons;
27883b3e1a9e79703da067d23756e5624a4f487d6278Chris Lattner      ConsumeToken(); // Eat the ':' or '::'.
2789a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian      if (Tok.is(tok::r_paren))
2790a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian        break;
2791458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor
2792458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor      if (Tok.is(tok::code_completion)) {
2793458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor        Actions.CodeCompleteObjCSelector(getCurScope(), KeyIdents.data(),
2794458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor                                         KeyIdents.size());
27957d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis        cutOffParsing();
2796458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor        return ExprError();
2797458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor      }
2798458433d2f0f5c96a9e0d21decdd44bebccf20b11Douglas Gregor
2799a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian      // Check for another keyword selector.
2800a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian      SourceLocation Loc;
28012fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner      SelIdent = ParseObjCSelectorPiece(Loc);
2802b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian      KeyIdents.push_back(SelIdent);
28033b3e1a9e79703da067d23756e5624a4f487d6278Chris Lattner      if (!SelIdent && Tok.isNot(tok::colon) && Tok.isNot(tok::coloncolon))
2804a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian        break;
2805a0818e3cd7d59d05e6da41015033b5574c3d7893Fariborz Jahanian    }
2806887407e71fd58de452361b77d72970e32b20ebe0Steve Naroff  }
28074a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor  T.consumeClose();
2808887407e71fd58de452361b77d72970e32b20ebe0Steve Naroff  Selector Sel = PP.getSelectorTable().getSelector(nColons, &KeyIdents[0]);
28091d922960e083906a586609ac6978678147250177Sebastian Redl  return Owned(Actions.ParseObjCSelectorExpression(Sel, AtLoc, SelectorLoc,
28104a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor                                                   T.getOpenLocation(),
28114a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor                                                   T.getCloseLocation()));
281258065b2d8038a4e9a91ea4813bd1774c0f6efacbGabor Greif }
2813140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian
2814140ab234c23f392d5422691c5de1ee3c15026defFariborz JahanianDecl *Parser::ParseLexedObjCMethodDefs(LexedMethod &LM) {
2815a24195aaf71cee202f92ea4bad50358f3d0b701fArgyrios Kyrtzidis
2816a24195aaf71cee202f92ea4bad50358f3d0b701fArgyrios Kyrtzidis  // Save the current token position.
2817a24195aaf71cee202f92ea4bad50358f3d0b701fArgyrios Kyrtzidis  SourceLocation OrigLoc = Tok.getLocation();
2818a24195aaf71cee202f92ea4bad50358f3d0b701fArgyrios Kyrtzidis
2819140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian  assert(!LM.Toks.empty() && "ParseLexedObjCMethodDef - Empty body!");
2820140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian  // Append the current token at the end of the new token stream so that it
2821140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian  // doesn't get lost.
2822140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian  LM.Toks.push_back(Tok);
2823140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian  PP.EnterTokenStream(LM.Toks.data(), LM.Toks.size(), true, false);
2824140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian
2825140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian  // MDecl might be null due to error in method prototype, etc.
2826140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian  Decl *MDecl = LM.D;
2827140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian  // Consume the previously pushed token.
2828140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian  ConsumeAnyToken();
2829140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian
2830140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian  assert(Tok.is(tok::l_brace) && "Inline objective-c method not starting with '{'");
2831140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian  SourceLocation BraceLoc = Tok.getLocation();
2832140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian  // Enter a scope for the method body.
2833140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian  ParseScope BodyScope(this,
2834140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian                       Scope::ObjCMethodScope|Scope::FnScope|Scope::DeclScope);
2835140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian
2836140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian  // Tell the actions module that we have entered a method definition with the
2837140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian  // specified Declarator for the method.
2838140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian  Actions.ActOnStartOfObjCMethodDef(getCurScope(), MDecl);
2839140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian
28406a91d385618ea4d28236c496f540a26877c95525Erik Verbruggen  if (SkipFunctionBodies && trySkippingFunctionBody()) {
28416a91d385618ea4d28236c496f540a26877c95525Erik Verbruggen    BodyScope.Exit();
28426a91d385618ea4d28236c496f540a26877c95525Erik Verbruggen    return Actions.ActOnFinishFunctionBody(MDecl, 0);
2843140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian  }
2844140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian
2845140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian  StmtResult FnBody(ParseCompoundStatementBody());
2846140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian
2847140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian  // If the function body could not be parsed, make a bogus compoundstmt.
2848625bb569df0c34feec0d52c0ec5215f21ef2e054Dmitri Gribenko  if (FnBody.isInvalid()) {
2849625bb569df0c34feec0d52c0ec5215f21ef2e054Dmitri Gribenko    Sema::CompoundScopeRAII CompoundScope(Actions);
2850140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian    FnBody = Actions.ActOnCompoundStmt(BraceLoc, BraceLoc,
2851140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian                                       MultiStmtArg(Actions), false);
2852625bb569df0c34feec0d52c0ec5215f21ef2e054Dmitri Gribenko  }
2853140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian
2854140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian  // Leave the function body scope.
2855140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian  BodyScope.Exit();
2856140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian
2857a24195aaf71cee202f92ea4bad50358f3d0b701fArgyrios Kyrtzidis  MDecl = Actions.ActOnFinishFunctionBody(MDecl, FnBody.take());
2858a24195aaf71cee202f92ea4bad50358f3d0b701fArgyrios Kyrtzidis
2859a24195aaf71cee202f92ea4bad50358f3d0b701fArgyrios Kyrtzidis  if (Tok.getLocation() != OrigLoc) {
2860a24195aaf71cee202f92ea4bad50358f3d0b701fArgyrios Kyrtzidis    // Due to parsing error, we either went over the cached tokens or
2861a24195aaf71cee202f92ea4bad50358f3d0b701fArgyrios Kyrtzidis    // there are still cached tokens left. If it's the latter case skip the
2862a24195aaf71cee202f92ea4bad50358f3d0b701fArgyrios Kyrtzidis    // leftover tokens.
2863a24195aaf71cee202f92ea4bad50358f3d0b701fArgyrios Kyrtzidis    // Since this is an uncommon situation that should be avoided, use the
2864a24195aaf71cee202f92ea4bad50358f3d0b701fArgyrios Kyrtzidis    // expensive isBeforeInTranslationUnit call.
2865a24195aaf71cee202f92ea4bad50358f3d0b701fArgyrios Kyrtzidis    if (PP.getSourceManager().isBeforeInTranslationUnit(Tok.getLocation(),
2866a24195aaf71cee202f92ea4bad50358f3d0b701fArgyrios Kyrtzidis                                                     OrigLoc))
2867a24195aaf71cee202f92ea4bad50358f3d0b701fArgyrios Kyrtzidis      while (Tok.getLocation() != OrigLoc && Tok.isNot(tok::eof))
2868a24195aaf71cee202f92ea4bad50358f3d0b701fArgyrios Kyrtzidis        ConsumeAnyToken();
2869a24195aaf71cee202f92ea4bad50358f3d0b701fArgyrios Kyrtzidis  }
2870a24195aaf71cee202f92ea4bad50358f3d0b701fArgyrios Kyrtzidis
2871a24195aaf71cee202f92ea4bad50358f3d0b701fArgyrios Kyrtzidis  return MDecl;
2872140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian}
2873