ParseDeclCXX.cpp revision 7eeb4ec11043d4860361348f2b19299d957d47a9
18f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner//===--- ParseDeclCXX.cpp - C++ Declaration Parsing -----------------------===//
28f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner//
38f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner//                     The LLVM Compiler Infrastructure
48f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner//
50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// This file is distributed under the University of Illinois Open Source
60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// License. See LICENSE.TXT for details.
78f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner//
88f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner//===----------------------------------------------------------------------===//
98f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner//
108f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner//  This file implements the C++ Declaration portions of the Parser interfaces.
118f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner//
128f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner//===----------------------------------------------------------------------===//
138f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner
140c6139d0c2497c4e8780340e0dc097de041f248eAnders Carlsson#include "clang/Basic/OperatorKinds.h"
151b7f89846f10681ce3cbe89ef5d60691d55bd918Douglas Gregor#include "clang/Parse/Parser.h"
16500d3297d2a21edeac4d46cbcbe21bc2352c2a28Chris Lattner#include "clang/Parse/ParseDiagnostic.h"
1719510856727e0e14a3696b2a72c35163bff2a71fJohn McCall#include "clang/Sema/DeclSpec.h"
1819510856727e0e14a3696b2a72c35163bff2a71fJohn McCall#include "clang/Sema/Scope.h"
1919510856727e0e14a3696b2a72c35163bff2a71fJohn McCall#include "clang/Sema/ParsedTemplate.h"
20f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall#include "clang/Sema/PrettyDeclStackTrace.h"
21d167ca0d26e43292b8b9e8d5300d92784ae0e27dChris Lattner#include "RAIIObjectsForParser.h"
228f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattnerusing namespace clang;
238f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner
248f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner/// ParseNamespace - We know that the current token is a namespace keyword. This
25d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl/// may either be a top level namespace or a block-level namespace alias. If
26d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl/// there was an inline keyword, it has already been parsed.
278f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner///
288f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner///       namespace-definition: [C++ 7.3: basic.namespace]
298f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner///         named-namespace-definition
308f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner///         unnamed-namespace-definition
318f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner///
328f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner///       unnamed-namespace-definition:
33d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl///         'inline'[opt] 'namespace' attributes[opt] '{' namespace-body '}'
348f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner///
358f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner///       named-namespace-definition:
368f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner///         original-namespace-definition
378f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner///         extension-namespace-definition
388f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner///
398f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner///       original-namespace-definition:
40d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl///         'inline'[opt] 'namespace' identifier attributes[opt]
41d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl///             '{' namespace-body '}'
428f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner///
438f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner///       extension-namespace-definition:
44d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl///         'inline'[opt] 'namespace' original-namespace-name
45d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl///             '{' namespace-body '}'
461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///
478f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner///       namespace-alias-definition:  [C++ 7.3.2: namespace.alias]
488f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner///         'namespace' identifier '=' qualified-namespace-specifier ';'
498f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner///
50d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseNamespace(unsigned Context,
51d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl                             SourceLocation &DeclEnd,
52d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl                             SourceLocation InlineLoc) {
5304d6666eee19bbf25bdfcb8e79eb8b00ace03f0cChris Lattner  assert(Tok.is(tok::kw_namespace) && "Not a namespace!");
548f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner  SourceLocation NamespaceLoc = ConsumeToken();  // eat the 'namespace'.
551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5649f40bd0c9c9de5e74727774fec429b47d36303aDouglas Gregor  if (Tok.is(tok::code_completion)) {
5723c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor    Actions.CodeCompleteNamespaceDecl(getCurScope());
58dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor    ConsumeCodeCompletionToken();
5949f40bd0c9c9de5e74727774fec429b47d36303aDouglas Gregor  }
60193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam
618f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner  SourceLocation IdentLoc;
628f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner  IdentifierInfo *Ident = 0;
636a588dd230c14a364d222d6057bbcf11afbd9ffdDouglas Gregor
646a588dd230c14a364d222d6057bbcf11afbd9ffdDouglas Gregor  Token attrTok;
651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6604d6666eee19bbf25bdfcb8e79eb8b00ace03f0cChris Lattner  if (Tok.is(tok::identifier)) {
678f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner    Ident = Tok.getIdentifierInfo();
688f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner    IdentLoc = ConsumeToken();  // eat the identifier.
698f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner  }
701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
718f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner  // Read label attributes, if present.
727f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  ParsedAttributes attrs;
736a588dd230c14a364d222d6057bbcf11afbd9ffdDouglas Gregor  if (Tok.is(tok::kw___attribute)) {
746a588dd230c14a364d222d6057bbcf11afbd9ffdDouglas Gregor    attrTok = Tok;
756a588dd230c14a364d222d6057bbcf11afbd9ffdDouglas Gregor
768f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner    // FIXME: save these somewhere.
777f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall    ParseGNUAttributes(attrs);
786a588dd230c14a364d222d6057bbcf11afbd9ffdDouglas Gregor  }
791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
806a588dd230c14a364d222d6057bbcf11afbd9ffdDouglas Gregor  if (Tok.is(tok::equal)) {
817f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall    if (!attrs.empty())
826a588dd230c14a364d222d6057bbcf11afbd9ffdDouglas Gregor      Diag(attrTok, diag::err_unexpected_namespace_attributes_alias);
83d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl    if (InlineLoc.isValid())
84d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl      Diag(InlineLoc, diag::err_inline_namespace_alias)
85d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl          << FixItHint::CreateRemoval(InlineLoc);
866a588dd230c14a364d222d6057bbcf11afbd9ffdDouglas Gregor
8797144fc41a9419bf6d74fc9450e8ef3f6e11f7e0Chris Lattner    return ParseNamespaceAlias(NamespaceLoc, IdentLoc, Ident, DeclEnd);
886a588dd230c14a364d222d6057bbcf11afbd9ffdDouglas Gregor  }
891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
905144832ae62cf97543b274d4bb88d5f74d0f7a20Chris Lattner  if (Tok.isNot(tok::l_brace)) {
911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    Diag(Tok, Ident ? diag::err_expected_lbrace :
925144832ae62cf97543b274d4bb88d5f74d0f7a20Chris Lattner         diag::err_expected_ident_lbrace);
93d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall    return 0;
945144832ae62cf97543b274d4bb88d5f74d0f7a20Chris Lattner  }
951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
965144832ae62cf97543b274d4bb88d5f74d0f7a20Chris Lattner  SourceLocation LBrace = ConsumeBrace();
972d1c5d313cd0c229cc614e74baa4c5756a4b46f4Argyrios Kyrtzidis
9823c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor  if (getCurScope()->isClassScope() || getCurScope()->isTemplateParamScope() ||
9923c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor      getCurScope()->isInObjcMethodScope() || getCurScope()->getBlockParent() ||
10023c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor      getCurScope()->getFnParent()) {
10195f1b15ce1b281c8517d77792abe540753fbcc12Douglas Gregor    Diag(LBrace, diag::err_namespace_nonnamespace_scope);
10295f1b15ce1b281c8517d77792abe540753fbcc12Douglas Gregor    SkipUntil(tok::r_brace, false);
103d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall    return 0;
10495f1b15ce1b281c8517d77792abe540753fbcc12Douglas Gregor  }
10595f1b15ce1b281c8517d77792abe540753fbcc12Douglas Gregor
10688e64ca96d6c00c6f3bd43772cd325bede795d2aSebastian Redl  // If we're still good, complain about inline namespaces in non-C++0x now.
10788e64ca96d6c00c6f3bd43772cd325bede795d2aSebastian Redl  if (!getLang().CPlusPlus0x && InlineLoc.isValid())
10888e64ca96d6c00c6f3bd43772cd325bede795d2aSebastian Redl    Diag(InlineLoc, diag::ext_inline_namespace);
10988e64ca96d6c00c6f3bd43772cd325bede795d2aSebastian Redl
1105144832ae62cf97543b274d4bb88d5f74d0f7a20Chris Lattner  // Enter a scope for the namespace.
1115144832ae62cf97543b274d4bb88d5f74d0f7a20Chris Lattner  ParseScope NamespaceScope(this, Scope::DeclScope);
1122d1c5d313cd0c229cc614e74baa4c5756a4b46f4Argyrios Kyrtzidis
113d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  Decl *NamespcDecl =
114d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl    Actions.ActOnStartNamespaceDef(getCurScope(), InlineLoc, IdentLoc, Ident,
1157f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall                                   LBrace, attrs.getList());
1162d1c5d313cd0c229cc614e74baa4c5756a4b46f4Argyrios Kyrtzidis
117f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall  PrettyDeclStackTraceEntry CrashInfo(Actions, NamespcDecl, NamespaceLoc,
118f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                      "parsing namespace");
1191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
120bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt  while (Tok.isNot(tok::r_brace) && Tok.isNot(tok::eof)) {
1217f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall    ParsedAttributesWithRange attrs;
1227f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall    MaybeParseCXX0XAttributes(attrs);
1237f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall    MaybeParseMicrosoftAttributes(attrs);
1247f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall    ParseExternalDeclaration(attrs);
125bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt  }
1261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1275144832ae62cf97543b274d4bb88d5f74d0f7a20Chris Lattner  // Leave the namespace scope.
1285144832ae62cf97543b274d4bb88d5f74d0f7a20Chris Lattner  NamespaceScope.Exit();
1298ba5d792032f475eb653ca6340eb51068df0fa90Argyrios Kyrtzidis
13097144fc41a9419bf6d74fc9450e8ef3f6e11f7e0Chris Lattner  SourceLocation RBraceLoc = MatchRHSPunctuation(tok::r_brace, LBrace);
13197144fc41a9419bf6d74fc9450e8ef3f6e11f7e0Chris Lattner  Actions.ActOnFinishNamespaceDef(NamespcDecl, RBraceLoc);
1322d1c5d313cd0c229cc614e74baa4c5756a4b46f4Argyrios Kyrtzidis
13397144fc41a9419bf6d74fc9450e8ef3f6e11f7e0Chris Lattner  DeclEnd = RBraceLoc;
1345144832ae62cf97543b274d4bb88d5f74d0f7a20Chris Lattner  return NamespcDecl;
1358f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner}
136c6fdc34ac0183bfa03d65f317c78b7bdac52897eChris Lattner
137f67606ae2febe3bb0718f05040c6c4bc2c2c3276Anders Carlsson/// ParseNamespaceAlias - Parse the part after the '=' in a namespace
138f67606ae2febe3bb0718f05040c6c4bc2c2c3276Anders Carlsson/// alias definition.
139f67606ae2febe3bb0718f05040c6c4bc2c2c3276Anders Carlsson///
140d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseNamespaceAlias(SourceLocation NamespaceLoc,
1411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                              SourceLocation AliasLoc,
14297144fc41a9419bf6d74fc9450e8ef3f6e11f7e0Chris Lattner                                              IdentifierInfo *Alias,
14397144fc41a9419bf6d74fc9450e8ef3f6e11f7e0Chris Lattner                                              SourceLocation &DeclEnd) {
144f67606ae2febe3bb0718f05040c6c4bc2c2c3276Anders Carlsson  assert(Tok.is(tok::equal) && "Not equal token");
1451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
146f67606ae2febe3bb0718f05040c6c4bc2c2c3276Anders Carlsson  ConsumeToken(); // eat the '='.
1471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14849f40bd0c9c9de5e74727774fec429b47d36303aDouglas Gregor  if (Tok.is(tok::code_completion)) {
14923c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor    Actions.CodeCompleteNamespaceAliasDecl(getCurScope());
150dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor    ConsumeCodeCompletionToken();
15149f40bd0c9c9de5e74727774fec429b47d36303aDouglas Gregor  }
152193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam
153f67606ae2febe3bb0718f05040c6c4bc2c2c3276Anders Carlsson  CXXScopeSpec SS;
154f67606ae2febe3bb0718f05040c6c4bc2c2c3276Anders Carlsson  // Parse (optional) nested-name-specifier.
155b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  ParseOptionalCXXScopeSpecifier(SS, ParsedType(), false);
156f67606ae2febe3bb0718f05040c6c4bc2c2c3276Anders Carlsson
157f67606ae2febe3bb0718f05040c6c4bc2c2c3276Anders Carlsson  if (SS.isInvalid() || Tok.isNot(tok::identifier)) {
158f67606ae2febe3bb0718f05040c6c4bc2c2c3276Anders Carlsson    Diag(Tok, diag::err_expected_namespace_name);
159f67606ae2febe3bb0718f05040c6c4bc2c2c3276Anders Carlsson    // Skip to end of the definition and eat the ';'.
160f67606ae2febe3bb0718f05040c6c4bc2c2c3276Anders Carlsson    SkipUntil(tok::semi);
161d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall    return 0;
162f67606ae2febe3bb0718f05040c6c4bc2c2c3276Anders Carlsson  }
163f67606ae2febe3bb0718f05040c6c4bc2c2c3276Anders Carlsson
164f67606ae2febe3bb0718f05040c6c4bc2c2c3276Anders Carlsson  // Parse identifier.
16503bd5a1e9a54b62b10ae8aeb6eb5245e2031d98bAnders Carlsson  IdentifierInfo *Ident = Tok.getIdentifierInfo();
16603bd5a1e9a54b62b10ae8aeb6eb5245e2031d98bAnders Carlsson  SourceLocation IdentLoc = ConsumeToken();
1671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
168f67606ae2febe3bb0718f05040c6c4bc2c2c3276Anders Carlsson  // Eat the ';'.
16997144fc41a9419bf6d74fc9450e8ef3f6e11f7e0Chris Lattner  DeclEnd = Tok.getLocation();
1706869d8ea1bb7d191b5b290f5a55ee74f2174829aChris Lattner  ExpectAndConsume(tok::semi, diag::err_expected_semi_after_namespace_name,
1716869d8ea1bb7d191b5b290f5a55ee74f2174829aChris Lattner                   "", tok::semi);
1721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
17323c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor  return Actions.ActOnNamespaceAliasDef(getCurScope(), NamespaceLoc, AliasLoc, Alias,
17403bd5a1e9a54b62b10ae8aeb6eb5245e2031d98bAnders Carlsson                                        SS, IdentLoc, Ident);
175f67606ae2febe3bb0718f05040c6c4bc2c2c3276Anders Carlsson}
176f67606ae2febe3bb0718f05040c6c4bc2c2c3276Anders Carlsson
177c6fdc34ac0183bfa03d65f317c78b7bdac52897eChris Lattner/// ParseLinkage - We know that the current token is a string_literal
178c6fdc34ac0183bfa03d65f317c78b7bdac52897eChris Lattner/// and just before that, that extern was seen.
179c6fdc34ac0183bfa03d65f317c78b7bdac52897eChris Lattner///
180c6fdc34ac0183bfa03d65f317c78b7bdac52897eChris Lattner///       linkage-specification: [C++ 7.5p2: dcl.link]
181c6fdc34ac0183bfa03d65f317c78b7bdac52897eChris Lattner///         'extern' string-literal '{' declaration-seq[opt] '}'
182c6fdc34ac0183bfa03d65f317c78b7bdac52897eChris Lattner///         'extern' string-literal declaration
183c6fdc34ac0183bfa03d65f317c78b7bdac52897eChris Lattner///
1847d64271b162eaf5cae264ff64465b28af623dc17Chris LattnerDecl *Parser::ParseLinkage(ParsingDeclSpec &DS, unsigned Context) {
185c19923dda3d28f67aab4726cd40bb07032758383Douglas Gregor  assert(Tok.is(tok::string_literal) && "Not a string literal!");
186193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam  llvm::SmallString<8> LangBuffer;
187453091cc2082e207ea2c2dda645a9bc01b37fb0cDouglas Gregor  bool Invalid = false;
188453091cc2082e207ea2c2dda645a9bc01b37fb0cDouglas Gregor  llvm::StringRef Lang = PP.getSpelling(Tok, LangBuffer, &Invalid);
189453091cc2082e207ea2c2dda645a9bc01b37fb0cDouglas Gregor  if (Invalid)
190d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall    return 0;
191c6fdc34ac0183bfa03d65f317c78b7bdac52897eChris Lattner
192c6fdc34ac0183bfa03d65f317c78b7bdac52897eChris Lattner  SourceLocation Loc = ConsumeStringToken();
193c6fdc34ac0183bfa03d65f317c78b7bdac52897eChris Lattner
194074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor  ParseScope LinkageScope(this, Scope::DeclScope);
195d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  Decl *LinkageSpec
19623c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor    = Actions.ActOnStartLinkageSpecification(getCurScope(),
197074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor                                             /*FIXME: */SourceLocation(),
198d56638180014e60538cd666cd11fde6d4698e051Benjamin Kramer                                             Loc, Lang,
1991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                       Tok.is(tok::l_brace)? Tok.getLocation()
200074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor                                                           : SourceLocation());
201074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor
2027f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  ParsedAttributesWithRange attrs;
2037f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  MaybeParseCXX0XAttributes(attrs);
2047f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  MaybeParseMicrosoftAttributes(attrs);
205193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam
206074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor  if (Tok.isNot(tok::l_brace)) {
20735f9a196ef897b9559de25aaecd957208f0b4f59Abramo Bagnara    DS.setExternInLinkageSpec(true);
2087f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall    ParseExternalDeclaration(attrs, &DS);
20923c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor    return Actions.ActOnFinishLinkageSpecification(getCurScope(), LinkageSpec,
210074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor                                                   SourceLocation());
2111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
212f44515a49b549171dc3ee9faa6281b72609da563Douglas Gregor
21363a011378d4b9483ce24400c163cb8d65ea096a5Douglas Gregor  DS.abort();
21463a011378d4b9483ce24400c163cb8d65ea096a5Douglas Gregor
2157f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  ProhibitAttributes(attrs);
216bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt
217f44515a49b549171dc3ee9faa6281b72609da563Douglas Gregor  SourceLocation LBrace = ConsumeBrace();
218f44515a49b549171dc3ee9faa6281b72609da563Douglas Gregor  while (Tok.isNot(tok::r_brace) && Tok.isNot(tok::eof)) {
2197f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall    ParsedAttributesWithRange attrs;
2207f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall    MaybeParseCXX0XAttributes(attrs);
2217f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall    MaybeParseMicrosoftAttributes(attrs);
2227f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall    ParseExternalDeclaration(attrs);
223f44515a49b549171dc3ee9faa6281b72609da563Douglas Gregor  }
224c6fdc34ac0183bfa03d65f317c78b7bdac52897eChris Lattner
225f44515a49b549171dc3ee9faa6281b72609da563Douglas Gregor  SourceLocation RBrace = MatchRHSPunctuation(tok::r_brace, LBrace);
2267d64271b162eaf5cae264ff64465b28af623dc17Chris Lattner  return Actions.ActOnFinishLinkageSpecification(getCurScope(), LinkageSpec,
2277d64271b162eaf5cae264ff64465b28af623dc17Chris Lattner                                                 RBrace);
228c6fdc34ac0183bfa03d65f317c78b7bdac52897eChris Lattner}
229e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor
230f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor/// ParseUsingDirectiveOrDeclaration - Parse C++ using using-declaration or
231f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor/// using-directive. Assumes that current token is 'using'.
232d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseUsingDirectiveOrDeclaration(unsigned Context,
23378b810559d89e996e00684335407443936ce34a1John McCall                                         const ParsedTemplateInfo &TemplateInfo,
23478b810559d89e996e00684335407443936ce34a1John McCall                                               SourceLocation &DeclEnd,
2357f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall                                             ParsedAttributesWithRange &attrs) {
236f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor  assert(Tok.is(tok::kw_using) && "Not using token");
237f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor
238f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor  // Eat 'using'.
239f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor  SourceLocation UsingLoc = ConsumeToken();
240f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor
24149f40bd0c9c9de5e74727774fec429b47d36303aDouglas Gregor  if (Tok.is(tok::code_completion)) {
24223c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor    Actions.CodeCompleteUsing(getCurScope());
243dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor    ConsumeCodeCompletionToken();
24449f40bd0c9c9de5e74727774fec429b47d36303aDouglas Gregor  }
245193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam
24678b810559d89e996e00684335407443936ce34a1John McCall  // 'using namespace' means this is a using-directive.
24778b810559d89e996e00684335407443936ce34a1John McCall  if (Tok.is(tok::kw_namespace)) {
24878b810559d89e996e00684335407443936ce34a1John McCall    // Template parameters are always an error here.
24978b810559d89e996e00684335407443936ce34a1John McCall    if (TemplateInfo.Kind) {
25078b810559d89e996e00684335407443936ce34a1John McCall      SourceRange R = TemplateInfo.getSourceRange();
25178b810559d89e996e00684335407443936ce34a1John McCall      Diag(UsingLoc, diag::err_templated_using_directive)
25278b810559d89e996e00684335407443936ce34a1John McCall        << R << FixItHint::CreateRemoval(R);
25378b810559d89e996e00684335407443936ce34a1John McCall    }
25478b810559d89e996e00684335407443936ce34a1John McCall
2557f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall    return ParseUsingDirective(Context, UsingLoc, DeclEnd, attrs);
25678b810559d89e996e00684335407443936ce34a1John McCall  }
257bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt
25878b810559d89e996e00684335407443936ce34a1John McCall  // Otherwise, it must be a using-declaration.
25978b810559d89e996e00684335407443936ce34a1John McCall
26078b810559d89e996e00684335407443936ce34a1John McCall  // Using declarations can't have attributes.
2617f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  ProhibitAttributes(attrs);
2622f27477a29b6f5365ee545c1cac666cc8b95f518Chris Lattner
26378b810559d89e996e00684335407443936ce34a1John McCall  return ParseUsingDeclaration(Context, TemplateInfo, UsingLoc, DeclEnd);
264f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor}
265f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor
266f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor/// ParseUsingDirective - Parse C++ using-directive, assumes
267f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor/// that current token is 'namespace' and 'using' was already parsed.
268f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor///
269f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor///       using-directive: [C++ 7.3.p4: namespace.udir]
270f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor///        'using' 'namespace' ::[opt] nested-name-specifier[opt]
271f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor///                 namespace-name ;
272f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor/// [GNU] using-directive:
273f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor///        'using' 'namespace' ::[opt] nested-name-specifier[opt]
274f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor///                 namespace-name attributes[opt] ;
275f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor///
276d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseUsingDirective(unsigned Context,
27778b810559d89e996e00684335407443936ce34a1John McCall                                  SourceLocation UsingLoc,
27878b810559d89e996e00684335407443936ce34a1John McCall                                  SourceLocation &DeclEnd,
2797f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall                                  ParsedAttributes &attrs) {
280f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor  assert(Tok.is(tok::kw_namespace) && "Not 'namespace' token");
281f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor
282f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor  // Eat 'namespace'.
283f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor  SourceLocation NamespcLoc = ConsumeToken();
284f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor
28549f40bd0c9c9de5e74727774fec429b47d36303aDouglas Gregor  if (Tok.is(tok::code_completion)) {
28623c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor    Actions.CodeCompleteUsingDirective(getCurScope());
287dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor    ConsumeCodeCompletionToken();
28849f40bd0c9c9de5e74727774fec429b47d36303aDouglas Gregor  }
289193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam
290f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor  CXXScopeSpec SS;
291f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor  // Parse (optional) nested-name-specifier.
292b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  ParseOptionalCXXScopeSpecifier(SS, ParsedType(), false);
293f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor
294f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor  IdentifierInfo *NamespcName = 0;
295f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor  SourceLocation IdentLoc = SourceLocation();
296f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor
297f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor  // Parse namespace-name.
298823c44e6d73141f642e207980b4021ddcf09897bChris Lattner  if (SS.isInvalid() || Tok.isNot(tok::identifier)) {
299f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor    Diag(Tok, diag::err_expected_namespace_name);
300f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor    // If there was invalid namespace name, skip to end of decl, and eat ';'.
301f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor    SkipUntil(tok::semi);
302f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor    // FIXME: Are there cases, when we would like to call ActOnUsingDirective?
303d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall    return 0;
304f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor  }
3051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
306823c44e6d73141f642e207980b4021ddcf09897bChris Lattner  // Parse identifier.
307823c44e6d73141f642e207980b4021ddcf09897bChris Lattner  NamespcName = Tok.getIdentifierInfo();
308823c44e6d73141f642e207980b4021ddcf09897bChris Lattner  IdentLoc = ConsumeToken();
3091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
310823c44e6d73141f642e207980b4021ddcf09897bChris Lattner  // Parse (optional) attributes (most likely GNU strong-using extension).
311bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt  bool GNUAttr = false;
312bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt  if (Tok.is(tok::kw___attribute)) {
313bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt    GNUAttr = true;
3147f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall    ParseGNUAttributes(attrs);
315bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt  }
3161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
317823c44e6d73141f642e207980b4021ddcf09897bChris Lattner  // Eat ';'.
31897144fc41a9419bf6d74fc9450e8ef3f6e11f7e0Chris Lattner  DeclEnd = Tok.getLocation();
3196869d8ea1bb7d191b5b290f5a55ee74f2174829aChris Lattner  ExpectAndConsume(tok::semi,
3209ba23b4ceacd77cd264501690a7a9e94184ef71bDouglas Gregor                   GNUAttr ? diag::err_expected_semi_after_attribute_list
3219ba23b4ceacd77cd264501690a7a9e94184ef71bDouglas Gregor                           : diag::err_expected_semi_after_namespace_name,
3229ba23b4ceacd77cd264501690a7a9e94184ef71bDouglas Gregor                   "", tok::semi);
323f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor
32423c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor  return Actions.ActOnUsingDirective(getCurScope(), UsingLoc, NamespcLoc, SS,
3257f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall                                     IdentLoc, NamespcName, attrs.getList());
326f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor}
327f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor
328f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor/// ParseUsingDeclaration - Parse C++ using-declaration. Assumes that
329f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor/// 'using' was already seen.
330f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor///
331f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor///     using-declaration: [C++ 7.3.p3: namespace.udecl]
332f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor///       'using' 'typename'[opt] ::[opt] nested-name-specifier
3339cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor///               unqualified-id
3349cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor///       'using' :: unqualified-id
335f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor///
336d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseUsingDeclaration(unsigned Context,
33778b810559d89e996e00684335407443936ce34a1John McCall                                    const ParsedTemplateInfo &TemplateInfo,
33878b810559d89e996e00684335407443936ce34a1John McCall                                    SourceLocation UsingLoc,
33978b810559d89e996e00684335407443936ce34a1John McCall                                    SourceLocation &DeclEnd,
34078b810559d89e996e00684335407443936ce34a1John McCall                                    AccessSpecifier AS) {
3419cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor  CXXScopeSpec SS;
3427ba107a1863ddfa1664555854f0d7bdb3c491c92John McCall  SourceLocation TypenameLoc;
3439cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor  bool IsTypeName;
3449cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor
34578b810559d89e996e00684335407443936ce34a1John McCall  // TODO: in C++0x, if we have template parameters this must be a
34678b810559d89e996e00684335407443936ce34a1John McCall  // template alias:
34778b810559d89e996e00684335407443936ce34a1John McCall  //   template <...> using id = type;
34878b810559d89e996e00684335407443936ce34a1John McCall
3499cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor  // Ignore optional 'typename'.
35012c118a8ff9f61a4d63146fe1a5c0d60987f99bbDouglas Gregor  // FIXME: This is wrong; we should parse this as a typename-specifier.
3519cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor  if (Tok.is(tok::kw_typename)) {
3527ba107a1863ddfa1664555854f0d7bdb3c491c92John McCall    TypenameLoc = Tok.getLocation();
3539cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor    ConsumeToken();
3549cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor    IsTypeName = true;
3559cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor  }
3569cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor  else
3579cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor    IsTypeName = false;
3589cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor
3599cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor  // Parse nested-name-specifier.
360b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  ParseOptionalCXXScopeSpecifier(SS, ParsedType(), false);
3619cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor
3629cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor  // Check nested-name specifier.
3639cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor  if (SS.isInvalid()) {
3649cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor    SkipUntil(tok::semi);
365d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall    return 0;
3669cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor  }
3671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
368193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam  // Parse the unqualified-id. We allow parsing of both constructor and
36912c118a8ff9f61a4d63146fe1a5c0d60987f99bbDouglas Gregor  // destructor names and allow the action module to diagnose any semantic
37012c118a8ff9f61a4d63146fe1a5c0d60987f99bbDouglas Gregor  // errors.
37112c118a8ff9f61a4d63146fe1a5c0d60987f99bbDouglas Gregor  UnqualifiedId Name;
372193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam  if (ParseUnqualifiedId(SS,
37312c118a8ff9f61a4d63146fe1a5c0d60987f99bbDouglas Gregor                         /*EnteringContext=*/false,
37412c118a8ff9f61a4d63146fe1a5c0d60987f99bbDouglas Gregor                         /*AllowDestructorName=*/true,
375193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam                         /*AllowConstructorName=*/true,
376b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                         ParsedType(),
37712c118a8ff9f61a4d63146fe1a5c0d60987f99bbDouglas Gregor                         Name)) {
3789cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor    SkipUntil(tok::semi);
379d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall    return 0;
3809cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor  }
381193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam
3829cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor  // Parse (optional) attributes (most likely GNU strong-using extension).
3837f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  ParsedAttributes attrs;
3847f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  MaybeParseGNUAttributes(attrs);
3851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3869cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor  // Eat ';'.
3879cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor  DeclEnd = Tok.getLocation();
3889cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor  ExpectAndConsume(tok::semi, diag::err_expected_semi_after,
3897f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall                   !attrs.empty() ? "attributes list" : "using declaration",
39012c118a8ff9f61a4d63146fe1a5c0d60987f99bbDouglas Gregor                   tok::semi);
3919cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor
39278b810559d89e996e00684335407443936ce34a1John McCall  // Diagnose an attempt to declare a templated using-declaration.
39378b810559d89e996e00684335407443936ce34a1John McCall  if (TemplateInfo.Kind) {
39478b810559d89e996e00684335407443936ce34a1John McCall    SourceRange R = TemplateInfo.getSourceRange();
39578b810559d89e996e00684335407443936ce34a1John McCall    Diag(UsingLoc, diag::err_templated_using_declaration)
39678b810559d89e996e00684335407443936ce34a1John McCall      << R << FixItHint::CreateRemoval(R);
39778b810559d89e996e00684335407443936ce34a1John McCall
39878b810559d89e996e00684335407443936ce34a1John McCall    // Unfortunately, we have to bail out instead of recovering by
39978b810559d89e996e00684335407443936ce34a1John McCall    // ignoring the parameters, just in case the nested name specifier
40078b810559d89e996e00684335407443936ce34a1John McCall    // depends on the parameters.
40178b810559d89e996e00684335407443936ce34a1John McCall    return 0;
40278b810559d89e996e00684335407443936ce34a1John McCall  }
40378b810559d89e996e00684335407443936ce34a1John McCall
4048113ecfa4e41e2c888b1794389dfe3bce6386493Ted Kremenek  return Actions.ActOnUsingDeclaration(getCurScope(), AS, true, UsingLoc, SS,
4057f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall                                       Name, attrs.getList(),
4067f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall                                       IsTypeName, TypenameLoc);
407f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor}
408f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor
409511d7aba3b12853fdb88729a0313b80a60eab8adAnders Carlsson/// ParseStaticAssertDeclaration - Parse C++0x static_assert-declaratoion.
410511d7aba3b12853fdb88729a0313b80a60eab8adAnders Carlsson///
411511d7aba3b12853fdb88729a0313b80a60eab8adAnders Carlsson///      static_assert-declaration:
412511d7aba3b12853fdb88729a0313b80a60eab8adAnders Carlsson///        static_assert ( constant-expression  ,  string-literal  ) ;
413511d7aba3b12853fdb88729a0313b80a60eab8adAnders Carlsson///
414d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseStaticAssertDeclaration(SourceLocation &DeclEnd){
415511d7aba3b12853fdb88729a0313b80a60eab8adAnders Carlsson  assert(Tok.is(tok::kw_static_assert) && "Not a static_assert declaration");
416511d7aba3b12853fdb88729a0313b80a60eab8adAnders Carlsson  SourceLocation StaticAssertLoc = ConsumeToken();
4171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
418511d7aba3b12853fdb88729a0313b80a60eab8adAnders Carlsson  if (Tok.isNot(tok::l_paren)) {
419511d7aba3b12853fdb88729a0313b80a60eab8adAnders Carlsson    Diag(Tok, diag::err_expected_lparen);
420d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall    return 0;
421511d7aba3b12853fdb88729a0313b80a60eab8adAnders Carlsson  }
4221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
423511d7aba3b12853fdb88729a0313b80a60eab8adAnders Carlsson  SourceLocation LParenLoc = ConsumeParen();
424e0762c92110dfdcdd207db461a4ea17afd168f1eDouglas Gregor
42560d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult AssertExpr(ParseConstantExpression());
426511d7aba3b12853fdb88729a0313b80a60eab8adAnders Carlsson  if (AssertExpr.isInvalid()) {
427511d7aba3b12853fdb88729a0313b80a60eab8adAnders Carlsson    SkipUntil(tok::semi);
428d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall    return 0;
429511d7aba3b12853fdb88729a0313b80a60eab8adAnders Carlsson  }
4301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
431ad5f960f9e42568a87bf5e03dce7ad878f9ba6daAnders Carlsson  if (ExpectAndConsume(tok::comma, diag::err_expected_comma, "", tok::semi))
432d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall    return 0;
433ad5f960f9e42568a87bf5e03dce7ad878f9ba6daAnders Carlsson
434511d7aba3b12853fdb88729a0313b80a60eab8adAnders Carlsson  if (Tok.isNot(tok::string_literal)) {
435511d7aba3b12853fdb88729a0313b80a60eab8adAnders Carlsson    Diag(Tok, diag::err_expected_string_literal);
436511d7aba3b12853fdb88729a0313b80a60eab8adAnders Carlsson    SkipUntil(tok::semi);
437d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall    return 0;
438511d7aba3b12853fdb88729a0313b80a60eab8adAnders Carlsson  }
4391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
44060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult AssertMessage(ParseStringLiteralExpression());
4411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  if (AssertMessage.isInvalid())
442d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall    return 0;
443511d7aba3b12853fdb88729a0313b80a60eab8adAnders Carlsson
44494b15fbc3a10cdfb1639528a8a773b66a1e7cd9eAnders Carlsson  MatchRHSPunctuation(tok::r_paren, LParenLoc);
4451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
44697144fc41a9419bf6d74fc9450e8ef3f6e11f7e0Chris Lattner  DeclEnd = Tok.getLocation();
4479ba23b4ceacd77cd264501690a7a9e94184ef71bDouglas Gregor  ExpectAndConsumeSemi(diag::err_expected_semi_after_static_assert);
448511d7aba3b12853fdb88729a0313b80a60eab8adAnders Carlsson
4499ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return Actions.ActOnStaticAssertDeclaration(StaticAssertLoc,
4509ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                              AssertExpr.take(),
4519ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                              AssertMessage.take());
452511d7aba3b12853fdb88729a0313b80a60eab8adAnders Carlsson}
453511d7aba3b12853fdb88729a0313b80a60eab8adAnders Carlsson
4546fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson/// ParseDecltypeSpecifier - Parse a C++0x decltype specifier.
4556fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson///
4566fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson/// 'decltype' ( expression )
4576fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson///
4586fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlssonvoid Parser::ParseDecltypeSpecifier(DeclSpec &DS) {
4596fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson  assert(Tok.is(tok::kw_decltype) && "Not a decltype specifier");
4606fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson
4616fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson  SourceLocation StartLoc = ConsumeToken();
4626fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson  SourceLocation LParenLoc = Tok.getLocation();
4631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  if (ExpectAndConsume(tok::l_paren, diag::err_expected_lparen_after,
4656fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson                       "decltype")) {
4666fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson    SkipUntil(tok::r_paren);
4676fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson    return;
4686fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson  }
4691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4706fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson  // Parse the expression
4711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4726fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson  // C++0x [dcl.type.simple]p4:
4736fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson  //   The operand of the decltype specifier is an unevaluated operand.
4746fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson  EnterExpressionEvaluationContext Unevaluated(Actions,
475f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                               Sema::Unevaluated);
47660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Result = ParseExpression();
4776fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson  if (Result.isInvalid()) {
4786fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson    SkipUntil(tok::r_paren);
4796fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson    return;
4806fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson  }
4811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4826fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson  // Match the ')'
4836fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson  SourceLocation RParenLoc;
4846fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson  if (Tok.is(tok::r_paren))
4856fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson    RParenLoc = ConsumeParen();
4866fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson  else
4876fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson    MatchRHSPunctuation(tok::r_paren, LParenLoc);
4881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4896fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson  if (RParenLoc.isInvalid())
4906fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson    return;
4916fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson
4926fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson  const char *PrevSpec = 0;
493fec54013fcd0eb72642741584ca04c1bc292bef8John McCall  unsigned DiagID;
4946fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson  // Check for duplicate type specifiers (e.g. "int decltype(a)").
4951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  if (DS.SetTypeSpecType(DeclSpec::TST_decltype, StartLoc, PrevSpec,
496fec54013fcd0eb72642741584ca04c1bc292bef8John McCall                         DiagID, Result.release()))
497fec54013fcd0eb72642741584ca04c1bc292bef8John McCall    Diag(StartLoc, DiagID) << PrevSpec;
4986fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson}
4996fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson
50042a552f8200ba5948661aee0106fce0c04e39818Douglas Gregor/// ParseClassName - Parse a C++ class-name, which names a class. Note
50142a552f8200ba5948661aee0106fce0c04e39818Douglas Gregor/// that we only check that the result names a type; semantic analysis
50242a552f8200ba5948661aee0106fce0c04e39818Douglas Gregor/// will need to verify that the type names a class. The result is
5037f43d6764797ab21216421aeb00f4ec314d503d1Douglas Gregor/// either a type or NULL, depending on whether a type name was
50442a552f8200ba5948661aee0106fce0c04e39818Douglas Gregor/// found.
50542a552f8200ba5948661aee0106fce0c04e39818Douglas Gregor///
50642a552f8200ba5948661aee0106fce0c04e39818Douglas Gregor///       class-name: [C++ 9.1]
50742a552f8200ba5948661aee0106fce0c04e39818Douglas Gregor///         identifier
5087f43d6764797ab21216421aeb00f4ec314d503d1Douglas Gregor///         simple-template-id
5091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///
51031a19b6989bbf326d2de5ae12e712e2a65ca9c34Douglas GregorParser::TypeResult Parser::ParseClassName(SourceLocation &EndLocation,
5119ab14541716928894821cf5d53d6b4c95ffdf3a3Jeffrey Yasskin                                          CXXScopeSpec *SS) {
5127f43d6764797ab21216421aeb00f4ec314d503d1Douglas Gregor  // Check whether we have a template-id that names a type.
5137f43d6764797ab21216421aeb00f4ec314d503d1Douglas Gregor  if (Tok.is(tok::annot_template_id)) {
5141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    TemplateIdAnnotation *TemplateId
5157f43d6764797ab21216421aeb00f4ec314d503d1Douglas Gregor      = static_cast<TemplateIdAnnotation *>(Tok.getAnnotationValue());
516d9b600c1a589200be905c53e2e10fceb57efa18dDouglas Gregor    if (TemplateId->Kind == TNK_Type_template ||
517d9b600c1a589200be905c53e2e10fceb57efa18dDouglas Gregor        TemplateId->Kind == TNK_Dependent_template_name) {
51831a19b6989bbf326d2de5ae12e712e2a65ca9c34Douglas Gregor      AnnotateTemplateIdTokenAsType(SS);
5197f43d6764797ab21216421aeb00f4ec314d503d1Douglas Gregor
5207f43d6764797ab21216421aeb00f4ec314d503d1Douglas Gregor      assert(Tok.is(tok::annot_typename) && "template-id -> type failed");
521b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall      ParsedType Type = getTypeAnnotation(Tok);
5227f43d6764797ab21216421aeb00f4ec314d503d1Douglas Gregor      EndLocation = Tok.getAnnotationEndLoc();
5237f43d6764797ab21216421aeb00f4ec314d503d1Douglas Gregor      ConsumeToken();
52431a19b6989bbf326d2de5ae12e712e2a65ca9c34Douglas Gregor
52531a19b6989bbf326d2de5ae12e712e2a65ca9c34Douglas Gregor      if (Type)
52631a19b6989bbf326d2de5ae12e712e2a65ca9c34Douglas Gregor        return Type;
52731a19b6989bbf326d2de5ae12e712e2a65ca9c34Douglas Gregor      return true;
5287f43d6764797ab21216421aeb00f4ec314d503d1Douglas Gregor    }
5297f43d6764797ab21216421aeb00f4ec314d503d1Douglas Gregor
5307f43d6764797ab21216421aeb00f4ec314d503d1Douglas Gregor    // Fall through to produce an error below.
5317f43d6764797ab21216421aeb00f4ec314d503d1Douglas Gregor  }
5327f43d6764797ab21216421aeb00f4ec314d503d1Douglas Gregor
53342a552f8200ba5948661aee0106fce0c04e39818Douglas Gregor  if (Tok.isNot(tok::identifier)) {
5341ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner    Diag(Tok, diag::err_expected_class_name);
53531a19b6989bbf326d2de5ae12e712e2a65ca9c34Douglas Gregor    return true;
53642a552f8200ba5948661aee0106fce0c04e39818Douglas Gregor  }
53742a552f8200ba5948661aee0106fce0c04e39818Douglas Gregor
53884d0a19828599e8623223632d59447fd498999cfDouglas Gregor  IdentifierInfo *Id = Tok.getIdentifierInfo();
53984d0a19828599e8623223632d59447fd498999cfDouglas Gregor  SourceLocation IdLoc = ConsumeToken();
54084d0a19828599e8623223632d59447fd498999cfDouglas Gregor
54184d0a19828599e8623223632d59447fd498999cfDouglas Gregor  if (Tok.is(tok::less)) {
54284d0a19828599e8623223632d59447fd498999cfDouglas Gregor    // It looks the user intended to write a template-id here, but the
54384d0a19828599e8623223632d59447fd498999cfDouglas Gregor    // template-name was wrong. Try to fix that.
54484d0a19828599e8623223632d59447fd498999cfDouglas Gregor    TemplateNameKind TNK = TNK_Type_template;
54584d0a19828599e8623223632d59447fd498999cfDouglas Gregor    TemplateTy Template;
54623c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor    if (!Actions.DiagnoseUnknownTemplateName(*Id, IdLoc, getCurScope(),
54784d0a19828599e8623223632d59447fd498999cfDouglas Gregor                                             SS, Template, TNK)) {
54884d0a19828599e8623223632d59447fd498999cfDouglas Gregor      Diag(IdLoc, diag::err_unknown_template_name)
54984d0a19828599e8623223632d59447fd498999cfDouglas Gregor        << Id;
55084d0a19828599e8623223632d59447fd498999cfDouglas Gregor    }
551193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam
55284d0a19828599e8623223632d59447fd498999cfDouglas Gregor    if (!Template)
55384d0a19828599e8623223632d59447fd498999cfDouglas Gregor      return true;
55484d0a19828599e8623223632d59447fd498999cfDouglas Gregor
555193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam    // Form the template name
55684d0a19828599e8623223632d59447fd498999cfDouglas Gregor    UnqualifiedId TemplateName;
55784d0a19828599e8623223632d59447fd498999cfDouglas Gregor    TemplateName.setIdentifier(Id, IdLoc);
558193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam
55984d0a19828599e8623223632d59447fd498999cfDouglas Gregor    // Parse the full template-id, then turn it into a type.
56084d0a19828599e8623223632d59447fd498999cfDouglas Gregor    if (AnnotateTemplateIdToken(Template, TNK, SS, TemplateName,
56184d0a19828599e8623223632d59447fd498999cfDouglas Gregor                                SourceLocation(), true))
56284d0a19828599e8623223632d59447fd498999cfDouglas Gregor      return true;
56384d0a19828599e8623223632d59447fd498999cfDouglas Gregor    if (TNK == TNK_Dependent_template_name)
56484d0a19828599e8623223632d59447fd498999cfDouglas Gregor      AnnotateTemplateIdTokenAsType(SS);
565193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam
56684d0a19828599e8623223632d59447fd498999cfDouglas Gregor    // If we didn't end up with a typename token, there's nothing more we
56784d0a19828599e8623223632d59447fd498999cfDouglas Gregor    // can do.
56884d0a19828599e8623223632d59447fd498999cfDouglas Gregor    if (Tok.isNot(tok::annot_typename))
56984d0a19828599e8623223632d59447fd498999cfDouglas Gregor      return true;
570193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam
57184d0a19828599e8623223632d59447fd498999cfDouglas Gregor    // Retrieve the type from the annotation token, consume that token, and
57284d0a19828599e8623223632d59447fd498999cfDouglas Gregor    // return.
57384d0a19828599e8623223632d59447fd498999cfDouglas Gregor    EndLocation = Tok.getAnnotationEndLoc();
574b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    ParsedType Type = getTypeAnnotation(Tok);
57584d0a19828599e8623223632d59447fd498999cfDouglas Gregor    ConsumeToken();
57684d0a19828599e8623223632d59447fd498999cfDouglas Gregor    return Type;
57784d0a19828599e8623223632d59447fd498999cfDouglas Gregor  }
57884d0a19828599e8623223632d59447fd498999cfDouglas Gregor
57942a552f8200ba5948661aee0106fce0c04e39818Douglas Gregor  // We have an identifier; check whether it is actually a type.
580b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  ParsedType Type = Actions.getTypeName(*Id, IdLoc, getCurScope(), SS, true);
581193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam  if (!Type) {
582124b878dba5007df0a268ea128a6ad8dc5dd2c5eDouglas Gregor    Diag(IdLoc, diag::err_expected_class_name);
58331a19b6989bbf326d2de5ae12e712e2a65ca9c34Douglas Gregor    return true;
58442a552f8200ba5948661aee0106fce0c04e39818Douglas Gregor  }
58542a552f8200ba5948661aee0106fce0c04e39818Douglas Gregor
58642a552f8200ba5948661aee0106fce0c04e39818Douglas Gregor  // Consume the identifier.
58784d0a19828599e8623223632d59447fd498999cfDouglas Gregor  EndLocation = IdLoc;
5885606220447c7901ba8d80147ddab893bb7949dd5Nick Lewycky
5895606220447c7901ba8d80147ddab893bb7949dd5Nick Lewycky  // Fake up a Declarator to use with ActOnTypeName.
5905606220447c7901ba8d80147ddab893bb7949dd5Nick Lewycky  DeclSpec DS;
5915606220447c7901ba8d80147ddab893bb7949dd5Nick Lewycky  DS.SetRangeStart(IdLoc);
5925606220447c7901ba8d80147ddab893bb7949dd5Nick Lewycky  DS.SetRangeEnd(EndLocation);
5935606220447c7901ba8d80147ddab893bb7949dd5Nick Lewycky  DS.getTypeSpecScope() = *SS;
5945606220447c7901ba8d80147ddab893bb7949dd5Nick Lewycky
5955606220447c7901ba8d80147ddab893bb7949dd5Nick Lewycky  const char *PrevSpec = 0;
5965606220447c7901ba8d80147ddab893bb7949dd5Nick Lewycky  unsigned DiagID;
5975606220447c7901ba8d80147ddab893bb7949dd5Nick Lewycky  DS.SetTypeSpecType(TST_typename, IdLoc, PrevSpec, DiagID, Type);
5985606220447c7901ba8d80147ddab893bb7949dd5Nick Lewycky
5995606220447c7901ba8d80147ddab893bb7949dd5Nick Lewycky  Declarator DeclaratorInfo(DS, Declarator::TypeNameContext);
6005606220447c7901ba8d80147ddab893bb7949dd5Nick Lewycky  return Actions.ActOnTypeName(getCurScope(), DeclaratorInfo);
60142a552f8200ba5948661aee0106fce0c04e39818Douglas Gregor}
60242a552f8200ba5948661aee0106fce0c04e39818Douglas Gregor
603e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// ParseClassSpecifier - Parse a C++ class-specifier [C++ class] or
604e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// elaborated-type-specifier [C++ dcl.type.elab]; we can't tell which
605e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// until we reach the start of a definition or see a token that
606d9bafa76f8d6eb9e4f4974ed322217f8df6bb82eSebastian Redl/// cannot start a definition. If SuppressDeclarations is true, we do know.
607e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor///
608e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor///       class-specifier: [C++ class]
609e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor///         class-head '{' member-specification[opt] '}'
610e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor///         class-head '{' member-specification[opt] '}' attributes[opt]
611e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor///       class-head:
612e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor///         class-key identifier[opt] base-clause[opt]
613e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor///         class-key nested-name-specifier identifier base-clause[opt]
614e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor///         class-key nested-name-specifier[opt] simple-template-id
615e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor///                          base-clause[opt]
616e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// [GNU]   class-key attributes[opt] identifier[opt] base-clause[opt]
6171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// [GNU]   class-key attributes[opt] nested-name-specifier
618e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor///                          identifier base-clause[opt]
6191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// [GNU]   class-key attributes[opt] nested-name-specifier[opt]
620e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor///                          simple-template-id base-clause[opt]
621e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor///       class-key:
622e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor///         'class'
623e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor///         'struct'
624e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor///         'union'
625e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor///
626e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor///       elaborated-type-specifier: [C++ dcl.type.elab]
6271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///         class-key ::[opt] nested-name-specifier[opt] identifier
6281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///         class-key ::[opt] nested-name-specifier[opt] 'template'[opt]
6291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///                          simple-template-id
630e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor///
631e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor///  Note that the C++ class-specifier and elaborated-type-specifier,
632e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor///  together, subsume the C99 struct-or-union-specifier:
633e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor///
634e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor///       struct-or-union-specifier: [C99 6.7.2.1]
635e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor///         struct-or-union identifier[opt] '{' struct-contents '}'
636e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor///         struct-or-union identifier
637e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// [GNU]   struct-or-union attributes[opt] identifier[opt] '{' struct-contents
638e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor///                                                         '}' attributes[opt]
639e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// [GNU]   struct-or-union attributes[opt] identifier
640e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor///       struct-or-union:
641e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor///         'struct'
642e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor///         'union'
6434c97d762d8c5a84f6554e5bfb31d28c90df64158Chris Lattnervoid Parser::ParseClassSpecifier(tok::TokenKind TagTokKind,
6444c97d762d8c5a84f6554e5bfb31d28c90df64158Chris Lattner                                 SourceLocation StartLoc, DeclSpec &DS,
6454d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor                                 const ParsedTemplateInfo &TemplateInfo,
646d9bafa76f8d6eb9e4f4974ed322217f8df6bb82eSebastian Redl                                 AccessSpecifier AS, bool SuppressDeclarations){
6474c97d762d8c5a84f6554e5bfb31d28c90df64158Chris Lattner  DeclSpec::TST TagType;
6484c97d762d8c5a84f6554e5bfb31d28c90df64158Chris Lattner  if (TagTokKind == tok::kw_struct)
6494c97d762d8c5a84f6554e5bfb31d28c90df64158Chris Lattner    TagType = DeclSpec::TST_struct;
6504c97d762d8c5a84f6554e5bfb31d28c90df64158Chris Lattner  else if (TagTokKind == tok::kw_class)
6514c97d762d8c5a84f6554e5bfb31d28c90df64158Chris Lattner    TagType = DeclSpec::TST_class;
6524c97d762d8c5a84f6554e5bfb31d28c90df64158Chris Lattner  else {
6534c97d762d8c5a84f6554e5bfb31d28c90df64158Chris Lattner    assert(TagTokKind == tok::kw_union && "Not a class specifier");
6544c97d762d8c5a84f6554e5bfb31d28c90df64158Chris Lattner    TagType = DeclSpec::TST_union;
6554c97d762d8c5a84f6554e5bfb31d28c90df64158Chris Lattner  }
656e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor
657374929f7e88f6c7a96382b3eb4201b721c418372Douglas Gregor  if (Tok.is(tok::code_completion)) {
658374929f7e88f6c7a96382b3eb4201b721c418372Douglas Gregor    // Code completion for a struct, class, or union name.
65923c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor    Actions.CodeCompleteTag(getCurScope(), TagType);
660dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor    ConsumeCodeCompletionToken();
661374929f7e88f6c7a96382b3eb4201b721c418372Douglas Gregor  }
662193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam
663926c4b486a08f698cd3a367fd6f1a3a07604358dChandler Carruth  // C++03 [temp.explicit] 14.7.2/8:
664926c4b486a08f698cd3a367fd6f1a3a07604358dChandler Carruth  //   The usual access checking rules do not apply to names used to specify
665926c4b486a08f698cd3a367fd6f1a3a07604358dChandler Carruth  //   explicit instantiations.
666926c4b486a08f698cd3a367fd6f1a3a07604358dChandler Carruth  //
667926c4b486a08f698cd3a367fd6f1a3a07604358dChandler Carruth  // As an extension we do not perform access checking on the names used to
668926c4b486a08f698cd3a367fd6f1a3a07604358dChandler Carruth  // specify explicit specializations either. This is important to allow
669926c4b486a08f698cd3a367fd6f1a3a07604358dChandler Carruth  // specializing traits classes for private types.
670926c4b486a08f698cd3a367fd6f1a3a07604358dChandler Carruth  bool SuppressingAccessChecks = false;
671926c4b486a08f698cd3a367fd6f1a3a07604358dChandler Carruth  if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation ||
672926c4b486a08f698cd3a367fd6f1a3a07604358dChandler Carruth      TemplateInfo.Kind == ParsedTemplateInfo::ExplicitSpecialization) {
673926c4b486a08f698cd3a367fd6f1a3a07604358dChandler Carruth    Actions.ActOnStartSuppressingAccessChecks();
674926c4b486a08f698cd3a367fd6f1a3a07604358dChandler Carruth    SuppressingAccessChecks = true;
675926c4b486a08f698cd3a367fd6f1a3a07604358dChandler Carruth  }
676926c4b486a08f698cd3a367fd6f1a3a07604358dChandler Carruth
6777f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  ParsedAttributes attrs;
678e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor  // If attributes exist after tag, parse them.
679e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor  if (Tok.is(tok::kw___attribute))
6807f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall    ParseGNUAttributes(attrs);
681e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor
682f59e17ecf06ac60065e2d02058bd6f21f5d216ccSteve Naroff  // If declspecs exist after tag, parse them.
683b1d397c23e1f8fd8b404d5731d531e7500f7140dJohn McCall  while (Tok.is(tok::kw___declspec))
6847f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall    ParseMicrosoftDeclSpec(attrs);
685193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam
686bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt  // If C++0x attributes exist here, parse them.
687bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt  // FIXME: Are we consistent with the ordering of parsing of different
688bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt  // styles of attributes?
6897f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  MaybeParseCXX0XAttributes(attrs);
6901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
691b117a60f7684261ddc8c8f14e8ef8a827e6af814Douglas Gregor  if (TagType == DeclSpec::TST_struct && Tok.is(tok::kw___is_pod)) {
692b117a60f7684261ddc8c8f14e8ef8a827e6af814Douglas Gregor    // GNU libstdc++ 4.2 uses __is_pod as the name of a struct template, but
693b117a60f7684261ddc8c8f14e8ef8a827e6af814Douglas Gregor    // __is_pod is a keyword in GCC >= 4.3. Therefore, when we see the
6941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    // token sequence "struct __is_pod", make __is_pod into a normal
695b117a60f7684261ddc8c8f14e8ef8a827e6af814Douglas Gregor    // identifier rather than a keyword, to allow libstdc++ 4.2 to work
696b117a60f7684261ddc8c8f14e8ef8a827e6af814Douglas Gregor    // properly.
697646395bbcaa849c94bc2a3246c71d809ca719f01Argyrios Kyrtzidis    Tok.getIdentifierInfo()->RevertTokenIDToIdentifier();
698b117a60f7684261ddc8c8f14e8ef8a827e6af814Douglas Gregor    Tok.setKind(tok::identifier);
699b117a60f7684261ddc8c8f14e8ef8a827e6af814Douglas Gregor  }
700b117a60f7684261ddc8c8f14e8ef8a827e6af814Douglas Gregor
701b117a60f7684261ddc8c8f14e8ef8a827e6af814Douglas Gregor  if (TagType == DeclSpec::TST_struct && Tok.is(tok::kw___is_empty)) {
702b117a60f7684261ddc8c8f14e8ef8a827e6af814Douglas Gregor    // GNU libstdc++ 4.2 uses __is_empty as the name of a struct template, but
703b117a60f7684261ddc8c8f14e8ef8a827e6af814Douglas Gregor    // __is_empty is a keyword in GCC >= 4.3. Therefore, when we see the
7041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    // token sequence "struct __is_empty", make __is_empty into a normal
705b117a60f7684261ddc8c8f14e8ef8a827e6af814Douglas Gregor    // identifier rather than a keyword, to allow libstdc++ 4.2 to work
706b117a60f7684261ddc8c8f14e8ef8a827e6af814Douglas Gregor    // properly.
707646395bbcaa849c94bc2a3246c71d809ca719f01Argyrios Kyrtzidis    Tok.getIdentifierInfo()->RevertTokenIDToIdentifier();
708b117a60f7684261ddc8c8f14e8ef8a827e6af814Douglas Gregor    Tok.setKind(tok::identifier);
709b117a60f7684261ddc8c8f14e8ef8a827e6af814Douglas Gregor  }
7101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
711eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  // Parse the (optional) nested-name-specifier.
712aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall  CXXScopeSpec &SS = DS.getTypeSpecScope();
71308d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner  if (getLang().CPlusPlus) {
71408d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner    // "FOO : BAR" is not a potential typo for "FOO::BAR".
71508d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner    ColonProtectionRAIIObject X(*this);
716193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam
717b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    if (ParseOptionalCXXScopeSpecifier(SS, ParsedType(), true))
718207014eb2b372aa33721e86d90a8a586ba8dc8aeJohn McCall      DS.SetTypeSpecError();
7199ba6166f4a78722e7df8ffbd64eb788bfdf2764aJohn McCall    if (SS.isSet())
72008d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner      if (Tok.isNot(tok::identifier) && Tok.isNot(tok::annot_template_id))
72108d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner        Diag(Tok, diag::err_expected_ident);
72208d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner  }
723cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor
7242cc782f7932f1069d9fa8bb5c518165802aad68dDouglas Gregor  TemplateParameterLists *TemplateParams = TemplateInfo.TemplateParams;
7252cc782f7932f1069d9fa8bb5c518165802aad68dDouglas Gregor
726cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor  // Parse the (optional) class name or simple-template-id.
727e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor  IdentifierInfo *Name = 0;
728e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor  SourceLocation NameLoc;
72939a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor  TemplateIdAnnotation *TemplateId = 0;
730e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor  if (Tok.is(tok::identifier)) {
731e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor    Name = Tok.getIdentifierInfo();
732e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor    NameLoc = ConsumeToken();
733193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam
7345ee3734c0b5222a7c445591a1f14102c1b3a289bDouglas Gregor    if (Tok.is(tok::less) && getLang().CPlusPlus) {
735193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam      // The name was supposed to refer to a template, but didn't.
7362cc782f7932f1069d9fa8bb5c518165802aad68dDouglas Gregor      // Eat the template argument list and try to continue parsing this as
7372cc782f7932f1069d9fa8bb5c518165802aad68dDouglas Gregor      // a class (or template thereof).
7382cc782f7932f1069d9fa8bb5c518165802aad68dDouglas Gregor      TemplateArgList TemplateArgs;
7392cc782f7932f1069d9fa8bb5c518165802aad68dDouglas Gregor      SourceLocation LAngleLoc, RAngleLoc;
740193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam      if (ParseTemplateIdAfterTemplateName(TemplateTy(), NameLoc, &SS,
7412cc782f7932f1069d9fa8bb5c518165802aad68dDouglas Gregor                                           true, LAngleLoc,
742314b97f8c564b465af605efaee23f91ec18a982bDouglas Gregor                                           TemplateArgs, RAngleLoc)) {
7432cc782f7932f1069d9fa8bb5c518165802aad68dDouglas Gregor        // We couldn't parse the template argument list at all, so don't
7442cc782f7932f1069d9fa8bb5c518165802aad68dDouglas Gregor        // try to give any location information for the list.
7452cc782f7932f1069d9fa8bb5c518165802aad68dDouglas Gregor        LAngleLoc = RAngleLoc = SourceLocation();
7462cc782f7932f1069d9fa8bb5c518165802aad68dDouglas Gregor      }
747193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam
7482cc782f7932f1069d9fa8bb5c518165802aad68dDouglas Gregor      Diag(NameLoc, diag::err_explicit_spec_non_template)
749c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor        << (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation)
7502cc782f7932f1069d9fa8bb5c518165802aad68dDouglas Gregor        << (TagType == DeclSpec::TST_class? 0
7512cc782f7932f1069d9fa8bb5c518165802aad68dDouglas Gregor            : TagType == DeclSpec::TST_struct? 1
7522cc782f7932f1069d9fa8bb5c518165802aad68dDouglas Gregor            : 2)
7532cc782f7932f1069d9fa8bb5c518165802aad68dDouglas Gregor        << Name
7542cc782f7932f1069d9fa8bb5c518165802aad68dDouglas Gregor        << SourceRange(LAngleLoc, RAngleLoc);
755193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam
756193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam      // Strip off the last template parameter list if it was empty, since
757c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor      // we've removed its template argument list.
758c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor      if (TemplateParams && TemplateInfo.LastParameterListWasEmpty) {
759c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor        if (TemplateParams && TemplateParams->size() > 1) {
760c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor          TemplateParams->pop_back();
761c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor        } else {
762c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor          TemplateParams = 0;
763193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam          const_cast<ParsedTemplateInfo&>(TemplateInfo).Kind
764c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor            = ParsedTemplateInfo::NonTemplate;
765c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor        }
766c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor      } else if (TemplateInfo.Kind
767c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor                                == ParsedTemplateInfo::ExplicitInstantiation) {
768c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor        // Pretend this is just a forward declaration.
7692cc782f7932f1069d9fa8bb5c518165802aad68dDouglas Gregor        TemplateParams = 0;
770193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam        const_cast<ParsedTemplateInfo&>(TemplateInfo).Kind
7712cc782f7932f1069d9fa8bb5c518165802aad68dDouglas Gregor          = ParsedTemplateInfo::NonTemplate;
772193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam        const_cast<ParsedTemplateInfo&>(TemplateInfo).TemplateLoc
773c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor          = SourceLocation();
774c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor        const_cast<ParsedTemplateInfo&>(TemplateInfo).ExternLoc
775c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor          = SourceLocation();
7762cc782f7932f1069d9fa8bb5c518165802aad68dDouglas Gregor      }
7772cc782f7932f1069d9fa8bb5c518165802aad68dDouglas Gregor    }
77839a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor  } else if (Tok.is(tok::annot_template_id)) {
77939a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor    TemplateId = static_cast<TemplateIdAnnotation *>(Tok.getAnnotationValue());
78039a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor    NameLoc = ConsumeToken();
781cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor
782c45c232440dfafedca1a3773b904fb42609b1b19Douglas Gregor    if (TemplateId->Kind != TNK_Type_template) {
78339a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor      // The template-name in the simple-template-id refers to
78439a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor      // something other than a class template. Give an appropriate
78539a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor      // error message and skip to the ';'.
78639a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor      SourceRange Range(NameLoc);
78739a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor      if (SS.isNotEmpty())
78839a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor        Range.setBegin(SS.getBeginLoc());
78939a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor
79039a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor      Diag(TemplateId->LAngleLoc, diag::err_template_spec_syntax_non_template)
79139a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor        << Name << static_cast<int>(TemplateId->Kind) << Range;
7921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
79339a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor      DS.SetTypeSpecError();
79439a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor      SkipUntil(tok::semi, false, true);
79539a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor      TemplateId->Destroy();
796926c4b486a08f698cd3a367fd6f1a3a07604358dChandler Carruth      if (SuppressingAccessChecks)
797926c4b486a08f698cd3a367fd6f1a3a07604358dChandler Carruth        Actions.ActOnStopSuppressingAccessChecks();
798926c4b486a08f698cd3a367fd6f1a3a07604358dChandler Carruth
79939a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor      return;
800cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor    }
801e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor  }
802e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor
803926c4b486a08f698cd3a367fd6f1a3a07604358dChandler Carruth  // As soon as we're finished parsing the class's template-id, turn access
804926c4b486a08f698cd3a367fd6f1a3a07604358dChandler Carruth  // checking back on.
805926c4b486a08f698cd3a367fd6f1a3a07604358dChandler Carruth  if (SuppressingAccessChecks)
806926c4b486a08f698cd3a367fd6f1a3a07604358dChandler Carruth    Actions.ActOnStopSuppressingAccessChecks();
807926c4b486a08f698cd3a367fd6f1a3a07604358dChandler Carruth
80867d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall  // There are four options here.  If we have 'struct foo;', then this
80967d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall  // is either a forward declaration or a friend declaration, which
81067d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall  // have to be treated differently.  If we have 'struct foo {...' or
81139a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor  // 'struct foo :...' then this is a definition. Otherwise we have
812e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor  // something like 'struct foo xyz', a reference.
813d9bafa76f8d6eb9e4f4974ed322217f8df6bb82eSebastian Redl  // However, in some contexts, things look like declarations but are just
814d9bafa76f8d6eb9e4f4974ed322217f8df6bb82eSebastian Redl  // references, e.g.
815d9bafa76f8d6eb9e4f4974ed322217f8df6bb82eSebastian Redl  // new struct s;
816d9bafa76f8d6eb9e4f4974ed322217f8df6bb82eSebastian Redl  // or
817d9bafa76f8d6eb9e4f4974ed322217f8df6bb82eSebastian Redl  // &T::operator struct s;
818d9bafa76f8d6eb9e4f4974ed322217f8df6bb82eSebastian Redl  // For these, SuppressDeclarations is true.
819f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall  Sema::TagUseKind TUK;
820d9bafa76f8d6eb9e4f4974ed322217f8df6bb82eSebastian Redl  if (SuppressDeclarations)
821f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    TUK = Sema::TUK_Reference;
822d9bafa76f8d6eb9e4f4974ed322217f8df6bb82eSebastian Redl  else if (Tok.is(tok::l_brace) || (getLang().CPlusPlus && Tok.is(tok::colon))){
823d85bea2affdd59d83d1be7d24b97f436484c3625Douglas Gregor    if (DS.isFriendSpecified()) {
824d85bea2affdd59d83d1be7d24b97f436484c3625Douglas Gregor      // C++ [class.friend]p2:
825d85bea2affdd59d83d1be7d24b97f436484c3625Douglas Gregor      //   A class shall not be defined in a friend declaration.
826d85bea2affdd59d83d1be7d24b97f436484c3625Douglas Gregor      Diag(Tok.getLocation(), diag::err_friend_decl_defines_class)
827d85bea2affdd59d83d1be7d24b97f436484c3625Douglas Gregor        << SourceRange(DS.getFriendSpecLoc());
828d85bea2affdd59d83d1be7d24b97f436484c3625Douglas Gregor
829d85bea2affdd59d83d1be7d24b97f436484c3625Douglas Gregor      // Skip everything up to the semicolon, so that this looks like a proper
830d85bea2affdd59d83d1be7d24b97f436484c3625Douglas Gregor      // friend class (or template thereof) declaration.
831d85bea2affdd59d83d1be7d24b97f436484c3625Douglas Gregor      SkipUntil(tok::semi, true, true);
832f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      TUK = Sema::TUK_Friend;
833d85bea2affdd59d83d1be7d24b97f436484c3625Douglas Gregor    } else {
834d85bea2affdd59d83d1be7d24b97f436484c3625Douglas Gregor      // Okay, this is a class definition.
835f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      TUK = Sema::TUK_Definition;
836d85bea2affdd59d83d1be7d24b97f436484c3625Douglas Gregor    }
837d85bea2affdd59d83d1be7d24b97f436484c3625Douglas Gregor  } else if (Tok.is(tok::semi))
838f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    TUK = DS.isFriendSpecified() ? Sema::TUK_Friend : Sema::TUK_Declaration;
839e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor  else
840f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    TUK = Sema::TUK_Reference;
841e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor
842207014eb2b372aa33721e86d90a8a586ba8dc8aeJohn McCall  if (!Name && !TemplateId && (DS.getTypeSpecType() == DeclSpec::TST_error ||
843f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                               TUK != Sema::TUK_Definition)) {
844207014eb2b372aa33721e86d90a8a586ba8dc8aeJohn McCall    if (DS.getTypeSpecType() != DeclSpec::TST_error) {
845207014eb2b372aa33721e86d90a8a586ba8dc8aeJohn McCall      // We have a declaration or reference to an anonymous class.
846207014eb2b372aa33721e86d90a8a586ba8dc8aeJohn McCall      Diag(StartLoc, diag::err_anon_type_definition)
847207014eb2b372aa33721e86d90a8a586ba8dc8aeJohn McCall        << DeclSpec::getSpecifierName(TagType);
848207014eb2b372aa33721e86d90a8a586ba8dc8aeJohn McCall    }
849e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor
850e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor    SkipUntil(tok::comma, true);
85139a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor
85239a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor    if (TemplateId)
85339a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor      TemplateId->Destroy();
854e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor    return;
855e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor  }
856e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor
857ddc29e116db3c3f4144355e67a0137b38b6bb6d1Douglas Gregor  // Create the tag portion of the class or class template.
858d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  DeclResult TagOrTempResult = true; // invalid
859d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  TypeResult TypeResult = true; // invalid
8604d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor
861402abb55fc2e0cdda5fb1ac90009b1f5f6774906Douglas Gregor  bool Owned = false;
862f1bbbb49f06a7462476cd88166fccda5feb15cabJohn McCall  if (TemplateId) {
8634d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor    // Explicit specialization, class template partial specialization,
8644d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor    // or explicit instantiation.
8651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    ASTTemplateArgsPtr TemplateArgsPtr(Actions,
86639a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor                                       TemplateId->getTemplateArgs(),
86739a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor                                       TemplateId->NumArgs);
8684d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor    if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation &&
869f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        TUK == Sema::TUK_Declaration) {
8704d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor      // This is an explicit instantiation of a class template.
8714d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor      TagOrTempResult
87223c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor        = Actions.ActOnExplicitInstantiation(getCurScope(),
87345f965581935791a018df829a14dff53c1dd8f47Douglas Gregor                                             TemplateInfo.ExternLoc,
8741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                             TemplateInfo.TemplateLoc,
8754d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor                                             TagType,
8761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                             StartLoc,
8774d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor                                             SS,
8782b5289b6fd7e3d9899868410a498c081c9595662John McCall                                             TemplateId->Template,
8791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                             TemplateId->TemplateNameLoc,
8801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                             TemplateId->LAngleLoc,
8814d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor                                             TemplateArgsPtr,
8821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                             TemplateId->RAngleLoc,
8837f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall                                             attrs.getList());
88474256f5ea6950c9fd34595aa124eb4740372f15cJohn McCall
88574256f5ea6950c9fd34595aa124eb4740372f15cJohn McCall    // Friend template-ids are treated as references unless
88674256f5ea6950c9fd34595aa124eb4740372f15cJohn McCall    // they have template headers, in which case they're ill-formed
88774256f5ea6950c9fd34595aa124eb4740372f15cJohn McCall    // (FIXME: "template <class T> friend class A<T>::B<int>;").
88874256f5ea6950c9fd34595aa124eb4740372f15cJohn McCall    // We diagnose this error in ActOnClassTemplateSpecialization.
889f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    } else if (TUK == Sema::TUK_Reference ||
890f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall               (TUK == Sema::TUK_Friend &&
89174256f5ea6950c9fd34595aa124eb4740372f15cJohn McCall                TemplateInfo.Kind == ParsedTemplateInfo::NonTemplate)) {
892c4e7019d5c9034a2d84ee4695f8e98dc025ac131John McCall      TypeResult
8932b5289b6fd7e3d9899868410a498c081c9595662John McCall        = Actions.ActOnTemplateIdType(TemplateId->Template,
8946b2becfc434b0bdced8560802c4d0e03148c61b8John McCall                                      TemplateId->TemplateNameLoc,
8956b2becfc434b0bdced8560802c4d0e03148c61b8John McCall                                      TemplateId->LAngleLoc,
8966b2becfc434b0bdced8560802c4d0e03148c61b8John McCall                                      TemplateArgsPtr,
8976b2becfc434b0bdced8560802c4d0e03148c61b8John McCall                                      TemplateId->RAngleLoc);
8986b2becfc434b0bdced8560802c4d0e03148c61b8John McCall
89945ab4b5f8961dadcef6545ed6956da5daf95c6cbCraig Silverstein      TypeResult = Actions.ActOnTagTemplateIdType(SS, TypeResult, TUK,
900c4e7019d5c9034a2d84ee4695f8e98dc025ac131John McCall                                                  TagType, StartLoc);
9014d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor    } else {
9024d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor      // This is an explicit specialization or a class template
9034d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor      // partial specialization.
9044d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor      TemplateParameterLists FakedParamLists;
9054d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor
9064d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor      if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation) {
9074d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor        // This looks like an explicit instantiation, because we have
9084d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor        // something like
9094d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor        //
9104d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor        //   template class Foo<X>
9114d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor        //
9123f5b61c394f4f205bcb4d316eb2a7a0a68b8af86Douglas Gregor        // but it actually has a definition. Most likely, this was
9134d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor        // meant to be an explicit specialization, but the user forgot
9144d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor        // the '<>' after 'template'.
915f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        assert(TUK == Sema::TUK_Definition && "Expected a definition here");
9164d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor
9171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump        SourceLocation LAngleLoc
9184d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor          = PP.getLocForEndOfToken(TemplateInfo.TemplateLoc);
9191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump        Diag(TemplateId->TemplateNameLoc,
9204d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor             diag::err_explicit_instantiation_with_definition)
9214d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor          << SourceRange(TemplateInfo.TemplateLoc)
922849b243d4065f56742a4677d6dc8277609a151f8Douglas Gregor          << FixItHint::CreateInsertion(LAngleLoc, "<>");
9234d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor
9244d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor        // Create a fake template parameter list that contains only
9254d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor        // "template<>", so that we treat this construct as a class
9264d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor        // template specialization.
9274d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor        FakedParamLists.push_back(
9281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump          Actions.ActOnTemplateParameterList(0, SourceLocation(),
9294d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor                                             TemplateInfo.TemplateLoc,
9301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                             LAngleLoc,
9311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                             0, 0,
9324d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor                                             LAngleLoc));
9334d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor        TemplateParams = &FakedParamLists;
9344d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor      }
9354d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor
9364d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor      // Build the class template specialization.
9374d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor      TagOrTempResult
93823c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor        = Actions.ActOnClassTemplateSpecialization(getCurScope(), TagType, TUK,
93939a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor                       StartLoc, SS,
9402b5289b6fd7e3d9899868410a498c081c9595662John McCall                       TemplateId->Template,
9411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                       TemplateId->TemplateNameLoc,
9421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                       TemplateId->LAngleLoc,
94339a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor                       TemplateArgsPtr,
9441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                       TemplateId->RAngleLoc,
9457f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall                       attrs.getList(),
946f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                       MultiTemplateParamsArg(Actions,
947cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor                                    TemplateParams? &(*TemplateParams)[0] : 0,
948cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor                                 TemplateParams? TemplateParams->size() : 0));
9494d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor    }
95039a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor    TemplateId->Destroy();
9513f5b61c394f4f205bcb4d316eb2a7a0a68b8af86Douglas Gregor  } else if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation &&
952f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall             TUK == Sema::TUK_Declaration) {
9533f5b61c394f4f205bcb4d316eb2a7a0a68b8af86Douglas Gregor    // Explicit instantiation of a member of a class template
9543f5b61c394f4f205bcb4d316eb2a7a0a68b8af86Douglas Gregor    // specialization, e.g.,
9553f5b61c394f4f205bcb4d316eb2a7a0a68b8af86Douglas Gregor    //
9563f5b61c394f4f205bcb4d316eb2a7a0a68b8af86Douglas Gregor    //   template struct Outer<int>::Inner;
9573f5b61c394f4f205bcb4d316eb2a7a0a68b8af86Douglas Gregor    //
9583f5b61c394f4f205bcb4d316eb2a7a0a68b8af86Douglas Gregor    TagOrTempResult
95923c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor      = Actions.ActOnExplicitInstantiation(getCurScope(),
96045f965581935791a018df829a14dff53c1dd8f47Douglas Gregor                                           TemplateInfo.ExternLoc,
9611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                           TemplateInfo.TemplateLoc,
9621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                           TagType, StartLoc, SS, Name,
9637f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall                                           NameLoc, attrs.getList());
9649a34edb710917798aa30263374f624f13b594605John McCall  } else if (TUK == Sema::TUK_Friend &&
9659a34edb710917798aa30263374f624f13b594605John McCall             TemplateInfo.Kind != ParsedTemplateInfo::NonTemplate) {
9669a34edb710917798aa30263374f624f13b594605John McCall    TagOrTempResult =
9679a34edb710917798aa30263374f624f13b594605John McCall      Actions.ActOnTemplatedFriendTag(getCurScope(), DS.getFriendSpecLoc(),
9689a34edb710917798aa30263374f624f13b594605John McCall                                      TagType, StartLoc, SS,
9697f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall                                      Name, NameLoc, attrs.getList(),
9709a34edb710917798aa30263374f624f13b594605John McCall                                      MultiTemplateParamsArg(Actions,
9719a34edb710917798aa30263374f624f13b594605John McCall                                    TemplateParams? &(*TemplateParams)[0] : 0,
9729a34edb710917798aa30263374f624f13b594605John McCall                                 TemplateParams? TemplateParams->size() : 0));
9733f5b61c394f4f205bcb4d316eb2a7a0a68b8af86Douglas Gregor  } else {
9743f5b61c394f4f205bcb4d316eb2a7a0a68b8af86Douglas Gregor    if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation &&
975f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        TUK == Sema::TUK_Definition) {
9763f5b61c394f4f205bcb4d316eb2a7a0a68b8af86Douglas Gregor      // FIXME: Diagnose this particular error.
9773f5b61c394f4f205bcb4d316eb2a7a0a68b8af86Douglas Gregor    }
9783f5b61c394f4f205bcb4d316eb2a7a0a68b8af86Douglas Gregor
979c4e7019d5c9034a2d84ee4695f8e98dc025ac131John McCall    bool IsDependent = false;
980c4e7019d5c9034a2d84ee4695f8e98dc025ac131John McCall
981a25c4080a490ea2bab6f54094dd75b19eae83770John McCall    // Don't pass down template parameter lists if this is just a tag
982a25c4080a490ea2bab6f54094dd75b19eae83770John McCall    // reference.  For example, we don't need the template parameters here:
983a25c4080a490ea2bab6f54094dd75b19eae83770John McCall    //   template <class T> class A *makeA(T t);
984a25c4080a490ea2bab6f54094dd75b19eae83770John McCall    MultiTemplateParamsArg TParams;
985a25c4080a490ea2bab6f54094dd75b19eae83770John McCall    if (TUK != Sema::TUK_Reference && TemplateParams)
986a25c4080a490ea2bab6f54094dd75b19eae83770John McCall      TParams =
987a25c4080a490ea2bab6f54094dd75b19eae83770John McCall        MultiTemplateParamsArg(&(*TemplateParams)[0], TemplateParams->size());
988a25c4080a490ea2bab6f54094dd75b19eae83770John McCall
9893f5b61c394f4f205bcb4d316eb2a7a0a68b8af86Douglas Gregor    // Declaration or definition of a class type
9909a34edb710917798aa30263374f624f13b594605John McCall    TagOrTempResult = Actions.ActOnTag(getCurScope(), TagType, TUK, StartLoc,
9917f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall                                       SS, Name, NameLoc, attrs.getList(), AS,
992a25c4080a490ea2bab6f54094dd75b19eae83770John McCall                                       TParams, Owned, IsDependent, false,
993a88cefd266c428be33cc06f7e8b00ff8fc97c1ffAbramo Bagnara                                       false, clang::TypeResult());
994c4e7019d5c9034a2d84ee4695f8e98dc025ac131John McCall
995c4e7019d5c9034a2d84ee4695f8e98dc025ac131John McCall    // If ActOnTag said the type was dependent, try again with the
996c4e7019d5c9034a2d84ee4695f8e98dc025ac131John McCall    // less common call.
9979a34edb710917798aa30263374f624f13b594605John McCall    if (IsDependent) {
9989a34edb710917798aa30263374f624f13b594605John McCall      assert(TUK == Sema::TUK_Reference || TUK == Sema::TUK_Friend);
99923c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor      TypeResult = Actions.ActOnDependentTag(getCurScope(), TagType, TUK,
1000193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam                                             SS, Name, StartLoc, NameLoc);
10019a34edb710917798aa30263374f624f13b594605John McCall    }
10023f5b61c394f4f205bcb4d316eb2a7a0a68b8af86Douglas Gregor  }
1003e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor
1004e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor  // If there is a body, parse it and inform the actions module.
1005f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall  if (TUK == Sema::TUK_Definition) {
1006bd0dfa5c37d422427080a0ae3af9b63e70e6e854John McCall    assert(Tok.is(tok::l_brace) ||
1007bd0dfa5c37d422427080a0ae3af9b63e70e6e854John McCall           (getLang().CPlusPlus && Tok.is(tok::colon)));
100807952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis    if (getLang().CPlusPlus)
1009212e81cc5151b3c42346e43cfd42499a53ffd39aDouglas Gregor      ParseCXXMemberSpecification(StartLoc, TagType, TagOrTempResult.get());
101007952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis    else
1011212e81cc5151b3c42346e43cfd42499a53ffd39aDouglas Gregor      ParseStructUnionBody(StartLoc, TagType, TagOrTempResult.get());
1012e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor  }
1013e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor
1014b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  // FIXME: The DeclSpec should keep the locations of both the keyword and the
1015b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  // name (if there is one).
1016b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  SourceLocation TSTLoc = NameLoc.isValid()? NameLoc : StartLoc;
1017b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall
1018b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  const char *PrevSpec = 0;
1019b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  unsigned DiagID;
1020b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  bool Result;
1021c4e7019d5c9034a2d84ee4695f8e98dc025ac131John McCall  if (!TypeResult.isInvalid()) {
1022b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    Result = DS.SetTypeSpecType(DeclSpec::TST_typename, TSTLoc,
1023b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                                PrevSpec, DiagID, TypeResult.get());
1024c4e7019d5c9034a2d84ee4695f8e98dc025ac131John McCall  } else if (!TagOrTempResult.isInvalid()) {
1025b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    Result = DS.SetTypeSpecType(TagType, TSTLoc, PrevSpec, DiagID,
1026b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                                TagOrTempResult.get(), Owned);
1027c4e7019d5c9034a2d84ee4695f8e98dc025ac131John McCall  } else {
1028ddc29e116db3c3f4144355e67a0137b38b6bb6d1Douglas Gregor    DS.SetTypeSpecError();
102966e9977ddd6b197317d149213b76a9af0d3df4deAnders Carlsson    return;
103066e9977ddd6b197317d149213b76a9af0d3df4deAnders Carlsson  }
10311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1032b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  if (Result)
1033fec54013fcd0eb72642741584ca04c1bc292bef8John McCall    Diag(StartLoc, DiagID) << PrevSpec;
1034193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam
10354ed5d91db256f7dbe6bf716da0b801004c197254Chris Lattner  // At this point, we've successfully parsed a class-specifier in 'definition'
10364ed5d91db256f7dbe6bf716da0b801004c197254Chris Lattner  // form (e.g. "struct foo { int x; }".  While we could just return here, we're
10374ed5d91db256f7dbe6bf716da0b801004c197254Chris Lattner  // going to look at what comes after it to improve error recovery.  If an
10384ed5d91db256f7dbe6bf716da0b801004c197254Chris Lattner  // impossible token occurs next, we assume that the programmer forgot a ; at
10394ed5d91db256f7dbe6bf716da0b801004c197254Chris Lattner  // the end of the declaration and recover that way.
10404ed5d91db256f7dbe6bf716da0b801004c197254Chris Lattner  //
10414ed5d91db256f7dbe6bf716da0b801004c197254Chris Lattner  // This switch enumerates the valid "follow" set for definition.
1042f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall  if (TUK == Sema::TUK_Definition) {
1043b3a4e432c90be98c6d918087750397e86d030368Chris Lattner    bool ExpectedSemi = true;
10444ed5d91db256f7dbe6bf716da0b801004c197254Chris Lattner    switch (Tok.getKind()) {
1045b3a4e432c90be98c6d918087750397e86d030368Chris Lattner    default: break;
10464ed5d91db256f7dbe6bf716da0b801004c197254Chris Lattner    case tok::semi:               // struct foo {...} ;
104799c952046600f6bfccf315aa7ad5b1be2d242cc3Chris Lattner    case tok::star:               // struct foo {...} *         P;
104899c952046600f6bfccf315aa7ad5b1be2d242cc3Chris Lattner    case tok::amp:                // struct foo {...} &         R = ...
104999c952046600f6bfccf315aa7ad5b1be2d242cc3Chris Lattner    case tok::identifier:         // struct foo {...} V         ;
105099c952046600f6bfccf315aa7ad5b1be2d242cc3Chris Lattner    case tok::r_paren:            //(struct foo {...} )         {4}
105199c952046600f6bfccf315aa7ad5b1be2d242cc3Chris Lattner    case tok::annot_cxxscope:     // struct foo {...} a::       b;
105299c952046600f6bfccf315aa7ad5b1be2d242cc3Chris Lattner    case tok::annot_typename:     // struct foo {...} a         ::b;
105399c952046600f6bfccf315aa7ad5b1be2d242cc3Chris Lattner    case tok::annot_template_id:  // struct foo {...} a<int>    ::b;
1054c2e1c1af8ffe750b827284f207b9207112c7cc4eChris Lattner    case tok::l_paren:            // struct foo {...} (         x);
105516acfee729e00536af827935ccfcf69be721e462Chris Lattner    case tok::comma:              // __builtin_offsetof(struct foo{...} ,
1056b3a4e432c90be98c6d918087750397e86d030368Chris Lattner      ExpectedSemi = false;
1057b3a4e432c90be98c6d918087750397e86d030368Chris Lattner      break;
1058b3a4e432c90be98c6d918087750397e86d030368Chris Lattner    // Type qualifiers
1059b3a4e432c90be98c6d918087750397e86d030368Chris Lattner    case tok::kw_const:           // struct foo {...} const     x;
1060b3a4e432c90be98c6d918087750397e86d030368Chris Lattner    case tok::kw_volatile:        // struct foo {...} volatile  x;
1061b3a4e432c90be98c6d918087750397e86d030368Chris Lattner    case tok::kw_restrict:        // struct foo {...} restrict  x;
1062b3a4e432c90be98c6d918087750397e86d030368Chris Lattner    case tok::kw_inline:          // struct foo {...} inline    foo() {};
106399c952046600f6bfccf315aa7ad5b1be2d242cc3Chris Lattner    // Storage-class specifiers
106499c952046600f6bfccf315aa7ad5b1be2d242cc3Chris Lattner    case tok::kw_static:          // struct foo {...} static    x;
106599c952046600f6bfccf315aa7ad5b1be2d242cc3Chris Lattner    case tok::kw_extern:          // struct foo {...} extern    x;
106699c952046600f6bfccf315aa7ad5b1be2d242cc3Chris Lattner    case tok::kw_typedef:         // struct foo {...} typedef   x;
106799c952046600f6bfccf315aa7ad5b1be2d242cc3Chris Lattner    case tok::kw_register:        // struct foo {...} register  x;
106899c952046600f6bfccf315aa7ad5b1be2d242cc3Chris Lattner    case tok::kw_auto:            // struct foo {...} auto      x;
106933f992425213f381fc503699b26ee8cf9b60494eDouglas Gregor    case tok::kw_mutable:         // struct foo {...} mutable      x;
1070b3a4e432c90be98c6d918087750397e86d030368Chris Lattner      // As shown above, type qualifiers and storage class specifiers absolutely
1071b3a4e432c90be98c6d918087750397e86d030368Chris Lattner      // can occur after class specifiers according to the grammar.  However,
1072b3a4e432c90be98c6d918087750397e86d030368Chris Lattner      // almost noone actually writes code like this.  If we see one of these,
1073b3a4e432c90be98c6d918087750397e86d030368Chris Lattner      // it is much more likely that someone missed a semi colon and the
1074b3a4e432c90be98c6d918087750397e86d030368Chris Lattner      // type/storage class specifier we're seeing is part of the *next*
1075b3a4e432c90be98c6d918087750397e86d030368Chris Lattner      // intended declaration, as in:
1076b3a4e432c90be98c6d918087750397e86d030368Chris Lattner      //
1077b3a4e432c90be98c6d918087750397e86d030368Chris Lattner      //   struct foo { ... }
1078b3a4e432c90be98c6d918087750397e86d030368Chris Lattner      //   typedef int X;
1079b3a4e432c90be98c6d918087750397e86d030368Chris Lattner      //
1080b3a4e432c90be98c6d918087750397e86d030368Chris Lattner      // We'd really like to emit a missing semicolon error instead of emitting
1081b3a4e432c90be98c6d918087750397e86d030368Chris Lattner      // an error on the 'int' saying that you can't have two type specifiers in
1082b3a4e432c90be98c6d918087750397e86d030368Chris Lattner      // the same declaration of X.  Because of this, we look ahead past this
1083b3a4e432c90be98c6d918087750397e86d030368Chris Lattner      // token to see if it's a type specifier.  If so, we know the code is
1084b3a4e432c90be98c6d918087750397e86d030368Chris Lattner      // otherwise invalid, so we can produce the expected semi error.
1085b3a4e432c90be98c6d918087750397e86d030368Chris Lattner      if (!isKnownToBeTypeSpecifier(NextToken()))
1086b3a4e432c90be98c6d918087750397e86d030368Chris Lattner        ExpectedSemi = false;
10874ed5d91db256f7dbe6bf716da0b801004c197254Chris Lattner      break;
1088193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam
1089193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam    case tok::r_brace:  // struct bar { struct foo {...} }
10904ed5d91db256f7dbe6bf716da0b801004c197254Chris Lattner      // Missing ';' at end of struct is accepted as an extension in C mode.
1091b3a4e432c90be98c6d918087750397e86d030368Chris Lattner      if (!getLang().CPlusPlus)
1092b3a4e432c90be98c6d918087750397e86d030368Chris Lattner        ExpectedSemi = false;
1093b3a4e432c90be98c6d918087750397e86d030368Chris Lattner      break;
1094b3a4e432c90be98c6d918087750397e86d030368Chris Lattner    }
1095193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam
1096b3a4e432c90be98c6d918087750397e86d030368Chris Lattner    if (ExpectedSemi) {
10974ed5d91db256f7dbe6bf716da0b801004c197254Chris Lattner      ExpectAndConsume(tok::semi, diag::err_expected_semi_after_tagdecl,
10984ed5d91db256f7dbe6bf716da0b801004c197254Chris Lattner                       TagType == DeclSpec::TST_class ? "class"
10994ed5d91db256f7dbe6bf716da0b801004c197254Chris Lattner                       : TagType == DeclSpec::TST_struct? "struct" : "union");
11004ed5d91db256f7dbe6bf716da0b801004c197254Chris Lattner      // Push this token back into the preprocessor and change our current token
11014ed5d91db256f7dbe6bf716da0b801004c197254Chris Lattner      // to ';' so that the rest of the code recovers as though there were an
11024ed5d91db256f7dbe6bf716da0b801004c197254Chris Lattner      // ';' after the definition.
11034ed5d91db256f7dbe6bf716da0b801004c197254Chris Lattner      PP.EnterToken(Tok);
1104193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam      Tok.setKind(tok::semi);
11054ed5d91db256f7dbe6bf716da0b801004c197254Chris Lattner    }
11064ed5d91db256f7dbe6bf716da0b801004c197254Chris Lattner  }
1107e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor}
1108e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor
11091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// ParseBaseClause - Parse the base-clause of a C++ class [C++ class.derived].
1110e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor///
1111e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor///       base-clause : [C++ class.derived]
1112e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor///         ':' base-specifier-list
1113e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor///       base-specifier-list:
1114e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor///         base-specifier '...'[opt]
1115e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor///         base-specifier-list ',' base-specifier '...'[opt]
1116d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallvoid Parser::ParseBaseClause(Decl *ClassDecl) {
1117e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor  assert(Tok.is(tok::colon) && "Not a base clause");
1118e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor  ConsumeToken();
1119e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor
1120f8268ae3196002bbab6adb830302e79b0f368f13Douglas Gregor  // Build up an array of parsed base specifiers.
1121ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  llvm::SmallVector<CXXBaseSpecifier *, 8> BaseInfo;
1122f8268ae3196002bbab6adb830302e79b0f368f13Douglas Gregor
1123e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor  while (true) {
1124e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor    // Parse a base-specifier.
1125f8268ae3196002bbab6adb830302e79b0f368f13Douglas Gregor    BaseResult Result = ParseBaseSpecifier(ClassDecl);
11265ac8aff3d7431dc7e4d64d960574a10c9f7e0078Douglas Gregor    if (Result.isInvalid()) {
1127e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor      // Skip the rest of this base specifier, up until the comma or
1128e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor      // opening brace.
1129f8268ae3196002bbab6adb830302e79b0f368f13Douglas Gregor      SkipUntil(tok::comma, tok::l_brace, true, true);
1130f8268ae3196002bbab6adb830302e79b0f368f13Douglas Gregor    } else {
1131f8268ae3196002bbab6adb830302e79b0f368f13Douglas Gregor      // Add this to our array of base specifiers.
11325ac8aff3d7431dc7e4d64d960574a10c9f7e0078Douglas Gregor      BaseInfo.push_back(Result.get());
1133e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor    }
1134e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor
1135e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor    // If the next token is a comma, consume it and keep reading
1136e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor    // base-specifiers.
1137e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor    if (Tok.isNot(tok::comma)) break;
11381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1139e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor    // Consume the comma.
1140e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor    ConsumeToken();
1141e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor  }
1142f8268ae3196002bbab6adb830302e79b0f368f13Douglas Gregor
1143f8268ae3196002bbab6adb830302e79b0f368f13Douglas Gregor  // Attach the base specifiers
1144beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad  Actions.ActOnBaseSpecifiers(ClassDecl, BaseInfo.data(), BaseInfo.size());
1145e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor}
1146e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor
1147e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// ParseBaseSpecifier - Parse a C++ base-specifier. A base-specifier is
1148e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// one entry in the base class list of a class specifier, for example:
1149e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor///    class foo : public bar, virtual private baz {
1150e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// 'public bar' and 'virtual private baz' are each base-specifiers.
1151e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor///
1152e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor///       base-specifier: [C++ class.derived]
1153e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor///         ::[opt] nested-name-specifier[opt] class-name
1154e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor///         'virtual' access-specifier[opt] ::[opt] nested-name-specifier[opt]
1155e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor///                        class-name
1156e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor///         access-specifier 'virtual'[opt] ::[opt] nested-name-specifier[opt]
1157e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor///                        class-name
1158d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallParser::BaseResult Parser::ParseBaseSpecifier(Decl *ClassDecl) {
1159e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor  bool IsVirtual = false;
1160e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor  SourceLocation StartLoc = Tok.getLocation();
1161e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor
1162e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor  // Parse the 'virtual' keyword.
1163e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor  if (Tok.is(tok::kw_virtual))  {
1164e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor    ConsumeToken();
1165e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor    IsVirtual = true;
1166e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor  }
1167e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor
1168e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor  // Parse an (optional) access specifier.
1169e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor  AccessSpecifier Access = getAccessSpecifierIfPresent();
117092f883177b162928a8e632e4e3b93fafd2b26072John McCall  if (Access != AS_none)
1171e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor    ConsumeToken();
11721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1173e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor  // Parse the 'virtual' keyword (again!), in case it came after the
1174e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor  // access specifier.
1175e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor  if (Tok.is(tok::kw_virtual))  {
1176e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor    SourceLocation VirtualLoc = ConsumeToken();
1177e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor    if (IsVirtual) {
1178e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor      // Complain about duplicate 'virtual'
11791ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner      Diag(VirtualLoc, diag::err_dup_virtual)
1180849b243d4065f56742a4677d6dc8277609a151f8Douglas Gregor        << FixItHint::CreateRemoval(VirtualLoc);
1181e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor    }
1182e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor
1183e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor    IsVirtual = true;
1184e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor  }
1185e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor
1186eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  // Parse optional '::' and optional nested-name-specifier.
1187eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  CXXScopeSpec SS;
1188b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  ParseOptionalCXXScopeSpecifier(SS, ParsedType(), /*EnteringContext=*/false);
1189e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor
1190e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor  // The location of the base class itself.
1191e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor  SourceLocation BaseLoc = Tok.getLocation();
119242a552f8200ba5948661aee0106fce0c04e39818Douglas Gregor
119342a552f8200ba5948661aee0106fce0c04e39818Douglas Gregor  // Parse the class-name.
11947f43d6764797ab21216421aeb00f4ec314d503d1Douglas Gregor  SourceLocation EndLocation;
119531a19b6989bbf326d2de5ae12e712e2a65ca9c34Douglas Gregor  TypeResult BaseType = ParseClassName(EndLocation, &SS);
119631a19b6989bbf326d2de5ae12e712e2a65ca9c34Douglas Gregor  if (BaseType.isInvalid())
119742a552f8200ba5948661aee0106fce0c04e39818Douglas Gregor    return true;
11981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1199f90b27ad077c3339b62befc892382845339f9490Douglas Gregor  // Parse the optional ellipsis (for a pack expansion). The ellipsis is
1200f90b27ad077c3339b62befc892382845339f9490Douglas Gregor  // actually part of the base-specifier-list grammar productions, but we
1201f90b27ad077c3339b62befc892382845339f9490Douglas Gregor  // parse it here for convenience.
1202f90b27ad077c3339b62befc892382845339f9490Douglas Gregor  SourceLocation EllipsisLoc;
1203f90b27ad077c3339b62befc892382845339f9490Douglas Gregor  if (Tok.is(tok::ellipsis))
1204f90b27ad077c3339b62befc892382845339f9490Douglas Gregor    EllipsisLoc = ConsumeToken();
1205f90b27ad077c3339b62befc892382845339f9490Douglas Gregor
12061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  // Find the complete source range for the base-specifier.
12077f43d6764797ab21216421aeb00f4ec314d503d1Douglas Gregor  SourceRange Range(StartLoc, EndLocation);
12081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1209e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor  // Notify semantic analysis that we have parsed a complete
1210e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor  // base-specifier.
1211a55e52c0802cae3b7c366a05c461d3d15074c1a3Sebastian Redl  return Actions.ActOnBaseSpecifier(ClassDecl, Range, IsVirtual, Access,
1212f90b27ad077c3339b62befc892382845339f9490Douglas Gregor                                    BaseType.get(), BaseLoc, EllipsisLoc);
1213e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor}
1214e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor
1215e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// getAccessSpecifierIfPresent - Determine whether the next token is
1216e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// a C++ access-specifier.
1217e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor///
1218e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor///       access-specifier: [C++ class.derived]
1219e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor///         'private'
1220e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor///         'protected'
1221e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor///         'public'
12221eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpAccessSpecifier Parser::getAccessSpecifierIfPresent() const {
1223e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor  switch (Tok.getKind()) {
1224e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor  default: return AS_none;
1225e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor  case tok::kw_private: return AS_private;
1226e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor  case tok::kw_protected: return AS_protected;
1227e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor  case tok::kw_public: return AS_public;
1228e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor  }
1229e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor}
12304cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis
1231d33133cdc1af466f9c276249b2621be03867888bEli Friedmanvoid Parser::HandleMemberFunctionDefaultArgs(Declarator& DeclaratorInfo,
1232d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall                                             Decl *ThisDecl) {
1233d33133cdc1af466f9c276249b2621be03867888bEli Friedman  // We just declared a member function. If this member function
1234d33133cdc1af466f9c276249b2621be03867888bEli Friedman  // has any default arguments, we'll need to parse them later.
1235d33133cdc1af466f9c276249b2621be03867888bEli Friedman  LateParsedMethodDeclaration *LateMethod = 0;
12361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  DeclaratorChunk::FunctionTypeInfo &FTI
1237075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    = DeclaratorInfo.getFunctionTypeInfo();
1238d33133cdc1af466f9c276249b2621be03867888bEli Friedman  for (unsigned ParamIdx = 0; ParamIdx < FTI.NumArgs; ++ParamIdx) {
1239d33133cdc1af466f9c276249b2621be03867888bEli Friedman    if (LateMethod || FTI.ArgInfo[ParamIdx].DefaultArgTokens) {
1240d33133cdc1af466f9c276249b2621be03867888bEli Friedman      if (!LateMethod) {
1241d33133cdc1af466f9c276249b2621be03867888bEli Friedman        // Push this method onto the stack of late-parsed method
1242d33133cdc1af466f9c276249b2621be03867888bEli Friedman        // declarations.
1243d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor        LateMethod = new LateParsedMethodDeclaration(this, ThisDecl);
1244d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor        getCurrentClass().LateParsedDeclarations.push_back(LateMethod);
124523c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor        LateMethod->TemplateScope = getCurScope()->isTemplateParamScope();
1246d33133cdc1af466f9c276249b2621be03867888bEli Friedman
1247d33133cdc1af466f9c276249b2621be03867888bEli Friedman        // Add all of the parameters prior to this one (they don't
1248d33133cdc1af466f9c276249b2621be03867888bEli Friedman        // have default arguments).
1249d33133cdc1af466f9c276249b2621be03867888bEli Friedman        LateMethod->DefaultArgs.reserve(FTI.NumArgs);
1250d33133cdc1af466f9c276249b2621be03867888bEli Friedman        for (unsigned I = 0; I < ParamIdx; ++I)
1251d33133cdc1af466f9c276249b2621be03867888bEli Friedman          LateMethod->DefaultArgs.push_back(
12528f8210c47797f013e0fb24a26f9c4751b10783feDouglas Gregor                             LateParsedDefaultArgument(FTI.ArgInfo[I].Param));
1253d33133cdc1af466f9c276249b2621be03867888bEli Friedman      }
1254d33133cdc1af466f9c276249b2621be03867888bEli Friedman
1255d33133cdc1af466f9c276249b2621be03867888bEli Friedman      // Add this parameter to the list of parameters (it or may
1256d33133cdc1af466f9c276249b2621be03867888bEli Friedman      // not have a default argument).
1257d33133cdc1af466f9c276249b2621be03867888bEli Friedman      LateMethod->DefaultArgs.push_back(
1258d33133cdc1af466f9c276249b2621be03867888bEli Friedman        LateParsedDefaultArgument(FTI.ArgInfo[ParamIdx].Param,
1259d33133cdc1af466f9c276249b2621be03867888bEli Friedman                                  FTI.ArgInfo[ParamIdx].DefaultArgTokens));
1260d33133cdc1af466f9c276249b2621be03867888bEli Friedman    }
1261d33133cdc1af466f9c276249b2621be03867888bEli Friedman  }
1262d33133cdc1af466f9c276249b2621be03867888bEli Friedman}
1263d33133cdc1af466f9c276249b2621be03867888bEli Friedman
12641f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson/// isCXX0XVirtSpecifier - Determine whether the next token is a C++0x
12651f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson/// virt-specifier.
12661f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson///
12671f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson///       virt-specifier:
12681f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson///         override
12691f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson///         final
12701f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson///         new
1271b971dbdb65149a7cf0c046380186d0204e5b411eAnders CarlssonVirtSpecifiers::VirtSpecifier Parser::isCXX0XVirtSpecifier() const {
12721f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson  if (Tok.is(tok::kw_new))
1273b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson    return VirtSpecifiers::VS_New;
1274b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson
1275b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson  if (Tok.is(tok::identifier)) {
1276b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson    IdentifierInfo *II = Tok.getIdentifierInfo();
12771f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson
12787eeb4ec11043d4860361348f2b19299d957d47a9Anders Carlsson    // Initialize the contextual keywords.
12797eeb4ec11043d4860361348f2b19299d957d47a9Anders Carlsson    if (!Ident_final) {
12807eeb4ec11043d4860361348f2b19299d957d47a9Anders Carlsson      Ident_final = &PP.getIdentifierTable().get("final");
12817eeb4ec11043d4860361348f2b19299d957d47a9Anders Carlsson      Ident_override = &PP.getIdentifierTable().get("override");
12827eeb4ec11043d4860361348f2b19299d957d47a9Anders Carlsson    }
12837eeb4ec11043d4860361348f2b19299d957d47a9Anders Carlsson
1284b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson    if (II == Ident_override)
1285b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson      return VirtSpecifiers::VS_Override;
12861f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson
1287b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson    if (II == Ident_final)
1288b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson      return VirtSpecifiers::VS_Final;
1289b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson  }
1290b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson
1291b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson  return VirtSpecifiers::VS_None;
12921f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson}
12931f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson
12941f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson/// ParseOptionalCXX0XVirtSpecifierSeq - Parse a virt-specifier-seq.
12951f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson///
12961f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson///       virt-specifier-seq:
12971f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson///         virt-specifier
12981f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson///         virt-specifier-seq virt-specifier
1299b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlssonvoid Parser::ParseOptionalCXX0XVirtSpecifierSeq(VirtSpecifiers &VS) {
13001f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson  if (!getLang().CPlusPlus0x)
13011f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson    return;
13021f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson
1303b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson  while (true) {
1304b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson    VirtSpecifiers::VirtSpecifier Specifier = isCXX0XVirtSpecifier();
1305b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson    if (Specifier == VirtSpecifiers::VS_None)
1306b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson      return;
1307b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson
1308b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson    // C++ [class.mem]p8:
1309b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson    //   A virt-specifier-seq shall contain at most one of each virt-specifier.
1310b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson    const char* PrevSpec = 0;
1311b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson    if (VS.SetVirtSpecifier(Specifier, Tok.getLocation(), PrevSpec))
1312b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson      Diag(Tok.getLocation(), diag::err_duplicate_virt_specifier)
1313b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson        << PrevSpec
1314b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson        << FixItHint::CreateRemoval(Tok.getLocation());
1315b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson
1316b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson    ConsumeToken();
1317b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson  }
13181f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson}
13191f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson
13204cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis/// ParseCXXClassMemberDeclaration - Parse a C++ class member declaration.
13214cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis///
13224cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis///       member-declaration:
13234cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis///         decl-specifier-seq[opt] member-declarator-list[opt] ';'
13244cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis///         function-definition ';'[opt]
13254cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis///         ::[opt] nested-name-specifier template[opt] unqualified-id ';'[TODO]
13264cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis///         using-declaration                                            [TODO]
1327511d7aba3b12853fdb88729a0313b80a60eab8adAnders Carlsson/// [C++0x] static_assert-declaration
13285aeccdbb4bdc94e48c04cacc59fa812af32109b2Anders Carlsson///         template-declaration
1329bc8d56496a6ecdba14769df03d75c001184f8c54Chris Lattner/// [GNU]   '__extension__' member-declaration
13304cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis///
13314cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis///       member-declarator-list:
13324cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis///         member-declarator
13334cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis///         member-declarator-list ',' member-declarator
13344cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis///
13354cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis///       member-declarator:
13361f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson///         declarator virt-specifier-seq[opt] pure-specifier[opt]
13374cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis///         declarator constant-initializer[opt]
13384cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis///         identifier[opt] ':' constant-expression
13394cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis///
13401f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson///       virt-specifier-seq:
13411f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson///         virt-specifier
13421f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson///         virt-specifier-seq virt-specifier
13431f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson///
13441f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson///       virt-specifier:
13451f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson///         override
13461f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson///         final
13471f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson///         new
13481f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson///
1349e2b6833d445c7a4ce64f1816c05f176ba1740acaSebastian Redl///       pure-specifier:
13504cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis///         '= 0'
13514cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis///
13524cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis///       constant-initializer:
13534cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis///         '=' constant-expression
13544cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis///
135537b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregorvoid Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS,
1356c9068d7dd94d439cec66c421115d15303e481025John McCall                                       const ParsedTemplateInfo &TemplateInfo,
1357c9068d7dd94d439cec66c421115d15303e481025John McCall                                       ParsingDeclRAIIObject *TemplateDiags) {
135860fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall  // Access declarations.
135960fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall  if (!TemplateInfo.Kind &&
136060fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall      (Tok.is(tok::identifier) || Tok.is(tok::coloncolon)) &&
13619ba6166f4a78722e7df8ffbd64eb788bfdf2764aJohn McCall      !TryAnnotateCXXScopeToken() &&
136260fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall      Tok.is(tok::annot_cxxscope)) {
136360fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall    bool isAccessDecl = false;
136460fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall    if (NextToken().is(tok::identifier))
136560fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall      isAccessDecl = GetLookAheadToken(2).is(tok::semi);
136660fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall    else
136760fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall      isAccessDecl = NextToken().is(tok::kw_operator);
136860fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall
136960fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall    if (isAccessDecl) {
137060fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall      // Collect the scope specifier token we annotated earlier.
137160fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall      CXXScopeSpec SS;
1372b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall      ParseOptionalCXXScopeSpecifier(SS, ParsedType(), false);
137360fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall
137460fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall      // Try to parse an unqualified-id.
137560fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall      UnqualifiedId Name;
1376b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall      if (ParseUnqualifiedId(SS, false, true, true, ParsedType(), Name)) {
137760fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall        SkipUntil(tok::semi);
137860fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall        return;
137960fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall      }
138060fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall
138160fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall      // TODO: recover from mistakenly-qualified operator declarations.
138260fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall      if (ExpectAndConsume(tok::semi,
138360fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall                           diag::err_expected_semi_after,
138460fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall                           "access declaration",
138560fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall                           tok::semi))
138660fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall        return;
138760fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall
138823c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor      Actions.ActOnUsingDeclaration(getCurScope(), AS,
138960fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall                                    false, SourceLocation(),
139060fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall                                    SS, Name,
139160fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall                                    /* AttrList */ 0,
139260fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall                                    /* IsTypeName */ false,
139360fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall                                    SourceLocation());
139460fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall      return;
139560fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall    }
139660fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall  }
139760fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall
1398511d7aba3b12853fdb88729a0313b80a60eab8adAnders Carlsson  // static_assert-declaration
1399682bf92db408a6cbc3d37b5496a99b6ef85041ecChris Lattner  if (Tok.is(tok::kw_static_assert)) {
140037b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor    // FIXME: Check for templates
140197144fc41a9419bf6d74fc9450e8ef3f6e11f7e0Chris Lattner    SourceLocation DeclEnd;
140297144fc41a9419bf6d74fc9450e8ef3f6e11f7e0Chris Lattner    ParseStaticAssertDeclaration(DeclEnd);
1403682bf92db408a6cbc3d37b5496a99b6ef85041ecChris Lattner    return;
1404682bf92db408a6cbc3d37b5496a99b6ef85041ecChris Lattner  }
14051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1406682bf92db408a6cbc3d37b5496a99b6ef85041ecChris Lattner  if (Tok.is(tok::kw_template)) {
14071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    assert(!TemplateInfo.TemplateParams &&
140837b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor           "Nested template improperly parsed?");
140997144fc41a9419bf6d74fc9450e8ef3f6e11f7e0Chris Lattner    SourceLocation DeclEnd;
14101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    ParseDeclarationStartingWithTemplate(Declarator::MemberContext, DeclEnd,
14114d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor                                         AS);
1412682bf92db408a6cbc3d37b5496a99b6ef85041ecChris Lattner    return;
1413682bf92db408a6cbc3d37b5496a99b6ef85041ecChris Lattner  }
14145aeccdbb4bdc94e48c04cacc59fa812af32109b2Anders Carlsson
1415bc8d56496a6ecdba14769df03d75c001184f8c54Chris Lattner  // Handle:  member-declaration ::= '__extension__' member-declaration
1416bc8d56496a6ecdba14769df03d75c001184f8c54Chris Lattner  if (Tok.is(tok::kw___extension__)) {
1417bc8d56496a6ecdba14769df03d75c001184f8c54Chris Lattner    // __extension__ silences extension warnings in the subexpression.
1418bc8d56496a6ecdba14769df03d75c001184f8c54Chris Lattner    ExtensionRAIIObject O(Diags);  // Use RAII to do this.
1419bc8d56496a6ecdba14769df03d75c001184f8c54Chris Lattner    ConsumeToken();
1420c9068d7dd94d439cec66c421115d15303e481025John McCall    return ParseCXXClassMemberDeclaration(AS, TemplateInfo, TemplateDiags);
1421bc8d56496a6ecdba14769df03d75c001184f8c54Chris Lattner  }
14229cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor
14234ed5d91db256f7dbe6bf716da0b801004c197254Chris Lattner  // Don't parse FOO:BAR as if it were a typo for FOO::BAR, in this context it
14244ed5d91db256f7dbe6bf716da0b801004c197254Chris Lattner  // is a bitfield.
1425a1efc8c8c6460d860d6509b05b341e77ed9bfe87Chris Lattner  ColonProtectionRAIIObject X(*this);
1426193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam
14277f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  ParsedAttributesWithRange attrs;
1428bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt  // Optional C++0x attribute-specifier
14297f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  MaybeParseCXX0XAttributes(attrs);
14307f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  MaybeParseMicrosoftAttributes(attrs);
1431bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt
14329cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor  if (Tok.is(tok::kw_using)) {
143337b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor    // FIXME: Check for template aliases
1434193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam
14357f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall    ProhibitAttributes(attrs);
14361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14379cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor    // Eat 'using'.
14389cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor    SourceLocation UsingLoc = ConsumeToken();
14399cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor
14409cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor    if (Tok.is(tok::kw_namespace)) {
14419cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor      Diag(UsingLoc, diag::err_using_namespace_in_class);
14429cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor      SkipUntil(tok::semi, true, true);
1443ae50d501f463d7032320ec31840f60ae68df3a55Chris Lattner    } else {
14449cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor      SourceLocation DeclEnd;
14459cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor      // Otherwise, it must be using-declaration.
144678b810559d89e996e00684335407443936ce34a1John McCall      ParseUsingDeclaration(Declarator::MemberContext, TemplateInfo,
144778b810559d89e996e00684335407443936ce34a1John McCall                            UsingLoc, DeclEnd, AS);
14489cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor    }
14499cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor    return;
14509cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor  }
14519cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor
14524cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  // decl-specifier-seq:
14534cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  // Parse the common declaration-specifiers piece.
1454c9068d7dd94d439cec66c421115d15303e481025John McCall  ParsingDeclSpec DS(*this, TemplateDiags);
14557f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  DS.takeAttributesFrom(attrs);
145637b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor  ParseDeclarationSpecifiers(DS, TemplateInfo, AS, DSC_class);
14574cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis
1458f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall  MultiTemplateParamsArg TemplateParams(Actions,
1459dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall      TemplateInfo.TemplateParams? TemplateInfo.TemplateParams->data() : 0,
1460dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall      TemplateInfo.TemplateParams? TemplateInfo.TemplateParams->size() : 0);
1461dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall
14624cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  if (Tok.is(tok::semi)) {
14634cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis    ConsumeToken();
1464d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall    Decl *TheDecl =
1465c9068d7dd94d439cec66c421115d15303e481025John McCall      Actions.ParsedFreeStandingDeclSpec(getCurScope(), AS, DS);
1466c9068d7dd94d439cec66c421115d15303e481025John McCall    DS.complete(TheDecl);
146767d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall    return;
14684cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  }
146907952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis
147054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  ParsingDeclarator DeclaratorInfo(*this, DS, Declarator::MemberContext);
14714cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis
14723a9fdb4742b21c0a3c27f18c5e4e94bab6f9e64cArgyrios Kyrtzidis  if (Tok.isNot(tok::colon)) {
1473a1efc8c8c6460d860d6509b05b341e77ed9bfe87Chris Lattner    // Don't parse FOO:BAR as if it were a typo for FOO::BAR.
1474a1efc8c8c6460d860d6509b05b341e77ed9bfe87Chris Lattner    ColonProtectionRAIIObject X(*this);
1475a1efc8c8c6460d860d6509b05b341e77ed9bfe87Chris Lattner
14763a9fdb4742b21c0a3c27f18c5e4e94bab6f9e64cArgyrios Kyrtzidis    // Parse the first declarator.
14773a9fdb4742b21c0a3c27f18c5e4e94bab6f9e64cArgyrios Kyrtzidis    ParseDeclarator(DeclaratorInfo);
14783a9fdb4742b21c0a3c27f18c5e4e94bab6f9e64cArgyrios Kyrtzidis    // Error parsing the declarator?
147910bd36882406cdf4805e35add1ce2f11ab9ae152Douglas Gregor    if (!DeclaratorInfo.hasName()) {
14803a9fdb4742b21c0a3c27f18c5e4e94bab6f9e64cArgyrios Kyrtzidis      // If so, skip until the semi-colon or a }.
14814cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis      SkipUntil(tok::r_brace, true);
14823a9fdb4742b21c0a3c27f18c5e4e94bab6f9e64cArgyrios Kyrtzidis      if (Tok.is(tok::semi))
14833a9fdb4742b21c0a3c27f18c5e4e94bab6f9e64cArgyrios Kyrtzidis        ConsumeToken();
1484682bf92db408a6cbc3d37b5496a99b6ef85041ecChris Lattner      return;
14854cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis    }
14864cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis
14871b2fc0f3e181d99fb34f60e711066fb11628ecd0John Thompson    // If attributes exist after the declarator, but before an '{', parse them.
14887f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall    MaybeParseGNUAttributes(DeclaratorInfo);
14891b2fc0f3e181d99fb34f60e711066fb11628ecd0John Thompson
14903a9fdb4742b21c0a3c27f18c5e4e94bab6f9e64cArgyrios Kyrtzidis    // function-definition:
14917ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor    if (Tok.is(tok::l_brace)
1492d3a413d3b8eb39bcee5944bc545d9997c1abe492Sebastian Redl        || (DeclaratorInfo.isFunctionDeclarator() &&
1493d3a413d3b8eb39bcee5944bc545d9997c1abe492Sebastian Redl            (Tok.is(tok::colon) || Tok.is(tok::kw_try)))) {
14943a9fdb4742b21c0a3c27f18c5e4e94bab6f9e64cArgyrios Kyrtzidis      if (!DeclaratorInfo.isFunctionDeclarator()) {
14953a9fdb4742b21c0a3c27f18c5e4e94bab6f9e64cArgyrios Kyrtzidis        Diag(Tok, diag::err_func_def_no_params);
14963a9fdb4742b21c0a3c27f18c5e4e94bab6f9e64cArgyrios Kyrtzidis        ConsumeBrace();
14973a9fdb4742b21c0a3c27f18c5e4e94bab6f9e64cArgyrios Kyrtzidis        SkipUntil(tok::r_brace, true);
14989ea416e598fa3cb09d67d514c4519c99abb81321Douglas Gregor
14999ea416e598fa3cb09d67d514c4519c99abb81321Douglas Gregor        // Consume the optional ';'
15009ea416e598fa3cb09d67d514c4519c99abb81321Douglas Gregor        if (Tok.is(tok::semi))
15019ea416e598fa3cb09d67d514c4519c99abb81321Douglas Gregor          ConsumeToken();
1502682bf92db408a6cbc3d37b5496a99b6ef85041ecChris Lattner        return;
15033a9fdb4742b21c0a3c27f18c5e4e94bab6f9e64cArgyrios Kyrtzidis      }
15043a9fdb4742b21c0a3c27f18c5e4e94bab6f9e64cArgyrios Kyrtzidis
15053a9fdb4742b21c0a3c27f18c5e4e94bab6f9e64cArgyrios Kyrtzidis      if (DS.getStorageClassSpec() == DeclSpec::SCS_typedef) {
15063a9fdb4742b21c0a3c27f18c5e4e94bab6f9e64cArgyrios Kyrtzidis        Diag(Tok, diag::err_function_declared_typedef);
15073a9fdb4742b21c0a3c27f18c5e4e94bab6f9e64cArgyrios Kyrtzidis        // This recovery skips the entire function body. It would be nice
15083a9fdb4742b21c0a3c27f18c5e4e94bab6f9e64cArgyrios Kyrtzidis        // to simply call ParseCXXInlineMethodDef() below, however Sema
15093a9fdb4742b21c0a3c27f18c5e4e94bab6f9e64cArgyrios Kyrtzidis        // assumes the declarator represents a function, not a typedef.
15103a9fdb4742b21c0a3c27f18c5e4e94bab6f9e64cArgyrios Kyrtzidis        ConsumeBrace();
15113a9fdb4742b21c0a3c27f18c5e4e94bab6f9e64cArgyrios Kyrtzidis        SkipUntil(tok::r_brace, true);
15129ea416e598fa3cb09d67d514c4519c99abb81321Douglas Gregor
15139ea416e598fa3cb09d67d514c4519c99abb81321Douglas Gregor        // Consume the optional ';'
15149ea416e598fa3cb09d67d514c4519c99abb81321Douglas Gregor        if (Tok.is(tok::semi))
15159ea416e598fa3cb09d67d514c4519c99abb81321Douglas Gregor          ConsumeToken();
1516682bf92db408a6cbc3d37b5496a99b6ef85041ecChris Lattner        return;
15173a9fdb4742b21c0a3c27f18c5e4e94bab6f9e64cArgyrios Kyrtzidis      }
15184cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis
151937b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor      ParseCXXInlineMethodDef(AS, DeclaratorInfo, TemplateInfo);
15209ea416e598fa3cb09d67d514c4519c99abb81321Douglas Gregor      // Consume the optional ';'
15219ea416e598fa3cb09d67d514c4519c99abb81321Douglas Gregor      if (Tok.is(tok::semi))
15229ea416e598fa3cb09d67d514c4519c99abb81321Douglas Gregor        ConsumeToken();
15239ea416e598fa3cb09d67d514c4519c99abb81321Douglas Gregor
1524682bf92db408a6cbc3d37b5496a99b6ef85041ecChris Lattner      return;
15253a9fdb4742b21c0a3c27f18c5e4e94bab6f9e64cArgyrios Kyrtzidis    }
15264cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  }
15274cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis
15284cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  // member-declarator-list:
15294cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  //   member-declarator
15304cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  //   member-declarator-list ',' member-declarator
15314cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis
1532d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  llvm::SmallVector<Decl *, 8> DeclsInGroup;
153360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult BitfieldSize;
153460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Init;
1535e2b6833d445c7a4ce64f1816c05f176ba1740acaSebastian Redl  bool Deleted = false;
15364cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis
15374cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  while (1) {
15384cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis    // member-declarator:
15394cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis    //   declarator pure-specifier[opt]
15404cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis    //   declarator constant-initializer[opt]
15414cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis    //   identifier[opt] ':' constant-expression
15424cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis    if (Tok.is(tok::colon)) {
15434cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis      ConsumeToken();
15440e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl      BitfieldSize = ParseConstantExpression();
15450e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl      if (BitfieldSize.isInvalid())
15464cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis        SkipUntil(tok::comma, true, true);
15474cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis    }
15481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1549b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson    VirtSpecifiers VS;
1550b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson    ParseOptionalCXX0XVirtSpecifierSeq(VS);
15511f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson
15524cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis    // pure-specifier:
15534cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis    //   '= 0'
15544cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis    //
15554cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis    // constant-initializer:
15564cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis    //   '=' constant-expression
1557e2b6833d445c7a4ce64f1816c05f176ba1740acaSebastian Redl    //
1558e2b6833d445c7a4ce64f1816c05f176ba1740acaSebastian Redl    // defaulted/deleted function-definition:
1559e2b6833d445c7a4ce64f1816c05f176ba1740acaSebastian Redl    //   '=' 'default'                          [TODO]
1560e2b6833d445c7a4ce64f1816c05f176ba1740acaSebastian Redl    //   '=' 'delete'
15614cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis    if (Tok.is(tok::equal)) {
15624cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis      ConsumeToken();
156337bf9d2bb74944c9d9a52522412bc077629977f1Anders Carlsson      if (Tok.is(tok::kw_delete)) {
156437bf9d2bb74944c9d9a52522412bc077629977f1Anders Carlsson        if (!getLang().CPlusPlus0x)
156537bf9d2bb74944c9d9a52522412bc077629977f1Anders Carlsson          Diag(Tok, diag::warn_deleted_function_accepted_as_extension);
1566e2b6833d445c7a4ce64f1816c05f176ba1740acaSebastian Redl        ConsumeToken();
1567e2b6833d445c7a4ce64f1816c05f176ba1740acaSebastian Redl        Deleted = true;
1568e2b6833d445c7a4ce64f1816c05f176ba1740acaSebastian Redl      } else {
1569e2b6833d445c7a4ce64f1816c05f176ba1740acaSebastian Redl        Init = ParseInitializer();
1570e2b6833d445c7a4ce64f1816c05f176ba1740acaSebastian Redl        if (Init.isInvalid())
1571e2b6833d445c7a4ce64f1816c05f176ba1740acaSebastian Redl          SkipUntil(tok::comma, true, true);
1572e2b6833d445c7a4ce64f1816c05f176ba1740acaSebastian Redl      }
15734cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis    }
15744cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis
1575e6563256a4b3b9fee70ce3335d28406607c1faafChris Lattner    // If a simple-asm-expr is present, parse it.
1576e6563256a4b3b9fee70ce3335d28406607c1faafChris Lattner    if (Tok.is(tok::kw_asm)) {
1577e6563256a4b3b9fee70ce3335d28406607c1faafChris Lattner      SourceLocation Loc;
157860d7b3a319d84d688752be3870615ac0f111fb16John McCall      ExprResult AsmLabel(ParseSimpleAsm(&Loc));
1579e6563256a4b3b9fee70ce3335d28406607c1faafChris Lattner      if (AsmLabel.isInvalid())
1580e6563256a4b3b9fee70ce3335d28406607c1faafChris Lattner        SkipUntil(tok::comma, true, true);
1581e6563256a4b3b9fee70ce3335d28406607c1faafChris Lattner
1582e6563256a4b3b9fee70ce3335d28406607c1faafChris Lattner      DeclaratorInfo.setAsmLabel(AsmLabel.release());
1583e6563256a4b3b9fee70ce3335d28406607c1faafChris Lattner      DeclaratorInfo.SetRangeEnd(Loc);
1584e6563256a4b3b9fee70ce3335d28406607c1faafChris Lattner    }
1585e6563256a4b3b9fee70ce3335d28406607c1faafChris Lattner
15864cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis    // If attributes exist after the declarator, parse them.
15877f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall    MaybeParseGNUAttributes(DeclaratorInfo);
15884cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis
158907952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis    // NOTE: If Sema is the Action module and declarator is an instance field,
1590682bf92db408a6cbc3d37b5496a99b6ef85041ecChris Lattner    // this call will *not* return the created decl; It will return null.
159107952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis    // See Sema::ActOnCXXMemberDeclarator for details.
159267d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall
1593d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall    Decl *ThisDecl = 0;
159467d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall    if (DS.isFriendSpecified()) {
1595bbbcdd9cc06b6078939129330ecc9bda3310984dJohn McCall      // TODO: handle initializers, bitfields, 'delete'
159623c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor      ThisDecl = Actions.ActOnFriendFunctionDecl(getCurScope(), DeclaratorInfo,
1597bbbcdd9cc06b6078939129330ecc9bda3310984dJohn McCall                                                 /*IsDefinition*/ false,
1598bbbcdd9cc06b6078939129330ecc9bda3310984dJohn McCall                                                 move(TemplateParams));
159937b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor    } else {
160023c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor      ThisDecl = Actions.ActOnCXXMemberDeclarator(getCurScope(), AS,
160167d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall                                                  DeclaratorInfo,
160237b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor                                                  move(TemplateParams),
160367d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall                                                  BitfieldSize.release(),
160467d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall                                                  Init.release(),
1605d1a7846699a82f85ff3ce6b2e383409537c3f5c5Sebastian Redl                                                  /*IsDefinition*/Deleted,
160667d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall                                                  Deleted);
160737b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor    }
1608682bf92db408a6cbc3d37b5496a99b6ef85041ecChris Lattner    if (ThisDecl)
1609682bf92db408a6cbc3d37b5496a99b6ef85041ecChris Lattner      DeclsInGroup.push_back(ThisDecl);
16104cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis
161172b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor    if (DeclaratorInfo.isFunctionDeclarator() &&
16121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump        DeclaratorInfo.getDeclSpec().getStorageClassSpec()
161372b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor          != DeclSpec::SCS_typedef) {
1614d33133cdc1af466f9c276249b2621be03867888bEli Friedman      HandleMemberFunctionDefaultArgs(DeclaratorInfo, ThisDecl);
161572b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor    }
161672b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor
161754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    DeclaratorInfo.complete(ThisDecl);
161854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall
16194cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis    // If we don't have a comma, it is either the end of the list (a ';')
16204cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis    // or an error, bail out.
16214cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis    if (Tok.isNot(tok::comma))
16224cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis      break;
16231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
16244cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis    // Consume the comma.
16254cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis    ConsumeToken();
16261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
16274cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis    // Parse the next declarator.
16284cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis    DeclaratorInfo.clear();
162915faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl    BitfieldSize = 0;
163015faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl    Init = 0;
1631e2b6833d445c7a4ce64f1816c05f176ba1740acaSebastian Redl    Deleted = false;
16321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
16334cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis    // Attributes are only allowed on the second declarator.
16347f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall    MaybeParseGNUAttributes(DeclaratorInfo);
16354cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis
16363a9fdb4742b21c0a3c27f18c5e4e94bab6f9e64cArgyrios Kyrtzidis    if (Tok.isNot(tok::colon))
16373a9fdb4742b21c0a3c27f18c5e4e94bab6f9e64cArgyrios Kyrtzidis      ParseDeclarator(DeclaratorInfo);
16384cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  }
16394cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis
1640ae50d501f463d7032320ec31840f60ae68df3a55Chris Lattner  if (ExpectAndConsume(tok::semi, diag::err_expected_semi_decl_list)) {
1641ae50d501f463d7032320ec31840f60ae68df3a55Chris Lattner    // Skip to end of block or statement.
1642ae50d501f463d7032320ec31840f60ae68df3a55Chris Lattner    SkipUntil(tok::r_brace, true, true);
1643ae50d501f463d7032320ec31840f60ae68df3a55Chris Lattner    // If we stopped at a ';', eat it.
1644ae50d501f463d7032320ec31840f60ae68df3a55Chris Lattner    if (Tok.is(tok::semi)) ConsumeToken();
1645682bf92db408a6cbc3d37b5496a99b6ef85041ecChris Lattner    return;
16464cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  }
16474cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis
164823c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor  Actions.FinalizeDeclaratorGroup(getCurScope(), DS, DeclsInGroup.data(),
1649ae50d501f463d7032320ec31840f60ae68df3a55Chris Lattner                                  DeclsInGroup.size());
16504cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis}
16514cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis
16524cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis/// ParseCXXMemberSpecification - Parse the class definition.
16534cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis///
16544cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis///       member-specification:
16554cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis///         member-declaration member-specification[opt]
16564cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis///         access-specifier ':' member-specification[opt]
16574cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis///
16584cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidisvoid Parser::ParseCXXMemberSpecification(SourceLocation RecordLoc,
1659d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall                                         unsigned TagType, Decl *TagDecl) {
166031fc07df7f0fc89ebf83ca05a20b29de45a7598dSanjiv Gupta  assert((TagType == DeclSpec::TST_struct ||
16614cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis         TagType == DeclSpec::TST_union  ||
166231fc07df7f0fc89ebf83ca05a20b29de45a7598dSanjiv Gupta         TagType == DeclSpec::TST_class) && "Invalid TagType!");
16634cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis
1664f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall  PrettyDeclStackTraceEntry CrashInfo(Actions, TagDecl, RecordLoc,
1665f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                      "parsing struct/union/class body");
16661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
166726997fd58c9560584edd154618f2f2c15ee68af4Douglas Gregor  // Determine whether this is a non-nested class. Note that local
166826997fd58c9560584edd154618f2f2c15ee68af4Douglas Gregor  // classes are *not* considered to be nested classes.
166926997fd58c9560584edd154618f2f2c15ee68af4Douglas Gregor  bool NonNestedClass = true;
167026997fd58c9560584edd154618f2f2c15ee68af4Douglas Gregor  if (!ClassStack.empty()) {
167123c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor    for (const Scope *S = getCurScope(); S; S = S->getParent()) {
167226997fd58c9560584edd154618f2f2c15ee68af4Douglas Gregor      if (S->isClassScope()) {
167326997fd58c9560584edd154618f2f2c15ee68af4Douglas Gregor        // We're inside a class scope, so this is a nested class.
167426997fd58c9560584edd154618f2f2c15ee68af4Douglas Gregor        NonNestedClass = false;
167526997fd58c9560584edd154618f2f2c15ee68af4Douglas Gregor        break;
167626997fd58c9560584edd154618f2f2c15ee68af4Douglas Gregor      }
167726997fd58c9560584edd154618f2f2c15ee68af4Douglas Gregor
167826997fd58c9560584edd154618f2f2c15ee68af4Douglas Gregor      if ((S->getFlags() & Scope::FnScope)) {
167926997fd58c9560584edd154618f2f2c15ee68af4Douglas Gregor        // If we're in a function or function template declared in the
168026997fd58c9560584edd154618f2f2c15ee68af4Douglas Gregor        // body of a class, then this is a local class rather than a
168126997fd58c9560584edd154618f2f2c15ee68af4Douglas Gregor        // nested class.
168226997fd58c9560584edd154618f2f2c15ee68af4Douglas Gregor        const Scope *Parent = S->getParent();
168326997fd58c9560584edd154618f2f2c15ee68af4Douglas Gregor        if (Parent->isTemplateParamScope())
168426997fd58c9560584edd154618f2f2c15ee68af4Douglas Gregor          Parent = Parent->getParent();
168526997fd58c9560584edd154618f2f2c15ee68af4Douglas Gregor        if (Parent->isClassScope())
168626997fd58c9560584edd154618f2f2c15ee68af4Douglas Gregor          break;
168726997fd58c9560584edd154618f2f2c15ee68af4Douglas Gregor      }
168826997fd58c9560584edd154618f2f2c15ee68af4Douglas Gregor    }
168926997fd58c9560584edd154618f2f2c15ee68af4Douglas Gregor  }
16904cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis
16914cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  // Enter a scope for the class.
16923218c4bb3b5d7250f12420de6db7ef3e3f805a75Douglas Gregor  ParseScope ClassScope(this, Scope::ClassScope|Scope::DeclScope);
16934cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis
16946569d68745c8213709740337d2be52b031384f58Douglas Gregor  // Note that we are parsing a new (potentially-nested) class definition.
169526997fd58c9560584edd154618f2f2c15ee68af4Douglas Gregor  ParsingClassDefinition ParsingDef(*this, TagDecl, NonNestedClass);
16966569d68745c8213709740337d2be52b031384f58Douglas Gregor
1697ddc29e116db3c3f4144355e67a0137b38b6bb6d1Douglas Gregor  if (TagDecl)
169823c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor    Actions.ActOnTagStartDefinition(getCurScope(), TagDecl);
1699bd0dfa5c37d422427080a0ae3af9b63e70e6e854John McCall
1700bd0dfa5c37d422427080a0ae3af9b63e70e6e854John McCall  if (Tok.is(tok::colon)) {
1701bd0dfa5c37d422427080a0ae3af9b63e70e6e854John McCall    ParseBaseClause(TagDecl);
1702bd0dfa5c37d422427080a0ae3af9b63e70e6e854John McCall
1703bd0dfa5c37d422427080a0ae3af9b63e70e6e854John McCall    if (!Tok.is(tok::l_brace)) {
1704bd0dfa5c37d422427080a0ae3af9b63e70e6e854John McCall      Diag(Tok, diag::err_expected_lbrace_after_base_specifiers);
1705db7bb4a4e7d9744cbc994c90932e6f056228e1ffJohn McCall
1706db7bb4a4e7d9744cbc994c90932e6f056228e1ffJohn McCall      if (TagDecl)
170723c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor        Actions.ActOnTagDefinitionError(getCurScope(), TagDecl);
1708bd0dfa5c37d422427080a0ae3af9b63e70e6e854John McCall      return;
1709bd0dfa5c37d422427080a0ae3af9b63e70e6e854John McCall    }
1710bd0dfa5c37d422427080a0ae3af9b63e70e6e854John McCall  }
1711bd0dfa5c37d422427080a0ae3af9b63e70e6e854John McCall
1712bd0dfa5c37d422427080a0ae3af9b63e70e6e854John McCall  assert(Tok.is(tok::l_brace));
1713bd0dfa5c37d422427080a0ae3af9b63e70e6e854John McCall
1714bd0dfa5c37d422427080a0ae3af9b63e70e6e854John McCall  SourceLocation LBraceLoc = ConsumeBrace();
1715bd0dfa5c37d422427080a0ae3af9b63e70e6e854John McCall
171642a4f66ffeb26e69b2f0ec873a5d41b0e39e634cJohn McCall  if (TagDecl)
171723c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor    Actions.ActOnStartCXXMemberDeclarations(getCurScope(), TagDecl, LBraceLoc);
1718f9368159334ff86ea5fa367225c1a580977f3b03John McCall
17194cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  // C++ 11p3: Members of a class defined with the keyword class are private
17204cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  // by default. Members of a class defined with the keywords struct or union
17214cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  // are public by default.
17224cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  AccessSpecifier CurAS;
17234cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  if (TagType == DeclSpec::TST_class)
17244cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis    CurAS = AS_private;
17254cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  else
17264cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis    CurAS = AS_public;
17274cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis
172807976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor  SourceLocation RBraceLoc;
172907976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor  if (TagDecl) {
173007976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor    // While we still have something to read, read the member-declarations.
173107976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor    while (Tok.isNot(tok::r_brace) && Tok.isNot(tok::eof)) {
173207976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor      // Each iteration of this loop reads one member-declaration.
173307976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor
173407976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor      // Check for extraneous top-level semicolon.
173507976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor      if (Tok.is(tok::semi)) {
173607976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor        Diag(Tok, diag::ext_extra_struct_semi)
173707976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor          << DeclSpec::getSpecifierName((DeclSpec::TST)TagType)
173807976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor          << FixItHint::CreateRemoval(Tok.getLocation());
173907976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor        ConsumeToken();
174007976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor        continue;
174107976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor      }
17421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
174307976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor      AccessSpecifier AS = getAccessSpecifierIfPresent();
174407976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor      if (AS != AS_none) {
174507976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor        // Current token is a C++ access specifier.
174607976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor        CurAS = AS;
174707976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor        SourceLocation ASLoc = Tok.getLocation();
174807976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor        ConsumeToken();
174907976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor        if (Tok.is(tok::colon))
175007976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor          Actions.ActOnAccessSpecifier(AS, ASLoc, Tok.getLocation());
175107976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor        else
175207976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor          Diag(Tok, diag::err_expected_colon);
175307976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor        ConsumeToken();
175407976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor        continue;
175507976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor      }
17564cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis
175707976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor      // FIXME: Make sure we don't have a template here.
17584cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis
175907976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor      // Parse all the comma separated declarators.
176007976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor      ParseCXXClassMemberDeclaration(CurAS);
176107976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor    }
17621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
176307976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor    RBraceLoc = MatchRHSPunctuation(tok::r_brace, LBraceLoc);
176407976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor  } else {
176507976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor    SkipUntil(tok::r_brace, false, false);
17664cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  }
17671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
17684cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  // If attributes exist after class contents, parse them.
17697f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  ParsedAttributes attrs;
17707f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  MaybeParseGNUAttributes(attrs);
17714cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis
177242a4f66ffeb26e69b2f0ec873a5d41b0e39e634cJohn McCall  if (TagDecl)
177323c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor    Actions.ActOnFinishCXXMemberSpecification(getCurScope(), RecordLoc, TagDecl,
177442a4f66ffeb26e69b2f0ec873a5d41b0e39e634cJohn McCall                                              LBraceLoc, RBraceLoc,
17757f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall                                              attrs.getList());
17764cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis
17774cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  // C++ 9.2p2: Within the class member-specification, the class is regarded as
17784cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  // complete within function bodies, default arguments,
17794cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  // exception-specifications, and constructor ctor-initializers (including
17804cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  // such things in nested classes).
17814cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  //
178272b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor  // FIXME: Only function bodies and constructor ctor-initializers are
178372b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor  // parsed correctly, fix the rest.
178407976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor  if (TagDecl && NonNestedClass) {
17854cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis    // We are not inside a nested class. This class and its nested classes
178672b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor    // are complete and we can parse the delayed portions of method
178772b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor    // declarations and the lexed inline method definitions.
1788e0cc047b1984fc301bbe6e98b6d197bed39ad562Douglas Gregor    SourceLocation SavedPrevTokLocation = PrevTokLocation;
17896569d68745c8213709740337d2be52b031384f58Douglas Gregor    ParseLexedMethodDeclarations(getCurrentClass());
17906569d68745c8213709740337d2be52b031384f58Douglas Gregor    ParseLexedMethodDefs(getCurrentClass());
1791e0cc047b1984fc301bbe6e98b6d197bed39ad562Douglas Gregor    PrevTokLocation = SavedPrevTokLocation;
17924cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  }
17934cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis
179442a4f66ffeb26e69b2f0ec873a5d41b0e39e634cJohn McCall  if (TagDecl)
179523c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor    Actions.ActOnTagFinishDefinition(getCurScope(), TagDecl, RBraceLoc);
1796db7bb4a4e7d9744cbc994c90932e6f056228e1ffJohn McCall
17974cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  // Leave the class scope.
17986569d68745c8213709740337d2be52b031384f58Douglas Gregor  ParsingDef.Pop();
17998935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor  ClassScope.Exit();
18004cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis}
18017ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor
18027ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor/// ParseConstructorInitializer - Parse a C++ constructor initializer,
18037ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor/// which explicitly initializes the members or base classes of a
18047ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor/// class (C++ [class.base.init]). For example, the three initializers
18057ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor/// after the ':' in the Derived constructor below:
18067ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor///
18077ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor/// @code
18087ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor/// class Base { };
18097ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor/// class Derived : Base {
18107ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor///   int x;
18117ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor///   float f;
18127ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor/// public:
18137ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor///   Derived(float f) : Base(), x(17), f(f) { }
18147ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor/// };
18157ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor/// @endcode
18167ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor///
18171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// [C++]  ctor-initializer:
18181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///          ':' mem-initializer-list
18197ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor///
18201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// [C++]  mem-initializer-list:
18213fb9e4b89f72823f162096086f0f964e6dcf66d6Douglas Gregor///          mem-initializer ...[opt]
18223fb9e4b89f72823f162096086f0f964e6dcf66d6Douglas Gregor///          mem-initializer ...[opt] , mem-initializer-list
1823d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallvoid Parser::ParseConstructorInitializer(Decl *ConstructorDecl) {
18247ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor  assert(Tok.is(tok::colon) && "Constructor initializer always starts with ':'");
18257ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor
18267ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor  SourceLocation ColonLoc = ConsumeToken();
18271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1828cbb67480094b3bcb5b715acd827cbad55e2a204cSean Hunt  llvm::SmallVector<CXXCtorInitializer*, 4> MemInitializers;
18299db7dbb918ca49f4ee6c181e4917e7b6ec547353Douglas Gregor  bool AnyErrors = false;
1830193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam
18317ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor  do {
18320133f525a23e18dd444880f7554f25fbcbd834e5Douglas Gregor    if (Tok.is(tok::code_completion)) {
18330133f525a23e18dd444880f7554f25fbcbd834e5Douglas Gregor      Actions.CodeCompleteConstructorInitializer(ConstructorDecl,
18340133f525a23e18dd444880f7554f25fbcbd834e5Douglas Gregor                                                 MemInitializers.data(),
18350133f525a23e18dd444880f7554f25fbcbd834e5Douglas Gregor                                                 MemInitializers.size());
18360133f525a23e18dd444880f7554f25fbcbd834e5Douglas Gregor      ConsumeCodeCompletionToken();
18370133f525a23e18dd444880f7554f25fbcbd834e5Douglas Gregor    } else {
18380133f525a23e18dd444880f7554f25fbcbd834e5Douglas Gregor      MemInitResult MemInit = ParseMemInitializer(ConstructorDecl);
18390133f525a23e18dd444880f7554f25fbcbd834e5Douglas Gregor      if (!MemInit.isInvalid())
18400133f525a23e18dd444880f7554f25fbcbd834e5Douglas Gregor        MemInitializers.push_back(MemInit.get());
18410133f525a23e18dd444880f7554f25fbcbd834e5Douglas Gregor      else
18420133f525a23e18dd444880f7554f25fbcbd834e5Douglas Gregor        AnyErrors = true;
18430133f525a23e18dd444880f7554f25fbcbd834e5Douglas Gregor    }
18440133f525a23e18dd444880f7554f25fbcbd834e5Douglas Gregor
18457ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor    if (Tok.is(tok::comma))
18467ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor      ConsumeToken();
18477ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor    else if (Tok.is(tok::l_brace))
18487ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor      break;
1849b1f6fa48960eae269a3931d1fc545ed468d9a4d2Douglas Gregor    // If the next token looks like a base or member initializer, assume that
1850b1f6fa48960eae269a3931d1fc545ed468d9a4d2Douglas Gregor    // we're just missing a comma.
1851751f6922376dfe9432795b65a3649179e4ef5cf5Douglas Gregor    else if (Tok.is(tok::identifier) || Tok.is(tok::coloncolon)) {
1852751f6922376dfe9432795b65a3649179e4ef5cf5Douglas Gregor      SourceLocation Loc = PP.getLocForEndOfToken(PrevTokLocation);
1853751f6922376dfe9432795b65a3649179e4ef5cf5Douglas Gregor      Diag(Loc, diag::err_ctor_init_missing_comma)
1854751f6922376dfe9432795b65a3649179e4ef5cf5Douglas Gregor        << FixItHint::CreateInsertion(Loc, ", ");
1855751f6922376dfe9432795b65a3649179e4ef5cf5Douglas Gregor    } else {
18567ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor      // Skip over garbage, until we get to '{'.  Don't eat the '{'.
1857d3a413d3b8eb39bcee5944bc545d9997c1abe492Sebastian Redl      Diag(Tok.getLocation(), diag::err_expected_lbrace_or_comma);
18587ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor      SkipUntil(tok::l_brace, true, true);
18597ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor      break;
18607ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor    }
18617ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor  } while (true);
18627ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor
18631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Actions.ActOnMemInitializers(ConstructorDecl, ColonLoc,
18649db7dbb918ca49f4ee6c181e4917e7b6ec547353Douglas Gregor                               MemInitializers.data(), MemInitializers.size(),
18659db7dbb918ca49f4ee6c181e4917e7b6ec547353Douglas Gregor                               AnyErrors);
18667ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor}
18677ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor
18687ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor/// ParseMemInitializer - Parse a C++ member initializer, which is
18697ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor/// part of a constructor initializer that explicitly initializes one
18707ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor/// member or base class (C++ [class.base.init]). See
18717ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor/// ParseConstructorInitializer for an example.
18727ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor///
18737ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor/// [C++] mem-initializer:
18747ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor///         mem-initializer-id '(' expression-list[opt] ')'
18751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///
18767ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor/// [C++] mem-initializer-id:
18777ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor///         '::'[opt] nested-name-specifier[opt] class-name
18787ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor///         identifier
1879d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallParser::MemInitResult Parser::ParseMemInitializer(Decl *ConstructorDecl) {
1880bcfad54a43e5570e09daddd976bd4545933e75b1Fariborz Jahanian  // parse '::'[opt] nested-name-specifier[opt]
1881bcfad54a43e5570e09daddd976bd4545933e75b1Fariborz Jahanian  CXXScopeSpec SS;
1882b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  ParseOptionalCXXScopeSpecifier(SS, ParsedType(), false);
1883b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  ParsedType TemplateTypeTy;
1884961743326fd18776f897bf4461345dba680ef637Fariborz Jahanian  if (Tok.is(tok::annot_template_id)) {
1885961743326fd18776f897bf4461345dba680ef637Fariborz Jahanian    TemplateIdAnnotation *TemplateId
1886961743326fd18776f897bf4461345dba680ef637Fariborz Jahanian      = static_cast<TemplateIdAnnotation *>(Tok.getAnnotationValue());
1887d9b600c1a589200be905c53e2e10fceb57efa18dDouglas Gregor    if (TemplateId->Kind == TNK_Type_template ||
1888d9b600c1a589200be905c53e2e10fceb57efa18dDouglas Gregor        TemplateId->Kind == TNK_Dependent_template_name) {
1889961743326fd18776f897bf4461345dba680ef637Fariborz Jahanian      AnnotateTemplateIdTokenAsType(&SS);
1890961743326fd18776f897bf4461345dba680ef637Fariborz Jahanian      assert(Tok.is(tok::annot_typename) && "template-id -> type failed");
1891b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall      TemplateTypeTy = getTypeAnnotation(Tok);
1892961743326fd18776f897bf4461345dba680ef637Fariborz Jahanian    }
1893961743326fd18776f897bf4461345dba680ef637Fariborz Jahanian  }
1894961743326fd18776f897bf4461345dba680ef637Fariborz Jahanian  if (!TemplateTypeTy && Tok.isNot(tok::identifier)) {
18951ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner    Diag(Tok, diag::err_expected_member_or_base_name);
18967ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor    return true;
18977ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor  }
18981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
18997ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor  // Get the identifier. This may be a member name or a class name,
19007ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor  // but we'll let the semantic analysis determine which it is.
1901961743326fd18776f897bf4461345dba680ef637Fariborz Jahanian  IdentifierInfo *II = Tok.is(tok::identifier) ? Tok.getIdentifierInfo() : 0;
19027ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor  SourceLocation IdLoc = ConsumeToken();
19037ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor
19047ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor  // Parse the '('.
19057ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor  if (Tok.isNot(tok::l_paren)) {
19061ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner    Diag(Tok, diag::err_expected_lparen);
19077ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor    return true;
19087ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor  }
19097ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor  SourceLocation LParenLoc = ConsumeParen();
19107ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor
19117ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor  // Parse the optional expression-list.
1912a55e52c0802cae3b7c366a05c461d3d15074c1a3Sebastian Redl  ExprVector ArgExprs(Actions);
19137ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor  CommaLocsTy CommaLocs;
19147ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor  if (Tok.isNot(tok::r_paren) && ParseExpressionList(ArgExprs, CommaLocs)) {
19157ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor    SkipUntil(tok::r_paren);
19167ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor    return true;
19177ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor  }
19187ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor
19197ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor  SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc);
19207ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor
19213fb9e4b89f72823f162096086f0f964e6dcf66d6Douglas Gregor  SourceLocation EllipsisLoc;
19223fb9e4b89f72823f162096086f0f964e6dcf66d6Douglas Gregor  if (Tok.is(tok::ellipsis))
19233fb9e4b89f72823f162096086f0f964e6dcf66d6Douglas Gregor    EllipsisLoc = ConsumeToken();
19243fb9e4b89f72823f162096086f0f964e6dcf66d6Douglas Gregor
192523c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor  return Actions.ActOnMemInitializer(ConstructorDecl, getCurScope(), SS, II,
1926961743326fd18776f897bf4461345dba680ef637Fariborz Jahanian                                     TemplateTypeTy, IdLoc,
1927a55e52c0802cae3b7c366a05c461d3d15074c1a3Sebastian Redl                                     LParenLoc, ArgExprs.take(),
19283fb9e4b89f72823f162096086f0f964e6dcf66d6Douglas Gregor                                     ArgExprs.size(), RParenLoc,
19293fb9e4b89f72823f162096086f0f964e6dcf66d6Douglas Gregor                                     EllipsisLoc);
19307ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor}
19310fe7bea6fca9737c6c145aaa4a2ad3abe595782aDouglas Gregor
19320fe7bea6fca9737c6c145aaa4a2ad3abe595782aDouglas Gregor/// ParseExceptionSpecification - Parse a C++ exception-specification
19330fe7bea6fca9737c6c145aaa4a2ad3abe595782aDouglas Gregor/// (C++ [except.spec]).
19340fe7bea6fca9737c6c145aaa4a2ad3abe595782aDouglas Gregor///
1935a4745616ebe36ba7699f18618382e764aa8183a1Douglas Gregor///       exception-specification:
1936a4745616ebe36ba7699f18618382e764aa8183a1Douglas Gregor///         'throw' '(' type-id-list [opt] ')'
1937a4745616ebe36ba7699f18618382e764aa8183a1Douglas Gregor/// [MS]    'throw' '(' '...' ')'
19381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///
1939a4745616ebe36ba7699f18618382e764aa8183a1Douglas Gregor///       type-id-list:
1940a04426c5416f22df1078f6b31c1619de73c40b59Douglas Gregor///         type-id ... [opt]
1941a04426c5416f22df1078f6b31c1619de73c40b59Douglas Gregor///         type-id-list ',' type-id ... [opt]
19420fe7bea6fca9737c6c145aaa4a2ad3abe595782aDouglas Gregor///
19437dc813462dd9fd3f6f4296f896a12de14264fef8Sebastian Redlbool Parser::ParseExceptionSpecification(SourceLocation &EndLoc,
1944b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                                         llvm::SmallVectorImpl<ParsedType>
1945ef65f06e8e440aec541442cfd73a8a836e9bc842Sebastian Redl                                             &Exceptions,
1946b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                                         llvm::SmallVectorImpl<SourceRange>
1947ef65f06e8e440aec541442cfd73a8a836e9bc842Sebastian Redl                                             &Ranges,
19487dc813462dd9fd3f6f4296f896a12de14264fef8Sebastian Redl                                         bool &hasAnyExceptionSpec) {
19490fe7bea6fca9737c6c145aaa4a2ad3abe595782aDouglas Gregor  assert(Tok.is(tok::kw_throw) && "expected throw");
19501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1951dec0984fce504a39a7f085774fb67cfd9957be58Jeffrey Yasskin  ConsumeToken();
19521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
19530fe7bea6fca9737c6c145aaa4a2ad3abe595782aDouglas Gregor  if (!Tok.is(tok::l_paren)) {
19540fe7bea6fca9737c6c145aaa4a2ad3abe595782aDouglas Gregor    return Diag(Tok, diag::err_expected_lparen_after) << "throw";
19550fe7bea6fca9737c6c145aaa4a2ad3abe595782aDouglas Gregor  }
19560fe7bea6fca9737c6c145aaa4a2ad3abe595782aDouglas Gregor  SourceLocation LParenLoc = ConsumeParen();
19570fe7bea6fca9737c6c145aaa4a2ad3abe595782aDouglas Gregor
1958a4745616ebe36ba7699f18618382e764aa8183a1Douglas Gregor  // Parse throw(...), a Microsoft extension that means "this function
1959a4745616ebe36ba7699f18618382e764aa8183a1Douglas Gregor  // can throw anything".
1960a4745616ebe36ba7699f18618382e764aa8183a1Douglas Gregor  if (Tok.is(tok::ellipsis)) {
19617dc813462dd9fd3f6f4296f896a12de14264fef8Sebastian Redl    hasAnyExceptionSpec = true;
1962a4745616ebe36ba7699f18618382e764aa8183a1Douglas Gregor    SourceLocation EllipsisLoc = ConsumeToken();
1963a4745616ebe36ba7699f18618382e764aa8183a1Douglas Gregor    if (!getLang().Microsoft)
1964a4745616ebe36ba7699f18618382e764aa8183a1Douglas Gregor      Diag(EllipsisLoc, diag::ext_ellipsis_exception_spec);
1965ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl    EndLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc);
1966a4745616ebe36ba7699f18618382e764aa8183a1Douglas Gregor    return false;
1967a4745616ebe36ba7699f18618382e764aa8183a1Douglas Gregor  }
1968a4745616ebe36ba7699f18618382e764aa8183a1Douglas Gregor
19690fe7bea6fca9737c6c145aaa4a2ad3abe595782aDouglas Gregor  // Parse the sequence of type-ids.
1970ef65f06e8e440aec541442cfd73a8a836e9bc842Sebastian Redl  SourceRange Range;
19710fe7bea6fca9737c6c145aaa4a2ad3abe595782aDouglas Gregor  while (Tok.isNot(tok::r_paren)) {
1972ef65f06e8e440aec541442cfd73a8a836e9bc842Sebastian Redl    TypeResult Res(ParseTypeName(&Range));
1973a04426c5416f22df1078f6b31c1619de73c40b59Douglas Gregor
1974a04426c5416f22df1078f6b31c1619de73c40b59Douglas Gregor    if (Tok.is(tok::ellipsis)) {
1975a04426c5416f22df1078f6b31c1619de73c40b59Douglas Gregor      // C++0x [temp.variadic]p5:
1976a04426c5416f22df1078f6b31c1619de73c40b59Douglas Gregor      //   - In a dynamic-exception-specification (15.4); the pattern is a
1977a04426c5416f22df1078f6b31c1619de73c40b59Douglas Gregor      //     type-id.
1978a04426c5416f22df1078f6b31c1619de73c40b59Douglas Gregor      SourceLocation Ellipsis = ConsumeToken();
1979a04426c5416f22df1078f6b31c1619de73c40b59Douglas Gregor      if (!Res.isInvalid())
1980a04426c5416f22df1078f6b31c1619de73c40b59Douglas Gregor        Res = Actions.ActOnPackExpansion(Res.get(), Ellipsis);
1981a04426c5416f22df1078f6b31c1619de73c40b59Douglas Gregor    }
1982a04426c5416f22df1078f6b31c1619de73c40b59Douglas Gregor
1983ef65f06e8e440aec541442cfd73a8a836e9bc842Sebastian Redl    if (!Res.isInvalid()) {
19847dc813462dd9fd3f6f4296f896a12de14264fef8Sebastian Redl      Exceptions.push_back(Res.get());
1985ef65f06e8e440aec541442cfd73a8a836e9bc842Sebastian Redl      Ranges.push_back(Range);
1986ef65f06e8e440aec541442cfd73a8a836e9bc842Sebastian Redl    }
1987a04426c5416f22df1078f6b31c1619de73c40b59Douglas Gregor
19880fe7bea6fca9737c6c145aaa4a2ad3abe595782aDouglas Gregor    if (Tok.is(tok::comma))
19890fe7bea6fca9737c6c145aaa4a2ad3abe595782aDouglas Gregor      ConsumeToken();
19907dc813462dd9fd3f6f4296f896a12de14264fef8Sebastian Redl    else
19910fe7bea6fca9737c6c145aaa4a2ad3abe595782aDouglas Gregor      break;
19920fe7bea6fca9737c6c145aaa4a2ad3abe595782aDouglas Gregor  }
19930fe7bea6fca9737c6c145aaa4a2ad3abe595782aDouglas Gregor
1994ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl  EndLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc);
19950fe7bea6fca9737c6c145aaa4a2ad3abe595782aDouglas Gregor  return false;
19960fe7bea6fca9737c6c145aaa4a2ad3abe595782aDouglas Gregor}
19976569d68745c8213709740337d2be52b031384f58Douglas Gregor
1998dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor/// ParseTrailingReturnType - Parse a trailing return type on a new-style
1999dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor/// function declaration.
2000dab60ad68a3a98d687305941a3852e793705f945Douglas GregorTypeResult Parser::ParseTrailingReturnType() {
2001dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  assert(Tok.is(tok::arrow) && "expected arrow");
2002dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor
2003dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  ConsumeToken();
2004dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor
2005dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  // FIXME: Need to suppress declarations when parsing this typename.
2006dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  // Otherwise in this function definition:
2007dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  //
2008dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  //   auto f() -> struct X {}
2009dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  //
2010dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  // struct X is parsed as class definition because of the trailing
2011dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  // brace.
2012dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor
2013dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  SourceRange Range;
2014dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  return ParseTypeName(&Range);
2015dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor}
2016dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor
20176569d68745c8213709740337d2be52b031384f58Douglas Gregor/// \brief We have just started parsing the definition of a new class,
20186569d68745c8213709740337d2be52b031384f58Douglas Gregor/// so push that class onto our stack of classes that is currently
20196569d68745c8213709740337d2be52b031384f58Douglas Gregor/// being parsed.
2020d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallvoid Parser::PushParsingClass(Decl *ClassDecl, bool NonNestedClass) {
202126997fd58c9560584edd154618f2f2c15ee68af4Douglas Gregor  assert((NonNestedClass || !ClassStack.empty()) &&
20226569d68745c8213709740337d2be52b031384f58Douglas Gregor         "Nested class without outer class");
202326997fd58c9560584edd154618f2f2c15ee68af4Douglas Gregor  ClassStack.push(new ParsingClass(ClassDecl, NonNestedClass));
20246569d68745c8213709740337d2be52b031384f58Douglas Gregor}
20256569d68745c8213709740337d2be52b031384f58Douglas Gregor
20266569d68745c8213709740337d2be52b031384f58Douglas Gregor/// \brief Deallocate the given parsed class and all of its nested
20276569d68745c8213709740337d2be52b031384f58Douglas Gregor/// classes.
20286569d68745c8213709740337d2be52b031384f58Douglas Gregorvoid Parser::DeallocateParsedClasses(Parser::ParsingClass *Class) {
2029d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  for (unsigned I = 0, N = Class->LateParsedDeclarations.size(); I != N; ++I)
2030d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor    delete Class->LateParsedDeclarations[I];
20316569d68745c8213709740337d2be52b031384f58Douglas Gregor  delete Class;
20326569d68745c8213709740337d2be52b031384f58Douglas Gregor}
20336569d68745c8213709740337d2be52b031384f58Douglas Gregor
20346569d68745c8213709740337d2be52b031384f58Douglas Gregor/// \brief Pop the top class of the stack of classes that are
20356569d68745c8213709740337d2be52b031384f58Douglas Gregor/// currently being parsed.
20366569d68745c8213709740337d2be52b031384f58Douglas Gregor///
20376569d68745c8213709740337d2be52b031384f58Douglas Gregor/// This routine should be called when we have finished parsing the
20386569d68745c8213709740337d2be52b031384f58Douglas Gregor/// definition of a class, but have not yet popped the Scope
20396569d68745c8213709740337d2be52b031384f58Douglas Gregor/// associated with the class's definition.
20406569d68745c8213709740337d2be52b031384f58Douglas Gregor///
20416569d68745c8213709740337d2be52b031384f58Douglas Gregor/// \returns true if the class we've popped is a top-level class,
20426569d68745c8213709740337d2be52b031384f58Douglas Gregor/// false otherwise.
20436569d68745c8213709740337d2be52b031384f58Douglas Gregorvoid Parser::PopParsingClass() {
20446569d68745c8213709740337d2be52b031384f58Douglas Gregor  assert(!ClassStack.empty() && "Mismatched push/pop for class parsing");
20451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
20466569d68745c8213709740337d2be52b031384f58Douglas Gregor  ParsingClass *Victim = ClassStack.top();
20476569d68745c8213709740337d2be52b031384f58Douglas Gregor  ClassStack.pop();
20486569d68745c8213709740337d2be52b031384f58Douglas Gregor  if (Victim->TopLevelClass) {
20496569d68745c8213709740337d2be52b031384f58Douglas Gregor    // Deallocate all of the nested classes of this class,
20506569d68745c8213709740337d2be52b031384f58Douglas Gregor    // recursively: we don't need to keep any of this information.
20516569d68745c8213709740337d2be52b031384f58Douglas Gregor    DeallocateParsedClasses(Victim);
20526569d68745c8213709740337d2be52b031384f58Douglas Gregor    return;
20531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
20546569d68745c8213709740337d2be52b031384f58Douglas Gregor  assert(!ClassStack.empty() && "Missing top-level class?");
20556569d68745c8213709740337d2be52b031384f58Douglas Gregor
2056d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  if (Victim->LateParsedDeclarations.empty()) {
20576569d68745c8213709740337d2be52b031384f58Douglas Gregor    // The victim is a nested class, but we will not need to perform
20586569d68745c8213709740337d2be52b031384f58Douglas Gregor    // any processing after the definition of this class since it has
20596569d68745c8213709740337d2be52b031384f58Douglas Gregor    // no members whose handling was delayed. Therefore, we can just
20606569d68745c8213709740337d2be52b031384f58Douglas Gregor    // remove this nested class.
2061d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor    DeallocateParsedClasses(Victim);
20626569d68745c8213709740337d2be52b031384f58Douglas Gregor    return;
20636569d68745c8213709740337d2be52b031384f58Douglas Gregor  }
20646569d68745c8213709740337d2be52b031384f58Douglas Gregor
20656569d68745c8213709740337d2be52b031384f58Douglas Gregor  // This nested class has some members that will need to be processed
20666569d68745c8213709740337d2be52b031384f58Douglas Gregor  // after the top-level class is completely defined. Therefore, add
20676569d68745c8213709740337d2be52b031384f58Douglas Gregor  // it to the list of nested classes within its parent.
206823c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor  assert(getCurScope()->isClassScope() && "Nested class outside of class scope?");
2069d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  ClassStack.top()->LateParsedDeclarations.push_back(new LateParsedClass(this, Victim));
207023c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor  Victim->TemplateScope = getCurScope()->getParent()->isTemplateParamScope();
20716569d68745c8213709740337d2be52b031384f58Douglas Gregor}
2072bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt
2073bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// ParseCXX0XAttributes - Parse a C++0x attribute-specifier. Currently only
2074bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// parses standard attributes.
2075bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt///
2076bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// [C++0x] attribute-specifier:
2077bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt///         '[' '[' attribute-list ']' ']'
2078bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt///
2079bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// [C++0x] attribute-list:
2080bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt///         attribute[opt]
2081bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt///         attribute-list ',' attribute[opt]
2082bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt///
2083bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// [C++0x] attribute:
2084bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt///         attribute-token attribute-argument-clause[opt]
2085bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt///
2086bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// [C++0x] attribute-token:
2087bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt///         identifier
2088bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt///         attribute-scoped-token
2089bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt///
2090bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// [C++0x] attribute-scoped-token:
2091bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt///         attribute-namespace '::' identifier
2092bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt///
2093bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// [C++0x] attribute-namespace:
2094bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt///         identifier
2095bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt///
2096bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// [C++0x] attribute-argument-clause:
2097bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt///         '(' balanced-token-seq ')'
2098bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt///
2099bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// [C++0x] balanced-token-seq:
2100bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt///         balanced-token
2101bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt///         balanced-token-seq balanced-token
2102bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt///
2103bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// [C++0x] balanced-token:
2104bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt///         '(' balanced-token-seq ')'
2105bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt///         '[' balanced-token-seq ']'
2106bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt///         '{' balanced-token-seq '}'
2107bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt///         any token but '(', ')', '[', ']', '{', or '}'
21087f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCallvoid Parser::ParseCXX0XAttributes(ParsedAttributesWithRange &attrs,
21097f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall                                  SourceLocation *endLoc) {
2110bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt  assert(Tok.is(tok::l_square) && NextToken().is(tok::l_square)
2111bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt      && "Not a C++0x attribute list");
2112bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt
2113bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt  SourceLocation StartLoc = Tok.getLocation(), Loc;
2114bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt
2115bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt  ConsumeBracket();
2116bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt  ConsumeBracket();
2117193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam
2118bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt  if (Tok.is(tok::comma)) {
2119bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt    Diag(Tok.getLocation(), diag::err_expected_ident);
2120bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt    ConsumeToken();
2121bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt  }
2122bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt
2123bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt  while (Tok.is(tok::identifier) || Tok.is(tok::comma)) {
2124bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt    // attribute not present
2125bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt    if (Tok.is(tok::comma)) {
2126bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt      ConsumeToken();
2127bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt      continue;
2128bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt    }
2129bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt
2130bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt    IdentifierInfo *ScopeName = 0, *AttrName = Tok.getIdentifierInfo();
2131bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt    SourceLocation ScopeLoc, AttrLoc = ConsumeToken();
2132193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam
2133bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt    // scoped attribute
2134bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt    if (Tok.is(tok::coloncolon)) {
2135bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt      ConsumeToken();
2136bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt
2137bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt      if (!Tok.is(tok::identifier)) {
2138bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt        Diag(Tok.getLocation(), diag::err_expected_ident);
2139bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt        SkipUntil(tok::r_square, tok::comma, true, true);
2140bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt        continue;
2141bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt      }
2142193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam
2143bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt      ScopeName = AttrName;
2144bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt      ScopeLoc = AttrLoc;
2145bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt
2146bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt      AttrName = Tok.getIdentifierInfo();
2147bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt      AttrLoc = ConsumeToken();
2148bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt    }
2149bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt
2150bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt    bool AttrParsed = false;
2151bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt    // No scoped names are supported; ideally we could put all non-standard
2152bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt    // attributes into namespaces.
2153bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt    if (!ScopeName) {
2154bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt      switch(AttributeList::getKind(AttrName))
2155bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt      {
2156bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt      // No arguments
21577725e67639fa2fe74f8775b7ed884a076ffdbffcSean Hunt      case AttributeList::AT_base_check:
21587725e67639fa2fe74f8775b7ed884a076ffdbffcSean Hunt      case AttributeList::AT_carries_dependency:
2159bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt      case AttributeList::AT_final:
21607725e67639fa2fe74f8775b7ed884a076ffdbffcSean Hunt      case AttributeList::AT_hiding:
21617725e67639fa2fe74f8775b7ed884a076ffdbffcSean Hunt      case AttributeList::AT_noreturn:
21627725e67639fa2fe74f8775b7ed884a076ffdbffcSean Hunt      case AttributeList::AT_override: {
2163bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt        if (Tok.is(tok::l_paren)) {
2164bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt          Diag(Tok.getLocation(), diag::err_cxx0x_attribute_forbids_arguments)
2165bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt            << AttrName->getName();
2166bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt          break;
2167bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt        }
2168bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt
21697f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall        attrs.add(AttrFactory.Create(AttrName, AttrLoc, 0, AttrLoc, 0,
21707f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall                                     SourceLocation(), 0, 0, false, true));
2171bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt        AttrParsed = true;
2172bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt        break;
2173bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt      }
2174bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt
2175bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt      // One argument; must be a type-id or assignment-expression
2176bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt      case AttributeList::AT_aligned: {
2177bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt        if (Tok.isNot(tok::l_paren)) {
2178bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt          Diag(Tok.getLocation(), diag::err_cxx0x_attribute_requires_arguments)
2179bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt            << AttrName->getName();
2180bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt          break;
2181bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt        }
2182bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt        SourceLocation ParamLoc = ConsumeParen();
2183bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt
218460d7b3a319d84d688752be3870615ac0f111fb16John McCall        ExprResult ArgExpr = ParseCXX0XAlignArgument(ParamLoc);
2185bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt
2186bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt        MatchRHSPunctuation(tok::r_paren, ParamLoc);
2187bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt
2188bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt        ExprVector ArgExprs(Actions);
2189bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt        ArgExprs.push_back(ArgExpr.release());
21907f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall        attrs.add(AttrFactory.Create(AttrName, AttrLoc, 0, AttrLoc,
21917f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall                                     0, ParamLoc, ArgExprs.take(), 1,
21927f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall                                     false, true));
2193bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt
2194bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt        AttrParsed = true;
2195bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt        break;
2196bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt      }
2197bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt
2198bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt      // Silence warnings
2199bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt      default: break;
2200bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt      }
2201bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt    }
2202bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt
2203bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt    // Skip the entire parameter clause, if any
2204bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt    if (!AttrParsed && Tok.is(tok::l_paren)) {
2205bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt      ConsumeParen();
2206bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt      // SkipUntil maintains the balancedness of tokens.
2207bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt      SkipUntil(tok::r_paren, false);
2208bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt    }
2209bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt  }
2210bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt
2211bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt  if (ExpectAndConsume(tok::r_square, diag::err_expected_rsquare))
2212bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt    SkipUntil(tok::r_square, false);
2213bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt  Loc = Tok.getLocation();
2214bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt  if (ExpectAndConsume(tok::r_square, diag::err_expected_rsquare))
2215bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt    SkipUntil(tok::r_square, false);
2216bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt
22177f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  attrs.Range = SourceRange(StartLoc, Loc);
2218bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt}
2219bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt
2220bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// ParseCXX0XAlignArgument - Parse the argument to C++0x's [[align]]
2221bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// attribute.
2222bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt///
2223bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// FIXME: Simply returns an alignof() expression if the argument is a
2224bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// type. Ideally, the type should be propagated directly into Sema.
2225bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt///
2226bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// [C++0x] 'align' '(' type-id ')'
2227bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// [C++0x] 'align' '(' assignment-expression ')'
222860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult Parser::ParseCXX0XAlignArgument(SourceLocation Start) {
2229bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt  if (isTypeIdInParens()) {
2230f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    EnterExpressionEvaluationContext Unevaluated(Actions, Sema::Unevaluated);
2231bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt    SourceLocation TypeLoc = Tok.getLocation();
2232b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    ParsedType Ty = ParseTypeName().get();
2233bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt    SourceRange TypeRange(Start, Tok.getLocation());
2234b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    return Actions.ActOnSizeOfAlignOfExpr(TypeLoc, false, true,
2235b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                                          Ty.getAsOpaquePtr(), TypeRange);
2236bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt  } else
2237bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt    return ParseConstantExpression();
2238bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt}
2239334d47e92e9f241576fdeb7477b69a03136ba854Francois Pichet
2240334d47e92e9f241576fdeb7477b69a03136ba854Francois Pichet/// ParseMicrosoftAttributes - Parse a Microsoft attribute [Attr]
2241334d47e92e9f241576fdeb7477b69a03136ba854Francois Pichet///
2242334d47e92e9f241576fdeb7477b69a03136ba854Francois Pichet/// [MS] ms-attribute:
2243334d47e92e9f241576fdeb7477b69a03136ba854Francois Pichet///             '[' token-seq ']'
2244334d47e92e9f241576fdeb7477b69a03136ba854Francois Pichet///
2245334d47e92e9f241576fdeb7477b69a03136ba854Francois Pichet/// [MS] ms-attribute-seq:
2246334d47e92e9f241576fdeb7477b69a03136ba854Francois Pichet///             ms-attribute[opt]
2247334d47e92e9f241576fdeb7477b69a03136ba854Francois Pichet///             ms-attribute ms-attribute-seq
22487f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCallvoid Parser::ParseMicrosoftAttributes(ParsedAttributes &attrs,
22497f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall                                      SourceLocation *endLoc) {
2250334d47e92e9f241576fdeb7477b69a03136ba854Francois Pichet  assert(Tok.is(tok::l_square) && "Not a Microsoft attribute list");
2251334d47e92e9f241576fdeb7477b69a03136ba854Francois Pichet
2252334d47e92e9f241576fdeb7477b69a03136ba854Francois Pichet  while (Tok.is(tok::l_square)) {
2253334d47e92e9f241576fdeb7477b69a03136ba854Francois Pichet    ConsumeBracket();
2254334d47e92e9f241576fdeb7477b69a03136ba854Francois Pichet    SkipUntil(tok::r_square, true, true);
22557f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall    if (endLoc) *endLoc = Tok.getLocation();
2256334d47e92e9f241576fdeb7477b69a03136ba854Francois Pichet    ExpectAndConsume(tok::r_square, diag::err_expected_rsquare);
2257334d47e92e9f241576fdeb7477b69a03136ba854Francois Pichet  }
2258334d47e92e9f241576fdeb7477b69a03136ba854Francois Pichet}
2259