ParseDeclCXX.cpp revision e4246a633b13197634225971b25df0cbdcec0c5d
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. 720b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall ParsedAttributes attrs(AttrFactory); 736a588dd230c14a364d222d6057bbcf11afbd9ffdDouglas Gregor if (Tok.is(tok::kw___attribute)) { 746a588dd230c14a364d222d6057bbcf11afbd9ffdDouglas Gregor attrTok = Tok; 757f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall ParseGNUAttributes(attrs); 766a588dd230c14a364d222d6057bbcf11afbd9ffdDouglas Gregor } 771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 786a588dd230c14a364d222d6057bbcf11afbd9ffdDouglas Gregor if (Tok.is(tok::equal)) { 797f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall if (!attrs.empty()) 806a588dd230c14a364d222d6057bbcf11afbd9ffdDouglas Gregor Diag(attrTok, diag::err_unexpected_namespace_attributes_alias); 81d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl if (InlineLoc.isValid()) 82d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl Diag(InlineLoc, diag::err_inline_namespace_alias) 83d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl << FixItHint::CreateRemoval(InlineLoc); 846a588dd230c14a364d222d6057bbcf11afbd9ffdDouglas Gregor 8597144fc41a9419bf6d74fc9450e8ef3f6e11f7e0Chris Lattner return ParseNamespaceAlias(NamespaceLoc, IdentLoc, Ident, DeclEnd); 866a588dd230c14a364d222d6057bbcf11afbd9ffdDouglas Gregor } 871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 885144832ae62cf97543b274d4bb88d5f74d0f7a20Chris Lattner if (Tok.isNot(tok::l_brace)) { 891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Diag(Tok, Ident ? diag::err_expected_lbrace : 905144832ae62cf97543b274d4bb88d5f74d0f7a20Chris Lattner diag::err_expected_ident_lbrace); 91d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 925144832ae62cf97543b274d4bb88d5f74d0f7a20Chris Lattner } 931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 945144832ae62cf97543b274d4bb88d5f74d0f7a20Chris Lattner SourceLocation LBrace = ConsumeBrace(); 952d1c5d313cd0c229cc614e74baa4c5756a4b46f4Argyrios Kyrtzidis 9623c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor if (getCurScope()->isClassScope() || getCurScope()->isTemplateParamScope() || 9723c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor getCurScope()->isInObjcMethodScope() || getCurScope()->getBlockParent() || 9823c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor getCurScope()->getFnParent()) { 9995f1b15ce1b281c8517d77792abe540753fbcc12Douglas Gregor Diag(LBrace, diag::err_namespace_nonnamespace_scope); 10095f1b15ce1b281c8517d77792abe540753fbcc12Douglas Gregor SkipUntil(tok::r_brace, false); 101d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 10295f1b15ce1b281c8517d77792abe540753fbcc12Douglas Gregor } 10395f1b15ce1b281c8517d77792abe540753fbcc12Douglas Gregor 10488e64ca96d6c00c6f3bd43772cd325bede795d2aSebastian Redl // If we're still good, complain about inline namespaces in non-C++0x now. 10588e64ca96d6c00c6f3bd43772cd325bede795d2aSebastian Redl if (!getLang().CPlusPlus0x && InlineLoc.isValid()) 10688e64ca96d6c00c6f3bd43772cd325bede795d2aSebastian Redl Diag(InlineLoc, diag::ext_inline_namespace); 10788e64ca96d6c00c6f3bd43772cd325bede795d2aSebastian Redl 1085144832ae62cf97543b274d4bb88d5f74d0f7a20Chris Lattner // Enter a scope for the namespace. 1095144832ae62cf97543b274d4bb88d5f74d0f7a20Chris Lattner ParseScope NamespaceScope(this, Scope::DeclScope); 1102d1c5d313cd0c229cc614e74baa4c5756a4b46f4Argyrios Kyrtzidis 111d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *NamespcDecl = 112acba90f30876b4140b738f0d3dd0e50724053a96Abramo Bagnara Actions.ActOnStartNamespaceDef(getCurScope(), InlineLoc, NamespaceLoc, 113acba90f30876b4140b738f0d3dd0e50724053a96Abramo Bagnara IdentLoc, Ident, LBrace, attrs.getList()); 1142d1c5d313cd0c229cc614e74baa4c5756a4b46f4Argyrios Kyrtzidis 115f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall PrettyDeclStackTraceEntry CrashInfo(Actions, NamespcDecl, NamespaceLoc, 116f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall "parsing namespace"); 1171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 118bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt while (Tok.isNot(tok::r_brace) && Tok.isNot(tok::eof)) { 1190b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall ParsedAttributesWithRange attrs(AttrFactory); 1207f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall MaybeParseCXX0XAttributes(attrs); 1217f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall MaybeParseMicrosoftAttributes(attrs); 1227f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall ParseExternalDeclaration(attrs); 123bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt } 1241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1255144832ae62cf97543b274d4bb88d5f74d0f7a20Chris Lattner // Leave the namespace scope. 1265144832ae62cf97543b274d4bb88d5f74d0f7a20Chris Lattner NamespaceScope.Exit(); 1278ba5d792032f475eb653ca6340eb51068df0fa90Argyrios Kyrtzidis 12897144fc41a9419bf6d74fc9450e8ef3f6e11f7e0Chris Lattner SourceLocation RBraceLoc = MatchRHSPunctuation(tok::r_brace, LBrace); 12997144fc41a9419bf6d74fc9450e8ef3f6e11f7e0Chris Lattner Actions.ActOnFinishNamespaceDef(NamespcDecl, RBraceLoc); 1302d1c5d313cd0c229cc614e74baa4c5756a4b46f4Argyrios Kyrtzidis 13197144fc41a9419bf6d74fc9450e8ef3f6e11f7e0Chris Lattner DeclEnd = RBraceLoc; 1325144832ae62cf97543b274d4bb88d5f74d0f7a20Chris Lattner return NamespcDecl; 1338f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner} 134c6fdc34ac0183bfa03d65f317c78b7bdac52897eChris Lattner 135f67606ae2febe3bb0718f05040c6c4bc2c2c3276Anders Carlsson/// ParseNamespaceAlias - Parse the part after the '=' in a namespace 136f67606ae2febe3bb0718f05040c6c4bc2c2c3276Anders Carlsson/// alias definition. 137f67606ae2febe3bb0718f05040c6c4bc2c2c3276Anders Carlsson/// 138d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseNamespaceAlias(SourceLocation NamespaceLoc, 1390b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall SourceLocation AliasLoc, 1400b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall IdentifierInfo *Alias, 1410b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall SourceLocation &DeclEnd) { 142f67606ae2febe3bb0718f05040c6c4bc2c2c3276Anders Carlsson assert(Tok.is(tok::equal) && "Not equal token"); 1431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 144f67606ae2febe3bb0718f05040c6c4bc2c2c3276Anders Carlsson ConsumeToken(); // eat the '='. 1451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14649f40bd0c9c9de5e74727774fec429b47d36303aDouglas Gregor if (Tok.is(tok::code_completion)) { 14723c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteNamespaceAliasDecl(getCurScope()); 148dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 14949f40bd0c9c9de5e74727774fec429b47d36303aDouglas Gregor } 150193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam 151f67606ae2febe3bb0718f05040c6c4bc2c2c3276Anders Carlsson CXXScopeSpec SS; 152f67606ae2febe3bb0718f05040c6c4bc2c2c3276Anders Carlsson // Parse (optional) nested-name-specifier. 153b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParseOptionalCXXScopeSpecifier(SS, ParsedType(), false); 154f67606ae2febe3bb0718f05040c6c4bc2c2c3276Anders Carlsson 155f67606ae2febe3bb0718f05040c6c4bc2c2c3276Anders Carlsson if (SS.isInvalid() || Tok.isNot(tok::identifier)) { 156f67606ae2febe3bb0718f05040c6c4bc2c2c3276Anders Carlsson Diag(Tok, diag::err_expected_namespace_name); 157f67606ae2febe3bb0718f05040c6c4bc2c2c3276Anders Carlsson // Skip to end of the definition and eat the ';'. 158f67606ae2febe3bb0718f05040c6c4bc2c2c3276Anders Carlsson SkipUntil(tok::semi); 159d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 160f67606ae2febe3bb0718f05040c6c4bc2c2c3276Anders Carlsson } 161f67606ae2febe3bb0718f05040c6c4bc2c2c3276Anders Carlsson 162f67606ae2febe3bb0718f05040c6c4bc2c2c3276Anders Carlsson // Parse identifier. 16303bd5a1e9a54b62b10ae8aeb6eb5245e2031d98bAnders Carlsson IdentifierInfo *Ident = Tok.getIdentifierInfo(); 16403bd5a1e9a54b62b10ae8aeb6eb5245e2031d98bAnders Carlsson SourceLocation IdentLoc = ConsumeToken(); 1651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 166f67606ae2febe3bb0718f05040c6c4bc2c2c3276Anders Carlsson // Eat the ';'. 16797144fc41a9419bf6d74fc9450e8ef3f6e11f7e0Chris Lattner DeclEnd = Tok.getLocation(); 1686869d8ea1bb7d191b5b290f5a55ee74f2174829aChris Lattner ExpectAndConsume(tok::semi, diag::err_expected_semi_after_namespace_name, 1696869d8ea1bb7d191b5b290f5a55ee74f2174829aChris Lattner "", tok::semi); 1701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 17123c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor return Actions.ActOnNamespaceAliasDef(getCurScope(), NamespaceLoc, AliasLoc, Alias, 17203bd5a1e9a54b62b10ae8aeb6eb5245e2031d98bAnders Carlsson SS, IdentLoc, Ident); 173f67606ae2febe3bb0718f05040c6c4bc2c2c3276Anders Carlsson} 174f67606ae2febe3bb0718f05040c6c4bc2c2c3276Anders Carlsson 175c6fdc34ac0183bfa03d65f317c78b7bdac52897eChris Lattner/// ParseLinkage - We know that the current token is a string_literal 176c6fdc34ac0183bfa03d65f317c78b7bdac52897eChris Lattner/// and just before that, that extern was seen. 177c6fdc34ac0183bfa03d65f317c78b7bdac52897eChris Lattner/// 178c6fdc34ac0183bfa03d65f317c78b7bdac52897eChris Lattner/// linkage-specification: [C++ 7.5p2: dcl.link] 179c6fdc34ac0183bfa03d65f317c78b7bdac52897eChris Lattner/// 'extern' string-literal '{' declaration-seq[opt] '}' 180c6fdc34ac0183bfa03d65f317c78b7bdac52897eChris Lattner/// 'extern' string-literal declaration 181c6fdc34ac0183bfa03d65f317c78b7bdac52897eChris Lattner/// 1827d64271b162eaf5cae264ff64465b28af623dc17Chris LattnerDecl *Parser::ParseLinkage(ParsingDeclSpec &DS, unsigned Context) { 183c19923dda3d28f67aab4726cd40bb07032758383Douglas Gregor assert(Tok.is(tok::string_literal) && "Not a string literal!"); 184193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam llvm::SmallString<8> LangBuffer; 185453091cc2082e207ea2c2dda645a9bc01b37fb0cDouglas Gregor bool Invalid = false; 186453091cc2082e207ea2c2dda645a9bc01b37fb0cDouglas Gregor llvm::StringRef Lang = PP.getSpelling(Tok, LangBuffer, &Invalid); 187453091cc2082e207ea2c2dda645a9bc01b37fb0cDouglas Gregor if (Invalid) 188d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 189c6fdc34ac0183bfa03d65f317c78b7bdac52897eChris Lattner 190c6fdc34ac0183bfa03d65f317c78b7bdac52897eChris Lattner SourceLocation Loc = ConsumeStringToken(); 191c6fdc34ac0183bfa03d65f317c78b7bdac52897eChris Lattner 192074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor ParseScope LinkageScope(this, Scope::DeclScope); 193d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *LinkageSpec 19423c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor = Actions.ActOnStartLinkageSpecification(getCurScope(), 195a2026c96d3935e7909e049ad9096762844544ed6Abramo Bagnara DS.getSourceRange().getBegin(), 196d56638180014e60538cd666cd11fde6d4698e051Benjamin Kramer Loc, Lang, 197a2026c96d3935e7909e049ad9096762844544ed6Abramo Bagnara Tok.is(tok::l_brace) ? Tok.getLocation() 198074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor : SourceLocation()); 199074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor 2000b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall ParsedAttributesWithRange attrs(AttrFactory); 2017f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall MaybeParseCXX0XAttributes(attrs); 2027f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall MaybeParseMicrosoftAttributes(attrs); 203193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam 204074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor if (Tok.isNot(tok::l_brace)) { 205f41e33c29cd4b21065956129d5e923f3d73d97d3Abramo Bagnara // Reset the source range in DS, as the leading "extern" 206f41e33c29cd4b21065956129d5e923f3d73d97d3Abramo Bagnara // does not really belong to the inner declaration ... 207f41e33c29cd4b21065956129d5e923f3d73d97d3Abramo Bagnara DS.SetRangeStart(SourceLocation()); 208f41e33c29cd4b21065956129d5e923f3d73d97d3Abramo Bagnara DS.SetRangeEnd(SourceLocation()); 209f41e33c29cd4b21065956129d5e923f3d73d97d3Abramo Bagnara // ... but anyway remember that such an "extern" was seen. 21035f9a196ef897b9559de25aaecd957208f0b4f59Abramo Bagnara DS.setExternInLinkageSpec(true); 2117f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall ParseExternalDeclaration(attrs, &DS); 21223c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor return Actions.ActOnFinishLinkageSpecification(getCurScope(), LinkageSpec, 213074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor SourceLocation()); 2141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 215f44515a49b549171dc3ee9faa6281b72609da563Douglas Gregor 21663a011378d4b9483ce24400c163cb8d65ea096a5Douglas Gregor DS.abort(); 21763a011378d4b9483ce24400c163cb8d65ea096a5Douglas Gregor 2187f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall ProhibitAttributes(attrs); 219bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt 220f44515a49b549171dc3ee9faa6281b72609da563Douglas Gregor SourceLocation LBrace = ConsumeBrace(); 221f44515a49b549171dc3ee9faa6281b72609da563Douglas Gregor while (Tok.isNot(tok::r_brace) && Tok.isNot(tok::eof)) { 2220b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall ParsedAttributesWithRange attrs(AttrFactory); 2237f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall MaybeParseCXX0XAttributes(attrs); 2247f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall MaybeParseMicrosoftAttributes(attrs); 2257f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall ParseExternalDeclaration(attrs); 226f44515a49b549171dc3ee9faa6281b72609da563Douglas Gregor } 227c6fdc34ac0183bfa03d65f317c78b7bdac52897eChris Lattner 228f44515a49b549171dc3ee9faa6281b72609da563Douglas Gregor SourceLocation RBrace = MatchRHSPunctuation(tok::r_brace, LBrace); 2297d64271b162eaf5cae264ff64465b28af623dc17Chris Lattner return Actions.ActOnFinishLinkageSpecification(getCurScope(), LinkageSpec, 2307d64271b162eaf5cae264ff64465b28af623dc17Chris Lattner RBrace); 231c6fdc34ac0183bfa03d65f317c78b7bdac52897eChris Lattner} 232e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor 233f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor/// ParseUsingDirectiveOrDeclaration - Parse C++ using using-declaration or 234f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor/// using-directive. Assumes that current token is 'using'. 235d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseUsingDirectiveOrDeclaration(unsigned Context, 23678b810559d89e996e00684335407443936ce34a1John McCall const ParsedTemplateInfo &TemplateInfo, 23778b810559d89e996e00684335407443936ce34a1John McCall SourceLocation &DeclEnd, 2387f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall ParsedAttributesWithRange &attrs) { 239f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor assert(Tok.is(tok::kw_using) && "Not using token"); 240f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor 241f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor // Eat 'using'. 242f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor SourceLocation UsingLoc = ConsumeToken(); 243f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor 24449f40bd0c9c9de5e74727774fec429b47d36303aDouglas Gregor if (Tok.is(tok::code_completion)) { 24523c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteUsing(getCurScope()); 246dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 24749f40bd0c9c9de5e74727774fec429b47d36303aDouglas Gregor } 248193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam 24978b810559d89e996e00684335407443936ce34a1John McCall // 'using namespace' means this is a using-directive. 25078b810559d89e996e00684335407443936ce34a1John McCall if (Tok.is(tok::kw_namespace)) { 25178b810559d89e996e00684335407443936ce34a1John McCall // Template parameters are always an error here. 25278b810559d89e996e00684335407443936ce34a1John McCall if (TemplateInfo.Kind) { 25378b810559d89e996e00684335407443936ce34a1John McCall SourceRange R = TemplateInfo.getSourceRange(); 25478b810559d89e996e00684335407443936ce34a1John McCall Diag(UsingLoc, diag::err_templated_using_directive) 25578b810559d89e996e00684335407443936ce34a1John McCall << R << FixItHint::CreateRemoval(R); 25678b810559d89e996e00684335407443936ce34a1John McCall } 25778b810559d89e996e00684335407443936ce34a1John McCall 2587f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall return ParseUsingDirective(Context, UsingLoc, DeclEnd, attrs); 25978b810559d89e996e00684335407443936ce34a1John McCall } 260bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt 261162e1c1b487352434552147967c3dd296ebee2f7Richard Smith // Otherwise, it must be a using-declaration or an alias-declaration. 26278b810559d89e996e00684335407443936ce34a1John McCall 26378b810559d89e996e00684335407443936ce34a1John McCall // Using declarations can't have attributes. 2647f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall ProhibitAttributes(attrs); 2652f27477a29b6f5365ee545c1cac666cc8b95f518Chris Lattner 26678b810559d89e996e00684335407443936ce34a1John McCall return ParseUsingDeclaration(Context, TemplateInfo, UsingLoc, DeclEnd); 267f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor} 268f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor 269f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor/// ParseUsingDirective - Parse C++ using-directive, assumes 270f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor/// that current token is 'namespace' and 'using' was already parsed. 271f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor/// 272f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor/// using-directive: [C++ 7.3.p4: namespace.udir] 273f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor/// 'using' 'namespace' ::[opt] nested-name-specifier[opt] 274f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor/// namespace-name ; 275f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor/// [GNU] using-directive: 276f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor/// 'using' 'namespace' ::[opt] nested-name-specifier[opt] 277f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor/// namespace-name attributes[opt] ; 278f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor/// 279d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseUsingDirective(unsigned Context, 28078b810559d89e996e00684335407443936ce34a1John McCall SourceLocation UsingLoc, 28178b810559d89e996e00684335407443936ce34a1John McCall SourceLocation &DeclEnd, 2827f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall ParsedAttributes &attrs) { 283f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor assert(Tok.is(tok::kw_namespace) && "Not 'namespace' token"); 284f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor 285f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor // Eat 'namespace'. 286f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor SourceLocation NamespcLoc = ConsumeToken(); 287f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor 28849f40bd0c9c9de5e74727774fec429b47d36303aDouglas Gregor if (Tok.is(tok::code_completion)) { 28923c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteUsingDirective(getCurScope()); 290dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 29149f40bd0c9c9de5e74727774fec429b47d36303aDouglas Gregor } 292193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam 293f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor CXXScopeSpec SS; 294f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor // Parse (optional) nested-name-specifier. 295b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParseOptionalCXXScopeSpecifier(SS, ParsedType(), false); 296f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor 297f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor IdentifierInfo *NamespcName = 0; 298f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor SourceLocation IdentLoc = SourceLocation(); 299f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor 300f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor // Parse namespace-name. 301823c44e6d73141f642e207980b4021ddcf09897bChris Lattner if (SS.isInvalid() || Tok.isNot(tok::identifier)) { 302f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor Diag(Tok, diag::err_expected_namespace_name); 303f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor // If there was invalid namespace name, skip to end of decl, and eat ';'. 304f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor SkipUntil(tok::semi); 305f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor // FIXME: Are there cases, when we would like to call ActOnUsingDirective? 306d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 307f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor } 3081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 309823c44e6d73141f642e207980b4021ddcf09897bChris Lattner // Parse identifier. 310823c44e6d73141f642e207980b4021ddcf09897bChris Lattner NamespcName = Tok.getIdentifierInfo(); 311823c44e6d73141f642e207980b4021ddcf09897bChris Lattner IdentLoc = ConsumeToken(); 3121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 313823c44e6d73141f642e207980b4021ddcf09897bChris Lattner // Parse (optional) attributes (most likely GNU strong-using extension). 314bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt bool GNUAttr = false; 315bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt if (Tok.is(tok::kw___attribute)) { 316bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt GNUAttr = true; 3177f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall ParseGNUAttributes(attrs); 318bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt } 3191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 320823c44e6d73141f642e207980b4021ddcf09897bChris Lattner // Eat ';'. 32197144fc41a9419bf6d74fc9450e8ef3f6e11f7e0Chris Lattner DeclEnd = Tok.getLocation(); 3226869d8ea1bb7d191b5b290f5a55ee74f2174829aChris Lattner ExpectAndConsume(tok::semi, 3239ba23b4ceacd77cd264501690a7a9e94184ef71bDouglas Gregor GNUAttr ? diag::err_expected_semi_after_attribute_list 3249ba23b4ceacd77cd264501690a7a9e94184ef71bDouglas Gregor : diag::err_expected_semi_after_namespace_name, 3259ba23b4ceacd77cd264501690a7a9e94184ef71bDouglas Gregor "", tok::semi); 326f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor 32723c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor return Actions.ActOnUsingDirective(getCurScope(), UsingLoc, NamespcLoc, SS, 3287f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall IdentLoc, NamespcName, attrs.getList()); 329f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor} 330f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor 331162e1c1b487352434552147967c3dd296ebee2f7Richard Smith/// ParseUsingDeclaration - Parse C++ using-declaration or alias-declaration. 332162e1c1b487352434552147967c3dd296ebee2f7Richard Smith/// Assumes that 'using' was already seen. 333f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor/// 334f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor/// using-declaration: [C++ 7.3.p3: namespace.udecl] 335f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor/// 'using' 'typename'[opt] ::[opt] nested-name-specifier 3369cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor/// unqualified-id 3379cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor/// 'using' :: unqualified-id 338f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor/// 339162e1c1b487352434552147967c3dd296ebee2f7Richard Smith/// alias-declaration: C++0x [decl.typedef]p2 340162e1c1b487352434552147967c3dd296ebee2f7Richard Smith/// 'using' identifier = type-id ; 341162e1c1b487352434552147967c3dd296ebee2f7Richard Smith/// 342d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseUsingDeclaration(unsigned Context, 34378b810559d89e996e00684335407443936ce34a1John McCall const ParsedTemplateInfo &TemplateInfo, 34478b810559d89e996e00684335407443936ce34a1John McCall SourceLocation UsingLoc, 34578b810559d89e996e00684335407443936ce34a1John McCall SourceLocation &DeclEnd, 34678b810559d89e996e00684335407443936ce34a1John McCall AccessSpecifier AS) { 3479cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor CXXScopeSpec SS; 3487ba107a1863ddfa1664555854f0d7bdb3c491c92John McCall SourceLocation TypenameLoc; 3499cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor bool IsTypeName; 3509cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor 3519cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor // Ignore optional 'typename'. 35212c118a8ff9f61a4d63146fe1a5c0d60987f99bbDouglas Gregor // FIXME: This is wrong; we should parse this as a typename-specifier. 3539cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor if (Tok.is(tok::kw_typename)) { 3547ba107a1863ddfa1664555854f0d7bdb3c491c92John McCall TypenameLoc = Tok.getLocation(); 3559cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor ConsumeToken(); 3569cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor IsTypeName = true; 3579cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor } 3589cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor else 3599cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor IsTypeName = false; 3609cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor 3619cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor // Parse nested-name-specifier. 362b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParseOptionalCXXScopeSpecifier(SS, ParsedType(), false); 3639cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor 3649cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor // Check nested-name specifier. 3659cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor if (SS.isInvalid()) { 3669cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor SkipUntil(tok::semi); 367d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 3689cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor } 3691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 370193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam // Parse the unqualified-id. We allow parsing of both constructor and 37112c118a8ff9f61a4d63146fe1a5c0d60987f99bbDouglas Gregor // destructor names and allow the action module to diagnose any semantic 37212c118a8ff9f61a4d63146fe1a5c0d60987f99bbDouglas Gregor // errors. 37312c118a8ff9f61a4d63146fe1a5c0d60987f99bbDouglas Gregor UnqualifiedId Name; 374193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam if (ParseUnqualifiedId(SS, 37512c118a8ff9f61a4d63146fe1a5c0d60987f99bbDouglas Gregor /*EnteringContext=*/false, 37612c118a8ff9f61a4d63146fe1a5c0d60987f99bbDouglas Gregor /*AllowDestructorName=*/true, 377193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam /*AllowConstructorName=*/true, 378b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType(), 37912c118a8ff9f61a4d63146fe1a5c0d60987f99bbDouglas Gregor Name)) { 3809cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor SkipUntil(tok::semi); 381d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 3829cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor } 383193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam 3840b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall ParsedAttributes attrs(AttrFactory); 385162e1c1b487352434552147967c3dd296ebee2f7Richard Smith 386162e1c1b487352434552147967c3dd296ebee2f7Richard Smith // Maybe this is an alias-declaration. 387162e1c1b487352434552147967c3dd296ebee2f7Richard Smith bool IsAliasDecl = Tok.is(tok::equal); 388162e1c1b487352434552147967c3dd296ebee2f7Richard Smith TypeResult TypeAlias; 389162e1c1b487352434552147967c3dd296ebee2f7Richard Smith if (IsAliasDecl) { 3903e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // TODO: Attribute support. C++0x attributes may appear before the equals. 3913e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // Where can GNU attributes appear? 392162e1c1b487352434552147967c3dd296ebee2f7Richard Smith ConsumeToken(); 393162e1c1b487352434552147967c3dd296ebee2f7Richard Smith 394162e1c1b487352434552147967c3dd296ebee2f7Richard Smith if (!getLang().CPlusPlus0x) 395162e1c1b487352434552147967c3dd296ebee2f7Richard Smith Diag(Tok.getLocation(), diag::ext_alias_declaration); 396162e1c1b487352434552147967c3dd296ebee2f7Richard Smith 3973e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // Type alias templates cannot be specialized. 3983e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith int SpecKind = -1; 399536e9c1f103f3e59ed47e35090819eb93596c35bRichard Smith if (TemplateInfo.Kind == ParsedTemplateInfo::Template && 400536e9c1f103f3e59ed47e35090819eb93596c35bRichard Smith Name.getKind() == UnqualifiedId::IK_TemplateId) 4013e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith SpecKind = 0; 4023e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitSpecialization) 4033e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith SpecKind = 1; 4043e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation) 4053e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith SpecKind = 2; 4063e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith if (SpecKind != -1) { 4073e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith SourceRange Range; 4083e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith if (SpecKind == 0) 4093e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith Range = SourceRange(Name.TemplateId->LAngleLoc, 4103e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith Name.TemplateId->RAngleLoc); 4113e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith else 4123e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith Range = TemplateInfo.getSourceRange(); 4133e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith Diag(Range.getBegin(), diag::err_alias_declaration_specialization) 4143e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith << SpecKind << Range; 4153e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith SkipUntil(tok::semi); 4163e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith return 0; 4173e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith } 4183e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith 419162e1c1b487352434552147967c3dd296ebee2f7Richard Smith // Name must be an identifier. 420162e1c1b487352434552147967c3dd296ebee2f7Richard Smith if (Name.getKind() != UnqualifiedId::IK_Identifier) { 421162e1c1b487352434552147967c3dd296ebee2f7Richard Smith Diag(Name.StartLocation, diag::err_alias_declaration_not_identifier); 422162e1c1b487352434552147967c3dd296ebee2f7Richard Smith // No removal fixit: can't recover from this. 423162e1c1b487352434552147967c3dd296ebee2f7Richard Smith SkipUntil(tok::semi); 424162e1c1b487352434552147967c3dd296ebee2f7Richard Smith return 0; 425162e1c1b487352434552147967c3dd296ebee2f7Richard Smith } else if (IsTypeName) 426162e1c1b487352434552147967c3dd296ebee2f7Richard Smith Diag(TypenameLoc, diag::err_alias_declaration_not_identifier) 427162e1c1b487352434552147967c3dd296ebee2f7Richard Smith << FixItHint::CreateRemoval(SourceRange(TypenameLoc, 428162e1c1b487352434552147967c3dd296ebee2f7Richard Smith SS.isNotEmpty() ? SS.getEndLoc() : TypenameLoc)); 429162e1c1b487352434552147967c3dd296ebee2f7Richard Smith else if (SS.isNotEmpty()) 430162e1c1b487352434552147967c3dd296ebee2f7Richard Smith Diag(SS.getBeginLoc(), diag::err_alias_declaration_not_identifier) 431162e1c1b487352434552147967c3dd296ebee2f7Richard Smith << FixItHint::CreateRemoval(SS.getRange()); 432162e1c1b487352434552147967c3dd296ebee2f7Richard Smith 4333e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith TypeAlias = ParseTypeName(0, TemplateInfo.Kind ? 4343e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith Declarator::AliasTemplateContext : 4353e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith Declarator::AliasDeclContext); 436162e1c1b487352434552147967c3dd296ebee2f7Richard Smith } else 437162e1c1b487352434552147967c3dd296ebee2f7Richard Smith // Parse (optional) attributes (most likely GNU strong-using extension). 438162e1c1b487352434552147967c3dd296ebee2f7Richard Smith MaybeParseGNUAttributes(attrs); 4391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4409cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor // Eat ';'. 4419cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor DeclEnd = Tok.getLocation(); 4429cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor ExpectAndConsume(tok::semi, diag::err_expected_semi_after, 443162e1c1b487352434552147967c3dd296ebee2f7Richard Smith !attrs.empty() ? "attributes list" : 444162e1c1b487352434552147967c3dd296ebee2f7Richard Smith IsAliasDecl ? "alias declaration" : "using declaration", 44512c118a8ff9f61a4d63146fe1a5c0d60987f99bbDouglas Gregor tok::semi); 4469cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor 44778b810559d89e996e00684335407443936ce34a1John McCall // Diagnose an attempt to declare a templated using-declaration. 4483e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // In C++0x, alias-declarations can be templates: 449162e1c1b487352434552147967c3dd296ebee2f7Richard Smith // template <...> using id = type; 4503e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith if (TemplateInfo.Kind && !IsAliasDecl) { 45178b810559d89e996e00684335407443936ce34a1John McCall SourceRange R = TemplateInfo.getSourceRange(); 45278b810559d89e996e00684335407443936ce34a1John McCall Diag(UsingLoc, diag::err_templated_using_declaration) 45378b810559d89e996e00684335407443936ce34a1John McCall << R << FixItHint::CreateRemoval(R); 45478b810559d89e996e00684335407443936ce34a1John McCall 45578b810559d89e996e00684335407443936ce34a1John McCall // Unfortunately, we have to bail out instead of recovering by 45678b810559d89e996e00684335407443936ce34a1John McCall // ignoring the parameters, just in case the nested name specifier 45778b810559d89e996e00684335407443936ce34a1John McCall // depends on the parameters. 45878b810559d89e996e00684335407443936ce34a1John McCall return 0; 45978b810559d89e996e00684335407443936ce34a1John McCall } 46078b810559d89e996e00684335407443936ce34a1John McCall 4613e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith if (IsAliasDecl) { 4623e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith TemplateParameterLists *TemplateParams = TemplateInfo.TemplateParams; 4633e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith MultiTemplateParamsArg TemplateParamsArg(Actions, 4643e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith TemplateParams ? TemplateParams->data() : 0, 4653e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith TemplateParams ? TemplateParams->size() : 0); 4663e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith return Actions.ActOnAliasDeclaration(getCurScope(), AS, TemplateParamsArg, 4673e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith UsingLoc, Name, TypeAlias); 4683e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith } 469162e1c1b487352434552147967c3dd296ebee2f7Richard Smith 4708113ecfa4e41e2c888b1794389dfe3bce6386493Ted Kremenek return Actions.ActOnUsingDeclaration(getCurScope(), AS, true, UsingLoc, SS, 4717f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall Name, attrs.getList(), 4727f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall IsTypeName, TypenameLoc); 473f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor} 474f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor 475c6eb44b321c543c5bcf28727228a0cceced57e2ePeter Collingbourne/// ParseStaticAssertDeclaration - Parse C++0x or C1X static_assert-declaration. 476511d7aba3b12853fdb88729a0313b80a60eab8adAnders Carlsson/// 477c6eb44b321c543c5bcf28727228a0cceced57e2ePeter Collingbourne/// [C++0x] static_assert-declaration: 478c6eb44b321c543c5bcf28727228a0cceced57e2ePeter Collingbourne/// static_assert ( constant-expression , string-literal ) ; 479c6eb44b321c543c5bcf28727228a0cceced57e2ePeter Collingbourne/// 480c6eb44b321c543c5bcf28727228a0cceced57e2ePeter Collingbourne/// [C1X] static_assert-declaration: 481c6eb44b321c543c5bcf28727228a0cceced57e2ePeter Collingbourne/// _Static_assert ( constant-expression , string-literal ) ; 482511d7aba3b12853fdb88729a0313b80a60eab8adAnders Carlsson/// 483d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseStaticAssertDeclaration(SourceLocation &DeclEnd){ 484c6eb44b321c543c5bcf28727228a0cceced57e2ePeter Collingbourne assert((Tok.is(tok::kw_static_assert) || Tok.is(tok::kw__Static_assert)) && 485c6eb44b321c543c5bcf28727228a0cceced57e2ePeter Collingbourne "Not a static_assert declaration"); 486c6eb44b321c543c5bcf28727228a0cceced57e2ePeter Collingbourne 487c6eb44b321c543c5bcf28727228a0cceced57e2ePeter Collingbourne if (Tok.is(tok::kw__Static_assert) && !getLang().C1X) 488c6eb44b321c543c5bcf28727228a0cceced57e2ePeter Collingbourne Diag(Tok, diag::ext_c1x_static_assert); 489c6eb44b321c543c5bcf28727228a0cceced57e2ePeter Collingbourne 490511d7aba3b12853fdb88729a0313b80a60eab8adAnders Carlsson SourceLocation StaticAssertLoc = ConsumeToken(); 4911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 492511d7aba3b12853fdb88729a0313b80a60eab8adAnders Carlsson if (Tok.isNot(tok::l_paren)) { 493511d7aba3b12853fdb88729a0313b80a60eab8adAnders Carlsson Diag(Tok, diag::err_expected_lparen); 494d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 495511d7aba3b12853fdb88729a0313b80a60eab8adAnders Carlsson } 4961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 497511d7aba3b12853fdb88729a0313b80a60eab8adAnders Carlsson SourceLocation LParenLoc = ConsumeParen(); 498e0762c92110dfdcdd207db461a4ea17afd168f1eDouglas Gregor 49960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult AssertExpr(ParseConstantExpression()); 500511d7aba3b12853fdb88729a0313b80a60eab8adAnders Carlsson if (AssertExpr.isInvalid()) { 501511d7aba3b12853fdb88729a0313b80a60eab8adAnders Carlsson SkipUntil(tok::semi); 502d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 503511d7aba3b12853fdb88729a0313b80a60eab8adAnders Carlsson } 5041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 505ad5f960f9e42568a87bf5e03dce7ad878f9ba6daAnders Carlsson if (ExpectAndConsume(tok::comma, diag::err_expected_comma, "", tok::semi)) 506d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 507ad5f960f9e42568a87bf5e03dce7ad878f9ba6daAnders Carlsson 508511d7aba3b12853fdb88729a0313b80a60eab8adAnders Carlsson if (Tok.isNot(tok::string_literal)) { 509511d7aba3b12853fdb88729a0313b80a60eab8adAnders Carlsson Diag(Tok, diag::err_expected_string_literal); 510511d7aba3b12853fdb88729a0313b80a60eab8adAnders Carlsson SkipUntil(tok::semi); 511d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 512511d7aba3b12853fdb88729a0313b80a60eab8adAnders Carlsson } 5131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 51460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult AssertMessage(ParseStringLiteralExpression()); 5151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (AssertMessage.isInvalid()) 516d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 517511d7aba3b12853fdb88729a0313b80a60eab8adAnders Carlsson 518a2026c96d3935e7909e049ad9096762844544ed6Abramo Bagnara SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); 5191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 52097144fc41a9419bf6d74fc9450e8ef3f6e11f7e0Chris Lattner DeclEnd = Tok.getLocation(); 5219ba23b4ceacd77cd264501690a7a9e94184ef71bDouglas Gregor ExpectAndConsumeSemi(diag::err_expected_semi_after_static_assert); 522511d7aba3b12853fdb88729a0313b80a60eab8adAnders Carlsson 5239ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return Actions.ActOnStaticAssertDeclaration(StaticAssertLoc, 5249ae2f076ca5ab1feb3ba95629099ec2319833701John McCall AssertExpr.take(), 525a2026c96d3935e7909e049ad9096762844544ed6Abramo Bagnara AssertMessage.take(), 526a2026c96d3935e7909e049ad9096762844544ed6Abramo Bagnara RParenLoc); 527511d7aba3b12853fdb88729a0313b80a60eab8adAnders Carlsson} 528511d7aba3b12853fdb88729a0313b80a60eab8adAnders Carlsson 5296fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson/// ParseDecltypeSpecifier - Parse a C++0x decltype specifier. 5306fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson/// 5316fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson/// 'decltype' ( expression ) 5326fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson/// 5336fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlssonvoid Parser::ParseDecltypeSpecifier(DeclSpec &DS) { 5346fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson assert(Tok.is(tok::kw_decltype) && "Not a decltype specifier"); 5356fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson 5366fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson SourceLocation StartLoc = ConsumeToken(); 5376fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson SourceLocation LParenLoc = Tok.getLocation(); 5381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (ExpectAndConsume(tok::l_paren, diag::err_expected_lparen_after, 5406fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson "decltype")) { 5416fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson SkipUntil(tok::r_paren); 5426fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson return; 5436fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson } 5441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5456fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson // Parse the expression 5461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5476fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson // C++0x [dcl.type.simple]p4: 5486fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson // The operand of the decltype specifier is an unevaluated operand. 5496fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson EnterExpressionEvaluationContext Unevaluated(Actions, 550f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Sema::Unevaluated); 55160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result = ParseExpression(); 5526fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson if (Result.isInvalid()) { 5536fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson SkipUntil(tok::r_paren); 5546fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson return; 5556fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson } 5561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5576fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson // Match the ')' 5586fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson SourceLocation RParenLoc; 5596fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson if (Tok.is(tok::r_paren)) 5606fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson RParenLoc = ConsumeParen(); 5616fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson else 5626fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson MatchRHSPunctuation(tok::r_paren, LParenLoc); 5631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5646fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson if (RParenLoc.isInvalid()) 5656fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson return; 5666fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson 5676fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson const char *PrevSpec = 0; 568fec54013fcd0eb72642741584ca04c1bc292bef8John McCall unsigned DiagID; 5696fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson // Check for duplicate type specifiers (e.g. "int decltype(a)"). 5701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (DS.SetTypeSpecType(DeclSpec::TST_decltype, StartLoc, PrevSpec, 571fec54013fcd0eb72642741584ca04c1bc292bef8John McCall DiagID, Result.release())) 572fec54013fcd0eb72642741584ca04c1bc292bef8John McCall Diag(StartLoc, DiagID) << PrevSpec; 5736fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson} 5746fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson 57542a552f8200ba5948661aee0106fce0c04e39818Douglas Gregor/// ParseClassName - Parse a C++ class-name, which names a class. Note 57642a552f8200ba5948661aee0106fce0c04e39818Douglas Gregor/// that we only check that the result names a type; semantic analysis 57742a552f8200ba5948661aee0106fce0c04e39818Douglas Gregor/// will need to verify that the type names a class. The result is 5787f43d6764797ab21216421aeb00f4ec314d503d1Douglas Gregor/// either a type or NULL, depending on whether a type name was 57942a552f8200ba5948661aee0106fce0c04e39818Douglas Gregor/// found. 58042a552f8200ba5948661aee0106fce0c04e39818Douglas Gregor/// 58142a552f8200ba5948661aee0106fce0c04e39818Douglas Gregor/// class-name: [C++ 9.1] 58242a552f8200ba5948661aee0106fce0c04e39818Douglas Gregor/// identifier 5837f43d6764797ab21216421aeb00f4ec314d503d1Douglas Gregor/// simple-template-id 5841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 58531a19b6989bbf326d2de5ae12e712e2a65ca9c34Douglas GregorParser::TypeResult Parser::ParseClassName(SourceLocation &EndLocation, 586059101f922de6eb765601459925f4c8914420b23Douglas Gregor CXXScopeSpec &SS) { 5877f43d6764797ab21216421aeb00f4ec314d503d1Douglas Gregor // Check whether we have a template-id that names a type. 5887f43d6764797ab21216421aeb00f4ec314d503d1Douglas Gregor if (Tok.is(tok::annot_template_id)) { 5891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TemplateIdAnnotation *TemplateId 5907f43d6764797ab21216421aeb00f4ec314d503d1Douglas Gregor = static_cast<TemplateIdAnnotation *>(Tok.getAnnotationValue()); 591d9b600c1a589200be905c53e2e10fceb57efa18dDouglas Gregor if (TemplateId->Kind == TNK_Type_template || 592d9b600c1a589200be905c53e2e10fceb57efa18dDouglas Gregor TemplateId->Kind == TNK_Dependent_template_name) { 593059101f922de6eb765601459925f4c8914420b23Douglas Gregor AnnotateTemplateIdTokenAsType(); 5947f43d6764797ab21216421aeb00f4ec314d503d1Douglas Gregor 5957f43d6764797ab21216421aeb00f4ec314d503d1Douglas Gregor assert(Tok.is(tok::annot_typename) && "template-id -> type failed"); 596b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType Type = getTypeAnnotation(Tok); 5977f43d6764797ab21216421aeb00f4ec314d503d1Douglas Gregor EndLocation = Tok.getAnnotationEndLoc(); 5987f43d6764797ab21216421aeb00f4ec314d503d1Douglas Gregor ConsumeToken(); 59931a19b6989bbf326d2de5ae12e712e2a65ca9c34Douglas Gregor 60031a19b6989bbf326d2de5ae12e712e2a65ca9c34Douglas Gregor if (Type) 60131a19b6989bbf326d2de5ae12e712e2a65ca9c34Douglas Gregor return Type; 60231a19b6989bbf326d2de5ae12e712e2a65ca9c34Douglas Gregor return true; 6037f43d6764797ab21216421aeb00f4ec314d503d1Douglas Gregor } 6047f43d6764797ab21216421aeb00f4ec314d503d1Douglas Gregor 6057f43d6764797ab21216421aeb00f4ec314d503d1Douglas Gregor // Fall through to produce an error below. 6067f43d6764797ab21216421aeb00f4ec314d503d1Douglas Gregor } 6077f43d6764797ab21216421aeb00f4ec314d503d1Douglas Gregor 60842a552f8200ba5948661aee0106fce0c04e39818Douglas Gregor if (Tok.isNot(tok::identifier)) { 6091ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_class_name); 61031a19b6989bbf326d2de5ae12e712e2a65ca9c34Douglas Gregor return true; 61142a552f8200ba5948661aee0106fce0c04e39818Douglas Gregor } 61242a552f8200ba5948661aee0106fce0c04e39818Douglas Gregor 61384d0a19828599e8623223632d59447fd498999cfDouglas Gregor IdentifierInfo *Id = Tok.getIdentifierInfo(); 61484d0a19828599e8623223632d59447fd498999cfDouglas Gregor SourceLocation IdLoc = ConsumeToken(); 61584d0a19828599e8623223632d59447fd498999cfDouglas Gregor 61684d0a19828599e8623223632d59447fd498999cfDouglas Gregor if (Tok.is(tok::less)) { 61784d0a19828599e8623223632d59447fd498999cfDouglas Gregor // It looks the user intended to write a template-id here, but the 61884d0a19828599e8623223632d59447fd498999cfDouglas Gregor // template-name was wrong. Try to fix that. 61984d0a19828599e8623223632d59447fd498999cfDouglas Gregor TemplateNameKind TNK = TNK_Type_template; 62084d0a19828599e8623223632d59447fd498999cfDouglas Gregor TemplateTy Template; 62123c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor if (!Actions.DiagnoseUnknownTemplateName(*Id, IdLoc, getCurScope(), 622059101f922de6eb765601459925f4c8914420b23Douglas Gregor &SS, Template, TNK)) { 62384d0a19828599e8623223632d59447fd498999cfDouglas Gregor Diag(IdLoc, diag::err_unknown_template_name) 62484d0a19828599e8623223632d59447fd498999cfDouglas Gregor << Id; 62584d0a19828599e8623223632d59447fd498999cfDouglas Gregor } 626193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam 62784d0a19828599e8623223632d59447fd498999cfDouglas Gregor if (!Template) 62884d0a19828599e8623223632d59447fd498999cfDouglas Gregor return true; 62984d0a19828599e8623223632d59447fd498999cfDouglas Gregor 630193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam // Form the template name 63184d0a19828599e8623223632d59447fd498999cfDouglas Gregor UnqualifiedId TemplateName; 63284d0a19828599e8623223632d59447fd498999cfDouglas Gregor TemplateName.setIdentifier(Id, IdLoc); 633193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam 63484d0a19828599e8623223632d59447fd498999cfDouglas Gregor // Parse the full template-id, then turn it into a type. 63584d0a19828599e8623223632d59447fd498999cfDouglas Gregor if (AnnotateTemplateIdToken(Template, TNK, SS, TemplateName, 63684d0a19828599e8623223632d59447fd498999cfDouglas Gregor SourceLocation(), true)) 63784d0a19828599e8623223632d59447fd498999cfDouglas Gregor return true; 63884d0a19828599e8623223632d59447fd498999cfDouglas Gregor if (TNK == TNK_Dependent_template_name) 639059101f922de6eb765601459925f4c8914420b23Douglas Gregor AnnotateTemplateIdTokenAsType(); 640193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam 64184d0a19828599e8623223632d59447fd498999cfDouglas Gregor // If we didn't end up with a typename token, there's nothing more we 64284d0a19828599e8623223632d59447fd498999cfDouglas Gregor // can do. 64384d0a19828599e8623223632d59447fd498999cfDouglas Gregor if (Tok.isNot(tok::annot_typename)) 64484d0a19828599e8623223632d59447fd498999cfDouglas Gregor return true; 645193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam 64684d0a19828599e8623223632d59447fd498999cfDouglas Gregor // Retrieve the type from the annotation token, consume that token, and 64784d0a19828599e8623223632d59447fd498999cfDouglas Gregor // return. 64884d0a19828599e8623223632d59447fd498999cfDouglas Gregor EndLocation = Tok.getAnnotationEndLoc(); 649b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType Type = getTypeAnnotation(Tok); 65084d0a19828599e8623223632d59447fd498999cfDouglas Gregor ConsumeToken(); 65184d0a19828599e8623223632d59447fd498999cfDouglas Gregor return Type; 65284d0a19828599e8623223632d59447fd498999cfDouglas Gregor } 65384d0a19828599e8623223632d59447fd498999cfDouglas Gregor 65442a552f8200ba5948661aee0106fce0c04e39818Douglas Gregor // We have an identifier; check whether it is actually a type. 655059101f922de6eb765601459925f4c8914420b23Douglas Gregor ParsedType Type = Actions.getTypeName(*Id, IdLoc, getCurScope(), &SS, true, 6569e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor false, ParsedType(), 6579e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor /*NonTrivialTypeSourceInfo=*/true); 658193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam if (!Type) { 659124b878dba5007df0a268ea128a6ad8dc5dd2c5eDouglas Gregor Diag(IdLoc, diag::err_expected_class_name); 66031a19b6989bbf326d2de5ae12e712e2a65ca9c34Douglas Gregor return true; 66142a552f8200ba5948661aee0106fce0c04e39818Douglas Gregor } 66242a552f8200ba5948661aee0106fce0c04e39818Douglas Gregor 66342a552f8200ba5948661aee0106fce0c04e39818Douglas Gregor // Consume the identifier. 66484d0a19828599e8623223632d59447fd498999cfDouglas Gregor EndLocation = IdLoc; 6655606220447c7901ba8d80147ddab893bb7949dd5Nick Lewycky 6665606220447c7901ba8d80147ddab893bb7949dd5Nick Lewycky // Fake up a Declarator to use with ActOnTypeName. 6670b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall DeclSpec DS(AttrFactory); 6685606220447c7901ba8d80147ddab893bb7949dd5Nick Lewycky DS.SetRangeStart(IdLoc); 6695606220447c7901ba8d80147ddab893bb7949dd5Nick Lewycky DS.SetRangeEnd(EndLocation); 670059101f922de6eb765601459925f4c8914420b23Douglas Gregor DS.getTypeSpecScope() = SS; 6715606220447c7901ba8d80147ddab893bb7949dd5Nick Lewycky 6725606220447c7901ba8d80147ddab893bb7949dd5Nick Lewycky const char *PrevSpec = 0; 6735606220447c7901ba8d80147ddab893bb7949dd5Nick Lewycky unsigned DiagID; 6745606220447c7901ba8d80147ddab893bb7949dd5Nick Lewycky DS.SetTypeSpecType(TST_typename, IdLoc, PrevSpec, DiagID, Type); 6755606220447c7901ba8d80147ddab893bb7949dd5Nick Lewycky 6765606220447c7901ba8d80147ddab893bb7949dd5Nick Lewycky Declarator DeclaratorInfo(DS, Declarator::TypeNameContext); 6775606220447c7901ba8d80147ddab893bb7949dd5Nick Lewycky return Actions.ActOnTypeName(getCurScope(), DeclaratorInfo); 67842a552f8200ba5948661aee0106fce0c04e39818Douglas Gregor} 67942a552f8200ba5948661aee0106fce0c04e39818Douglas Gregor 680e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// ParseClassSpecifier - Parse a C++ class-specifier [C++ class] or 681e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// elaborated-type-specifier [C++ dcl.type.elab]; we can't tell which 682e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// until we reach the start of a definition or see a token that 683d9bafa76f8d6eb9e4f4974ed322217f8df6bb82eSebastian Redl/// cannot start a definition. If SuppressDeclarations is true, we do know. 684e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// 685e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// class-specifier: [C++ class] 686e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// class-head '{' member-specification[opt] '}' 687e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// class-head '{' member-specification[opt] '}' attributes[opt] 688e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// class-head: 689e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// class-key identifier[opt] base-clause[opt] 690e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// class-key nested-name-specifier identifier base-clause[opt] 691e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// class-key nested-name-specifier[opt] simple-template-id 692e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// base-clause[opt] 693e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// [GNU] class-key attributes[opt] identifier[opt] base-clause[opt] 6941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// [GNU] class-key attributes[opt] nested-name-specifier 695e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// identifier base-clause[opt] 6961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// [GNU] class-key attributes[opt] nested-name-specifier[opt] 697e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// simple-template-id base-clause[opt] 698e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// class-key: 699e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// 'class' 700e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// 'struct' 701e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// 'union' 702e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// 703e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// elaborated-type-specifier: [C++ dcl.type.elab] 7041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// class-key ::[opt] nested-name-specifier[opt] identifier 7051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// class-key ::[opt] nested-name-specifier[opt] 'template'[opt] 7061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// simple-template-id 707e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// 708e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// Note that the C++ class-specifier and elaborated-type-specifier, 709e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// together, subsume the C99 struct-or-union-specifier: 710e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// 711e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// struct-or-union-specifier: [C99 6.7.2.1] 712e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// struct-or-union identifier[opt] '{' struct-contents '}' 713e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// struct-or-union identifier 714e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// [GNU] struct-or-union attributes[opt] identifier[opt] '{' struct-contents 715e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// '}' attributes[opt] 716e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// [GNU] struct-or-union attributes[opt] identifier 717e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// struct-or-union: 718e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// 'struct' 719e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// 'union' 7204c97d762d8c5a84f6554e5bfb31d28c90df64158Chris Lattnervoid Parser::ParseClassSpecifier(tok::TokenKind TagTokKind, 7214c97d762d8c5a84f6554e5bfb31d28c90df64158Chris Lattner SourceLocation StartLoc, DeclSpec &DS, 7224d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor const ParsedTemplateInfo &TemplateInfo, 723d9bafa76f8d6eb9e4f4974ed322217f8df6bb82eSebastian Redl AccessSpecifier AS, bool SuppressDeclarations){ 7244c97d762d8c5a84f6554e5bfb31d28c90df64158Chris Lattner DeclSpec::TST TagType; 7254c97d762d8c5a84f6554e5bfb31d28c90df64158Chris Lattner if (TagTokKind == tok::kw_struct) 7264c97d762d8c5a84f6554e5bfb31d28c90df64158Chris Lattner TagType = DeclSpec::TST_struct; 7274c97d762d8c5a84f6554e5bfb31d28c90df64158Chris Lattner else if (TagTokKind == tok::kw_class) 7284c97d762d8c5a84f6554e5bfb31d28c90df64158Chris Lattner TagType = DeclSpec::TST_class; 7294c97d762d8c5a84f6554e5bfb31d28c90df64158Chris Lattner else { 7304c97d762d8c5a84f6554e5bfb31d28c90df64158Chris Lattner assert(TagTokKind == tok::kw_union && "Not a class specifier"); 7314c97d762d8c5a84f6554e5bfb31d28c90df64158Chris Lattner TagType = DeclSpec::TST_union; 7324c97d762d8c5a84f6554e5bfb31d28c90df64158Chris Lattner } 733e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor 734374929f7e88f6c7a96382b3eb4201b721c418372Douglas Gregor if (Tok.is(tok::code_completion)) { 735374929f7e88f6c7a96382b3eb4201b721c418372Douglas Gregor // Code completion for a struct, class, or union name. 73623c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteTag(getCurScope(), TagType); 737dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 738374929f7e88f6c7a96382b3eb4201b721c418372Douglas Gregor } 739193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam 740926c4b486a08f698cd3a367fd6f1a3a07604358dChandler Carruth // C++03 [temp.explicit] 14.7.2/8: 741926c4b486a08f698cd3a367fd6f1a3a07604358dChandler Carruth // The usual access checking rules do not apply to names used to specify 742926c4b486a08f698cd3a367fd6f1a3a07604358dChandler Carruth // explicit instantiations. 743926c4b486a08f698cd3a367fd6f1a3a07604358dChandler Carruth // 744926c4b486a08f698cd3a367fd6f1a3a07604358dChandler Carruth // As an extension we do not perform access checking on the names used to 745926c4b486a08f698cd3a367fd6f1a3a07604358dChandler Carruth // specify explicit specializations either. This is important to allow 746926c4b486a08f698cd3a367fd6f1a3a07604358dChandler Carruth // specializing traits classes for private types. 747926c4b486a08f698cd3a367fd6f1a3a07604358dChandler Carruth bool SuppressingAccessChecks = false; 748926c4b486a08f698cd3a367fd6f1a3a07604358dChandler Carruth if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation || 749926c4b486a08f698cd3a367fd6f1a3a07604358dChandler Carruth TemplateInfo.Kind == ParsedTemplateInfo::ExplicitSpecialization) { 750926c4b486a08f698cd3a367fd6f1a3a07604358dChandler Carruth Actions.ActOnStartSuppressingAccessChecks(); 751926c4b486a08f698cd3a367fd6f1a3a07604358dChandler Carruth SuppressingAccessChecks = true; 752926c4b486a08f698cd3a367fd6f1a3a07604358dChandler Carruth } 753926c4b486a08f698cd3a367fd6f1a3a07604358dChandler Carruth 7540b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall ParsedAttributes attrs(AttrFactory); 755e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor // If attributes exist after tag, parse them. 756e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor if (Tok.is(tok::kw___attribute)) 7577f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall ParseGNUAttributes(attrs); 758e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor 759f59e17ecf06ac60065e2d02058bd6f21f5d216ccSteve Naroff // If declspecs exist after tag, parse them. 760b1d397c23e1f8fd8b404d5731d531e7500f7140dJohn McCall while (Tok.is(tok::kw___declspec)) 7617f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall ParseMicrosoftDeclSpec(attrs); 762193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam 763bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt // If C++0x attributes exist here, parse them. 764bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt // FIXME: Are we consistent with the ordering of parsing of different 765bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt // styles of attributes? 7667f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall MaybeParseCXX0XAttributes(attrs); 7671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 76820c0da7787c9a7d2529e42a4a91d777778595d74John Wiegley if (TagType == DeclSpec::TST_struct && 769b467cda8d97a1a18ee1aa62db3b7b21b2c294cebDouglas Gregor !Tok.is(tok::identifier) && 770b467cda8d97a1a18ee1aa62db3b7b21b2c294cebDouglas Gregor Tok.getIdentifierInfo() && 771b467cda8d97a1a18ee1aa62db3b7b21b2c294cebDouglas Gregor (Tok.is(tok::kw___is_arithmetic) || 772b467cda8d97a1a18ee1aa62db3b7b21b2c294cebDouglas Gregor Tok.is(tok::kw___is_convertible) || 77320c0da7787c9a7d2529e42a4a91d777778595d74John Wiegley Tok.is(tok::kw___is_empty) || 774b467cda8d97a1a18ee1aa62db3b7b21b2c294cebDouglas Gregor Tok.is(tok::kw___is_floating_point) || 775b467cda8d97a1a18ee1aa62db3b7b21b2c294cebDouglas Gregor Tok.is(tok::kw___is_function) || 77620c0da7787c9a7d2529e42a4a91d777778595d74John Wiegley Tok.is(tok::kw___is_fundamental) || 777b467cda8d97a1a18ee1aa62db3b7b21b2c294cebDouglas Gregor Tok.is(tok::kw___is_integral) || 778b467cda8d97a1a18ee1aa62db3b7b21b2c294cebDouglas Gregor Tok.is(tok::kw___is_member_function_pointer) || 779b467cda8d97a1a18ee1aa62db3b7b21b2c294cebDouglas Gregor Tok.is(tok::kw___is_member_pointer) || 780b467cda8d97a1a18ee1aa62db3b7b21b2c294cebDouglas Gregor Tok.is(tok::kw___is_pod) || 781b467cda8d97a1a18ee1aa62db3b7b21b2c294cebDouglas Gregor Tok.is(tok::kw___is_pointer) || 782b467cda8d97a1a18ee1aa62db3b7b21b2c294cebDouglas Gregor Tok.is(tok::kw___is_same) || 783877222e2491bbc40a5c74cc100c540983f306b70Douglas Gregor Tok.is(tok::kw___is_scalar) || 784b467cda8d97a1a18ee1aa62db3b7b21b2c294cebDouglas Gregor Tok.is(tok::kw___is_signed) || 785b467cda8d97a1a18ee1aa62db3b7b21b2c294cebDouglas Gregor Tok.is(tok::kw___is_unsigned) || 786b467cda8d97a1a18ee1aa62db3b7b21b2c294cebDouglas Gregor Tok.is(tok::kw___is_void))) { 787b467cda8d97a1a18ee1aa62db3b7b21b2c294cebDouglas Gregor // GNU libstdc++ 4.2 and libc++ uaw certain intrinsic names as the 788b467cda8d97a1a18ee1aa62db3b7b21b2c294cebDouglas Gregor // name of struct templates, but some are keywords in GCC >= 4.3 789b467cda8d97a1a18ee1aa62db3b7b21b2c294cebDouglas Gregor // and Clang. Therefore, when we see the token sequence "struct 790b467cda8d97a1a18ee1aa62db3b7b21b2c294cebDouglas Gregor // X", make X into a normal identifier rather than a keyword, to 791b467cda8d97a1a18ee1aa62db3b7b21b2c294cebDouglas Gregor // allow libstdc++ 4.2 and libc++ to work properly. 792646395bbcaa849c94bc2a3246c71d809ca719f01Argyrios Kyrtzidis Tok.getIdentifierInfo()->RevertTokenIDToIdentifier(); 793b117a60f7684261ddc8c8f14e8ef8a827e6af814Douglas Gregor Tok.setKind(tok::identifier); 794b117a60f7684261ddc8c8f14e8ef8a827e6af814Douglas Gregor } 7951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 796eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis // Parse the (optional) nested-name-specifier. 797aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall CXXScopeSpec &SS = DS.getTypeSpecScope(); 79808d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner if (getLang().CPlusPlus) { 79908d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner // "FOO : BAR" is not a potential typo for "FOO::BAR". 80008d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner ColonProtectionRAIIObject X(*this); 801193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam 802b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall if (ParseOptionalCXXScopeSpecifier(SS, ParsedType(), true)) 803207014eb2b372aa33721e86d90a8a586ba8dc8aeJohn McCall DS.SetTypeSpecError(); 8049ba6166f4a78722e7df8ffbd64eb788bfdf2764aJohn McCall if (SS.isSet()) 80508d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner if (Tok.isNot(tok::identifier) && Tok.isNot(tok::annot_template_id)) 80608d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner Diag(Tok, diag::err_expected_ident); 80708d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner } 808cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor 8092cc782f7932f1069d9fa8bb5c518165802aad68dDouglas Gregor TemplateParameterLists *TemplateParams = TemplateInfo.TemplateParams; 8102cc782f7932f1069d9fa8bb5c518165802aad68dDouglas Gregor 811cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor // Parse the (optional) class name or simple-template-id. 812e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor IdentifierInfo *Name = 0; 813e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor SourceLocation NameLoc; 81439a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor TemplateIdAnnotation *TemplateId = 0; 815e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor if (Tok.is(tok::identifier)) { 816e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor Name = Tok.getIdentifierInfo(); 817e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor NameLoc = ConsumeToken(); 818193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam 8195ee3734c0b5222a7c445591a1f14102c1b3a289bDouglas Gregor if (Tok.is(tok::less) && getLang().CPlusPlus) { 820193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam // The name was supposed to refer to a template, but didn't. 8212cc782f7932f1069d9fa8bb5c518165802aad68dDouglas Gregor // Eat the template argument list and try to continue parsing this as 8222cc782f7932f1069d9fa8bb5c518165802aad68dDouglas Gregor // a class (or template thereof). 8232cc782f7932f1069d9fa8bb5c518165802aad68dDouglas Gregor TemplateArgList TemplateArgs; 8242cc782f7932f1069d9fa8bb5c518165802aad68dDouglas Gregor SourceLocation LAngleLoc, RAngleLoc; 825059101f922de6eb765601459925f4c8914420b23Douglas Gregor if (ParseTemplateIdAfterTemplateName(TemplateTy(), NameLoc, SS, 8262cc782f7932f1069d9fa8bb5c518165802aad68dDouglas Gregor true, LAngleLoc, 827314b97f8c564b465af605efaee23f91ec18a982bDouglas Gregor TemplateArgs, RAngleLoc)) { 8282cc782f7932f1069d9fa8bb5c518165802aad68dDouglas Gregor // We couldn't parse the template argument list at all, so don't 8292cc782f7932f1069d9fa8bb5c518165802aad68dDouglas Gregor // try to give any location information for the list. 8302cc782f7932f1069d9fa8bb5c518165802aad68dDouglas Gregor LAngleLoc = RAngleLoc = SourceLocation(); 8312cc782f7932f1069d9fa8bb5c518165802aad68dDouglas Gregor } 832193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam 8332cc782f7932f1069d9fa8bb5c518165802aad68dDouglas Gregor Diag(NameLoc, diag::err_explicit_spec_non_template) 834c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor << (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation) 8352cc782f7932f1069d9fa8bb5c518165802aad68dDouglas Gregor << (TagType == DeclSpec::TST_class? 0 8362cc782f7932f1069d9fa8bb5c518165802aad68dDouglas Gregor : TagType == DeclSpec::TST_struct? 1 8372cc782f7932f1069d9fa8bb5c518165802aad68dDouglas Gregor : 2) 8382cc782f7932f1069d9fa8bb5c518165802aad68dDouglas Gregor << Name 8392cc782f7932f1069d9fa8bb5c518165802aad68dDouglas Gregor << SourceRange(LAngleLoc, RAngleLoc); 840193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam 841193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam // Strip off the last template parameter list if it was empty, since 842c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor // we've removed its template argument list. 843c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor if (TemplateParams && TemplateInfo.LastParameterListWasEmpty) { 844c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor if (TemplateParams && TemplateParams->size() > 1) { 845c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor TemplateParams->pop_back(); 846c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor } else { 847c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor TemplateParams = 0; 848193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam const_cast<ParsedTemplateInfo&>(TemplateInfo).Kind 849c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor = ParsedTemplateInfo::NonTemplate; 850c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor } 851c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor } else if (TemplateInfo.Kind 852c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor == ParsedTemplateInfo::ExplicitInstantiation) { 853c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor // Pretend this is just a forward declaration. 8542cc782f7932f1069d9fa8bb5c518165802aad68dDouglas Gregor TemplateParams = 0; 855193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam const_cast<ParsedTemplateInfo&>(TemplateInfo).Kind 8562cc782f7932f1069d9fa8bb5c518165802aad68dDouglas Gregor = ParsedTemplateInfo::NonTemplate; 857193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam const_cast<ParsedTemplateInfo&>(TemplateInfo).TemplateLoc 858c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor = SourceLocation(); 859c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor const_cast<ParsedTemplateInfo&>(TemplateInfo).ExternLoc 860c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor = SourceLocation(); 8612cc782f7932f1069d9fa8bb5c518165802aad68dDouglas Gregor } 8622cc782f7932f1069d9fa8bb5c518165802aad68dDouglas Gregor } 86339a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor } else if (Tok.is(tok::annot_template_id)) { 86439a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor TemplateId = static_cast<TemplateIdAnnotation *>(Tok.getAnnotationValue()); 86539a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor NameLoc = ConsumeToken(); 866cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor 867059101f922de6eb765601459925f4c8914420b23Douglas Gregor if (TemplateId->Kind != TNK_Type_template && 868059101f922de6eb765601459925f4c8914420b23Douglas Gregor TemplateId->Kind != TNK_Dependent_template_name) { 86939a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor // The template-name in the simple-template-id refers to 87039a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor // something other than a class template. Give an appropriate 87139a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor // error message and skip to the ';'. 87239a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor SourceRange Range(NameLoc); 87339a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor if (SS.isNotEmpty()) 87439a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor Range.setBegin(SS.getBeginLoc()); 87539a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor 87639a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor Diag(TemplateId->LAngleLoc, diag::err_template_spec_syntax_non_template) 87739a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor << Name << static_cast<int>(TemplateId->Kind) << Range; 8781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 87939a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor DS.SetTypeSpecError(); 88039a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor SkipUntil(tok::semi, false, true); 88139a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor TemplateId->Destroy(); 882926c4b486a08f698cd3a367fd6f1a3a07604358dChandler Carruth if (SuppressingAccessChecks) 883926c4b486a08f698cd3a367fd6f1a3a07604358dChandler Carruth Actions.ActOnStopSuppressingAccessChecks(); 884926c4b486a08f698cd3a367fd6f1a3a07604358dChandler Carruth 88539a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor return; 886cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor } 887e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor } 888e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor 889926c4b486a08f698cd3a367fd6f1a3a07604358dChandler Carruth // As soon as we're finished parsing the class's template-id, turn access 890926c4b486a08f698cd3a367fd6f1a3a07604358dChandler Carruth // checking back on. 891926c4b486a08f698cd3a367fd6f1a3a07604358dChandler Carruth if (SuppressingAccessChecks) 892926c4b486a08f698cd3a367fd6f1a3a07604358dChandler Carruth Actions.ActOnStopSuppressingAccessChecks(); 893926c4b486a08f698cd3a367fd6f1a3a07604358dChandler Carruth 89467d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall // There are four options here. If we have 'struct foo;', then this 89567d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall // is either a forward declaration or a friend declaration, which 896cc54d594d4f6509c0e3a8e349e481d9b5d899df6Anders Carlsson // have to be treated differently. If we have 'struct foo {...', 8971d20927fd0a08c26ef0e86e26f42073fd582ff77Anders Carlsson // 'struct foo :...' or 'struct foo final[opt]' then this is a 898cc54d594d4f6509c0e3a8e349e481d9b5d899df6Anders Carlsson // definition. Otherwise we have something like 'struct foo xyz', a reference. 899d9bafa76f8d6eb9e4f4974ed322217f8df6bb82eSebastian Redl // However, in some contexts, things look like declarations but are just 900d9bafa76f8d6eb9e4f4974ed322217f8df6bb82eSebastian Redl // references, e.g. 901d9bafa76f8d6eb9e4f4974ed322217f8df6bb82eSebastian Redl // new struct s; 902d9bafa76f8d6eb9e4f4974ed322217f8df6bb82eSebastian Redl // or 903d9bafa76f8d6eb9e4f4974ed322217f8df6bb82eSebastian Redl // &T::operator struct s; 904d9bafa76f8d6eb9e4f4974ed322217f8df6bb82eSebastian Redl // For these, SuppressDeclarations is true. 905f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Sema::TagUseKind TUK; 906d9bafa76f8d6eb9e4f4974ed322217f8df6bb82eSebastian Redl if (SuppressDeclarations) 907f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall TUK = Sema::TUK_Reference; 908cc54d594d4f6509c0e3a8e349e481d9b5d899df6Anders Carlsson else if (Tok.is(tok::l_brace) || 909cc54d594d4f6509c0e3a8e349e481d9b5d899df6Anders Carlsson (getLang().CPlusPlus && Tok.is(tok::colon)) || 9108a29ba0d66bce99014651f1e3351aef6c3361d3fAnders Carlsson isCXX0XFinalKeyword()) { 911d85bea2affdd59d83d1be7d24b97f436484c3625Douglas Gregor if (DS.isFriendSpecified()) { 912d85bea2affdd59d83d1be7d24b97f436484c3625Douglas Gregor // C++ [class.friend]p2: 913d85bea2affdd59d83d1be7d24b97f436484c3625Douglas Gregor // A class shall not be defined in a friend declaration. 914d85bea2affdd59d83d1be7d24b97f436484c3625Douglas Gregor Diag(Tok.getLocation(), diag::err_friend_decl_defines_class) 915d85bea2affdd59d83d1be7d24b97f436484c3625Douglas Gregor << SourceRange(DS.getFriendSpecLoc()); 916d85bea2affdd59d83d1be7d24b97f436484c3625Douglas Gregor 917d85bea2affdd59d83d1be7d24b97f436484c3625Douglas Gregor // Skip everything up to the semicolon, so that this looks like a proper 918d85bea2affdd59d83d1be7d24b97f436484c3625Douglas Gregor // friend class (or template thereof) declaration. 919d85bea2affdd59d83d1be7d24b97f436484c3625Douglas Gregor SkipUntil(tok::semi, true, true); 920f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall TUK = Sema::TUK_Friend; 921d85bea2affdd59d83d1be7d24b97f436484c3625Douglas Gregor } else { 922d85bea2affdd59d83d1be7d24b97f436484c3625Douglas Gregor // Okay, this is a class definition. 923f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall TUK = Sema::TUK_Definition; 924d85bea2affdd59d83d1be7d24b97f436484c3625Douglas Gregor } 925d85bea2affdd59d83d1be7d24b97f436484c3625Douglas Gregor } else if (Tok.is(tok::semi)) 926f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall TUK = DS.isFriendSpecified() ? Sema::TUK_Friend : Sema::TUK_Declaration; 927e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor else 928f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall TUK = Sema::TUK_Reference; 929e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor 930207014eb2b372aa33721e86d90a8a586ba8dc8aeJohn McCall if (!Name && !TemplateId && (DS.getTypeSpecType() == DeclSpec::TST_error || 931f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall TUK != Sema::TUK_Definition)) { 932207014eb2b372aa33721e86d90a8a586ba8dc8aeJohn McCall if (DS.getTypeSpecType() != DeclSpec::TST_error) { 933207014eb2b372aa33721e86d90a8a586ba8dc8aeJohn McCall // We have a declaration or reference to an anonymous class. 934207014eb2b372aa33721e86d90a8a586ba8dc8aeJohn McCall Diag(StartLoc, diag::err_anon_type_definition) 935207014eb2b372aa33721e86d90a8a586ba8dc8aeJohn McCall << DeclSpec::getSpecifierName(TagType); 936207014eb2b372aa33721e86d90a8a586ba8dc8aeJohn McCall } 937e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor 938e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor SkipUntil(tok::comma, true); 93939a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor 94039a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor if (TemplateId) 94139a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor TemplateId->Destroy(); 942e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor return; 943e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor } 944e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor 945ddc29e116db3c3f4144355e67a0137b38b6bb6d1Douglas Gregor // Create the tag portion of the class or class template. 946d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall DeclResult TagOrTempResult = true; // invalid 947d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall TypeResult TypeResult = true; // invalid 9484d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor 949402abb55fc2e0cdda5fb1ac90009b1f5f6774906Douglas Gregor bool Owned = false; 950f1bbbb49f06a7462476cd88166fccda5feb15cabJohn McCall if (TemplateId) { 9514d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor // Explicit specialization, class template partial specialization, 9524d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor // or explicit instantiation. 9531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ASTTemplateArgsPtr TemplateArgsPtr(Actions, 95439a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor TemplateId->getTemplateArgs(), 95539a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor TemplateId->NumArgs); 9564d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation && 957f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall TUK == Sema::TUK_Declaration) { 9584d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor // This is an explicit instantiation of a class template. 9594d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor TagOrTempResult 96023c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor = Actions.ActOnExplicitInstantiation(getCurScope(), 96145f965581935791a018df829a14dff53c1dd8f47Douglas Gregor TemplateInfo.ExternLoc, 9621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TemplateInfo.TemplateLoc, 9634d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor TagType, 9641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump StartLoc, 9654d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor SS, 9662b5289b6fd7e3d9899868410a498c081c9595662John McCall TemplateId->Template, 9671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TemplateId->TemplateNameLoc, 9681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TemplateId->LAngleLoc, 9694d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor TemplateArgsPtr, 9701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TemplateId->RAngleLoc, 9717f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall attrs.getList()); 97274256f5ea6950c9fd34595aa124eb4740372f15cJohn McCall 97374256f5ea6950c9fd34595aa124eb4740372f15cJohn McCall // Friend template-ids are treated as references unless 97474256f5ea6950c9fd34595aa124eb4740372f15cJohn McCall // they have template headers, in which case they're ill-formed 97574256f5ea6950c9fd34595aa124eb4740372f15cJohn McCall // (FIXME: "template <class T> friend class A<T>::B<int>;"). 97674256f5ea6950c9fd34595aa124eb4740372f15cJohn McCall // We diagnose this error in ActOnClassTemplateSpecialization. 977f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall } else if (TUK == Sema::TUK_Reference || 978f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall (TUK == Sema::TUK_Friend && 97974256f5ea6950c9fd34595aa124eb4740372f15cJohn McCall TemplateInfo.Kind == ParsedTemplateInfo::NonTemplate)) { 980059101f922de6eb765601459925f4c8914420b23Douglas Gregor TypeResult = Actions.ActOnTagTemplateIdType(TUK, TagType, 981059101f922de6eb765601459925f4c8914420b23Douglas Gregor StartLoc, 982059101f922de6eb765601459925f4c8914420b23Douglas Gregor TemplateId->SS, 983059101f922de6eb765601459925f4c8914420b23Douglas Gregor TemplateId->Template, 984059101f922de6eb765601459925f4c8914420b23Douglas Gregor TemplateId->TemplateNameLoc, 985059101f922de6eb765601459925f4c8914420b23Douglas Gregor TemplateId->LAngleLoc, 986059101f922de6eb765601459925f4c8914420b23Douglas Gregor TemplateArgsPtr, 987059101f922de6eb765601459925f4c8914420b23Douglas Gregor TemplateId->RAngleLoc); 9884d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor } else { 9894d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor // This is an explicit specialization or a class template 9904d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor // partial specialization. 9914d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor TemplateParameterLists FakedParamLists; 9924d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor 9934d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation) { 9944d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor // This looks like an explicit instantiation, because we have 9954d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor // something like 9964d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor // 9974d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor // template class Foo<X> 9984d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor // 9993f5b61c394f4f205bcb4d316eb2a7a0a68b8af86Douglas Gregor // but it actually has a definition. Most likely, this was 10004d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor // meant to be an explicit specialization, but the user forgot 10014d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor // the '<>' after 'template'. 1002f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall assert(TUK == Sema::TUK_Definition && "Expected a definition here"); 10034d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor 10041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation LAngleLoc 10054d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor = PP.getLocForEndOfToken(TemplateInfo.TemplateLoc); 10061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Diag(TemplateId->TemplateNameLoc, 10074d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor diag::err_explicit_instantiation_with_definition) 10084d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor << SourceRange(TemplateInfo.TemplateLoc) 1009849b243d4065f56742a4677d6dc8277609a151f8Douglas Gregor << FixItHint::CreateInsertion(LAngleLoc, "<>"); 10104d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor 10114d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor // Create a fake template parameter list that contains only 10124d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor // "template<>", so that we treat this construct as a class 10134d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor // template specialization. 10144d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor FakedParamLists.push_back( 10151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Actions.ActOnTemplateParameterList(0, SourceLocation(), 10164d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor TemplateInfo.TemplateLoc, 10171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump LAngleLoc, 10181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 0, 0, 10194d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor LAngleLoc)); 10204d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor TemplateParams = &FakedParamLists; 10214d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor } 10224d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor 10234d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor // Build the class template specialization. 10244d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor TagOrTempResult 102523c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor = Actions.ActOnClassTemplateSpecialization(getCurScope(), TagType, TUK, 102639a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor StartLoc, SS, 10272b5289b6fd7e3d9899868410a498c081c9595662John McCall TemplateId->Template, 10281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TemplateId->TemplateNameLoc, 10291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TemplateId->LAngleLoc, 103039a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor TemplateArgsPtr, 10311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TemplateId->RAngleLoc, 10327f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall attrs.getList(), 1033f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall MultiTemplateParamsArg(Actions, 1034cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor TemplateParams? &(*TemplateParams)[0] : 0, 1035cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor TemplateParams? TemplateParams->size() : 0)); 10364d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor } 103739a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor TemplateId->Destroy(); 10383f5b61c394f4f205bcb4d316eb2a7a0a68b8af86Douglas Gregor } else if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation && 1039f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall TUK == Sema::TUK_Declaration) { 10403f5b61c394f4f205bcb4d316eb2a7a0a68b8af86Douglas Gregor // Explicit instantiation of a member of a class template 10413f5b61c394f4f205bcb4d316eb2a7a0a68b8af86Douglas Gregor // specialization, e.g., 10423f5b61c394f4f205bcb4d316eb2a7a0a68b8af86Douglas Gregor // 10433f5b61c394f4f205bcb4d316eb2a7a0a68b8af86Douglas Gregor // template struct Outer<int>::Inner; 10443f5b61c394f4f205bcb4d316eb2a7a0a68b8af86Douglas Gregor // 10453f5b61c394f4f205bcb4d316eb2a7a0a68b8af86Douglas Gregor TagOrTempResult 104623c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor = Actions.ActOnExplicitInstantiation(getCurScope(), 104745f965581935791a018df829a14dff53c1dd8f47Douglas Gregor TemplateInfo.ExternLoc, 10481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TemplateInfo.TemplateLoc, 10491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TagType, StartLoc, SS, Name, 10507f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall NameLoc, attrs.getList()); 10519a34edb710917798aa30263374f624f13b594605John McCall } else if (TUK == Sema::TUK_Friend && 10529a34edb710917798aa30263374f624f13b594605John McCall TemplateInfo.Kind != ParsedTemplateInfo::NonTemplate) { 10539a34edb710917798aa30263374f624f13b594605John McCall TagOrTempResult = 10549a34edb710917798aa30263374f624f13b594605John McCall Actions.ActOnTemplatedFriendTag(getCurScope(), DS.getFriendSpecLoc(), 10559a34edb710917798aa30263374f624f13b594605John McCall TagType, StartLoc, SS, 10567f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall Name, NameLoc, attrs.getList(), 10579a34edb710917798aa30263374f624f13b594605John McCall MultiTemplateParamsArg(Actions, 10589a34edb710917798aa30263374f624f13b594605John McCall TemplateParams? &(*TemplateParams)[0] : 0, 10599a34edb710917798aa30263374f624f13b594605John McCall TemplateParams? TemplateParams->size() : 0)); 10603f5b61c394f4f205bcb4d316eb2a7a0a68b8af86Douglas Gregor } else { 10613f5b61c394f4f205bcb4d316eb2a7a0a68b8af86Douglas Gregor if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation && 1062f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall TUK == Sema::TUK_Definition) { 10633f5b61c394f4f205bcb4d316eb2a7a0a68b8af86Douglas Gregor // FIXME: Diagnose this particular error. 10643f5b61c394f4f205bcb4d316eb2a7a0a68b8af86Douglas Gregor } 10653f5b61c394f4f205bcb4d316eb2a7a0a68b8af86Douglas Gregor 1066c4e7019d5c9034a2d84ee4695f8e98dc025ac131John McCall bool IsDependent = false; 1067c4e7019d5c9034a2d84ee4695f8e98dc025ac131John McCall 1068a25c4080a490ea2bab6f54094dd75b19eae83770John McCall // Don't pass down template parameter lists if this is just a tag 1069a25c4080a490ea2bab6f54094dd75b19eae83770John McCall // reference. For example, we don't need the template parameters here: 1070a25c4080a490ea2bab6f54094dd75b19eae83770John McCall // template <class T> class A *makeA(T t); 1071a25c4080a490ea2bab6f54094dd75b19eae83770John McCall MultiTemplateParamsArg TParams; 1072a25c4080a490ea2bab6f54094dd75b19eae83770John McCall if (TUK != Sema::TUK_Reference && TemplateParams) 1073a25c4080a490ea2bab6f54094dd75b19eae83770John McCall TParams = 1074a25c4080a490ea2bab6f54094dd75b19eae83770John McCall MultiTemplateParamsArg(&(*TemplateParams)[0], TemplateParams->size()); 1075a25c4080a490ea2bab6f54094dd75b19eae83770John McCall 10763f5b61c394f4f205bcb4d316eb2a7a0a68b8af86Douglas Gregor // Declaration or definition of a class type 10779a34edb710917798aa30263374f624f13b594605John McCall TagOrTempResult = Actions.ActOnTag(getCurScope(), TagType, TUK, StartLoc, 10787f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall SS, Name, NameLoc, attrs.getList(), AS, 1079a25c4080a490ea2bab6f54094dd75b19eae83770John McCall TParams, Owned, IsDependent, false, 1080a88cefd266c428be33cc06f7e8b00ff8fc97c1ffAbramo Bagnara false, clang::TypeResult()); 1081c4e7019d5c9034a2d84ee4695f8e98dc025ac131John McCall 1082c4e7019d5c9034a2d84ee4695f8e98dc025ac131John McCall // If ActOnTag said the type was dependent, try again with the 1083c4e7019d5c9034a2d84ee4695f8e98dc025ac131John McCall // less common call. 10849a34edb710917798aa30263374f624f13b594605John McCall if (IsDependent) { 10859a34edb710917798aa30263374f624f13b594605John McCall assert(TUK == Sema::TUK_Reference || TUK == Sema::TUK_Friend); 108623c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor TypeResult = Actions.ActOnDependentTag(getCurScope(), TagType, TUK, 1087193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam SS, Name, StartLoc, NameLoc); 10889a34edb710917798aa30263374f624f13b594605John McCall } 10893f5b61c394f4f205bcb4d316eb2a7a0a68b8af86Douglas Gregor } 1090e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor 1091e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor // If there is a body, parse it and inform the actions module. 1092f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall if (TUK == Sema::TUK_Definition) { 1093bd0dfa5c37d422427080a0ae3af9b63e70e6e854John McCall assert(Tok.is(tok::l_brace) || 1094cc54d594d4f6509c0e3a8e349e481d9b5d899df6Anders Carlsson (getLang().CPlusPlus && Tok.is(tok::colon)) || 10958a29ba0d66bce99014651f1e3351aef6c3361d3fAnders Carlsson isCXX0XFinalKeyword()); 109607952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis if (getLang().CPlusPlus) 1097212e81cc5151b3c42346e43cfd42499a53ffd39aDouglas Gregor ParseCXXMemberSpecification(StartLoc, TagType, TagOrTempResult.get()); 109807952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis else 1099212e81cc5151b3c42346e43cfd42499a53ffd39aDouglas Gregor ParseStructUnionBody(StartLoc, TagType, TagOrTempResult.get()); 1100e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor } 1101e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor 1102b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall const char *PrevSpec = 0; 1103b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall unsigned DiagID; 1104b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall bool Result; 1105c4e7019d5c9034a2d84ee4695f8e98dc025ac131John McCall if (!TypeResult.isInvalid()) { 11060daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara Result = DS.SetTypeSpecType(DeclSpec::TST_typename, StartLoc, 11070daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara NameLoc.isValid() ? NameLoc : StartLoc, 1108b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall PrevSpec, DiagID, TypeResult.get()); 1109c4e7019d5c9034a2d84ee4695f8e98dc025ac131John McCall } else if (!TagOrTempResult.isInvalid()) { 11100daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara Result = DS.SetTypeSpecType(TagType, StartLoc, 11110daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara NameLoc.isValid() ? NameLoc : StartLoc, 11120daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara PrevSpec, DiagID, TagOrTempResult.get(), Owned); 1113c4e7019d5c9034a2d84ee4695f8e98dc025ac131John McCall } else { 1114ddc29e116db3c3f4144355e67a0137b38b6bb6d1Douglas Gregor DS.SetTypeSpecError(); 111566e9977ddd6b197317d149213b76a9af0d3df4deAnders Carlsson return; 111666e9977ddd6b197317d149213b76a9af0d3df4deAnders Carlsson } 11171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1118b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall if (Result) 1119fec54013fcd0eb72642741584ca04c1bc292bef8John McCall Diag(StartLoc, DiagID) << PrevSpec; 1120193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam 11214ed5d91db256f7dbe6bf716da0b801004c197254Chris Lattner // At this point, we've successfully parsed a class-specifier in 'definition' 11224ed5d91db256f7dbe6bf716da0b801004c197254Chris Lattner // form (e.g. "struct foo { int x; }". While we could just return here, we're 11234ed5d91db256f7dbe6bf716da0b801004c197254Chris Lattner // going to look at what comes after it to improve error recovery. If an 11244ed5d91db256f7dbe6bf716da0b801004c197254Chris Lattner // impossible token occurs next, we assume that the programmer forgot a ; at 11254ed5d91db256f7dbe6bf716da0b801004c197254Chris Lattner // the end of the declaration and recover that way. 11264ed5d91db256f7dbe6bf716da0b801004c197254Chris Lattner // 11274ed5d91db256f7dbe6bf716da0b801004c197254Chris Lattner // This switch enumerates the valid "follow" set for definition. 1128f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall if (TUK == Sema::TUK_Definition) { 1129b3a4e432c90be98c6d918087750397e86d030368Chris Lattner bool ExpectedSemi = true; 11304ed5d91db256f7dbe6bf716da0b801004c197254Chris Lattner switch (Tok.getKind()) { 1131b3a4e432c90be98c6d918087750397e86d030368Chris Lattner default: break; 11324ed5d91db256f7dbe6bf716da0b801004c197254Chris Lattner case tok::semi: // struct foo {...} ; 113399c952046600f6bfccf315aa7ad5b1be2d242cc3Chris Lattner case tok::star: // struct foo {...} * P; 113499c952046600f6bfccf315aa7ad5b1be2d242cc3Chris Lattner case tok::amp: // struct foo {...} & R = ... 113599c952046600f6bfccf315aa7ad5b1be2d242cc3Chris Lattner case tok::identifier: // struct foo {...} V ; 113699c952046600f6bfccf315aa7ad5b1be2d242cc3Chris Lattner case tok::r_paren: //(struct foo {...} ) {4} 113799c952046600f6bfccf315aa7ad5b1be2d242cc3Chris Lattner case tok::annot_cxxscope: // struct foo {...} a:: b; 113899c952046600f6bfccf315aa7ad5b1be2d242cc3Chris Lattner case tok::annot_typename: // struct foo {...} a ::b; 113999c952046600f6bfccf315aa7ad5b1be2d242cc3Chris Lattner case tok::annot_template_id: // struct foo {...} a<int> ::b; 1140c2e1c1af8ffe750b827284f207b9207112c7cc4eChris Lattner case tok::l_paren: // struct foo {...} ( x); 114116acfee729e00536af827935ccfcf69be721e462Chris Lattner case tok::comma: // __builtin_offsetof(struct foo{...} , 1142b3a4e432c90be98c6d918087750397e86d030368Chris Lattner ExpectedSemi = false; 1143b3a4e432c90be98c6d918087750397e86d030368Chris Lattner break; 1144b3a4e432c90be98c6d918087750397e86d030368Chris Lattner // Type qualifiers 1145b3a4e432c90be98c6d918087750397e86d030368Chris Lattner case tok::kw_const: // struct foo {...} const x; 1146b3a4e432c90be98c6d918087750397e86d030368Chris Lattner case tok::kw_volatile: // struct foo {...} volatile x; 1147b3a4e432c90be98c6d918087750397e86d030368Chris Lattner case tok::kw_restrict: // struct foo {...} restrict x; 1148b3a4e432c90be98c6d918087750397e86d030368Chris Lattner case tok::kw_inline: // struct foo {...} inline foo() {}; 114999c952046600f6bfccf315aa7ad5b1be2d242cc3Chris Lattner // Storage-class specifiers 115099c952046600f6bfccf315aa7ad5b1be2d242cc3Chris Lattner case tok::kw_static: // struct foo {...} static x; 115199c952046600f6bfccf315aa7ad5b1be2d242cc3Chris Lattner case tok::kw_extern: // struct foo {...} extern x; 115299c952046600f6bfccf315aa7ad5b1be2d242cc3Chris Lattner case tok::kw_typedef: // struct foo {...} typedef x; 115399c952046600f6bfccf315aa7ad5b1be2d242cc3Chris Lattner case tok::kw_register: // struct foo {...} register x; 115499c952046600f6bfccf315aa7ad5b1be2d242cc3Chris Lattner case tok::kw_auto: // struct foo {...} auto x; 115533f992425213f381fc503699b26ee8cf9b60494eDouglas Gregor case tok::kw_mutable: // struct foo {...} mutable x; 1156b3a4e432c90be98c6d918087750397e86d030368Chris Lattner // As shown above, type qualifiers and storage class specifiers absolutely 1157b3a4e432c90be98c6d918087750397e86d030368Chris Lattner // can occur after class specifiers according to the grammar. However, 1158fc8f0e14ad142ed811e90fbd9a30e419e301c717Chris Lattner // almost no one actually writes code like this. If we see one of these, 1159b3a4e432c90be98c6d918087750397e86d030368Chris Lattner // it is much more likely that someone missed a semi colon and the 1160b3a4e432c90be98c6d918087750397e86d030368Chris Lattner // type/storage class specifier we're seeing is part of the *next* 1161b3a4e432c90be98c6d918087750397e86d030368Chris Lattner // intended declaration, as in: 1162b3a4e432c90be98c6d918087750397e86d030368Chris Lattner // 1163b3a4e432c90be98c6d918087750397e86d030368Chris Lattner // struct foo { ... } 1164b3a4e432c90be98c6d918087750397e86d030368Chris Lattner // typedef int X; 1165b3a4e432c90be98c6d918087750397e86d030368Chris Lattner // 1166b3a4e432c90be98c6d918087750397e86d030368Chris Lattner // We'd really like to emit a missing semicolon error instead of emitting 1167b3a4e432c90be98c6d918087750397e86d030368Chris Lattner // an error on the 'int' saying that you can't have two type specifiers in 1168b3a4e432c90be98c6d918087750397e86d030368Chris Lattner // the same declaration of X. Because of this, we look ahead past this 1169b3a4e432c90be98c6d918087750397e86d030368Chris Lattner // token to see if it's a type specifier. If so, we know the code is 1170b3a4e432c90be98c6d918087750397e86d030368Chris Lattner // otherwise invalid, so we can produce the expected semi error. 1171b3a4e432c90be98c6d918087750397e86d030368Chris Lattner if (!isKnownToBeTypeSpecifier(NextToken())) 1172b3a4e432c90be98c6d918087750397e86d030368Chris Lattner ExpectedSemi = false; 11734ed5d91db256f7dbe6bf716da0b801004c197254Chris Lattner break; 1174193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam 1175193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam case tok::r_brace: // struct bar { struct foo {...} } 11764ed5d91db256f7dbe6bf716da0b801004c197254Chris Lattner // Missing ';' at end of struct is accepted as an extension in C mode. 1177b3a4e432c90be98c6d918087750397e86d030368Chris Lattner if (!getLang().CPlusPlus) 1178b3a4e432c90be98c6d918087750397e86d030368Chris Lattner ExpectedSemi = false; 1179b3a4e432c90be98c6d918087750397e86d030368Chris Lattner break; 1180b3a4e432c90be98c6d918087750397e86d030368Chris Lattner } 1181193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam 1182b3a4e432c90be98c6d918087750397e86d030368Chris Lattner if (ExpectedSemi) { 11834ed5d91db256f7dbe6bf716da0b801004c197254Chris Lattner ExpectAndConsume(tok::semi, diag::err_expected_semi_after_tagdecl, 11844ed5d91db256f7dbe6bf716da0b801004c197254Chris Lattner TagType == DeclSpec::TST_class ? "class" 11854ed5d91db256f7dbe6bf716da0b801004c197254Chris Lattner : TagType == DeclSpec::TST_struct? "struct" : "union"); 11864ed5d91db256f7dbe6bf716da0b801004c197254Chris Lattner // Push this token back into the preprocessor and change our current token 11874ed5d91db256f7dbe6bf716da0b801004c197254Chris Lattner // to ';' so that the rest of the code recovers as though there were an 11884ed5d91db256f7dbe6bf716da0b801004c197254Chris Lattner // ';' after the definition. 11894ed5d91db256f7dbe6bf716da0b801004c197254Chris Lattner PP.EnterToken(Tok); 1190193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam Tok.setKind(tok::semi); 11914ed5d91db256f7dbe6bf716da0b801004c197254Chris Lattner } 11924ed5d91db256f7dbe6bf716da0b801004c197254Chris Lattner } 1193e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor} 1194e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor 11951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// ParseBaseClause - Parse the base-clause of a C++ class [C++ class.derived]. 1196e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// 1197e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// base-clause : [C++ class.derived] 1198e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// ':' base-specifier-list 1199e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// base-specifier-list: 1200e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// base-specifier '...'[opt] 1201e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// base-specifier-list ',' base-specifier '...'[opt] 1202d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallvoid Parser::ParseBaseClause(Decl *ClassDecl) { 1203e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor assert(Tok.is(tok::colon) && "Not a base clause"); 1204e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor ConsumeToken(); 1205e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor 1206f8268ae3196002bbab6adb830302e79b0f368f13Douglas Gregor // Build up an array of parsed base specifiers. 1207ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall llvm::SmallVector<CXXBaseSpecifier *, 8> BaseInfo; 1208f8268ae3196002bbab6adb830302e79b0f368f13Douglas Gregor 1209e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor while (true) { 1210e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor // Parse a base-specifier. 1211f8268ae3196002bbab6adb830302e79b0f368f13Douglas Gregor BaseResult Result = ParseBaseSpecifier(ClassDecl); 12125ac8aff3d7431dc7e4d64d960574a10c9f7e0078Douglas Gregor if (Result.isInvalid()) { 1213e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor // Skip the rest of this base specifier, up until the comma or 1214e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor // opening brace. 1215f8268ae3196002bbab6adb830302e79b0f368f13Douglas Gregor SkipUntil(tok::comma, tok::l_brace, true, true); 1216f8268ae3196002bbab6adb830302e79b0f368f13Douglas Gregor } else { 1217f8268ae3196002bbab6adb830302e79b0f368f13Douglas Gregor // Add this to our array of base specifiers. 12185ac8aff3d7431dc7e4d64d960574a10c9f7e0078Douglas Gregor BaseInfo.push_back(Result.get()); 1219e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor } 1220e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor 1221e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor // If the next token is a comma, consume it and keep reading 1222e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor // base-specifiers. 1223e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor if (Tok.isNot(tok::comma)) break; 12241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1225e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor // Consume the comma. 1226e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor ConsumeToken(); 1227e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor } 1228f8268ae3196002bbab6adb830302e79b0f368f13Douglas Gregor 1229f8268ae3196002bbab6adb830302e79b0f368f13Douglas Gregor // Attach the base specifiers 1230beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad Actions.ActOnBaseSpecifiers(ClassDecl, BaseInfo.data(), BaseInfo.size()); 1231e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor} 1232e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor 1233e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// ParseBaseSpecifier - Parse a C++ base-specifier. A base-specifier is 1234e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// one entry in the base class list of a class specifier, for example: 1235e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// class foo : public bar, virtual private baz { 1236e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// 'public bar' and 'virtual private baz' are each base-specifiers. 1237e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// 1238e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// base-specifier: [C++ class.derived] 1239e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// ::[opt] nested-name-specifier[opt] class-name 1240e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// 'virtual' access-specifier[opt] ::[opt] nested-name-specifier[opt] 1241e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// class-name 1242e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// access-specifier 'virtual'[opt] ::[opt] nested-name-specifier[opt] 1243e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// class-name 1244d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallParser::BaseResult Parser::ParseBaseSpecifier(Decl *ClassDecl) { 1245e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor bool IsVirtual = false; 1246e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor SourceLocation StartLoc = Tok.getLocation(); 1247e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor 1248e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor // Parse the 'virtual' keyword. 1249e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor if (Tok.is(tok::kw_virtual)) { 1250e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor ConsumeToken(); 1251e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor IsVirtual = true; 1252e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor } 1253e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor 1254e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor // Parse an (optional) access specifier. 1255e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor AccessSpecifier Access = getAccessSpecifierIfPresent(); 125692f883177b162928a8e632e4e3b93fafd2b26072John McCall if (Access != AS_none) 1257e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor ConsumeToken(); 12581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1259e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor // Parse the 'virtual' keyword (again!), in case it came after the 1260e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor // access specifier. 1261e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor if (Tok.is(tok::kw_virtual)) { 1262e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor SourceLocation VirtualLoc = ConsumeToken(); 1263e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor if (IsVirtual) { 1264e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor // Complain about duplicate 'virtual' 12651ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(VirtualLoc, diag::err_dup_virtual) 1266849b243d4065f56742a4677d6dc8277609a151f8Douglas Gregor << FixItHint::CreateRemoval(VirtualLoc); 1267e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor } 1268e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor 1269e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor IsVirtual = true; 1270e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor } 1271e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor 1272eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis // Parse optional '::' and optional nested-name-specifier. 1273eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis CXXScopeSpec SS; 1274b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParseOptionalCXXScopeSpecifier(SS, ParsedType(), /*EnteringContext=*/false); 1275e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor 1276e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor // The location of the base class itself. 1277e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor SourceLocation BaseLoc = Tok.getLocation(); 127842a552f8200ba5948661aee0106fce0c04e39818Douglas Gregor 127942a552f8200ba5948661aee0106fce0c04e39818Douglas Gregor // Parse the class-name. 12807f43d6764797ab21216421aeb00f4ec314d503d1Douglas Gregor SourceLocation EndLocation; 1281059101f922de6eb765601459925f4c8914420b23Douglas Gregor TypeResult BaseType = ParseClassName(EndLocation, SS); 128231a19b6989bbf326d2de5ae12e712e2a65ca9c34Douglas Gregor if (BaseType.isInvalid()) 128342a552f8200ba5948661aee0106fce0c04e39818Douglas Gregor return true; 12841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1285f90b27ad077c3339b62befc892382845339f9490Douglas Gregor // Parse the optional ellipsis (for a pack expansion). The ellipsis is 1286f90b27ad077c3339b62befc892382845339f9490Douglas Gregor // actually part of the base-specifier-list grammar productions, but we 1287f90b27ad077c3339b62befc892382845339f9490Douglas Gregor // parse it here for convenience. 1288f90b27ad077c3339b62befc892382845339f9490Douglas Gregor SourceLocation EllipsisLoc; 1289f90b27ad077c3339b62befc892382845339f9490Douglas Gregor if (Tok.is(tok::ellipsis)) 1290f90b27ad077c3339b62befc892382845339f9490Douglas Gregor EllipsisLoc = ConsumeToken(); 1291f90b27ad077c3339b62befc892382845339f9490Douglas Gregor 12921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // Find the complete source range for the base-specifier. 12937f43d6764797ab21216421aeb00f4ec314d503d1Douglas Gregor SourceRange Range(StartLoc, EndLocation); 12941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1295e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor // Notify semantic analysis that we have parsed a complete 1296e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor // base-specifier. 1297a55e52c0802cae3b7c366a05c461d3d15074c1a3Sebastian Redl return Actions.ActOnBaseSpecifier(ClassDecl, Range, IsVirtual, Access, 1298f90b27ad077c3339b62befc892382845339f9490Douglas Gregor BaseType.get(), BaseLoc, EllipsisLoc); 1299e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor} 1300e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor 1301e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// getAccessSpecifierIfPresent - Determine whether the next token is 1302e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// a C++ access-specifier. 1303e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// 1304e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// access-specifier: [C++ class.derived] 1305e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// 'private' 1306e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// 'protected' 1307e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// 'public' 13081eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpAccessSpecifier Parser::getAccessSpecifierIfPresent() const { 1309e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor switch (Tok.getKind()) { 1310e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor default: return AS_none; 1311e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor case tok::kw_private: return AS_private; 1312e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor case tok::kw_protected: return AS_protected; 1313e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor case tok::kw_public: return AS_public; 1314e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor } 1315e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor} 13164cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 1317d33133cdc1af466f9c276249b2621be03867888bEli Friedmanvoid Parser::HandleMemberFunctionDefaultArgs(Declarator& DeclaratorInfo, 1318d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ThisDecl) { 1319d33133cdc1af466f9c276249b2621be03867888bEli Friedman // We just declared a member function. If this member function 1320d33133cdc1af466f9c276249b2621be03867888bEli Friedman // has any default arguments, we'll need to parse them later. 1321d33133cdc1af466f9c276249b2621be03867888bEli Friedman LateParsedMethodDeclaration *LateMethod = 0; 13221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DeclaratorChunk::FunctionTypeInfo &FTI 1323075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara = DeclaratorInfo.getFunctionTypeInfo(); 1324d33133cdc1af466f9c276249b2621be03867888bEli Friedman for (unsigned ParamIdx = 0; ParamIdx < FTI.NumArgs; ++ParamIdx) { 1325d33133cdc1af466f9c276249b2621be03867888bEli Friedman if (LateMethod || FTI.ArgInfo[ParamIdx].DefaultArgTokens) { 1326d33133cdc1af466f9c276249b2621be03867888bEli Friedman if (!LateMethod) { 1327d33133cdc1af466f9c276249b2621be03867888bEli Friedman // Push this method onto the stack of late-parsed method 1328d33133cdc1af466f9c276249b2621be03867888bEli Friedman // declarations. 1329d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor LateMethod = new LateParsedMethodDeclaration(this, ThisDecl); 1330d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor getCurrentClass().LateParsedDeclarations.push_back(LateMethod); 133123c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor LateMethod->TemplateScope = getCurScope()->isTemplateParamScope(); 1332d33133cdc1af466f9c276249b2621be03867888bEli Friedman 1333d33133cdc1af466f9c276249b2621be03867888bEli Friedman // Add all of the parameters prior to this one (they don't 1334d33133cdc1af466f9c276249b2621be03867888bEli Friedman // have default arguments). 1335d33133cdc1af466f9c276249b2621be03867888bEli Friedman LateMethod->DefaultArgs.reserve(FTI.NumArgs); 1336d33133cdc1af466f9c276249b2621be03867888bEli Friedman for (unsigned I = 0; I < ParamIdx; ++I) 1337d33133cdc1af466f9c276249b2621be03867888bEli Friedman LateMethod->DefaultArgs.push_back( 13388f8210c47797f013e0fb24a26f9c4751b10783feDouglas Gregor LateParsedDefaultArgument(FTI.ArgInfo[I].Param)); 1339d33133cdc1af466f9c276249b2621be03867888bEli Friedman } 1340d33133cdc1af466f9c276249b2621be03867888bEli Friedman 1341d33133cdc1af466f9c276249b2621be03867888bEli Friedman // Add this parameter to the list of parameters (it or may 1342d33133cdc1af466f9c276249b2621be03867888bEli Friedman // not have a default argument). 1343d33133cdc1af466f9c276249b2621be03867888bEli Friedman LateMethod->DefaultArgs.push_back( 1344d33133cdc1af466f9c276249b2621be03867888bEli Friedman LateParsedDefaultArgument(FTI.ArgInfo[ParamIdx].Param, 1345d33133cdc1af466f9c276249b2621be03867888bEli Friedman FTI.ArgInfo[ParamIdx].DefaultArgTokens)); 1346d33133cdc1af466f9c276249b2621be03867888bEli Friedman } 1347d33133cdc1af466f9c276249b2621be03867888bEli Friedman } 1348d33133cdc1af466f9c276249b2621be03867888bEli Friedman} 1349d33133cdc1af466f9c276249b2621be03867888bEli Friedman 13501f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson/// isCXX0XVirtSpecifier - Determine whether the next token is a C++0x 13511f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson/// virt-specifier. 13521f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson/// 13531f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson/// virt-specifier: 13541f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson/// override 13551f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson/// final 1356cc54d594d4f6509c0e3a8e349e481d9b5d899df6Anders CarlssonVirtSpecifiers::Specifier Parser::isCXX0XVirtSpecifier() const { 1357ce93a7cee6c0ea979c12b278771a79c4d6a37fc0Anders Carlsson if (!getLang().CPlusPlus) 1358cc54d594d4f6509c0e3a8e349e481d9b5d899df6Anders Carlsson return VirtSpecifiers::VS_None; 1359cc54d594d4f6509c0e3a8e349e481d9b5d899df6Anders Carlsson 1360b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson if (Tok.is(tok::identifier)) { 1361b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson IdentifierInfo *II = Tok.getIdentifierInfo(); 13621f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson 13637eeb4ec11043d4860361348f2b19299d957d47a9Anders Carlsson // Initialize the contextual keywords. 13647eeb4ec11043d4860361348f2b19299d957d47a9Anders Carlsson if (!Ident_final) { 13657eeb4ec11043d4860361348f2b19299d957d47a9Anders Carlsson Ident_final = &PP.getIdentifierTable().get("final"); 13667eeb4ec11043d4860361348f2b19299d957d47a9Anders Carlsson Ident_override = &PP.getIdentifierTable().get("override"); 13677eeb4ec11043d4860361348f2b19299d957d47a9Anders Carlsson } 13687eeb4ec11043d4860361348f2b19299d957d47a9Anders Carlsson 1369b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson if (II == Ident_override) 1370b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson return VirtSpecifiers::VS_Override; 13711f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson 1372b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson if (II == Ident_final) 1373b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson return VirtSpecifiers::VS_Final; 1374b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson } 1375b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson 1376b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson return VirtSpecifiers::VS_None; 13771f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson} 13781f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson 13791f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson/// ParseOptionalCXX0XVirtSpecifierSeq - Parse a virt-specifier-seq. 13801f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson/// 13811f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson/// virt-specifier-seq: 13821f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson/// virt-specifier 13831f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson/// virt-specifier-seq virt-specifier 1384b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlssonvoid Parser::ParseOptionalCXX0XVirtSpecifierSeq(VirtSpecifiers &VS) { 1385b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson while (true) { 1386cc54d594d4f6509c0e3a8e349e481d9b5d899df6Anders Carlsson VirtSpecifiers::Specifier Specifier = isCXX0XVirtSpecifier(); 1387b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson if (Specifier == VirtSpecifiers::VS_None) 1388b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson return; 1389b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson 1390b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson // C++ [class.mem]p8: 1391b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson // A virt-specifier-seq shall contain at most one of each virt-specifier. 1392cc54d594d4f6509c0e3a8e349e481d9b5d899df6Anders Carlsson const char *PrevSpec = 0; 139346127a96b6dd6b93aa18d5f7a55bc2db8b52a2c9Anders Carlsson if (VS.SetSpecifier(Specifier, Tok.getLocation(), PrevSpec)) 1394b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson Diag(Tok.getLocation(), diag::err_duplicate_virt_specifier) 1395b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson << PrevSpec 1396b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson << FixItHint::CreateRemoval(Tok.getLocation()); 1397b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson 1398ce93a7cee6c0ea979c12b278771a79c4d6a37fc0Anders Carlsson if (!getLang().CPlusPlus0x) 1399ce93a7cee6c0ea979c12b278771a79c4d6a37fc0Anders Carlsson Diag(Tok.getLocation(), diag::ext_override_control_keyword) 1400ce93a7cee6c0ea979c12b278771a79c4d6a37fc0Anders Carlsson << VirtSpecifiers::getSpecifierName(Specifier); 1401b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson ConsumeToken(); 1402b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson } 14031f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson} 14041f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson 14058a29ba0d66bce99014651f1e3351aef6c3361d3fAnders Carlsson/// isCXX0XFinalKeyword - Determine whether the next token is a C++0x 14068a29ba0d66bce99014651f1e3351aef6c3361d3fAnders Carlsson/// contextual 'final' keyword. 14078a29ba0d66bce99014651f1e3351aef6c3361d3fAnders Carlssonbool Parser::isCXX0XFinalKeyword() const { 1408ce93a7cee6c0ea979c12b278771a79c4d6a37fc0Anders Carlsson if (!getLang().CPlusPlus) 14098a29ba0d66bce99014651f1e3351aef6c3361d3fAnders Carlsson return false; 1410cc54d594d4f6509c0e3a8e349e481d9b5d899df6Anders Carlsson 14118a29ba0d66bce99014651f1e3351aef6c3361d3fAnders Carlsson if (!Tok.is(tok::identifier)) 14128a29ba0d66bce99014651f1e3351aef6c3361d3fAnders Carlsson return false; 1413cc54d594d4f6509c0e3a8e349e481d9b5d899df6Anders Carlsson 14148a29ba0d66bce99014651f1e3351aef6c3361d3fAnders Carlsson // Initialize the contextual keywords. 14158a29ba0d66bce99014651f1e3351aef6c3361d3fAnders Carlsson if (!Ident_final) { 14168a29ba0d66bce99014651f1e3351aef6c3361d3fAnders Carlsson Ident_final = &PP.getIdentifierTable().get("final"); 14178a29ba0d66bce99014651f1e3351aef6c3361d3fAnders Carlsson Ident_override = &PP.getIdentifierTable().get("override"); 1418cc54d594d4f6509c0e3a8e349e481d9b5d899df6Anders Carlsson } 14198a29ba0d66bce99014651f1e3351aef6c3361d3fAnders Carlsson 14208a29ba0d66bce99014651f1e3351aef6c3361d3fAnders Carlsson return Tok.getIdentifierInfo() == Ident_final; 1421cc54d594d4f6509c0e3a8e349e481d9b5d899df6Anders Carlsson} 1422cc54d594d4f6509c0e3a8e349e481d9b5d899df6Anders Carlsson 14234cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis/// ParseCXXClassMemberDeclaration - Parse a C++ class member declaration. 14244cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis/// 14254cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis/// member-declaration: 14264cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis/// decl-specifier-seq[opt] member-declarator-list[opt] ';' 14274cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis/// function-definition ';'[opt] 14284cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis/// ::[opt] nested-name-specifier template[opt] unqualified-id ';'[TODO] 14294cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis/// using-declaration [TODO] 1430511d7aba3b12853fdb88729a0313b80a60eab8adAnders Carlsson/// [C++0x] static_assert-declaration 14315aeccdbb4bdc94e48c04cacc59fa812af32109b2Anders Carlsson/// template-declaration 1432bc8d56496a6ecdba14769df03d75c001184f8c54Chris Lattner/// [GNU] '__extension__' member-declaration 14334cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis/// 14344cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis/// member-declarator-list: 14354cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis/// member-declarator 14364cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis/// member-declarator-list ',' member-declarator 14374cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis/// 14384cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis/// member-declarator: 14391f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson/// declarator virt-specifier-seq[opt] pure-specifier[opt] 14404cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis/// declarator constant-initializer[opt] 14414cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis/// identifier[opt] ':' constant-expression 14424cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis/// 14431f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson/// virt-specifier-seq: 14441f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson/// virt-specifier 14451f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson/// virt-specifier-seq virt-specifier 14461f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson/// 14471f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson/// virt-specifier: 14481f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson/// override 14491f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson/// final 14501f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson/// new 14511f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson/// 1452e2b6833d445c7a4ce64f1816c05f176ba1740acaSebastian Redl/// pure-specifier: 14534cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis/// '= 0' 14544cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis/// 14554cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis/// constant-initializer: 14564cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis/// '=' constant-expression 14574cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis/// 145837b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregorvoid Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS, 1459c9068d7dd94d439cec66c421115d15303e481025John McCall const ParsedTemplateInfo &TemplateInfo, 1460c9068d7dd94d439cec66c421115d15303e481025John McCall ParsingDeclRAIIObject *TemplateDiags) { 14618a9013d24864272cf5b18c908a267bd7a2bda4c4Douglas Gregor if (Tok.is(tok::at)) { 14628a9013d24864272cf5b18c908a267bd7a2bda4c4Douglas Gregor if (getLang().ObjC1 && NextToken().isObjCAtKeyword(tok::objc_defs)) 14638a9013d24864272cf5b18c908a267bd7a2bda4c4Douglas Gregor Diag(Tok, diag::err_at_defs_cxx); 14648a9013d24864272cf5b18c908a267bd7a2bda4c4Douglas Gregor else 14658a9013d24864272cf5b18c908a267bd7a2bda4c4Douglas Gregor Diag(Tok, diag::err_at_in_class); 14668a9013d24864272cf5b18c908a267bd7a2bda4c4Douglas Gregor 14678a9013d24864272cf5b18c908a267bd7a2bda4c4Douglas Gregor ConsumeToken(); 14688a9013d24864272cf5b18c908a267bd7a2bda4c4Douglas Gregor SkipUntil(tok::r_brace); 14698a9013d24864272cf5b18c908a267bd7a2bda4c4Douglas Gregor return; 14708a9013d24864272cf5b18c908a267bd7a2bda4c4Douglas Gregor } 14718a9013d24864272cf5b18c908a267bd7a2bda4c4Douglas Gregor 147260fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall // Access declarations. 147360fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall if (!TemplateInfo.Kind && 147460fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall (Tok.is(tok::identifier) || Tok.is(tok::coloncolon)) && 14759ba6166f4a78722e7df8ffbd64eb788bfdf2764aJohn McCall !TryAnnotateCXXScopeToken() && 147660fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall Tok.is(tok::annot_cxxscope)) { 147760fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall bool isAccessDecl = false; 147860fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall if (NextToken().is(tok::identifier)) 147960fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall isAccessDecl = GetLookAheadToken(2).is(tok::semi); 148060fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall else 148160fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall isAccessDecl = NextToken().is(tok::kw_operator); 148260fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall 148360fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall if (isAccessDecl) { 148460fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall // Collect the scope specifier token we annotated earlier. 148560fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall CXXScopeSpec SS; 1486b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParseOptionalCXXScopeSpecifier(SS, ParsedType(), false); 148760fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall 148860fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall // Try to parse an unqualified-id. 148960fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall UnqualifiedId Name; 1490b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall if (ParseUnqualifiedId(SS, false, true, true, ParsedType(), Name)) { 149160fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall SkipUntil(tok::semi); 149260fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall return; 149360fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall } 149460fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall 149560fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall // TODO: recover from mistakenly-qualified operator declarations. 149660fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall if (ExpectAndConsume(tok::semi, 149760fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall diag::err_expected_semi_after, 149860fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall "access declaration", 149960fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall tok::semi)) 150060fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall return; 150160fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall 150223c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.ActOnUsingDeclaration(getCurScope(), AS, 150360fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall false, SourceLocation(), 150460fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall SS, Name, 150560fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall /* AttrList */ 0, 150660fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall /* IsTypeName */ false, 150760fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall SourceLocation()); 150860fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall return; 150960fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall } 151060fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall } 151160fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall 1512511d7aba3b12853fdb88729a0313b80a60eab8adAnders Carlsson // static_assert-declaration 1513c6eb44b321c543c5bcf28727228a0cceced57e2ePeter Collingbourne if (Tok.is(tok::kw_static_assert) || Tok.is(tok::kw__Static_assert)) { 151437b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor // FIXME: Check for templates 151597144fc41a9419bf6d74fc9450e8ef3f6e11f7e0Chris Lattner SourceLocation DeclEnd; 151697144fc41a9419bf6d74fc9450e8ef3f6e11f7e0Chris Lattner ParseStaticAssertDeclaration(DeclEnd); 1517682bf92db408a6cbc3d37b5496a99b6ef85041ecChris Lattner return; 1518682bf92db408a6cbc3d37b5496a99b6ef85041ecChris Lattner } 15191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1520682bf92db408a6cbc3d37b5496a99b6ef85041ecChris Lattner if (Tok.is(tok::kw_template)) { 15211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert(!TemplateInfo.TemplateParams && 152237b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor "Nested template improperly parsed?"); 152397144fc41a9419bf6d74fc9450e8ef3f6e11f7e0Chris Lattner SourceLocation DeclEnd; 15241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ParseDeclarationStartingWithTemplate(Declarator::MemberContext, DeclEnd, 15254d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor AS); 1526682bf92db408a6cbc3d37b5496a99b6ef85041ecChris Lattner return; 1527682bf92db408a6cbc3d37b5496a99b6ef85041ecChris Lattner } 15285aeccdbb4bdc94e48c04cacc59fa812af32109b2Anders Carlsson 1529bc8d56496a6ecdba14769df03d75c001184f8c54Chris Lattner // Handle: member-declaration ::= '__extension__' member-declaration 1530bc8d56496a6ecdba14769df03d75c001184f8c54Chris Lattner if (Tok.is(tok::kw___extension__)) { 1531bc8d56496a6ecdba14769df03d75c001184f8c54Chris Lattner // __extension__ silences extension warnings in the subexpression. 1532bc8d56496a6ecdba14769df03d75c001184f8c54Chris Lattner ExtensionRAIIObject O(Diags); // Use RAII to do this. 1533bc8d56496a6ecdba14769df03d75c001184f8c54Chris Lattner ConsumeToken(); 1534c9068d7dd94d439cec66c421115d15303e481025John McCall return ParseCXXClassMemberDeclaration(AS, TemplateInfo, TemplateDiags); 1535bc8d56496a6ecdba14769df03d75c001184f8c54Chris Lattner } 15369cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor 15374ed5d91db256f7dbe6bf716da0b801004c197254Chris Lattner // Don't parse FOO:BAR as if it were a typo for FOO::BAR, in this context it 15384ed5d91db256f7dbe6bf716da0b801004c197254Chris Lattner // is a bitfield. 1539a1efc8c8c6460d860d6509b05b341e77ed9bfe87Chris Lattner ColonProtectionRAIIObject X(*this); 1540193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam 15410b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall ParsedAttributesWithRange attrs(AttrFactory); 1542bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt // Optional C++0x attribute-specifier 15437f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall MaybeParseCXX0XAttributes(attrs); 15447f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall MaybeParseMicrosoftAttributes(attrs); 1545bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt 15469cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor if (Tok.is(tok::kw_using)) { 15477f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall ProhibitAttributes(attrs); 15481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15499cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor // Eat 'using'. 15509cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor SourceLocation UsingLoc = ConsumeToken(); 15519cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor 15529cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor if (Tok.is(tok::kw_namespace)) { 15539cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor Diag(UsingLoc, diag::err_using_namespace_in_class); 15549cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor SkipUntil(tok::semi, true, true); 1555ae50d501f463d7032320ec31840f60ae68df3a55Chris Lattner } else { 15569cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor SourceLocation DeclEnd; 15573e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // Otherwise, it must be a using-declaration or an alias-declaration. 155878b810559d89e996e00684335407443936ce34a1John McCall ParseUsingDeclaration(Declarator::MemberContext, TemplateInfo, 155978b810559d89e996e00684335407443936ce34a1John McCall UsingLoc, DeclEnd, AS); 15609cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor } 15619cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor return; 15629cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor } 15639cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor 15644cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // decl-specifier-seq: 15654cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // Parse the common declaration-specifiers piece. 1566c9068d7dd94d439cec66c421115d15303e481025John McCall ParsingDeclSpec DS(*this, TemplateDiags); 15677f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall DS.takeAttributesFrom(attrs); 156837b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor ParseDeclarationSpecifiers(DS, TemplateInfo, AS, DSC_class); 15694cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 1570f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall MultiTemplateParamsArg TemplateParams(Actions, 1571dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall TemplateInfo.TemplateParams? TemplateInfo.TemplateParams->data() : 0, 1572dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall TemplateInfo.TemplateParams? TemplateInfo.TemplateParams->size() : 0); 1573dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall 15744cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis if (Tok.is(tok::semi)) { 15754cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis ConsumeToken(); 1576d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *TheDecl = 15770f4be74ff0273e505d383f89174ef539828424edChandler Carruth Actions.ParsedFreeStandingDeclSpec(getCurScope(), AS, DS, TemplateParams); 1578c9068d7dd94d439cec66c421115d15303e481025John McCall DS.complete(TheDecl); 157967d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall return; 15804cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis } 158107952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis 158254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ParsingDeclarator DeclaratorInfo(*this, DS, Declarator::MemberContext); 15834867347e82648d3baf09524b98b09c297a5a198fNico Weber VirtSpecifiers VS; 15846a24747beed797b2f1184c66ca45beb4db20eb08Francois Pichet ExprResult Init; 15854cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 15863a9fdb4742b21c0a3c27f18c5e4e94bab6f9e64cArgyrios Kyrtzidis if (Tok.isNot(tok::colon)) { 1587a1efc8c8c6460d860d6509b05b341e77ed9bfe87Chris Lattner // Don't parse FOO:BAR as if it were a typo for FOO::BAR. 1588a1efc8c8c6460d860d6509b05b341e77ed9bfe87Chris Lattner ColonProtectionRAIIObject X(*this); 1589a1efc8c8c6460d860d6509b05b341e77ed9bfe87Chris Lattner 15903a9fdb4742b21c0a3c27f18c5e4e94bab6f9e64cArgyrios Kyrtzidis // Parse the first declarator. 15913a9fdb4742b21c0a3c27f18c5e4e94bab6f9e64cArgyrios Kyrtzidis ParseDeclarator(DeclaratorInfo); 15923a9fdb4742b21c0a3c27f18c5e4e94bab6f9e64cArgyrios Kyrtzidis // Error parsing the declarator? 159310bd36882406cdf4805e35add1ce2f11ab9ae152Douglas Gregor if (!DeclaratorInfo.hasName()) { 15943a9fdb4742b21c0a3c27f18c5e4e94bab6f9e64cArgyrios Kyrtzidis // If so, skip until the semi-colon or a }. 1595d941fa4ff0d0d64b5a541dbd4f99693bff7f6e8dSebastian Redl SkipUntil(tok::r_brace, true, true); 15963a9fdb4742b21c0a3c27f18c5e4e94bab6f9e64cArgyrios Kyrtzidis if (Tok.is(tok::semi)) 15973a9fdb4742b21c0a3c27f18c5e4e94bab6f9e64cArgyrios Kyrtzidis ConsumeToken(); 1598682bf92db408a6cbc3d37b5496a99b6ef85041ecChris Lattner return; 15994cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis } 16004cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 16014867347e82648d3baf09524b98b09c297a5a198fNico Weber ParseOptionalCXX0XVirtSpecifierSeq(VS); 16024867347e82648d3baf09524b98b09c297a5a198fNico Weber 16031b2fc0f3e181d99fb34f60e711066fb11628ecd0John Thompson // If attributes exist after the declarator, but before an '{', parse them. 16047f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall MaybeParseGNUAttributes(DeclaratorInfo); 16051b2fc0f3e181d99fb34f60e711066fb11628ecd0John Thompson 16066a24747beed797b2f1184c66ca45beb4db20eb08Francois Pichet // MSVC permits pure specifier on inline functions declared at class scope. 16076a24747beed797b2f1184c66ca45beb4db20eb08Francois Pichet // Hence check for =0 before checking for function definition. 16086a24747beed797b2f1184c66ca45beb4db20eb08Francois Pichet if (getLang().Microsoft && Tok.is(tok::equal) && 16096a24747beed797b2f1184c66ca45beb4db20eb08Francois Pichet DeclaratorInfo.isFunctionDeclarator() && 16106a24747beed797b2f1184c66ca45beb4db20eb08Francois Pichet NextToken().is(tok::numeric_constant)) { 16116a24747beed797b2f1184c66ca45beb4db20eb08Francois Pichet ConsumeToken(); 16126a24747beed797b2f1184c66ca45beb4db20eb08Francois Pichet Init = ParseInitializer(); 16136a24747beed797b2f1184c66ca45beb4db20eb08Francois Pichet if (Init.isInvalid()) 16146a24747beed797b2f1184c66ca45beb4db20eb08Francois Pichet SkipUntil(tok::comma, true, true); 16156a24747beed797b2f1184c66ca45beb4db20eb08Francois Pichet } 16166a24747beed797b2f1184c66ca45beb4db20eb08Francois Pichet 1617e4246a633b13197634225971b25df0cbdcec0c5dSean Hunt bool IsDefinition = false; 16183a9fdb4742b21c0a3c27f18c5e4e94bab6f9e64cArgyrios Kyrtzidis // function-definition: 1619e4246a633b13197634225971b25df0cbdcec0c5dSean Hunt if (Tok.is(tok::l_brace)) { 1620e4246a633b13197634225971b25df0cbdcec0c5dSean Hunt IsDefinition = true; 1621e4246a633b13197634225971b25df0cbdcec0c5dSean Hunt } else if (DeclaratorInfo.isFunctionDeclarator()) { 1622e4246a633b13197634225971b25df0cbdcec0c5dSean Hunt if (Tok.is(tok::colon) || Tok.is(tok::kw_try)) { 1623e4246a633b13197634225971b25df0cbdcec0c5dSean Hunt IsDefinition = true; 1624e4246a633b13197634225971b25df0cbdcec0c5dSean Hunt } else if (Tok.is(tok::equal)) { 1625e4246a633b13197634225971b25df0cbdcec0c5dSean Hunt const Token &KW = NextToken(); 1626e4246a633b13197634225971b25df0cbdcec0c5dSean Hunt if (KW.is(tok::kw_default) || KW.is(tok::kw_delete)) 1627e4246a633b13197634225971b25df0cbdcec0c5dSean Hunt IsDefinition = true; 1628e4246a633b13197634225971b25df0cbdcec0c5dSean Hunt } 1629e4246a633b13197634225971b25df0cbdcec0c5dSean Hunt } 1630e4246a633b13197634225971b25df0cbdcec0c5dSean Hunt 1631e4246a633b13197634225971b25df0cbdcec0c5dSean Hunt if (IsDefinition) { 16323a9fdb4742b21c0a3c27f18c5e4e94bab6f9e64cArgyrios Kyrtzidis if (!DeclaratorInfo.isFunctionDeclarator()) { 16333a9fdb4742b21c0a3c27f18c5e4e94bab6f9e64cArgyrios Kyrtzidis Diag(Tok, diag::err_func_def_no_params); 16343a9fdb4742b21c0a3c27f18c5e4e94bab6f9e64cArgyrios Kyrtzidis ConsumeBrace(); 16353a9fdb4742b21c0a3c27f18c5e4e94bab6f9e64cArgyrios Kyrtzidis SkipUntil(tok::r_brace, true); 16369ea416e598fa3cb09d67d514c4519c99abb81321Douglas Gregor 16379ea416e598fa3cb09d67d514c4519c99abb81321Douglas Gregor // Consume the optional ';' 16389ea416e598fa3cb09d67d514c4519c99abb81321Douglas Gregor if (Tok.is(tok::semi)) 16399ea416e598fa3cb09d67d514c4519c99abb81321Douglas Gregor ConsumeToken(); 1640682bf92db408a6cbc3d37b5496a99b6ef85041ecChris Lattner return; 16413a9fdb4742b21c0a3c27f18c5e4e94bab6f9e64cArgyrios Kyrtzidis } 16423a9fdb4742b21c0a3c27f18c5e4e94bab6f9e64cArgyrios Kyrtzidis 16433a9fdb4742b21c0a3c27f18c5e4e94bab6f9e64cArgyrios Kyrtzidis if (DS.getStorageClassSpec() == DeclSpec::SCS_typedef) { 16443a9fdb4742b21c0a3c27f18c5e4e94bab6f9e64cArgyrios Kyrtzidis Diag(Tok, diag::err_function_declared_typedef); 16453a9fdb4742b21c0a3c27f18c5e4e94bab6f9e64cArgyrios Kyrtzidis // This recovery skips the entire function body. It would be nice 16463a9fdb4742b21c0a3c27f18c5e4e94bab6f9e64cArgyrios Kyrtzidis // to simply call ParseCXXInlineMethodDef() below, however Sema 16473a9fdb4742b21c0a3c27f18c5e4e94bab6f9e64cArgyrios Kyrtzidis // assumes the declarator represents a function, not a typedef. 16483a9fdb4742b21c0a3c27f18c5e4e94bab6f9e64cArgyrios Kyrtzidis ConsumeBrace(); 16493a9fdb4742b21c0a3c27f18c5e4e94bab6f9e64cArgyrios Kyrtzidis SkipUntil(tok::r_brace, true); 16509ea416e598fa3cb09d67d514c4519c99abb81321Douglas Gregor 16519ea416e598fa3cb09d67d514c4519c99abb81321Douglas Gregor // Consume the optional ';' 16529ea416e598fa3cb09d67d514c4519c99abb81321Douglas Gregor if (Tok.is(tok::semi)) 16539ea416e598fa3cb09d67d514c4519c99abb81321Douglas Gregor ConsumeToken(); 1654682bf92db408a6cbc3d37b5496a99b6ef85041ecChris Lattner return; 16553a9fdb4742b21c0a3c27f18c5e4e94bab6f9e64cArgyrios Kyrtzidis } 16564cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 16576a24747beed797b2f1184c66ca45beb4db20eb08Francois Pichet ParseCXXInlineMethodDef(AS, DeclaratorInfo, TemplateInfo, VS, Init); 1658e4246a633b13197634225971b25df0cbdcec0c5dSean Hunt 1659e4246a633b13197634225971b25df0cbdcec0c5dSean Hunt // Consume the ';' - it's optional unless we have a delete or default 1660e4246a633b13197634225971b25df0cbdcec0c5dSean Hunt if (Tok.is(tok::semi)) { 16619ea416e598fa3cb09d67d514c4519c99abb81321Douglas Gregor ConsumeToken(); 1662e4246a633b13197634225971b25df0cbdcec0c5dSean Hunt } 16639ea416e598fa3cb09d67d514c4519c99abb81321Douglas Gregor 1664682bf92db408a6cbc3d37b5496a99b6ef85041ecChris Lattner return; 16653a9fdb4742b21c0a3c27f18c5e4e94bab6f9e64cArgyrios Kyrtzidis } 16664cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis } 16674cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 16684cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // member-declarator-list: 16694cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // member-declarator 16704cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // member-declarator-list ',' member-declarator 16714cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 1672d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall llvm::SmallVector<Decl *, 8> DeclsInGroup; 167360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult BitfieldSize; 16744cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 16754cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis while (1) { 16764cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // member-declarator: 16774cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // declarator pure-specifier[opt] 16784cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // declarator constant-initializer[opt] 16794cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // identifier[opt] ':' constant-expression 16804cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis if (Tok.is(tok::colon)) { 16814cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis ConsumeToken(); 16820e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl BitfieldSize = ParseConstantExpression(); 16830e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (BitfieldSize.isInvalid()) 16844cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis SkipUntil(tok::comma, true, true); 16854cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis } 16861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1687b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson ParseOptionalCXX0XVirtSpecifierSeq(VS); 16881f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson 16894cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // pure-specifier: 16904cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // '= 0' 16914cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // 16924cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // constant-initializer: 16934cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // '=' constant-expression 1694e2b6833d445c7a4ce64f1816c05f176ba1740acaSebastian Redl // 1695e2b6833d445c7a4ce64f1816c05f176ba1740acaSebastian Redl // defaulted/deleted function-definition: 1696e2b6833d445c7a4ce64f1816c05f176ba1740acaSebastian Redl // '=' 'default' [TODO] 1697e2b6833d445c7a4ce64f1816c05f176ba1740acaSebastian Redl // '=' 'delete' 16984cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis if (Tok.is(tok::equal)) { 16994cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis ConsumeToken(); 170037bf9d2bb74944c9d9a52522412bc077629977f1Anders Carlsson if (Tok.is(tok::kw_delete)) { 1701e4246a633b13197634225971b25df0cbdcec0c5dSean Hunt if (DeclaratorInfo.isFunctionDeclarator()) 1702e4246a633b13197634225971b25df0cbdcec0c5dSean Hunt Diag(ConsumeToken(), diag::err_default_delete_in_multiple_declaration) 1703e4246a633b13197634225971b25df0cbdcec0c5dSean Hunt << 1 /* delete */; 1704e4246a633b13197634225971b25df0cbdcec0c5dSean Hunt else 1705e4246a633b13197634225971b25df0cbdcec0c5dSean Hunt Diag(ConsumeToken(), diag::err_deleted_non_function); 1706fe2695eec167b28578825576863228f86b392f24Sean Hunt } else if (Tok.is(tok::kw_default)) { 1707e4246a633b13197634225971b25df0cbdcec0c5dSean Hunt if (DeclaratorInfo.isFunctionDeclarator()) 1708e4246a633b13197634225971b25df0cbdcec0c5dSean Hunt Diag(Tok, diag::err_default_delete_in_multiple_declaration) 1709e4246a633b13197634225971b25df0cbdcec0c5dSean Hunt << 1 /* delete */; 1710e4246a633b13197634225971b25df0cbdcec0c5dSean Hunt else 1711e4246a633b13197634225971b25df0cbdcec0c5dSean Hunt Diag(ConsumeToken(), diag::err_default_special_members); 1712e2b6833d445c7a4ce64f1816c05f176ba1740acaSebastian Redl } else { 1713e2b6833d445c7a4ce64f1816c05f176ba1740acaSebastian Redl Init = ParseInitializer(); 1714e2b6833d445c7a4ce64f1816c05f176ba1740acaSebastian Redl if (Init.isInvalid()) 1715e2b6833d445c7a4ce64f1816c05f176ba1740acaSebastian Redl SkipUntil(tok::comma, true, true); 1716e2b6833d445c7a4ce64f1816c05f176ba1740acaSebastian Redl } 17174cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis } 17184cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 1719e6563256a4b3b9fee70ce3335d28406607c1faafChris Lattner // If a simple-asm-expr is present, parse it. 1720e6563256a4b3b9fee70ce3335d28406607c1faafChris Lattner if (Tok.is(tok::kw_asm)) { 1721e6563256a4b3b9fee70ce3335d28406607c1faafChris Lattner SourceLocation Loc; 172260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult AsmLabel(ParseSimpleAsm(&Loc)); 1723e6563256a4b3b9fee70ce3335d28406607c1faafChris Lattner if (AsmLabel.isInvalid()) 1724e6563256a4b3b9fee70ce3335d28406607c1faafChris Lattner SkipUntil(tok::comma, true, true); 1725e6563256a4b3b9fee70ce3335d28406607c1faafChris Lattner 1726e6563256a4b3b9fee70ce3335d28406607c1faafChris Lattner DeclaratorInfo.setAsmLabel(AsmLabel.release()); 1727e6563256a4b3b9fee70ce3335d28406607c1faafChris Lattner DeclaratorInfo.SetRangeEnd(Loc); 1728e6563256a4b3b9fee70ce3335d28406607c1faafChris Lattner } 1729e6563256a4b3b9fee70ce3335d28406607c1faafChris Lattner 17304cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // If attributes exist after the declarator, parse them. 17317f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall MaybeParseGNUAttributes(DeclaratorInfo); 17324cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 173307952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis // NOTE: If Sema is the Action module and declarator is an instance field, 1734682bf92db408a6cbc3d37b5496a99b6ef85041ecChris Lattner // this call will *not* return the created decl; It will return null. 173507952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis // See Sema::ActOnCXXMemberDeclarator for details. 173667d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall 1737d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ThisDecl = 0; 173867d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall if (DS.isFriendSpecified()) { 1739bbbcdd9cc06b6078939129330ecc9bda3310984dJohn McCall // TODO: handle initializers, bitfields, 'delete' 174023c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor ThisDecl = Actions.ActOnFriendFunctionDecl(getCurScope(), DeclaratorInfo, 1741bbbcdd9cc06b6078939129330ecc9bda3310984dJohn McCall /*IsDefinition*/ false, 1742bbbcdd9cc06b6078939129330ecc9bda3310984dJohn McCall move(TemplateParams)); 174337b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor } else { 174423c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor ThisDecl = Actions.ActOnCXXMemberDeclarator(getCurScope(), AS, 174567d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall DeclaratorInfo, 174637b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor move(TemplateParams), 174767d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall BitfieldSize.release(), 1748e4246a633b13197634225971b25df0cbdcec0c5dSean Hunt VS, Init.release(), false); 174937b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor } 1750682bf92db408a6cbc3d37b5496a99b6ef85041ecChris Lattner if (ThisDecl) 1751682bf92db408a6cbc3d37b5496a99b6ef85041ecChris Lattner DeclsInGroup.push_back(ThisDecl); 17524cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 175372b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor if (DeclaratorInfo.isFunctionDeclarator() && 17541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DeclaratorInfo.getDeclSpec().getStorageClassSpec() 175572b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor != DeclSpec::SCS_typedef) { 1756d33133cdc1af466f9c276249b2621be03867888bEli Friedman HandleMemberFunctionDefaultArgs(DeclaratorInfo, ThisDecl); 175772b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor } 175872b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 175954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall DeclaratorInfo.complete(ThisDecl); 176054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 17614cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // If we don't have a comma, it is either the end of the list (a ';') 17624cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // or an error, bail out. 17634cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis if (Tok.isNot(tok::comma)) 17644cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis break; 17651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 17664cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // Consume the comma. 17674cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis ConsumeToken(); 17681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 17694cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // Parse the next declarator. 17704cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis DeclaratorInfo.clear(); 17714867347e82648d3baf09524b98b09c297a5a198fNico Weber VS.clear(); 177215faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl BitfieldSize = 0; 177315faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl Init = 0; 17741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 17754cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // Attributes are only allowed on the second declarator. 17767f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall MaybeParseGNUAttributes(DeclaratorInfo); 17774cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 17783a9fdb4742b21c0a3c27f18c5e4e94bab6f9e64cArgyrios Kyrtzidis if (Tok.isNot(tok::colon)) 17793a9fdb4742b21c0a3c27f18c5e4e94bab6f9e64cArgyrios Kyrtzidis ParseDeclarator(DeclaratorInfo); 17804cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis } 17814cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 1782ae50d501f463d7032320ec31840f60ae68df3a55Chris Lattner if (ExpectAndConsume(tok::semi, diag::err_expected_semi_decl_list)) { 1783ae50d501f463d7032320ec31840f60ae68df3a55Chris Lattner // Skip to end of block or statement. 1784ae50d501f463d7032320ec31840f60ae68df3a55Chris Lattner SkipUntil(tok::r_brace, true, true); 1785ae50d501f463d7032320ec31840f60ae68df3a55Chris Lattner // If we stopped at a ';', eat it. 1786ae50d501f463d7032320ec31840f60ae68df3a55Chris Lattner if (Tok.is(tok::semi)) ConsumeToken(); 1787682bf92db408a6cbc3d37b5496a99b6ef85041ecChris Lattner return; 17884cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis } 17894cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 179023c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.FinalizeDeclaratorGroup(getCurScope(), DS, DeclsInGroup.data(), 1791ae50d501f463d7032320ec31840f60ae68df3a55Chris Lattner DeclsInGroup.size()); 17924cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis} 17934cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 17944cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis/// ParseCXXMemberSpecification - Parse the class definition. 17954cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis/// 17964cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis/// member-specification: 17974cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis/// member-declaration member-specification[opt] 17984cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis/// access-specifier ':' member-specification[opt] 17994cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis/// 18004cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidisvoid Parser::ParseCXXMemberSpecification(SourceLocation RecordLoc, 1801d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall unsigned TagType, Decl *TagDecl) { 180231fc07df7f0fc89ebf83ca05a20b29de45a7598dSanjiv Gupta assert((TagType == DeclSpec::TST_struct || 18034cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis TagType == DeclSpec::TST_union || 180431fc07df7f0fc89ebf83ca05a20b29de45a7598dSanjiv Gupta TagType == DeclSpec::TST_class) && "Invalid TagType!"); 18054cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 1806f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall PrettyDeclStackTraceEntry CrashInfo(Actions, TagDecl, RecordLoc, 1807f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall "parsing struct/union/class body"); 18081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 180926997fd58c9560584edd154618f2f2c15ee68af4Douglas Gregor // Determine whether this is a non-nested class. Note that local 181026997fd58c9560584edd154618f2f2c15ee68af4Douglas Gregor // classes are *not* considered to be nested classes. 181126997fd58c9560584edd154618f2f2c15ee68af4Douglas Gregor bool NonNestedClass = true; 181226997fd58c9560584edd154618f2f2c15ee68af4Douglas Gregor if (!ClassStack.empty()) { 181323c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor for (const Scope *S = getCurScope(); S; S = S->getParent()) { 181426997fd58c9560584edd154618f2f2c15ee68af4Douglas Gregor if (S->isClassScope()) { 181526997fd58c9560584edd154618f2f2c15ee68af4Douglas Gregor // We're inside a class scope, so this is a nested class. 181626997fd58c9560584edd154618f2f2c15ee68af4Douglas Gregor NonNestedClass = false; 181726997fd58c9560584edd154618f2f2c15ee68af4Douglas Gregor break; 181826997fd58c9560584edd154618f2f2c15ee68af4Douglas Gregor } 181926997fd58c9560584edd154618f2f2c15ee68af4Douglas Gregor 182026997fd58c9560584edd154618f2f2c15ee68af4Douglas Gregor if ((S->getFlags() & Scope::FnScope)) { 182126997fd58c9560584edd154618f2f2c15ee68af4Douglas Gregor // If we're in a function or function template declared in the 182226997fd58c9560584edd154618f2f2c15ee68af4Douglas Gregor // body of a class, then this is a local class rather than a 182326997fd58c9560584edd154618f2f2c15ee68af4Douglas Gregor // nested class. 182426997fd58c9560584edd154618f2f2c15ee68af4Douglas Gregor const Scope *Parent = S->getParent(); 182526997fd58c9560584edd154618f2f2c15ee68af4Douglas Gregor if (Parent->isTemplateParamScope()) 182626997fd58c9560584edd154618f2f2c15ee68af4Douglas Gregor Parent = Parent->getParent(); 182726997fd58c9560584edd154618f2f2c15ee68af4Douglas Gregor if (Parent->isClassScope()) 182826997fd58c9560584edd154618f2f2c15ee68af4Douglas Gregor break; 182926997fd58c9560584edd154618f2f2c15ee68af4Douglas Gregor } 183026997fd58c9560584edd154618f2f2c15ee68af4Douglas Gregor } 183126997fd58c9560584edd154618f2f2c15ee68af4Douglas Gregor } 18324cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 18334cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // Enter a scope for the class. 18343218c4bb3b5d7250f12420de6db7ef3e3f805a75Douglas Gregor ParseScope ClassScope(this, Scope::ClassScope|Scope::DeclScope); 18354cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 18366569d68745c8213709740337d2be52b031384f58Douglas Gregor // Note that we are parsing a new (potentially-nested) class definition. 183726997fd58c9560584edd154618f2f2c15ee68af4Douglas Gregor ParsingClassDefinition ParsingDef(*this, TagDecl, NonNestedClass); 18386569d68745c8213709740337d2be52b031384f58Douglas Gregor 1839ddc29e116db3c3f4144355e67a0137b38b6bb6d1Douglas Gregor if (TagDecl) 184023c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.ActOnTagStartDefinition(getCurScope(), TagDecl); 1841bd0dfa5c37d422427080a0ae3af9b63e70e6e854John McCall 1842b184a18a0a52e4bec33ef70f13bfcc29aafa14f2Anders Carlsson SourceLocation FinalLoc; 1843b184a18a0a52e4bec33ef70f13bfcc29aafa14f2Anders Carlsson 1844b184a18a0a52e4bec33ef70f13bfcc29aafa14f2Anders Carlsson // Parse the optional 'final' keyword. 1845b184a18a0a52e4bec33ef70f13bfcc29aafa14f2Anders Carlsson if (getLang().CPlusPlus && Tok.is(tok::identifier)) { 1846b184a18a0a52e4bec33ef70f13bfcc29aafa14f2Anders Carlsson IdentifierInfo *II = Tok.getIdentifierInfo(); 1847b184a18a0a52e4bec33ef70f13bfcc29aafa14f2Anders Carlsson 1848b184a18a0a52e4bec33ef70f13bfcc29aafa14f2Anders Carlsson // Initialize the contextual keywords. 1849b184a18a0a52e4bec33ef70f13bfcc29aafa14f2Anders Carlsson if (!Ident_final) { 1850b184a18a0a52e4bec33ef70f13bfcc29aafa14f2Anders Carlsson Ident_final = &PP.getIdentifierTable().get("final"); 1851b184a18a0a52e4bec33ef70f13bfcc29aafa14f2Anders Carlsson Ident_override = &PP.getIdentifierTable().get("override"); 1852b184a18a0a52e4bec33ef70f13bfcc29aafa14f2Anders Carlsson } 1853b184a18a0a52e4bec33ef70f13bfcc29aafa14f2Anders Carlsson 1854b184a18a0a52e4bec33ef70f13bfcc29aafa14f2Anders Carlsson if (II == Ident_final) 1855b184a18a0a52e4bec33ef70f13bfcc29aafa14f2Anders Carlsson FinalLoc = ConsumeToken(); 1856b184a18a0a52e4bec33ef70f13bfcc29aafa14f2Anders Carlsson 1857b184a18a0a52e4bec33ef70f13bfcc29aafa14f2Anders Carlsson if (!getLang().CPlusPlus0x) 1858b184a18a0a52e4bec33ef70f13bfcc29aafa14f2Anders Carlsson Diag(FinalLoc, diag::ext_override_control_keyword) << "final"; 1859b184a18a0a52e4bec33ef70f13bfcc29aafa14f2Anders Carlsson } 1860cc54d594d4f6509c0e3a8e349e481d9b5d899df6Anders Carlsson 1861bd0dfa5c37d422427080a0ae3af9b63e70e6e854John McCall if (Tok.is(tok::colon)) { 1862bd0dfa5c37d422427080a0ae3af9b63e70e6e854John McCall ParseBaseClause(TagDecl); 1863bd0dfa5c37d422427080a0ae3af9b63e70e6e854John McCall 1864bd0dfa5c37d422427080a0ae3af9b63e70e6e854John McCall if (!Tok.is(tok::l_brace)) { 1865bd0dfa5c37d422427080a0ae3af9b63e70e6e854John McCall Diag(Tok, diag::err_expected_lbrace_after_base_specifiers); 1866db7bb4a4e7d9744cbc994c90932e6f056228e1ffJohn McCall 1867db7bb4a4e7d9744cbc994c90932e6f056228e1ffJohn McCall if (TagDecl) 186823c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.ActOnTagDefinitionError(getCurScope(), TagDecl); 1869bd0dfa5c37d422427080a0ae3af9b63e70e6e854John McCall return; 1870bd0dfa5c37d422427080a0ae3af9b63e70e6e854John McCall } 1871bd0dfa5c37d422427080a0ae3af9b63e70e6e854John McCall } 1872bd0dfa5c37d422427080a0ae3af9b63e70e6e854John McCall 1873bd0dfa5c37d422427080a0ae3af9b63e70e6e854John McCall assert(Tok.is(tok::l_brace)); 1874bd0dfa5c37d422427080a0ae3af9b63e70e6e854John McCall 1875bd0dfa5c37d422427080a0ae3af9b63e70e6e854John McCall SourceLocation LBraceLoc = ConsumeBrace(); 1876bd0dfa5c37d422427080a0ae3af9b63e70e6e854John McCall 187742a4f66ffeb26e69b2f0ec873a5d41b0e39e634cJohn McCall if (TagDecl) 18782c3ee54e51d835a35bbf781c69e17f39e2ba0480Anders Carlsson Actions.ActOnStartCXXMemberDeclarations(getCurScope(), TagDecl, FinalLoc, 1879dfc2f1035d23e294b298766a3cf51dfe249d53a2Anders Carlsson LBraceLoc); 1880f9368159334ff86ea5fa367225c1a580977f3b03John McCall 18814cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // C++ 11p3: Members of a class defined with the keyword class are private 18824cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // by default. Members of a class defined with the keywords struct or union 18834cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // are public by default. 18844cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis AccessSpecifier CurAS; 18854cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis if (TagType == DeclSpec::TST_class) 18864cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis CurAS = AS_private; 18874cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis else 18884cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis CurAS = AS_public; 18894cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 189007976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor SourceLocation RBraceLoc; 189107976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor if (TagDecl) { 189207976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor // While we still have something to read, read the member-declarations. 189307976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor while (Tok.isNot(tok::r_brace) && Tok.isNot(tok::eof)) { 189407976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor // Each iteration of this loop reads one member-declaration. 189507976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor 189607976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor // Check for extraneous top-level semicolon. 189707976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor if (Tok.is(tok::semi)) { 189807976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor Diag(Tok, diag::ext_extra_struct_semi) 189907976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor << DeclSpec::getSpecifierName((DeclSpec::TST)TagType) 190007976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor << FixItHint::CreateRemoval(Tok.getLocation()); 190107976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor ConsumeToken(); 190207976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor continue; 190307976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor } 19041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 190507976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor AccessSpecifier AS = getAccessSpecifierIfPresent(); 190607976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor if (AS != AS_none) { 190707976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor // Current token is a C++ access specifier. 190807976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor CurAS = AS; 190907976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor SourceLocation ASLoc = Tok.getLocation(); 191007976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor ConsumeToken(); 191107976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor if (Tok.is(tok::colon)) 191207976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor Actions.ActOnAccessSpecifier(AS, ASLoc, Tok.getLocation()); 191307976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor else 191407976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor Diag(Tok, diag::err_expected_colon); 191507976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor ConsumeToken(); 191607976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor continue; 191707976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor } 19184cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 191907976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor // FIXME: Make sure we don't have a template here. 19204cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 192107976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor // Parse all the comma separated declarators. 192207976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor ParseCXXClassMemberDeclaration(CurAS); 192307976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor } 19241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 192507976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor RBraceLoc = MatchRHSPunctuation(tok::r_brace, LBraceLoc); 192607976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor } else { 192707976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor SkipUntil(tok::r_brace, false, false); 19284cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis } 19291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19304cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // If attributes exist after class contents, parse them. 19310b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall ParsedAttributes attrs(AttrFactory); 19327f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall MaybeParseGNUAttributes(attrs); 19334cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 193442a4f66ffeb26e69b2f0ec873a5d41b0e39e634cJohn McCall if (TagDecl) 193523c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.ActOnFinishCXXMemberSpecification(getCurScope(), RecordLoc, TagDecl, 193642a4f66ffeb26e69b2f0ec873a5d41b0e39e634cJohn McCall LBraceLoc, RBraceLoc, 19377f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall attrs.getList()); 19384cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 19394cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // C++ 9.2p2: Within the class member-specification, the class is regarded as 19404cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // complete within function bodies, default arguments, 19414cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // exception-specifications, and constructor ctor-initializers (including 19424cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // such things in nested classes). 19434cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // 194472b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor // FIXME: Only function bodies and constructor ctor-initializers are 194572b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor // parsed correctly, fix the rest. 194607976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor if (TagDecl && NonNestedClass) { 19474cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // We are not inside a nested class. This class and its nested classes 194872b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor // are complete and we can parse the delayed portions of method 194972b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor // declarations and the lexed inline method definitions. 1950e0cc047b1984fc301bbe6e98b6d197bed39ad562Douglas Gregor SourceLocation SavedPrevTokLocation = PrevTokLocation; 19516569d68745c8213709740337d2be52b031384f58Douglas Gregor ParseLexedMethodDeclarations(getCurrentClass()); 19526569d68745c8213709740337d2be52b031384f58Douglas Gregor ParseLexedMethodDefs(getCurrentClass()); 1953e0cc047b1984fc301bbe6e98b6d197bed39ad562Douglas Gregor PrevTokLocation = SavedPrevTokLocation; 19544cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis } 19554cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 195642a4f66ffeb26e69b2f0ec873a5d41b0e39e634cJohn McCall if (TagDecl) 195723c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.ActOnTagFinishDefinition(getCurScope(), TagDecl, RBraceLoc); 1958db7bb4a4e7d9744cbc994c90932e6f056228e1ffJohn McCall 19594cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // Leave the class scope. 19606569d68745c8213709740337d2be52b031384f58Douglas Gregor ParsingDef.Pop(); 19618935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor ClassScope.Exit(); 19624cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis} 19637ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor 19647ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor/// ParseConstructorInitializer - Parse a C++ constructor initializer, 19657ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor/// which explicitly initializes the members or base classes of a 19667ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor/// class (C++ [class.base.init]). For example, the three initializers 19677ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor/// after the ':' in the Derived constructor below: 19687ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor/// 19697ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor/// @code 19707ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor/// class Base { }; 19717ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor/// class Derived : Base { 19727ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor/// int x; 19737ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor/// float f; 19747ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor/// public: 19757ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor/// Derived(float f) : Base(), x(17), f(f) { } 19767ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor/// }; 19777ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor/// @endcode 19787ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor/// 19791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// [C++] ctor-initializer: 19801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// ':' mem-initializer-list 19817ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor/// 19821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// [C++] mem-initializer-list: 19833fb9e4b89f72823f162096086f0f964e6dcf66d6Douglas Gregor/// mem-initializer ...[opt] 19843fb9e4b89f72823f162096086f0f964e6dcf66d6Douglas Gregor/// mem-initializer ...[opt] , mem-initializer-list 1985d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallvoid Parser::ParseConstructorInitializer(Decl *ConstructorDecl) { 19867ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor assert(Tok.is(tok::colon) && "Constructor initializer always starts with ':'"); 19877ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor 198828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley // Poison the SEH identifiers so they are flagged as illegal in constructor initializers 198928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley PoisonSEHIdentifiersRAIIObject PoisonSEHIdentifiers(*this, true); 19907ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor SourceLocation ColonLoc = ConsumeToken(); 19911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1992cbb67480094b3bcb5b715acd827cbad55e2a204cSean Hunt llvm::SmallVector<CXXCtorInitializer*, 4> MemInitializers; 19939db7dbb918ca49f4ee6c181e4917e7b6ec547353Douglas Gregor bool AnyErrors = false; 1994193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam 19957ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor do { 19960133f525a23e18dd444880f7554f25fbcbd834e5Douglas Gregor if (Tok.is(tok::code_completion)) { 19970133f525a23e18dd444880f7554f25fbcbd834e5Douglas Gregor Actions.CodeCompleteConstructorInitializer(ConstructorDecl, 19980133f525a23e18dd444880f7554f25fbcbd834e5Douglas Gregor MemInitializers.data(), 19990133f525a23e18dd444880f7554f25fbcbd834e5Douglas Gregor MemInitializers.size()); 20000133f525a23e18dd444880f7554f25fbcbd834e5Douglas Gregor ConsumeCodeCompletionToken(); 20010133f525a23e18dd444880f7554f25fbcbd834e5Douglas Gregor } else { 20020133f525a23e18dd444880f7554f25fbcbd834e5Douglas Gregor MemInitResult MemInit = ParseMemInitializer(ConstructorDecl); 20030133f525a23e18dd444880f7554f25fbcbd834e5Douglas Gregor if (!MemInit.isInvalid()) 20040133f525a23e18dd444880f7554f25fbcbd834e5Douglas Gregor MemInitializers.push_back(MemInit.get()); 20050133f525a23e18dd444880f7554f25fbcbd834e5Douglas Gregor else 20060133f525a23e18dd444880f7554f25fbcbd834e5Douglas Gregor AnyErrors = true; 20070133f525a23e18dd444880f7554f25fbcbd834e5Douglas Gregor } 20080133f525a23e18dd444880f7554f25fbcbd834e5Douglas Gregor 20097ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor if (Tok.is(tok::comma)) 20107ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor ConsumeToken(); 20117ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor else if (Tok.is(tok::l_brace)) 20127ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor break; 2013b1f6fa48960eae269a3931d1fc545ed468d9a4d2Douglas Gregor // If the next token looks like a base or member initializer, assume that 2014b1f6fa48960eae269a3931d1fc545ed468d9a4d2Douglas Gregor // we're just missing a comma. 2015751f6922376dfe9432795b65a3649179e4ef5cf5Douglas Gregor else if (Tok.is(tok::identifier) || Tok.is(tok::coloncolon)) { 2016751f6922376dfe9432795b65a3649179e4ef5cf5Douglas Gregor SourceLocation Loc = PP.getLocForEndOfToken(PrevTokLocation); 2017751f6922376dfe9432795b65a3649179e4ef5cf5Douglas Gregor Diag(Loc, diag::err_ctor_init_missing_comma) 2018751f6922376dfe9432795b65a3649179e4ef5cf5Douglas Gregor << FixItHint::CreateInsertion(Loc, ", "); 2019751f6922376dfe9432795b65a3649179e4ef5cf5Douglas Gregor } else { 20207ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor // Skip over garbage, until we get to '{'. Don't eat the '{'. 2021d3a413d3b8eb39bcee5944bc545d9997c1abe492Sebastian Redl Diag(Tok.getLocation(), diag::err_expected_lbrace_or_comma); 20227ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor SkipUntil(tok::l_brace, true, true); 20237ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor break; 20247ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor } 20257ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor } while (true); 20267ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor 20271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Actions.ActOnMemInitializers(ConstructorDecl, ColonLoc, 20289db7dbb918ca49f4ee6c181e4917e7b6ec547353Douglas Gregor MemInitializers.data(), MemInitializers.size(), 20299db7dbb918ca49f4ee6c181e4917e7b6ec547353Douglas Gregor AnyErrors); 20307ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor} 20317ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor 20327ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor/// ParseMemInitializer - Parse a C++ member initializer, which is 20337ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor/// part of a constructor initializer that explicitly initializes one 20347ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor/// member or base class (C++ [class.base.init]). See 20357ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor/// ParseConstructorInitializer for an example. 20367ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor/// 20377ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor/// [C++] mem-initializer: 20387ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor/// mem-initializer-id '(' expression-list[opt] ')' 20391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 20407ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor/// [C++] mem-initializer-id: 20417ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor/// '::'[opt] nested-name-specifier[opt] class-name 20427ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor/// identifier 2043d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallParser::MemInitResult Parser::ParseMemInitializer(Decl *ConstructorDecl) { 2044bcfad54a43e5570e09daddd976bd4545933e75b1Fariborz Jahanian // parse '::'[opt] nested-name-specifier[opt] 2045bcfad54a43e5570e09daddd976bd4545933e75b1Fariborz Jahanian CXXScopeSpec SS; 2046b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParseOptionalCXXScopeSpecifier(SS, ParsedType(), false); 2047b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType TemplateTypeTy; 2048961743326fd18776f897bf4461345dba680ef637Fariborz Jahanian if (Tok.is(tok::annot_template_id)) { 2049961743326fd18776f897bf4461345dba680ef637Fariborz Jahanian TemplateIdAnnotation *TemplateId 2050961743326fd18776f897bf4461345dba680ef637Fariborz Jahanian = static_cast<TemplateIdAnnotation *>(Tok.getAnnotationValue()); 2051d9b600c1a589200be905c53e2e10fceb57efa18dDouglas Gregor if (TemplateId->Kind == TNK_Type_template || 2052d9b600c1a589200be905c53e2e10fceb57efa18dDouglas Gregor TemplateId->Kind == TNK_Dependent_template_name) { 2053059101f922de6eb765601459925f4c8914420b23Douglas Gregor AnnotateTemplateIdTokenAsType(); 2054961743326fd18776f897bf4461345dba680ef637Fariborz Jahanian assert(Tok.is(tok::annot_typename) && "template-id -> type failed"); 2055b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall TemplateTypeTy = getTypeAnnotation(Tok); 2056961743326fd18776f897bf4461345dba680ef637Fariborz Jahanian } 2057961743326fd18776f897bf4461345dba680ef637Fariborz Jahanian } 2058961743326fd18776f897bf4461345dba680ef637Fariborz Jahanian if (!TemplateTypeTy && Tok.isNot(tok::identifier)) { 20591ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_member_or_base_name); 20607ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor return true; 20617ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor } 20621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20637ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor // Get the identifier. This may be a member name or a class name, 20647ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor // but we'll let the semantic analysis determine which it is. 2065961743326fd18776f897bf4461345dba680ef637Fariborz Jahanian IdentifierInfo *II = Tok.is(tok::identifier) ? Tok.getIdentifierInfo() : 0; 20667ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor SourceLocation IdLoc = ConsumeToken(); 20677ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor 20687ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor // Parse the '('. 20697ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor if (Tok.isNot(tok::l_paren)) { 20701ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_lparen); 20717ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor return true; 20727ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor } 20737ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor SourceLocation LParenLoc = ConsumeParen(); 20747ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor 20757ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor // Parse the optional expression-list. 2076a55e52c0802cae3b7c366a05c461d3d15074c1a3Sebastian Redl ExprVector ArgExprs(Actions); 20777ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor CommaLocsTy CommaLocs; 20787ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor if (Tok.isNot(tok::r_paren) && ParseExpressionList(ArgExprs, CommaLocs)) { 20797ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor SkipUntil(tok::r_paren); 20807ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor return true; 20817ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor } 20827ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor 20837ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); 20847ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor 20853fb9e4b89f72823f162096086f0f964e6dcf66d6Douglas Gregor SourceLocation EllipsisLoc; 20863fb9e4b89f72823f162096086f0f964e6dcf66d6Douglas Gregor if (Tok.is(tok::ellipsis)) 20873fb9e4b89f72823f162096086f0f964e6dcf66d6Douglas Gregor EllipsisLoc = ConsumeToken(); 20883fb9e4b89f72823f162096086f0f964e6dcf66d6Douglas Gregor 208923c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor return Actions.ActOnMemInitializer(ConstructorDecl, getCurScope(), SS, II, 2090961743326fd18776f897bf4461345dba680ef637Fariborz Jahanian TemplateTypeTy, IdLoc, 2091a55e52c0802cae3b7c366a05c461d3d15074c1a3Sebastian Redl LParenLoc, ArgExprs.take(), 20923fb9e4b89f72823f162096086f0f964e6dcf66d6Douglas Gregor ArgExprs.size(), RParenLoc, 20933fb9e4b89f72823f162096086f0f964e6dcf66d6Douglas Gregor EllipsisLoc); 20947ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor} 20950fe7bea6fca9737c6c145aaa4a2ad3abe595782aDouglas Gregor 20967acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl/// \brief Parse a C++ exception-specification if present (C++0x [except.spec]). 20970fe7bea6fca9737c6c145aaa4a2ad3abe595782aDouglas Gregor/// 2098a4745616ebe36ba7699f18618382e764aa8183a1Douglas Gregor/// exception-specification: 20997acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl/// dynamic-exception-specification 21007acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl/// noexcept-specification 21017acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl/// 21027acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl/// noexcept-specification: 21037acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl/// 'noexcept' 21047acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl/// 'noexcept' '(' constant-expression ')' 21057acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian RedlExceptionSpecificationType 21067acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian RedlParser::MaybeParseExceptionSpecification(SourceRange &SpecificationRange, 21077acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl llvm::SmallVectorImpl<ParsedType> &DynamicExceptions, 21087acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl llvm::SmallVectorImpl<SourceRange> &DynamicExceptionRanges, 21097acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl ExprResult &NoexceptExpr) { 21107acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl ExceptionSpecificationType Result = EST_None; 21117acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl 21127acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl // See if there's a dynamic specification. 21137acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl if (Tok.is(tok::kw_throw)) { 21147acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl Result = ParseDynamicExceptionSpecification(SpecificationRange, 21157acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl DynamicExceptions, 21167acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl DynamicExceptionRanges); 21177acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl assert(DynamicExceptions.size() == DynamicExceptionRanges.size() && 21187acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl "Produced different number of exception types and ranges."); 21197acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl } 21207acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl 21217acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl // If there's no noexcept specification, we're done. 21227acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl if (Tok.isNot(tok::kw_noexcept)) 21237acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl return Result; 21247acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl 21257acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl // If we already had a dynamic specification, parse the noexcept for, 21267acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl // recovery, but emit a diagnostic and don't store the results. 21277acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl SourceRange NoexceptRange; 21287acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl ExceptionSpecificationType NoexceptType = EST_None; 21297acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl 21307acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl SourceLocation KeywordLoc = ConsumeToken(); 21317acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl if (Tok.is(tok::l_paren)) { 21327acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl // There is an argument. 21337acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl SourceLocation LParenLoc = ConsumeParen(); 21347acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl NoexceptType = EST_ComputedNoexcept; 21357acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl NoexceptExpr = ParseConstantExpression(); 213660618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl // The argument must be contextually convertible to bool. We use 213760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl // ActOnBooleanCondition for this purpose. 213860618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl if (!NoexceptExpr.isInvalid()) 213960618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl NoexceptExpr = Actions.ActOnBooleanCondition(getCurScope(), KeywordLoc, 214060618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl NoexceptExpr.get()); 21417acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); 21427acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl NoexceptRange = SourceRange(KeywordLoc, RParenLoc); 21437acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl } else { 21447acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl // There is no argument. 21457acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl NoexceptType = EST_BasicNoexcept; 21467acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl NoexceptRange = SourceRange(KeywordLoc, KeywordLoc); 21477acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl } 21487acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl 21497acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl if (Result == EST_None) { 21507acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl SpecificationRange = NoexceptRange; 21517acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl Result = NoexceptType; 21527acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl 21537acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl // If there's a dynamic specification after a noexcept specification, 21547acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl // parse that and ignore the results. 21557acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl if (Tok.is(tok::kw_throw)) { 21567acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl Diag(Tok.getLocation(), diag::err_dynamic_and_noexcept_specification); 21577acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl ParseDynamicExceptionSpecification(NoexceptRange, DynamicExceptions, 21587acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl DynamicExceptionRanges); 21597acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl } 21607acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl } else { 21617acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl Diag(Tok.getLocation(), diag::err_dynamic_and_noexcept_specification); 21627acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl } 21637acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl 21647acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl return Result; 21657acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl} 21667acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl 21677acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl/// ParseDynamicExceptionSpecification - Parse a C++ 21687acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl/// dynamic-exception-specification (C++ [except.spec]). 21697acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl/// 21707acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl/// dynamic-exception-specification: 2171a4745616ebe36ba7699f18618382e764aa8183a1Douglas Gregor/// 'throw' '(' type-id-list [opt] ')' 2172a4745616ebe36ba7699f18618382e764aa8183a1Douglas Gregor/// [MS] 'throw' '(' '...' ')' 21731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 2174a4745616ebe36ba7699f18618382e764aa8183a1Douglas Gregor/// type-id-list: 2175a04426c5416f22df1078f6b31c1619de73c40b59Douglas Gregor/// type-id ... [opt] 2176a04426c5416f22df1078f6b31c1619de73c40b59Douglas Gregor/// type-id-list ',' type-id ... [opt] 21770fe7bea6fca9737c6c145aaa4a2ad3abe595782aDouglas Gregor/// 21787acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian RedlExceptionSpecificationType Parser::ParseDynamicExceptionSpecification( 21797acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl SourceRange &SpecificationRange, 21807acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl llvm::SmallVectorImpl<ParsedType> &Exceptions, 21817acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl llvm::SmallVectorImpl<SourceRange> &Ranges) { 21820fe7bea6fca9737c6c145aaa4a2ad3abe595782aDouglas Gregor assert(Tok.is(tok::kw_throw) && "expected throw"); 21831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21847acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl SpecificationRange.setBegin(ConsumeToken()); 21851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21860fe7bea6fca9737c6c145aaa4a2ad3abe595782aDouglas Gregor if (!Tok.is(tok::l_paren)) { 21877acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl Diag(Tok, diag::err_expected_lparen_after) << "throw"; 21887acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl SpecificationRange.setEnd(SpecificationRange.getBegin()); 218960618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl return EST_DynamicNone; 21900fe7bea6fca9737c6c145aaa4a2ad3abe595782aDouglas Gregor } 21910fe7bea6fca9737c6c145aaa4a2ad3abe595782aDouglas Gregor SourceLocation LParenLoc = ConsumeParen(); 21920fe7bea6fca9737c6c145aaa4a2ad3abe595782aDouglas Gregor 2193a4745616ebe36ba7699f18618382e764aa8183a1Douglas Gregor // Parse throw(...), a Microsoft extension that means "this function 2194a4745616ebe36ba7699f18618382e764aa8183a1Douglas Gregor // can throw anything". 2195a4745616ebe36ba7699f18618382e764aa8183a1Douglas Gregor if (Tok.is(tok::ellipsis)) { 2196a4745616ebe36ba7699f18618382e764aa8183a1Douglas Gregor SourceLocation EllipsisLoc = ConsumeToken(); 2197a4745616ebe36ba7699f18618382e764aa8183a1Douglas Gregor if (!getLang().Microsoft) 2198a4745616ebe36ba7699f18618382e764aa8183a1Douglas Gregor Diag(EllipsisLoc, diag::ext_ellipsis_exception_spec); 21997acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); 22007acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl SpecificationRange.setEnd(RParenLoc); 220160618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl return EST_MSAny; 2202a4745616ebe36ba7699f18618382e764aa8183a1Douglas Gregor } 2203a4745616ebe36ba7699f18618382e764aa8183a1Douglas Gregor 22040fe7bea6fca9737c6c145aaa4a2ad3abe595782aDouglas Gregor // Parse the sequence of type-ids. 2205ef65f06e8e440aec541442cfd73a8a836e9bc842Sebastian Redl SourceRange Range; 22060fe7bea6fca9737c6c145aaa4a2ad3abe595782aDouglas Gregor while (Tok.isNot(tok::r_paren)) { 2207ef65f06e8e440aec541442cfd73a8a836e9bc842Sebastian Redl TypeResult Res(ParseTypeName(&Range)); 22087acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl 2209a04426c5416f22df1078f6b31c1619de73c40b59Douglas Gregor if (Tok.is(tok::ellipsis)) { 2210a04426c5416f22df1078f6b31c1619de73c40b59Douglas Gregor // C++0x [temp.variadic]p5: 2211a04426c5416f22df1078f6b31c1619de73c40b59Douglas Gregor // - In a dynamic-exception-specification (15.4); the pattern is a 2212a04426c5416f22df1078f6b31c1619de73c40b59Douglas Gregor // type-id. 2213a04426c5416f22df1078f6b31c1619de73c40b59Douglas Gregor SourceLocation Ellipsis = ConsumeToken(); 22147acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl Range.setEnd(Ellipsis); 2215a04426c5416f22df1078f6b31c1619de73c40b59Douglas Gregor if (!Res.isInvalid()) 2216a04426c5416f22df1078f6b31c1619de73c40b59Douglas Gregor Res = Actions.ActOnPackExpansion(Res.get(), Ellipsis); 2217a04426c5416f22df1078f6b31c1619de73c40b59Douglas Gregor } 22187acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl 2219ef65f06e8e440aec541442cfd73a8a836e9bc842Sebastian Redl if (!Res.isInvalid()) { 22207dc813462dd9fd3f6f4296f896a12de14264fef8Sebastian Redl Exceptions.push_back(Res.get()); 2221ef65f06e8e440aec541442cfd73a8a836e9bc842Sebastian Redl Ranges.push_back(Range); 2222ef65f06e8e440aec541442cfd73a8a836e9bc842Sebastian Redl } 2223a04426c5416f22df1078f6b31c1619de73c40b59Douglas Gregor 22240fe7bea6fca9737c6c145aaa4a2ad3abe595782aDouglas Gregor if (Tok.is(tok::comma)) 22250fe7bea6fca9737c6c145aaa4a2ad3abe595782aDouglas Gregor ConsumeToken(); 22267dc813462dd9fd3f6f4296f896a12de14264fef8Sebastian Redl else 22270fe7bea6fca9737c6c145aaa4a2ad3abe595782aDouglas Gregor break; 22280fe7bea6fca9737c6c145aaa4a2ad3abe595782aDouglas Gregor } 22290fe7bea6fca9737c6c145aaa4a2ad3abe595782aDouglas Gregor 22307acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl SpecificationRange.setEnd(MatchRHSPunctuation(tok::r_paren, LParenLoc)); 223160618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl return Exceptions.empty() ? EST_DynamicNone : EST_Dynamic; 22320fe7bea6fca9737c6c145aaa4a2ad3abe595782aDouglas Gregor} 22336569d68745c8213709740337d2be52b031384f58Douglas Gregor 2234dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor/// ParseTrailingReturnType - Parse a trailing return type on a new-style 2235dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor/// function declaration. 2236dab60ad68a3a98d687305941a3852e793705f945Douglas GregorTypeResult Parser::ParseTrailingReturnType() { 2237dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor assert(Tok.is(tok::arrow) && "expected arrow"); 2238dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor 2239dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor ConsumeToken(); 2240dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor 2241dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor // FIXME: Need to suppress declarations when parsing this typename. 2242dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor // Otherwise in this function definition: 2243dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor // 2244dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor // auto f() -> struct X {} 2245dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor // 2246dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor // struct X is parsed as class definition because of the trailing 2247dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor // brace. 2248dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor 2249dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor SourceRange Range; 2250dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor return ParseTypeName(&Range); 2251dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor} 2252dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor 22536569d68745c8213709740337d2be52b031384f58Douglas Gregor/// \brief We have just started parsing the definition of a new class, 22546569d68745c8213709740337d2be52b031384f58Douglas Gregor/// so push that class onto our stack of classes that is currently 22556569d68745c8213709740337d2be52b031384f58Douglas Gregor/// being parsed. 2256eee1d5434ebfa955ffc3c493aecd68bb7b3f4838John McCallSema::ParsingClassState 2257eee1d5434ebfa955ffc3c493aecd68bb7b3f4838John McCallParser::PushParsingClass(Decl *ClassDecl, bool NonNestedClass) { 225826997fd58c9560584edd154618f2f2c15ee68af4Douglas Gregor assert((NonNestedClass || !ClassStack.empty()) && 22596569d68745c8213709740337d2be52b031384f58Douglas Gregor "Nested class without outer class"); 226026997fd58c9560584edd154618f2f2c15ee68af4Douglas Gregor ClassStack.push(new ParsingClass(ClassDecl, NonNestedClass)); 2261eee1d5434ebfa955ffc3c493aecd68bb7b3f4838John McCall return Actions.PushParsingClass(); 22626569d68745c8213709740337d2be52b031384f58Douglas Gregor} 22636569d68745c8213709740337d2be52b031384f58Douglas Gregor 22646569d68745c8213709740337d2be52b031384f58Douglas Gregor/// \brief Deallocate the given parsed class and all of its nested 22656569d68745c8213709740337d2be52b031384f58Douglas Gregor/// classes. 22666569d68745c8213709740337d2be52b031384f58Douglas Gregorvoid Parser::DeallocateParsedClasses(Parser::ParsingClass *Class) { 2267d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor for (unsigned I = 0, N = Class->LateParsedDeclarations.size(); I != N; ++I) 2268d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor delete Class->LateParsedDeclarations[I]; 22696569d68745c8213709740337d2be52b031384f58Douglas Gregor delete Class; 22706569d68745c8213709740337d2be52b031384f58Douglas Gregor} 22716569d68745c8213709740337d2be52b031384f58Douglas Gregor 22726569d68745c8213709740337d2be52b031384f58Douglas Gregor/// \brief Pop the top class of the stack of classes that are 22736569d68745c8213709740337d2be52b031384f58Douglas Gregor/// currently being parsed. 22746569d68745c8213709740337d2be52b031384f58Douglas Gregor/// 22756569d68745c8213709740337d2be52b031384f58Douglas Gregor/// This routine should be called when we have finished parsing the 22766569d68745c8213709740337d2be52b031384f58Douglas Gregor/// definition of a class, but have not yet popped the Scope 22776569d68745c8213709740337d2be52b031384f58Douglas Gregor/// associated with the class's definition. 22786569d68745c8213709740337d2be52b031384f58Douglas Gregor/// 22796569d68745c8213709740337d2be52b031384f58Douglas Gregor/// \returns true if the class we've popped is a top-level class, 22806569d68745c8213709740337d2be52b031384f58Douglas Gregor/// false otherwise. 2281eee1d5434ebfa955ffc3c493aecd68bb7b3f4838John McCallvoid Parser::PopParsingClass(Sema::ParsingClassState state) { 22826569d68745c8213709740337d2be52b031384f58Douglas Gregor assert(!ClassStack.empty() && "Mismatched push/pop for class parsing"); 22831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2284eee1d5434ebfa955ffc3c493aecd68bb7b3f4838John McCall Actions.PopParsingClass(state); 2285eee1d5434ebfa955ffc3c493aecd68bb7b3f4838John McCall 22866569d68745c8213709740337d2be52b031384f58Douglas Gregor ParsingClass *Victim = ClassStack.top(); 22876569d68745c8213709740337d2be52b031384f58Douglas Gregor ClassStack.pop(); 22886569d68745c8213709740337d2be52b031384f58Douglas Gregor if (Victim->TopLevelClass) { 22896569d68745c8213709740337d2be52b031384f58Douglas Gregor // Deallocate all of the nested classes of this class, 22906569d68745c8213709740337d2be52b031384f58Douglas Gregor // recursively: we don't need to keep any of this information. 22916569d68745c8213709740337d2be52b031384f58Douglas Gregor DeallocateParsedClasses(Victim); 22926569d68745c8213709740337d2be52b031384f58Douglas Gregor return; 22931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 22946569d68745c8213709740337d2be52b031384f58Douglas Gregor assert(!ClassStack.empty() && "Missing top-level class?"); 22956569d68745c8213709740337d2be52b031384f58Douglas Gregor 2296d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor if (Victim->LateParsedDeclarations.empty()) { 22976569d68745c8213709740337d2be52b031384f58Douglas Gregor // The victim is a nested class, but we will not need to perform 22986569d68745c8213709740337d2be52b031384f58Douglas Gregor // any processing after the definition of this class since it has 22996569d68745c8213709740337d2be52b031384f58Douglas Gregor // no members whose handling was delayed. Therefore, we can just 23006569d68745c8213709740337d2be52b031384f58Douglas Gregor // remove this nested class. 2301d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor DeallocateParsedClasses(Victim); 23026569d68745c8213709740337d2be52b031384f58Douglas Gregor return; 23036569d68745c8213709740337d2be52b031384f58Douglas Gregor } 23046569d68745c8213709740337d2be52b031384f58Douglas Gregor 23056569d68745c8213709740337d2be52b031384f58Douglas Gregor // This nested class has some members that will need to be processed 23066569d68745c8213709740337d2be52b031384f58Douglas Gregor // after the top-level class is completely defined. Therefore, add 23076569d68745c8213709740337d2be52b031384f58Douglas Gregor // it to the list of nested classes within its parent. 230823c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor assert(getCurScope()->isClassScope() && "Nested class outside of class scope?"); 2309d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor ClassStack.top()->LateParsedDeclarations.push_back(new LateParsedClass(this, Victim)); 231023c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Victim->TemplateScope = getCurScope()->getParent()->isTemplateParamScope(); 23116569d68745c8213709740337d2be52b031384f58Douglas Gregor} 2312bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt 2313bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// ParseCXX0XAttributes - Parse a C++0x attribute-specifier. Currently only 2314bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// parses standard attributes. 2315bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// 2316bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// [C++0x] attribute-specifier: 2317bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// '[' '[' attribute-list ']' ']' 2318bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// 2319bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// [C++0x] attribute-list: 2320bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// attribute[opt] 2321bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// attribute-list ',' attribute[opt] 2322bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// 2323bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// [C++0x] attribute: 2324bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// attribute-token attribute-argument-clause[opt] 2325bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// 2326bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// [C++0x] attribute-token: 2327bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// identifier 2328bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// attribute-scoped-token 2329bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// 2330bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// [C++0x] attribute-scoped-token: 2331bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// attribute-namespace '::' identifier 2332bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// 2333bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// [C++0x] attribute-namespace: 2334bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// identifier 2335bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// 2336bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// [C++0x] attribute-argument-clause: 2337bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// '(' balanced-token-seq ')' 2338bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// 2339bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// [C++0x] balanced-token-seq: 2340bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// balanced-token 2341bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// balanced-token-seq balanced-token 2342bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// 2343bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// [C++0x] balanced-token: 2344bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// '(' balanced-token-seq ')' 2345bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// '[' balanced-token-seq ']' 2346bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// '{' balanced-token-seq '}' 2347bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// any token but '(', ')', '[', ']', '{', or '}' 23487f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCallvoid Parser::ParseCXX0XAttributes(ParsedAttributesWithRange &attrs, 23497f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall SourceLocation *endLoc) { 2350bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt assert(Tok.is(tok::l_square) && NextToken().is(tok::l_square) 2351bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt && "Not a C++0x attribute list"); 2352bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt 2353bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt SourceLocation StartLoc = Tok.getLocation(), Loc; 2354bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt 2355bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt ConsumeBracket(); 2356bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt ConsumeBracket(); 2357193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam 2358bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt if (Tok.is(tok::comma)) { 2359bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt Diag(Tok.getLocation(), diag::err_expected_ident); 2360bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt ConsumeToken(); 2361bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt } 2362bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt 2363bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt while (Tok.is(tok::identifier) || Tok.is(tok::comma)) { 2364bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt // attribute not present 2365bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt if (Tok.is(tok::comma)) { 2366bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt ConsumeToken(); 2367bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt continue; 2368bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt } 2369bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt 2370bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt IdentifierInfo *ScopeName = 0, *AttrName = Tok.getIdentifierInfo(); 2371bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt SourceLocation ScopeLoc, AttrLoc = ConsumeToken(); 2372193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam 2373bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt // scoped attribute 2374bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt if (Tok.is(tok::coloncolon)) { 2375bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt ConsumeToken(); 2376bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt 2377bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt if (!Tok.is(tok::identifier)) { 2378bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt Diag(Tok.getLocation(), diag::err_expected_ident); 2379bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt SkipUntil(tok::r_square, tok::comma, true, true); 2380bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt continue; 2381bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt } 2382193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam 2383bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt ScopeName = AttrName; 2384bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt ScopeLoc = AttrLoc; 2385bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt 2386bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt AttrName = Tok.getIdentifierInfo(); 2387bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt AttrLoc = ConsumeToken(); 2388bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt } 2389bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt 2390bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt bool AttrParsed = false; 2391bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt // No scoped names are supported; ideally we could put all non-standard 2392bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt // attributes into namespaces. 2393bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt if (!ScopeName) { 2394bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt switch(AttributeList::getKind(AttrName)) 2395bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt { 2396bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt // No arguments 23977725e67639fa2fe74f8775b7ed884a076ffdbffcSean Hunt case AttributeList::AT_carries_dependency: 239815e14a289583616e582a23b320933e846a742626Anders Carlsson case AttributeList::AT_noreturn: { 2399bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt if (Tok.is(tok::l_paren)) { 2400bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt Diag(Tok.getLocation(), diag::err_cxx0x_attribute_forbids_arguments) 2401bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt << AttrName->getName(); 2402bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt break; 2403bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt } 2404bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt 24050b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall attrs.addNew(AttrName, AttrLoc, 0, AttrLoc, 0, 24060b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall SourceLocation(), 0, 0, false, true); 2407bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt AttrParsed = true; 2408bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt break; 2409bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt } 2410bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt 2411bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt // One argument; must be a type-id or assignment-expression 2412bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt case AttributeList::AT_aligned: { 2413bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt if (Tok.isNot(tok::l_paren)) { 2414bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt Diag(Tok.getLocation(), diag::err_cxx0x_attribute_requires_arguments) 2415bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt << AttrName->getName(); 2416bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt break; 2417bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt } 2418bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt SourceLocation ParamLoc = ConsumeParen(); 2419bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt 242060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ArgExpr = ParseCXX0XAlignArgument(ParamLoc); 2421bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt 2422bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt MatchRHSPunctuation(tok::r_paren, ParamLoc); 2423bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt 2424bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt ExprVector ArgExprs(Actions); 2425bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt ArgExprs.push_back(ArgExpr.release()); 24260b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall attrs.addNew(AttrName, AttrLoc, 0, AttrLoc, 24270b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall 0, ParamLoc, ArgExprs.take(), 1, 24280b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall false, true); 2429bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt 2430bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt AttrParsed = true; 2431bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt break; 2432bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt } 2433bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt 2434bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt // Silence warnings 2435bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt default: break; 2436bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt } 2437bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt } 2438bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt 2439bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt // Skip the entire parameter clause, if any 2440bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt if (!AttrParsed && Tok.is(tok::l_paren)) { 2441bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt ConsumeParen(); 2442bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt // SkipUntil maintains the balancedness of tokens. 2443bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt SkipUntil(tok::r_paren, false); 2444bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt } 2445bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt } 2446bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt 2447bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt if (ExpectAndConsume(tok::r_square, diag::err_expected_rsquare)) 2448bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt SkipUntil(tok::r_square, false); 2449bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt Loc = Tok.getLocation(); 2450bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt if (ExpectAndConsume(tok::r_square, diag::err_expected_rsquare)) 2451bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt SkipUntil(tok::r_square, false); 2452bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt 24537f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall attrs.Range = SourceRange(StartLoc, Loc); 2454bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt} 2455bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt 2456bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// ParseCXX0XAlignArgument - Parse the argument to C++0x's [[align]] 2457bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// attribute. 2458bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// 2459bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// FIXME: Simply returns an alignof() expression if the argument is a 2460bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// type. Ideally, the type should be propagated directly into Sema. 2461bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// 2462bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// [C++0x] 'align' '(' type-id ')' 2463bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// [C++0x] 'align' '(' assignment-expression ')' 246460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult Parser::ParseCXX0XAlignArgument(SourceLocation Start) { 2465bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt if (isTypeIdInParens()) { 2466f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall EnterExpressionEvaluationContext Unevaluated(Actions, Sema::Unevaluated); 2467bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt SourceLocation TypeLoc = Tok.getLocation(); 2468b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType Ty = ParseTypeName().get(); 2469bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt SourceRange TypeRange(Start, Tok.getLocation()); 2470f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne return Actions.ActOnUnaryExprOrTypeTraitExpr(TypeLoc, UETT_AlignOf, true, 2471f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne Ty.getAsOpaquePtr(), TypeRange); 2472bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt } else 2473bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt return ParseConstantExpression(); 2474bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt} 2475334d47e92e9f241576fdeb7477b69a03136ba854Francois Pichet 2476334d47e92e9f241576fdeb7477b69a03136ba854Francois Pichet/// ParseMicrosoftAttributes - Parse a Microsoft attribute [Attr] 2477334d47e92e9f241576fdeb7477b69a03136ba854Francois Pichet/// 2478334d47e92e9f241576fdeb7477b69a03136ba854Francois Pichet/// [MS] ms-attribute: 2479334d47e92e9f241576fdeb7477b69a03136ba854Francois Pichet/// '[' token-seq ']' 2480334d47e92e9f241576fdeb7477b69a03136ba854Francois Pichet/// 2481334d47e92e9f241576fdeb7477b69a03136ba854Francois Pichet/// [MS] ms-attribute-seq: 2482334d47e92e9f241576fdeb7477b69a03136ba854Francois Pichet/// ms-attribute[opt] 2483334d47e92e9f241576fdeb7477b69a03136ba854Francois Pichet/// ms-attribute ms-attribute-seq 24847f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCallvoid Parser::ParseMicrosoftAttributes(ParsedAttributes &attrs, 24857f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall SourceLocation *endLoc) { 2486334d47e92e9f241576fdeb7477b69a03136ba854Francois Pichet assert(Tok.is(tok::l_square) && "Not a Microsoft attribute list"); 2487334d47e92e9f241576fdeb7477b69a03136ba854Francois Pichet 2488334d47e92e9f241576fdeb7477b69a03136ba854Francois Pichet while (Tok.is(tok::l_square)) { 2489334d47e92e9f241576fdeb7477b69a03136ba854Francois Pichet ConsumeBracket(); 2490334d47e92e9f241576fdeb7477b69a03136ba854Francois Pichet SkipUntil(tok::r_square, true, true); 24917f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall if (endLoc) *endLoc = Tok.getLocation(); 2492334d47e92e9f241576fdeb7477b69a03136ba854Francois Pichet ExpectAndConsume(tok::r_square, diag::err_expected_rsquare); 2493334d47e92e9f241576fdeb7477b69a03136ba854Francois Pichet } 2494334d47e92e9f241576fdeb7477b69a03136ba854Francois Pichet} 2495