ParseExprCXX.cpp revision 6ee326af4e77e6f05973486097884d7431f2108d
15f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===--- ParseExprCXX.cpp - C++ Expression Parsing ------------------------===// 25f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 35f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// The LLVM Compiler Infrastructure 45f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// This file is distributed under the University of Illinois Open Source 60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// License. See LICENSE.TXT for details. 75f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 85f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 95f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// This file implements the Expression parsing implementation for C++. 115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14500d3297d2a21edeac4d46cbcbe21bc2352c2a28Chris Lattner#include "clang/Parse/ParseDiagnostic.h" 155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/Parse/Parser.h" 16bc61bd8109d9accf8f966b59e3f16a1497e72adfDouglas Gregor#include "RAIIObjectsForParser.h" 17dc3b723d35067e5d13474247b94a10c869cc7e58Eli Friedman#include "clang/Basic/PrettyStackTrace.h" 1833762775706e81c17ca774102ceda36049ecc593Richard Smith#include "clang/Lex/LiteralSupport.h" 1919510856727e0e14a3696b2a72c35163bff2a71fJohn McCall#include "clang/Sema/DeclSpec.h" 20ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor#include "clang/Sema/Scope.h" 2119510856727e0e14a3696b2a72c35163bff2a71fJohn McCall#include "clang/Sema/ParsedTemplate.h" 223f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor#include "llvm/Support/ErrorHandling.h" 233f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing namespace clang; 255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 26ea698b3f6cad84f7f583282dce3e03e24fe80e98Richard Smithstatic int SelectDigraphErrorMessage(tok::TokenKind Kind) { 27ea698b3f6cad84f7f583282dce3e03e24fe80e98Richard Smith switch (Kind) { 28ea698b3f6cad84f7f583282dce3e03e24fe80e98Richard Smith case tok::kw_template: return 0; 29ea698b3f6cad84f7f583282dce3e03e24fe80e98Richard Smith case tok::kw_const_cast: return 1; 30ea698b3f6cad84f7f583282dce3e03e24fe80e98Richard Smith case tok::kw_dynamic_cast: return 2; 31ea698b3f6cad84f7f583282dce3e03e24fe80e98Richard Smith case tok::kw_reinterpret_cast: return 3; 32ea698b3f6cad84f7f583282dce3e03e24fe80e98Richard Smith case tok::kw_static_cast: return 4; 33ea698b3f6cad84f7f583282dce3e03e24fe80e98Richard Smith default: 34b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie llvm_unreachable("Unknown type for digraph error message."); 35ea698b3f6cad84f7f583282dce3e03e24fe80e98Richard Smith } 36ea698b3f6cad84f7f583282dce3e03e24fe80e98Richard Smith} 37ea698b3f6cad84f7f583282dce3e03e24fe80e98Richard Smith 38ea698b3f6cad84f7f583282dce3e03e24fe80e98Richard Smith// Are the two tokens adjacent in the same source file? 39ea698b3f6cad84f7f583282dce3e03e24fe80e98Richard Smithstatic bool AreTokensAdjacent(Preprocessor &PP, Token &First, Token &Second) { 40ea698b3f6cad84f7f583282dce3e03e24fe80e98Richard Smith SourceManager &SM = PP.getSourceManager(); 41ea698b3f6cad84f7f583282dce3e03e24fe80e98Richard Smith SourceLocation FirstLoc = SM.getSpellingLoc(First.getLocation()); 42a64ccefdf0ea4e03ec88805d71b0af74950c7472Argyrios Kyrtzidis SourceLocation FirstEnd = FirstLoc.getLocWithOffset(First.getLength()); 43ea698b3f6cad84f7f583282dce3e03e24fe80e98Richard Smith return FirstEnd == SM.getSpellingLoc(Second.getLocation()); 44ea698b3f6cad84f7f583282dce3e03e24fe80e98Richard Smith} 45ea698b3f6cad84f7f583282dce3e03e24fe80e98Richard Smith 46ea698b3f6cad84f7f583282dce3e03e24fe80e98Richard Smith// Suggest fixit for "<::" after a cast. 47ea698b3f6cad84f7f583282dce3e03e24fe80e98Richard Smithstatic void FixDigraph(Parser &P, Preprocessor &PP, Token &DigraphToken, 48ea698b3f6cad84f7f583282dce3e03e24fe80e98Richard Smith Token &ColonToken, tok::TokenKind Kind, bool AtDigraph) { 49ea698b3f6cad84f7f583282dce3e03e24fe80e98Richard Smith // Pull '<:' and ':' off token stream. 50ea698b3f6cad84f7f583282dce3e03e24fe80e98Richard Smith if (!AtDigraph) 51ea698b3f6cad84f7f583282dce3e03e24fe80e98Richard Smith PP.Lex(DigraphToken); 52ea698b3f6cad84f7f583282dce3e03e24fe80e98Richard Smith PP.Lex(ColonToken); 53ea698b3f6cad84f7f583282dce3e03e24fe80e98Richard Smith 54ea698b3f6cad84f7f583282dce3e03e24fe80e98Richard Smith SourceRange Range; 55ea698b3f6cad84f7f583282dce3e03e24fe80e98Richard Smith Range.setBegin(DigraphToken.getLocation()); 56ea698b3f6cad84f7f583282dce3e03e24fe80e98Richard Smith Range.setEnd(ColonToken.getLocation()); 57ea698b3f6cad84f7f583282dce3e03e24fe80e98Richard Smith P.Diag(DigraphToken.getLocation(), diag::err_missing_whitespace_digraph) 58ea698b3f6cad84f7f583282dce3e03e24fe80e98Richard Smith << SelectDigraphErrorMessage(Kind) 59ea698b3f6cad84f7f583282dce3e03e24fe80e98Richard Smith << FixItHint::CreateReplacement(Range, "< ::"); 60ea698b3f6cad84f7f583282dce3e03e24fe80e98Richard Smith 61ea698b3f6cad84f7f583282dce3e03e24fe80e98Richard Smith // Update token information to reflect their change in token type. 62ea698b3f6cad84f7f583282dce3e03e24fe80e98Richard Smith ColonToken.setKind(tok::coloncolon); 63a64ccefdf0ea4e03ec88805d71b0af74950c7472Argyrios Kyrtzidis ColonToken.setLocation(ColonToken.getLocation().getLocWithOffset(-1)); 64ea698b3f6cad84f7f583282dce3e03e24fe80e98Richard Smith ColonToken.setLength(2); 65ea698b3f6cad84f7f583282dce3e03e24fe80e98Richard Smith DigraphToken.setKind(tok::less); 66ea698b3f6cad84f7f583282dce3e03e24fe80e98Richard Smith DigraphToken.setLength(1); 67ea698b3f6cad84f7f583282dce3e03e24fe80e98Richard Smith 68ea698b3f6cad84f7f583282dce3e03e24fe80e98Richard Smith // Push new tokens back to token stream. 69ea698b3f6cad84f7f583282dce3e03e24fe80e98Richard Smith PP.EnterToken(ColonToken); 70ea698b3f6cad84f7f583282dce3e03e24fe80e98Richard Smith if (!AtDigraph) 71ea698b3f6cad84f7f583282dce3e03e24fe80e98Richard Smith PP.EnterToken(DigraphToken); 72ea698b3f6cad84f7f583282dce3e03e24fe80e98Richard Smith} 73ea698b3f6cad84f7f583282dce3e03e24fe80e98Richard Smith 74950be71c745409e373ae8a834490f9026c8ac222Richard Trieu// Check for '<::' which should be '< ::' instead of '[:' when following 75950be71c745409e373ae8a834490f9026c8ac222Richard Trieu// a template name. 76950be71c745409e373ae8a834490f9026c8ac222Richard Trieuvoid Parser::CheckForTemplateAndDigraph(Token &Next, ParsedType ObjectType, 77950be71c745409e373ae8a834490f9026c8ac222Richard Trieu bool EnteringContext, 78950be71c745409e373ae8a834490f9026c8ac222Richard Trieu IdentifierInfo &II, CXXScopeSpec &SS) { 79c11030ea936f6952deb5a1423ce1648173cd417eRichard Trieu if (!Next.is(tok::l_square) || Next.getLength() != 2) 80950be71c745409e373ae8a834490f9026c8ac222Richard Trieu return; 81950be71c745409e373ae8a834490f9026c8ac222Richard Trieu 82950be71c745409e373ae8a834490f9026c8ac222Richard Trieu Token SecondToken = GetLookAheadToken(2); 83950be71c745409e373ae8a834490f9026c8ac222Richard Trieu if (!SecondToken.is(tok::colon) || !AreTokensAdjacent(PP, Next, SecondToken)) 84950be71c745409e373ae8a834490f9026c8ac222Richard Trieu return; 85950be71c745409e373ae8a834490f9026c8ac222Richard Trieu 86950be71c745409e373ae8a834490f9026c8ac222Richard Trieu TemplateTy Template; 87950be71c745409e373ae8a834490f9026c8ac222Richard Trieu UnqualifiedId TemplateName; 88950be71c745409e373ae8a834490f9026c8ac222Richard Trieu TemplateName.setIdentifier(&II, Tok.getLocation()); 89950be71c745409e373ae8a834490f9026c8ac222Richard Trieu bool MemberOfUnknownSpecialization; 90950be71c745409e373ae8a834490f9026c8ac222Richard Trieu if (!Actions.isTemplateName(getCurScope(), SS, /*hasTemplateKeyword=*/false, 91950be71c745409e373ae8a834490f9026c8ac222Richard Trieu TemplateName, ObjectType, EnteringContext, 92950be71c745409e373ae8a834490f9026c8ac222Richard Trieu Template, MemberOfUnknownSpecialization)) 93950be71c745409e373ae8a834490f9026c8ac222Richard Trieu return; 94950be71c745409e373ae8a834490f9026c8ac222Richard Trieu 95950be71c745409e373ae8a834490f9026c8ac222Richard Trieu FixDigraph(*this, PP, Next, SecondToken, tok::kw_template, 96950be71c745409e373ae8a834490f9026c8ac222Richard Trieu /*AtDigraph*/false); 97950be71c745409e373ae8a834490f9026c8ac222Richard Trieu} 98950be71c745409e373ae8a834490f9026c8ac222Richard Trieu 991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// \brief Parse global scope or nested-name-specifier if present. 1002dd078ae50ff7be1fb25ebeedde45e9ab691a4f0Douglas Gregor/// 1012dd078ae50ff7be1fb25ebeedde45e9ab691a4f0Douglas Gregor/// Parses a C++ global scope specifier ('::') or nested-name-specifier (which 1021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// may be preceded by '::'). Note that this routine will not parse ::new or 1032dd078ae50ff7be1fb25ebeedde45e9ab691a4f0Douglas Gregor/// ::delete; it will just leave them in the token stream. 104eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis/// 105eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis/// '::'[opt] nested-name-specifier 106eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis/// '::' 107eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis/// 108eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis/// nested-name-specifier: 109eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis/// type-name '::' 110eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis/// namespace-name '::' 111eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis/// nested-name-specifier identifier '::' 1122dd078ae50ff7be1fb25ebeedde45e9ab691a4f0Douglas Gregor/// nested-name-specifier 'template'[opt] simple-template-id '::' 1132dd078ae50ff7be1fb25ebeedde45e9ab691a4f0Douglas Gregor/// 1142dd078ae50ff7be1fb25ebeedde45e9ab691a4f0Douglas Gregor/// 1151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// \param SS the scope specifier that will be set to the parsed 1162dd078ae50ff7be1fb25ebeedde45e9ab691a4f0Douglas Gregor/// nested-name-specifier (or empty) 1172dd078ae50ff7be1fb25ebeedde45e9ab691a4f0Douglas Gregor/// 1181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// \param ObjectType if this nested-name-specifier is being parsed following 1192dd078ae50ff7be1fb25ebeedde45e9ab691a4f0Douglas Gregor/// the "." or "->" of a member access expression, this parameter provides the 1202dd078ae50ff7be1fb25ebeedde45e9ab691a4f0Douglas Gregor/// type of the object whose members are being accessed. 121eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis/// 1222dd078ae50ff7be1fb25ebeedde45e9ab691a4f0Douglas Gregor/// \param EnteringContext whether we will be entering into the context of 1232dd078ae50ff7be1fb25ebeedde45e9ab691a4f0Douglas Gregor/// the nested-name-specifier after parsing it. 1242dd078ae50ff7be1fb25ebeedde45e9ab691a4f0Douglas Gregor/// 125d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor/// \param MayBePseudoDestructor When non-NULL, points to a flag that 126d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor/// indicates whether this nested-name-specifier may be part of a 127d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor/// pseudo-destructor name. In this case, the flag will be set false 128d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor/// if we don't actually end up parsing a destructor name. Moreorover, 129d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor/// if we do end up determining that we are parsing a destructor name, 130d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor/// the last component of the nested-name-specifier is not parsed as 131d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor/// part of the scope specifier. 132d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor 133b10cd04880672103660e5844e51ee91af7361a20Douglas Gregor/// member access expression, e.g., the \p T:: in \p p->T::m. 134b10cd04880672103660e5844e51ee91af7361a20Douglas Gregor/// 1359ba6166f4a78722e7df8ffbd64eb788bfdf2764aJohn McCall/// \returns true if there was an error parsing a scope specifier 136495c35d291da48c4f5655bbb54d15128ddde0d4dDouglas Gregorbool Parser::ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS, 137b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ObjectType, 138b10cd04880672103660e5844e51ee91af7361a20Douglas Gregor bool EnteringContext, 1394147d307086cf024a40a080e2bf379e9725f6f41Francois Pichet bool *MayBePseudoDestructor, 1404147d307086cf024a40a080e2bf379e9725f6f41Francois Pichet bool IsTypename) { 1414e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie assert(getLangOpts().CPlusPlus && 1427452c6fc567ea1799f617395d0fa4c7ed075e5d9Chris Lattner "Call sites of this function should be guarded by checking for C++"); 1431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 144eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis if (Tok.is(tok::annot_cxxscope)) { 145c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor Actions.RestoreNestedNameSpecifierAnnotation(Tok.getAnnotationValue(), 146c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor Tok.getAnnotationRange(), 147c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor SS); 148eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis ConsumeToken(); 1499ba6166f4a78722e7df8ffbd64eb788bfdf2764aJohn McCall return false; 150eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis } 151e607e808c2b90724a2a6fd841e850f07de1f5b30Chris Lattner 15239a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor bool HasScopeSpecifier = false; 15339a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor 1545b4547318bb179fc76f984f0eeaaf615927e795cChris Lattner if (Tok.is(tok::coloncolon)) { 1555b4547318bb179fc76f984f0eeaaf615927e795cChris Lattner // ::new and ::delete aren't nested-name-specifiers. 1565b4547318bb179fc76f984f0eeaaf615927e795cChris Lattner tok::TokenKind NextKind = NextToken().getKind(); 1575b4547318bb179fc76f984f0eeaaf615927e795cChris Lattner if (NextKind == tok::kw_new || NextKind == tok::kw_delete) 1585b4547318bb179fc76f984f0eeaaf615927e795cChris Lattner return false; 1591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 16055a7cefc846765ac7d142a63f773747a20518d71Chris Lattner // '::' - Global scope qualifier. 1612e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor if (Actions.ActOnCXXGlobalScopeSpecifier(getCurScope(), ConsumeToken(), SS)) 1622e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor return true; 1632e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor 16439a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor HasScopeSpecifier = true; 165eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis } 166eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis 167d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor bool CheckForDestructor = false; 168d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor if (MayBePseudoDestructor && *MayBePseudoDestructor) { 169d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor CheckForDestructor = true; 170d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor *MayBePseudoDestructor = false; 171d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor } 172d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor 17342d6d0c91ab089cb252ab2f91c16d4557f458a2cDavid Blaikie if (Tok.is(tok::kw_decltype) || Tok.is(tok::annot_decltype)) { 17442d6d0c91ab089cb252ab2f91c16d4557f458a2cDavid Blaikie DeclSpec DS(AttrFactory); 17542d6d0c91ab089cb252ab2f91c16d4557f458a2cDavid Blaikie SourceLocation DeclLoc = Tok.getLocation(); 17642d6d0c91ab089cb252ab2f91c16d4557f458a2cDavid Blaikie SourceLocation EndLoc = ParseDecltypeSpecifier(DS); 17742d6d0c91ab089cb252ab2f91c16d4557f458a2cDavid Blaikie if (Tok.isNot(tok::coloncolon)) { 17842d6d0c91ab089cb252ab2f91c16d4557f458a2cDavid Blaikie AnnotateExistingDecltypeSpecifier(DS, DeclLoc, EndLoc); 17942d6d0c91ab089cb252ab2f91c16d4557f458a2cDavid Blaikie return false; 18042d6d0c91ab089cb252ab2f91c16d4557f458a2cDavid Blaikie } 18142d6d0c91ab089cb252ab2f91c16d4557f458a2cDavid Blaikie 18242d6d0c91ab089cb252ab2f91c16d4557f458a2cDavid Blaikie SourceLocation CCLoc = ConsumeToken(); 18342d6d0c91ab089cb252ab2f91c16d4557f458a2cDavid Blaikie if (Actions.ActOnCXXNestedNameSpecifierDecltype(SS, DS, CCLoc)) 18442d6d0c91ab089cb252ab2f91c16d4557f458a2cDavid Blaikie SS.SetInvalid(SourceRange(DeclLoc, CCLoc)); 18542d6d0c91ab089cb252ab2f91c16d4557f458a2cDavid Blaikie 18642d6d0c91ab089cb252ab2f91c16d4557f458a2cDavid Blaikie HasScopeSpecifier = true; 18742d6d0c91ab089cb252ab2f91c16d4557f458a2cDavid Blaikie } 18842d6d0c91ab089cb252ab2f91c16d4557f458a2cDavid Blaikie 18939a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor while (true) { 1902dd078ae50ff7be1fb25ebeedde45e9ab691a4f0Douglas Gregor if (HasScopeSpecifier) { 1912dd078ae50ff7be1fb25ebeedde45e9ab691a4f0Douglas Gregor // C++ [basic.lookup.classref]p5: 1922dd078ae50ff7be1fb25ebeedde45e9ab691a4f0Douglas Gregor // If the qualified-id has the form 1933b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor // 1942dd078ae50ff7be1fb25ebeedde45e9ab691a4f0Douglas Gregor // ::class-name-or-namespace-name::... 1953b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor // 1962dd078ae50ff7be1fb25ebeedde45e9ab691a4f0Douglas Gregor // the class-name-or-namespace-name is looked up in global scope as a 1972dd078ae50ff7be1fb25ebeedde45e9ab691a4f0Douglas Gregor // class-name or namespace-name. 1982dd078ae50ff7be1fb25ebeedde45e9ab691a4f0Douglas Gregor // 1992dd078ae50ff7be1fb25ebeedde45e9ab691a4f0Douglas Gregor // To implement this, we clear out the object type as soon as we've 2002dd078ae50ff7be1fb25ebeedde45e9ab691a4f0Douglas Gregor // seen a leading '::' or part of a nested-name-specifier. 201b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ObjectType = ParsedType(); 20281b747b7fcc91c2fba9a3183d8fac80adbfc1d3eDouglas Gregor 20381b747b7fcc91c2fba9a3183d8fac80adbfc1d3eDouglas Gregor if (Tok.is(tok::code_completion)) { 20481b747b7fcc91c2fba9a3183d8fac80adbfc1d3eDouglas Gregor // Code completion for a nested-name-specifier, where the code 20581b747b7fcc91c2fba9a3183d8fac80adbfc1d3eDouglas Gregor // code completion token follows the '::'. 20623c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteQualifiedId(getCurScope(), SS, EnteringContext); 207b6b2b180c6857af75c6683f7107a7c8994f074edArgyrios Kyrtzidis // Include code completion token into the range of the scope otherwise 208b6b2b180c6857af75c6683f7107a7c8994f074edArgyrios Kyrtzidis // when we try to annotate the scope tokens the dangling code completion 209b6b2b180c6857af75c6683f7107a7c8994f074edArgyrios Kyrtzidis // token will cause assertion in 210b6b2b180c6857af75c6683f7107a7c8994f074edArgyrios Kyrtzidis // Preprocessor::AnnotatePreviousCachedTokens. 2117d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis SS.setEndLoc(Tok.getLocation()); 2127d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis cutOffParsing(); 2137d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis return true; 21481b747b7fcc91c2fba9a3183d8fac80adbfc1d3eDouglas Gregor } 2152dd078ae50ff7be1fb25ebeedde45e9ab691a4f0Douglas Gregor } 2161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21739a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor // nested-name-specifier: 21877cf72a95baa18e82737bb45131e9658a00fee16Chris Lattner // nested-name-specifier 'template'[opt] simple-template-id '::' 21977cf72a95baa18e82737bb45131e9658a00fee16Chris Lattner 22077cf72a95baa18e82737bb45131e9658a00fee16Chris Lattner // Parse the optional 'template' keyword, then make sure we have 22177cf72a95baa18e82737bb45131e9658a00fee16Chris Lattner // 'identifier <' after it. 22277cf72a95baa18e82737bb45131e9658a00fee16Chris Lattner if (Tok.is(tok::kw_template)) { 2232dd078ae50ff7be1fb25ebeedde45e9ab691a4f0Douglas Gregor // If we don't have a scope specifier or an object type, this isn't a 224eab975dce83fcf6a7fa8fc9379944d4b1aaf1a00Eli Friedman // nested-name-specifier, since they aren't allowed to start with 225eab975dce83fcf6a7fa8fc9379944d4b1aaf1a00Eli Friedman // 'template'. 2262dd078ae50ff7be1fb25ebeedde45e9ab691a4f0Douglas Gregor if (!HasScopeSpecifier && !ObjectType) 227eab975dce83fcf6a7fa8fc9379944d4b1aaf1a00Eli Friedman break; 228eab975dce83fcf6a7fa8fc9379944d4b1aaf1a00Eli Friedman 2297bb87fca7d22a8a194d04188746b90f46512975fDouglas Gregor TentativeParsingAction TPA(*this); 23077cf72a95baa18e82737bb45131e9658a00fee16Chris Lattner SourceLocation TemplateKWLoc = ConsumeToken(); 231ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor 232ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor UnqualifiedId TemplateName; 233ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor if (Tok.is(tok::identifier)) { 234ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor // Consume the identifier. 2357bb87fca7d22a8a194d04188746b90f46512975fDouglas Gregor TemplateName.setIdentifier(Tok.getIdentifierInfo(), Tok.getLocation()); 236ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor ConsumeToken(); 237ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor } else if (Tok.is(tok::kw_operator)) { 238ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor if (ParseUnqualifiedIdOperator(SS, EnteringContext, ObjectType, 2397bb87fca7d22a8a194d04188746b90f46512975fDouglas Gregor TemplateName)) { 2407bb87fca7d22a8a194d04188746b90f46512975fDouglas Gregor TPA.Commit(); 241ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor break; 2427bb87fca7d22a8a194d04188746b90f46512975fDouglas Gregor } 243ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor 244e6252d1587f98dbac704178e7b2ce53116048310Sean Hunt if (TemplateName.getKind() != UnqualifiedId::IK_OperatorFunctionId && 245e6252d1587f98dbac704178e7b2ce53116048310Sean Hunt TemplateName.getKind() != UnqualifiedId::IK_LiteralOperatorId) { 246ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor Diag(TemplateName.getSourceRange().getBegin(), 247ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor diag::err_id_after_template_in_nested_name_spec) 248ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor << TemplateName.getSourceRange(); 2497bb87fca7d22a8a194d04188746b90f46512975fDouglas Gregor TPA.Commit(); 250ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor break; 251ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor } 252ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor } else { 2537bb87fca7d22a8a194d04188746b90f46512975fDouglas Gregor TPA.Revert(); 25477cf72a95baa18e82737bb45131e9658a00fee16Chris Lattner break; 25577cf72a95baa18e82737bb45131e9658a00fee16Chris Lattner } 2561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2577bb87fca7d22a8a194d04188746b90f46512975fDouglas Gregor // If the next token is not '<', we have a qualified-id that refers 2587bb87fca7d22a8a194d04188746b90f46512975fDouglas Gregor // to a template name, such as T::template apply, but is not a 2597bb87fca7d22a8a194d04188746b90f46512975fDouglas Gregor // template-id. 2607bb87fca7d22a8a194d04188746b90f46512975fDouglas Gregor if (Tok.isNot(tok::less)) { 2617bb87fca7d22a8a194d04188746b90f46512975fDouglas Gregor TPA.Revert(); 2627bb87fca7d22a8a194d04188746b90f46512975fDouglas Gregor break; 2637bb87fca7d22a8a194d04188746b90f46512975fDouglas Gregor } 2647bb87fca7d22a8a194d04188746b90f46512975fDouglas Gregor 2657bb87fca7d22a8a194d04188746b90f46512975fDouglas Gregor // Commit to parsing the template-id. 2667bb87fca7d22a8a194d04188746b90f46512975fDouglas Gregor TPA.Commit(); 267d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor TemplateTy Template; 268e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (TemplateNameKind TNK 269e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara = Actions.ActOnDependentTemplateName(getCurScope(), 270e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SS, TemplateKWLoc, TemplateName, 271e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara ObjectType, EnteringContext, 272e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara Template)) { 273e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (AnnotateTemplateIdToken(Template, TNK, SS, TemplateKWLoc, 274e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara TemplateName, false)) 275d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor return true; 276d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor } else 2779ba6166f4a78722e7df8ffbd64eb788bfdf2764aJohn McCall return true; 2781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 27977cf72a95baa18e82737bb45131e9658a00fee16Chris Lattner continue; 28077cf72a95baa18e82737bb45131e9658a00fee16Chris Lattner } 2811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 28239a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor if (Tok.is(tok::annot_template_id) && NextToken().is(tok::coloncolon)) { 2831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // We have 28439a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor // 28539a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor // simple-template-id '::' 28639a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor // 28739a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor // So we need to check whether the simple-template-id is of the 288c45c232440dfafedca1a3773b904fb42609b1b19Douglas Gregor // right kind (it should name a type or be dependent), and then 289c45c232440dfafedca1a3773b904fb42609b1b19Douglas Gregor // convert it into a type within the nested-name-specifier. 29025a767651d14db87aa03dd5fe3e011d877dd4100Argyrios Kyrtzidis TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Tok); 291d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor if (CheckForDestructor && GetLookAheadToken(2).is(tok::tilde)) { 292d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor *MayBePseudoDestructor = true; 2939ba6166f4a78722e7df8ffbd64eb788bfdf2764aJohn McCall return false; 294d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor } 295d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor 2966cd9d4aa13c2145c8b4398453974515b734bfe42Douglas Gregor // Consume the template-id token. 2976cd9d4aa13c2145c8b4398453974515b734bfe42Douglas Gregor ConsumeToken(); 2986cd9d4aa13c2145c8b4398453974515b734bfe42Douglas Gregor 2996cd9d4aa13c2145c8b4398453974515b734bfe42Douglas Gregor assert(Tok.is(tok::coloncolon) && "NextToken() not working properly!"); 3006cd9d4aa13c2145c8b4398453974515b734bfe42Douglas Gregor SourceLocation CCLoc = ConsumeToken(); 3011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3026796fc1adcaf57c38d072a238b016b2834afbe0dDavid Blaikie HasScopeSpecifier = true; 3036cd9d4aa13c2145c8b4398453974515b734bfe42Douglas Gregor 3046cd9d4aa13c2145c8b4398453974515b734bfe42Douglas Gregor ASTTemplateArgsPtr TemplateArgsPtr(Actions, 3056cd9d4aa13c2145c8b4398453974515b734bfe42Douglas Gregor TemplateId->getTemplateArgs(), 3066cd9d4aa13c2145c8b4398453974515b734bfe42Douglas Gregor TemplateId->NumArgs); 3076cd9d4aa13c2145c8b4398453974515b734bfe42Douglas Gregor 3086cd9d4aa13c2145c8b4398453974515b734bfe42Douglas Gregor if (Actions.ActOnCXXNestedNameSpecifier(getCurScope(), 309e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SS, 310e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara TemplateId->TemplateKWLoc, 3116cd9d4aa13c2145c8b4398453974515b734bfe42Douglas Gregor TemplateId->Template, 3126cd9d4aa13c2145c8b4398453974515b734bfe42Douglas Gregor TemplateId->TemplateNameLoc, 3136cd9d4aa13c2145c8b4398453974515b734bfe42Douglas Gregor TemplateId->LAngleLoc, 3146cd9d4aa13c2145c8b4398453974515b734bfe42Douglas Gregor TemplateArgsPtr, 3156cd9d4aa13c2145c8b4398453974515b734bfe42Douglas Gregor TemplateId->RAngleLoc, 3166cd9d4aa13c2145c8b4398453974515b734bfe42Douglas Gregor CCLoc, 3176cd9d4aa13c2145c8b4398453974515b734bfe42Douglas Gregor EnteringContext)) { 3186cd9d4aa13c2145c8b4398453974515b734bfe42Douglas Gregor SourceLocation StartLoc 3196cd9d4aa13c2145c8b4398453974515b734bfe42Douglas Gregor = SS.getBeginLoc().isValid()? SS.getBeginLoc() 3206cd9d4aa13c2145c8b4398453974515b734bfe42Douglas Gregor : TemplateId->TemplateNameLoc; 3216cd9d4aa13c2145c8b4398453974515b734bfe42Douglas Gregor SS.SetInvalid(SourceRange(StartLoc, CCLoc)); 32267b9e831943300ce54e564e601971828ce4def15Chris Lattner } 323eccce7e246a17e12a2afd6eabb9ac7c8d582db4eArgyrios Kyrtzidis 3246cd9d4aa13c2145c8b4398453974515b734bfe42Douglas Gregor continue; 32539a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor } 32639a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor 3275c7f786e3269ee2b512ecf13ccf556c47be83a76Chris Lattner 3285c7f786e3269ee2b512ecf13ccf556c47be83a76Chris Lattner // The rest of the nested-name-specifier possibilities start with 3295c7f786e3269ee2b512ecf13ccf556c47be83a76Chris Lattner // tok::identifier. 3305c7f786e3269ee2b512ecf13ccf556c47be83a76Chris Lattner if (Tok.isNot(tok::identifier)) 3315c7f786e3269ee2b512ecf13ccf556c47be83a76Chris Lattner break; 3325c7f786e3269ee2b512ecf13ccf556c47be83a76Chris Lattner 3335c7f786e3269ee2b512ecf13ccf556c47be83a76Chris Lattner IdentifierInfo &II = *Tok.getIdentifierInfo(); 3345c7f786e3269ee2b512ecf13ccf556c47be83a76Chris Lattner 3355c7f786e3269ee2b512ecf13ccf556c47be83a76Chris Lattner // nested-name-specifier: 3365c7f786e3269ee2b512ecf13ccf556c47be83a76Chris Lattner // type-name '::' 3375c7f786e3269ee2b512ecf13ccf556c47be83a76Chris Lattner // namespace-name '::' 3385c7f786e3269ee2b512ecf13ccf556c47be83a76Chris Lattner // nested-name-specifier identifier '::' 3395c7f786e3269ee2b512ecf13ccf556c47be83a76Chris Lattner Token Next = NextToken(); 34046646491834cd8faabb22482dfe93b24ce28a6c1Chris Lattner 34146646491834cd8faabb22482dfe93b24ce28a6c1Chris Lattner // If we get foo:bar, this is almost certainly a typo for foo::bar. Recover 34246646491834cd8faabb22482dfe93b24ce28a6c1Chris Lattner // and emit a fixit hint for it. 343b10cd04880672103660e5844e51ee91af7361a20Douglas Gregor if (Next.is(tok::colon) && !ColonIsSacred) { 3442e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor if (Actions.IsInvalidUnlessNestedName(getCurScope(), SS, II, 3452e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor Tok.getLocation(), 3462e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor Next.getLocation(), ObjectType, 347b10cd04880672103660e5844e51ee91af7361a20Douglas Gregor EnteringContext) && 348b10cd04880672103660e5844e51ee91af7361a20Douglas Gregor // If the token after the colon isn't an identifier, it's still an 349b10cd04880672103660e5844e51ee91af7361a20Douglas Gregor // error, but they probably meant something else strange so don't 350b10cd04880672103660e5844e51ee91af7361a20Douglas Gregor // recover like this. 351b10cd04880672103660e5844e51ee91af7361a20Douglas Gregor PP.LookAhead(1).is(tok::identifier)) { 352b10cd04880672103660e5844e51ee91af7361a20Douglas Gregor Diag(Next, diag::err_unexected_colon_in_nested_name_spec) 353849b243d4065f56742a4677d6dc8277609a151f8Douglas Gregor << FixItHint::CreateReplacement(Next.getLocation(), "::"); 354b10cd04880672103660e5844e51ee91af7361a20Douglas Gregor 355b10cd04880672103660e5844e51ee91af7361a20Douglas Gregor // Recover as if the user wrote '::'. 356b10cd04880672103660e5844e51ee91af7361a20Douglas Gregor Next.setKind(tok::coloncolon); 357b10cd04880672103660e5844e51ee91af7361a20Douglas Gregor } 35846646491834cd8faabb22482dfe93b24ce28a6c1Chris Lattner } 35946646491834cd8faabb22482dfe93b24ce28a6c1Chris Lattner 3605c7f786e3269ee2b512ecf13ccf556c47be83a76Chris Lattner if (Next.is(tok::coloncolon)) { 36177549080fb7b9af31606b3c1b4830a94429fb1fdDouglas Gregor if (CheckForDestructor && GetLookAheadToken(2).is(tok::tilde) && 36223c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor !Actions.isNonTypeNestedNameSpecifier(getCurScope(), SS, Tok.getLocation(), 36377549080fb7b9af31606b3c1b4830a94429fb1fdDouglas Gregor II, ObjectType)) { 364d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor *MayBePseudoDestructor = true; 3659ba6166f4a78722e7df8ffbd64eb788bfdf2764aJohn McCall return false; 366d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor } 367d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor 3685c7f786e3269ee2b512ecf13ccf556c47be83a76Chris Lattner // We have an identifier followed by a '::'. Lookup this name 3695c7f786e3269ee2b512ecf13ccf556c47be83a76Chris Lattner // as the name in a nested-name-specifier. 3705c7f786e3269ee2b512ecf13ccf556c47be83a76Chris Lattner SourceLocation IdLoc = ConsumeToken(); 37146646491834cd8faabb22482dfe93b24ce28a6c1Chris Lattner assert((Tok.is(tok::coloncolon) || Tok.is(tok::colon)) && 37246646491834cd8faabb22482dfe93b24ce28a6c1Chris Lattner "NextToken() not working properly!"); 3735c7f786e3269ee2b512ecf13ccf556c47be83a76Chris Lattner SourceLocation CCLoc = ConsumeToken(); 3741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3752e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor HasScopeSpecifier = true; 3762e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor if (Actions.ActOnCXXNestedNameSpecifier(getCurScope(), II, IdLoc, CCLoc, 3772e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor ObjectType, EnteringContext, SS)) 3782e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor SS.SetInvalid(SourceRange(IdLoc, CCLoc)); 3792e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor 3805c7f786e3269ee2b512ecf13ccf556c47be83a76Chris Lattner continue; 3815c7f786e3269ee2b512ecf13ccf556c47be83a76Chris Lattner } 3821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 383950be71c745409e373ae8a834490f9026c8ac222Richard Trieu CheckForTemplateAndDigraph(Next, ObjectType, EnteringContext, II, SS); 384ea698b3f6cad84f7f583282dce3e03e24fe80e98Richard Smith 3855c7f786e3269ee2b512ecf13ccf556c47be83a76Chris Lattner // nested-name-specifier: 3865c7f786e3269ee2b512ecf13ccf556c47be83a76Chris Lattner // type-name '<' 3875c7f786e3269ee2b512ecf13ccf556c47be83a76Chris Lattner if (Next.is(tok::less)) { 3885c7f786e3269ee2b512ecf13ccf556c47be83a76Chris Lattner TemplateTy Template; 389014e88d94ff83e3aad4e33b16413a2d1817ec208Douglas Gregor UnqualifiedId TemplateName; 390014e88d94ff83e3aad4e33b16413a2d1817ec208Douglas Gregor TemplateName.setIdentifier(&II, Tok.getLocation()); 3911fd6d44d7ca97631497551bbf98866263143d706Douglas Gregor bool MemberOfUnknownSpecialization; 39223c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor if (TemplateNameKind TNK = Actions.isTemplateName(getCurScope(), SS, 3937c15353ccaed24f2df932571166bf305c1b98b6dAbramo Bagnara /*hasTemplateKeyword=*/false, 394014e88d94ff83e3aad4e33b16413a2d1817ec208Douglas Gregor TemplateName, 3952dd078ae50ff7be1fb25ebeedde45e9ab691a4f0Douglas Gregor ObjectType, 396495c35d291da48c4f5655bbb54d15128ddde0d4dDouglas Gregor EnteringContext, 3971fd6d44d7ca97631497551bbf98866263143d706Douglas Gregor Template, 3981fd6d44d7ca97631497551bbf98866263143d706Douglas Gregor MemberOfUnknownSpecialization)) { 3996796fc1adcaf57c38d072a238b016b2834afbe0dDavid Blaikie // We have found a template name, so annotate this token 4005c7f786e3269ee2b512ecf13ccf556c47be83a76Chris Lattner // with a template-id annotation. We do not permit the 4015c7f786e3269ee2b512ecf13ccf556c47be83a76Chris Lattner // template-id to be translated into a type annotation, 4025c7f786e3269ee2b512ecf13ccf556c47be83a76Chris Lattner // because some clients (e.g., the parsing of class template 4035c7f786e3269ee2b512ecf13ccf556c47be83a76Chris Lattner // specializations) still want to see the original template-id 4045c7f786e3269ee2b512ecf13ccf556c47be83a76Chris Lattner // token. 405ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor ConsumeToken(); 406e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (AnnotateTemplateIdToken(Template, TNK, SS, SourceLocation(), 407e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara TemplateName, false)) 4089ba6166f4a78722e7df8ffbd64eb788bfdf2764aJohn McCall return true; 4095c7f786e3269ee2b512ecf13ccf556c47be83a76Chris Lattner continue; 410d5ab9b0a0ae24f7d0f49f6f10fd1b247e64b3306Douglas Gregor } 411d5ab9b0a0ae24f7d0f49f6f10fd1b247e64b3306Douglas Gregor 412d5ab9b0a0ae24f7d0f49f6f10fd1b247e64b3306Douglas Gregor if (MemberOfUnknownSpecialization && (ObjectType || SS.isSet()) && 4134147d307086cf024a40a080e2bf379e9725f6f41Francois Pichet (IsTypename || IsTemplateArgumentList(1))) { 414d5ab9b0a0ae24f7d0f49f6f10fd1b247e64b3306Douglas Gregor // We have something like t::getAs<T>, where getAs is a 415d5ab9b0a0ae24f7d0f49f6f10fd1b247e64b3306Douglas Gregor // member of an unknown specialization. However, this will only 416d5ab9b0a0ae24f7d0f49f6f10fd1b247e64b3306Douglas Gregor // parse correctly as a template, so suggest the keyword 'template' 417d5ab9b0a0ae24f7d0f49f6f10fd1b247e64b3306Douglas Gregor // before 'getAs' and treat this as a dependent template name. 4184147d307086cf024a40a080e2bf379e9725f6f41Francois Pichet unsigned DiagID = diag::err_missing_dependent_template_keyword; 4194e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (getLangOpts().MicrosoftExt) 420cf320c6388c90f1938c264e87d77a0e43946e2c3Francois Pichet DiagID = diag::warn_missing_dependent_template_keyword; 4214147d307086cf024a40a080e2bf379e9725f6f41Francois Pichet 4224147d307086cf024a40a080e2bf379e9725f6f41Francois Pichet Diag(Tok.getLocation(), DiagID) 423d5ab9b0a0ae24f7d0f49f6f10fd1b247e64b3306Douglas Gregor << II.getName() 424d5ab9b0a0ae24f7d0f49f6f10fd1b247e64b3306Douglas Gregor << FixItHint::CreateInsertion(Tok.getLocation(), "template "); 425d5ab9b0a0ae24f7d0f49f6f10fd1b247e64b3306Douglas Gregor 426d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor if (TemplateNameKind TNK 42723c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor = Actions.ActOnDependentTemplateName(getCurScope(), 428e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SS, SourceLocation(), 429d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor TemplateName, ObjectType, 430d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor EnteringContext, Template)) { 431d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor // Consume the identifier. 432d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor ConsumeToken(); 433e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (AnnotateTemplateIdToken(Template, TNK, SS, SourceLocation(), 434e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara TemplateName, false)) 435e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return true; 436d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor } 437d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor else 438d5ab9b0a0ae24f7d0f49f6f10fd1b247e64b3306Douglas Gregor return true; 439d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor 440d5ab9b0a0ae24f7d0f49f6f10fd1b247e64b3306Douglas Gregor continue; 4415c7f786e3269ee2b512ecf13ccf556c47be83a76Chris Lattner } 4425c7f786e3269ee2b512ecf13ccf556c47be83a76Chris Lattner } 4435c7f786e3269ee2b512ecf13ccf556c47be83a76Chris Lattner 44439a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor // We don't have any tokens that form the beginning of a 44539a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor // nested-name-specifier, so we're done. 44639a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor break; 44739a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor } 4481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 449d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor // Even if we didn't see any pieces of a nested-name-specifier, we 450d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor // still check whether there is a tilde in this position, which 451d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor // indicates a potential pseudo-destructor. 452d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor if (CheckForDestructor && Tok.is(tok::tilde)) 453d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor *MayBePseudoDestructor = true; 454d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor 4559ba6166f4a78722e7df8ffbd64eb788bfdf2764aJohn McCall return false; 456eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis} 457eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis 458eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis/// ParseCXXIdExpression - Handle id-expression. 459eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis/// 460eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis/// id-expression: 461eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis/// unqualified-id 462eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis/// qualified-id 463eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis/// 464eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis/// qualified-id: 465eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis/// '::'[opt] nested-name-specifier 'template'[opt] unqualified-id 466eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis/// '::' identifier 467eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis/// '::' operator-function-id 468edce4dd44732dfad69f28822dddcf2b8e92b4483Douglas Gregor/// '::' template-id 469eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis/// 470eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis/// NOTE: The standard specifies that, for qualified-id, the parser does not 471eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis/// expect: 472eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis/// 473eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis/// '::' conversion-function-id 474eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis/// '::' '~' class-name 475eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis/// 476eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis/// This may cause a slight inconsistency on diagnostics: 477eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis/// 478eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis/// class C {}; 479eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis/// namespace A {} 480eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis/// void f() { 481eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis/// :: A :: ~ C(); // Some Sema error about using destructor with a 482eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis/// // namespace. 483eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis/// :: ~ C(); // Some Parser error like 'unexpected ~'. 484eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis/// } 485eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis/// 486eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis/// We simplify the parser a bit and make it work like: 487eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis/// 488eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis/// qualified-id: 489eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis/// '::'[opt] nested-name-specifier 'template'[opt] unqualified-id 490eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis/// '::' unqualified-id 491eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis/// 492eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis/// That way Sema can handle and report similar errors for namespaces and the 493eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis/// global scope. 494eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis/// 495ebc07d57be9e0722b4b9c66625e1fca43dcc2ee0Sebastian Redl/// The isAddressOfOperand parameter indicates that this id-expression is a 496ebc07d57be9e0722b4b9c66625e1fca43dcc2ee0Sebastian Redl/// direct operand of the address-of operator. This is, besides member contexts, 497ebc07d57be9e0722b4b9c66625e1fca43dcc2ee0Sebastian Redl/// the only place where a qualified-id naming a non-static class member may 498ebc07d57be9e0722b4b9c66625e1fca43dcc2ee0Sebastian Redl/// appear. 499ebc07d57be9e0722b4b9c66625e1fca43dcc2ee0Sebastian Redl/// 50060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult Parser::ParseCXXIdExpression(bool isAddressOfOperand) { 501eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis // qualified-id: 502eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis // '::'[opt] nested-name-specifier 'template'[opt] unqualified-id 503eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis // '::' unqualified-id 504eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis // 505eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis CXXScopeSpec SS; 506efaa93aaa2653f4eb40e6a22e504a448da94aaf8Douglas Gregor ParseOptionalCXXScopeSpecifier(SS, ParsedType(), /*EnteringContext=*/false); 507e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 508e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc; 50902a24ee67c0a91bdb0db8a651d5748595652e670Douglas Gregor UnqualifiedId Name; 510e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (ParseUnqualifiedId(SS, 511e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /*EnteringContext=*/false, 512e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /*AllowDestructorName=*/false, 513e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /*AllowConstructorName=*/false, 514b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall /*ObjectType=*/ ParsedType(), 515e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara TemplateKWLoc, 51602a24ee67c0a91bdb0db8a651d5748595652e670Douglas Gregor Name)) 51702a24ee67c0a91bdb0db8a651d5748595652e670Douglas Gregor return ExprError(); 518b681b61fea36618778b8030360e90e3f4641233bJohn McCall 519b681b61fea36618778b8030360e90e3f4641233bJohn McCall // This is only the direct operand of an & operator if it is not 520b681b61fea36618778b8030360e90e3f4641233bJohn McCall // followed by a postfix-expression suffix. 5219c72c6088d591ace8503b842d39448c2040f3033John McCall if (isAddressOfOperand && isPostfixExpressionSuffixStart()) 5229c72c6088d591ace8503b842d39448c2040f3033John McCall isAddressOfOperand = false; 523e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 524e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return Actions.ActOnIdExpression(getCurScope(), SS, TemplateKWLoc, Name, 525e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara Tok.is(tok::l_paren), isAddressOfOperand); 526eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis} 527eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis 528ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor/// ParseLambdaExpression - Parse a C++0x lambda expression. 529ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor/// 530ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor/// lambda-expression: 531ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor/// lambda-introducer lambda-declarator[opt] compound-statement 532ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor/// 533ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor/// lambda-introducer: 534ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor/// '[' lambda-capture[opt] ']' 535ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor/// 536ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor/// lambda-capture: 537ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor/// capture-default 538ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor/// capture-list 539ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor/// capture-default ',' capture-list 540ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor/// 541ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor/// capture-default: 542ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor/// '&' 543ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor/// '=' 544ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor/// 545ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor/// capture-list: 546ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor/// capture 547ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor/// capture-list ',' capture 548ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor/// 549ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor/// capture: 550ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor/// identifier 551ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor/// '&' identifier 552ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor/// 'this' 553ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor/// 554ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor/// lambda-declarator: 555ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor/// '(' parameter-declaration-clause ')' attribute-specifier[opt] 556ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor/// 'mutable'[opt] exception-specification[opt] 557ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor/// trailing-return-type[opt] 558ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor/// 559ae7902c4293d9de8b9591759513f0d075f45022aDouglas GregorExprResult Parser::ParseLambdaExpression() { 560ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor // Parse lambda-introducer. 561ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor LambdaIntroducer Intro; 562ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor 563ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor llvm::Optional<unsigned> DiagID(ParseLambdaIntroducer(Intro)); 564ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor if (DiagID) { 565ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor Diag(Tok, DiagID.getValue()); 566ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor SkipUntil(tok::r_square); 567dc3b723d35067e5d13474247b94a10c869cc7e58Eli Friedman SkipUntil(tok::l_brace); 568dc3b723d35067e5d13474247b94a10c869cc7e58Eli Friedman SkipUntil(tok::r_brace); 569dc3b723d35067e5d13474247b94a10c869cc7e58Eli Friedman return ExprError(); 570ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor } 571ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor 572ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor return ParseLambdaExpressionAfterIntroducer(Intro); 573ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor} 574ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor 575ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor/// TryParseLambdaExpression - Use lookahead and potentially tentative 576ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor/// parsing to determine if we are looking at a C++0x lambda expression, and parse 577ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor/// it if we are. 578ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor/// 579ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor/// If we are not looking at a lambda expression, returns ExprError(). 580ae7902c4293d9de8b9591759513f0d075f45022aDouglas GregorExprResult Parser::TryParseLambdaExpression() { 5814e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie assert(getLangOpts().CPlusPlus0x 582ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor && Tok.is(tok::l_square) 583ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor && "Not at the start of a possible lambda expression."); 584ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor 585ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor const Token Next = NextToken(), After = GetLookAheadToken(2); 586ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor 587ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor // If lookahead indicates this is a lambda... 588ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor if (Next.is(tok::r_square) || // [] 589ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor Next.is(tok::equal) || // [= 590ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor (Next.is(tok::amp) && // [&] or [&, 591ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor (After.is(tok::r_square) || 592ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor After.is(tok::comma))) || 593ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor (Next.is(tok::identifier) && // [identifier] 594ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor After.is(tok::r_square))) { 595ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor return ParseLambdaExpression(); 596ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor } 597ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor 598dc3b723d35067e5d13474247b94a10c869cc7e58Eli Friedman // If lookahead indicates an ObjC message send... 599dc3b723d35067e5d13474247b94a10c869cc7e58Eli Friedman // [identifier identifier 600ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor if (Next.is(tok::identifier) && After.is(tok::identifier)) { 601dc3b723d35067e5d13474247b94a10c869cc7e58Eli Friedman return ExprEmpty(); 602ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor } 603ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor 604dc3b723d35067e5d13474247b94a10c869cc7e58Eli Friedman // Here, we're stuck: lambda introducers and Objective-C message sends are 605dc3b723d35067e5d13474247b94a10c869cc7e58Eli Friedman // unambiguous, but it requires arbitrary lookhead. [a,b,c,d,e,f,g] is a 606dc3b723d35067e5d13474247b94a10c869cc7e58Eli Friedman // lambda, and [a,b,c,d,e,f,g h] is a Objective-C message send. Instead of 607dc3b723d35067e5d13474247b94a10c869cc7e58Eli Friedman // writing two routines to parse a lambda introducer, just try to parse 608dc3b723d35067e5d13474247b94a10c869cc7e58Eli Friedman // a lambda introducer first, and fall back if that fails. 609dc3b723d35067e5d13474247b94a10c869cc7e58Eli Friedman // (TryParseLambdaIntroducer never produces any diagnostic output.) 610ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor LambdaIntroducer Intro; 611ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor if (TryParseLambdaIntroducer(Intro)) 612dc3b723d35067e5d13474247b94a10c869cc7e58Eli Friedman return ExprEmpty(); 613ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor return ParseLambdaExpressionAfterIntroducer(Intro); 614ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor} 615ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor 616ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor/// ParseLambdaExpression - Parse a lambda introducer. 617ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor/// 618ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor/// Returns a DiagnosticID if it hit something unexpected. 61981f3bff7c202d688c9298bc049fdb5b6f77057b1Douglas Gregorllvm::Optional<unsigned> Parser::ParseLambdaIntroducer(LambdaIntroducer &Intro){ 620ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor typedef llvm::Optional<unsigned> DiagResult; 621ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor 622ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor assert(Tok.is(tok::l_square) && "Lambda expressions begin with '['."); 6234a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor BalancedDelimiterTracker T(*this, tok::l_square); 6244a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor T.consumeOpen(); 6254a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor 6264a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor Intro.Range.setBegin(T.getOpenLocation()); 627ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor 628ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor bool first = true; 629ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor 630ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor // Parse capture-default. 631ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor if (Tok.is(tok::amp) && 632ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor (NextToken().is(tok::comma) || NextToken().is(tok::r_square))) { 633ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor Intro.Default = LCD_ByRef; 6343ac109cd17151bb8ad3a40b0cbb0e1923cd6c4a0Douglas Gregor Intro.DefaultLoc = ConsumeToken(); 635ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor first = false; 636ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor } else if (Tok.is(tok::equal)) { 637ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor Intro.Default = LCD_ByCopy; 6383ac109cd17151bb8ad3a40b0cbb0e1923cd6c4a0Douglas Gregor Intro.DefaultLoc = ConsumeToken(); 639ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor first = false; 640ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor } 641ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor 642ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor while (Tok.isNot(tok::r_square)) { 643ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor if (!first) { 64481f3bff7c202d688c9298bc049fdb5b6f77057b1Douglas Gregor if (Tok.isNot(tok::comma)) { 64581f3bff7c202d688c9298bc049fdb5b6f77057b1Douglas Gregor if (Tok.is(tok::code_completion)) { 64681f3bff7c202d688c9298bc049fdb5b6f77057b1Douglas Gregor Actions.CodeCompleteLambdaIntroducer(getCurScope(), Intro, 64781f3bff7c202d688c9298bc049fdb5b6f77057b1Douglas Gregor /*AfterAmpersand=*/false); 64881f3bff7c202d688c9298bc049fdb5b6f77057b1Douglas Gregor ConsumeCodeCompletionToken(); 64981f3bff7c202d688c9298bc049fdb5b6f77057b1Douglas Gregor break; 65081f3bff7c202d688c9298bc049fdb5b6f77057b1Douglas Gregor } 65181f3bff7c202d688c9298bc049fdb5b6f77057b1Douglas Gregor 652ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor return DiagResult(diag::err_expected_comma_or_rsquare); 65381f3bff7c202d688c9298bc049fdb5b6f77057b1Douglas Gregor } 654ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor ConsumeToken(); 655ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor } 656ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor 65781f3bff7c202d688c9298bc049fdb5b6f77057b1Douglas Gregor if (Tok.is(tok::code_completion)) { 65881f3bff7c202d688c9298bc049fdb5b6f77057b1Douglas Gregor // If we're in Objective-C++ and we have a bare '[', then this is more 65981f3bff7c202d688c9298bc049fdb5b6f77057b1Douglas Gregor // likely to be a message receiver. 6604e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (getLangOpts().ObjC1 && first) 66181f3bff7c202d688c9298bc049fdb5b6f77057b1Douglas Gregor Actions.CodeCompleteObjCMessageReceiver(getCurScope()); 66281f3bff7c202d688c9298bc049fdb5b6f77057b1Douglas Gregor else 66381f3bff7c202d688c9298bc049fdb5b6f77057b1Douglas Gregor Actions.CodeCompleteLambdaIntroducer(getCurScope(), Intro, 66481f3bff7c202d688c9298bc049fdb5b6f77057b1Douglas Gregor /*AfterAmpersand=*/false); 66581f3bff7c202d688c9298bc049fdb5b6f77057b1Douglas Gregor ConsumeCodeCompletionToken(); 66681f3bff7c202d688c9298bc049fdb5b6f77057b1Douglas Gregor break; 66781f3bff7c202d688c9298bc049fdb5b6f77057b1Douglas Gregor } 668ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor 66981f3bff7c202d688c9298bc049fdb5b6f77057b1Douglas Gregor first = false; 67081f3bff7c202d688c9298bc049fdb5b6f77057b1Douglas Gregor 671ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor // Parse capture. 672ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor LambdaCaptureKind Kind = LCK_ByCopy; 673ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor SourceLocation Loc; 674ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor IdentifierInfo* Id = 0; 675a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor SourceLocation EllipsisLoc; 676a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor 677ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor if (Tok.is(tok::kw_this)) { 678ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor Kind = LCK_This; 679ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor Loc = ConsumeToken(); 680ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor } else { 681ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor if (Tok.is(tok::amp)) { 682ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor Kind = LCK_ByRef; 683ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor ConsumeToken(); 68481f3bff7c202d688c9298bc049fdb5b6f77057b1Douglas Gregor 68581f3bff7c202d688c9298bc049fdb5b6f77057b1Douglas Gregor if (Tok.is(tok::code_completion)) { 68681f3bff7c202d688c9298bc049fdb5b6f77057b1Douglas Gregor Actions.CodeCompleteLambdaIntroducer(getCurScope(), Intro, 68781f3bff7c202d688c9298bc049fdb5b6f77057b1Douglas Gregor /*AfterAmpersand=*/true); 68881f3bff7c202d688c9298bc049fdb5b6f77057b1Douglas Gregor ConsumeCodeCompletionToken(); 68981f3bff7c202d688c9298bc049fdb5b6f77057b1Douglas Gregor break; 69081f3bff7c202d688c9298bc049fdb5b6f77057b1Douglas Gregor } 691ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor } 692ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor 693ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor if (Tok.is(tok::identifier)) { 694ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor Id = Tok.getIdentifierInfo(); 695ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor Loc = ConsumeToken(); 696a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor 697a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor if (Tok.is(tok::ellipsis)) 698a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor EllipsisLoc = ConsumeToken(); 699ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor } else if (Tok.is(tok::kw_this)) { 700ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor // FIXME: If we want to suggest a fixit here, will need to return more 701ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor // than just DiagnosticID. Perhaps full DiagnosticBuilder that can be 702ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor // Clear()ed to prevent emission in case of tentative parsing? 703ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor return DiagResult(diag::err_this_captured_by_reference); 704ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor } else { 705ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor return DiagResult(diag::err_expected_capture); 706ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor } 707ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor } 708ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor 709a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor Intro.addCapture(Kind, Loc, Id, EllipsisLoc); 710ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor } 711ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor 7124a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor T.consumeClose(); 7134a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor Intro.Range.setEnd(T.getCloseLocation()); 714ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor 715ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor return DiagResult(); 716ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor} 717ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor 71881f3bff7c202d688c9298bc049fdb5b6f77057b1Douglas Gregor/// TryParseLambdaIntroducer - Tentatively parse a lambda introducer. 719ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor/// 720ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor/// Returns true if it hit something unexpected. 721ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregorbool Parser::TryParseLambdaIntroducer(LambdaIntroducer &Intro) { 722ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor TentativeParsingAction PA(*this); 723ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor 724ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor llvm::Optional<unsigned> DiagID(ParseLambdaIntroducer(Intro)); 725ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor 726ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor if (DiagID) { 727ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor PA.Revert(); 728ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor return true; 729ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor } 730ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor 731ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor PA.Commit(); 732ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor return false; 733ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor} 734ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor 735ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor/// ParseLambdaExpressionAfterIntroducer - Parse the rest of a lambda 736ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor/// expression. 737ae7902c4293d9de8b9591759513f0d075f45022aDouglas GregorExprResult Parser::ParseLambdaExpressionAfterIntroducer( 738ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor LambdaIntroducer &Intro) { 739dc3b723d35067e5d13474247b94a10c869cc7e58Eli Friedman SourceLocation LambdaBeginLoc = Intro.Range.getBegin(); 740dc3b723d35067e5d13474247b94a10c869cc7e58Eli Friedman Diag(LambdaBeginLoc, diag::warn_cxx98_compat_lambda); 741dc3b723d35067e5d13474247b94a10c869cc7e58Eli Friedman 742dc3b723d35067e5d13474247b94a10c869cc7e58Eli Friedman PrettyStackTraceLoc CrashInfo(PP.getSourceManager(), LambdaBeginLoc, 743dc3b723d35067e5d13474247b94a10c869cc7e58Eli Friedman "lambda expression parsing"); 744dc3b723d35067e5d13474247b94a10c869cc7e58Eli Friedman 745ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor // Parse lambda-declarator[opt]. 746ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor DeclSpec DS(AttrFactory); 747f88c400085eac7068399d0a01dbad89f8c579f07Eli Friedman Declarator D(DS, Declarator::LambdaExprContext); 748ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor 749ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor if (Tok.is(tok::l_paren)) { 750ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor ParseScope PrototypeScope(this, 751ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor Scope::FunctionPrototypeScope | 752ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor Scope::DeclScope); 753ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor 7544a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor SourceLocation DeclLoc, DeclEndLoc; 7554a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor BalancedDelimiterTracker T(*this, tok::l_paren); 7564a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor T.consumeOpen(); 7574a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor DeclLoc = T.getOpenLocation(); 758ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor 759ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor // Parse parameter-declaration-clause. 760ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor ParsedAttributes Attr(AttrFactory); 761ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor llvm::SmallVector<DeclaratorChunk::ParamInfo, 16> ParamInfo; 762ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor SourceLocation EllipsisLoc; 763ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor 764ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor if (Tok.isNot(tok::r_paren)) 765ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor ParseParameterDeclarationClause(D, Attr, ParamInfo, EllipsisLoc); 766ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor 7674a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor T.consumeClose(); 7684a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor DeclEndLoc = T.getCloseLocation(); 769ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor 770ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor // Parse 'mutable'[opt]. 771ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor SourceLocation MutableLoc; 772ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor if (Tok.is(tok::kw_mutable)) { 773ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor MutableLoc = ConsumeToken(); 774ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor DeclEndLoc = MutableLoc; 775ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor } 776ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor 777ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor // Parse exception-specification[opt]. 778ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor ExceptionSpecificationType ESpecType = EST_None; 779ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor SourceRange ESpecRange; 780ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor llvm::SmallVector<ParsedType, 2> DynamicExceptions; 781ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor llvm::SmallVector<SourceRange, 2> DynamicExceptionRanges; 782ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor ExprResult NoexceptExpr; 783ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor ESpecType = MaybeParseExceptionSpecification(ESpecRange, 784ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor DynamicExceptions, 785ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor DynamicExceptionRanges, 786ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor NoexceptExpr); 787ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor 788ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor if (ESpecType != EST_None) 789ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor DeclEndLoc = ESpecRange.getEnd(); 790ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor 791ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor // Parse attribute-specifier[opt]. 792ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor MaybeParseCXX0XAttributes(Attr, &DeclEndLoc); 793ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor 794ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor // Parse trailing-return-type[opt]. 795ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor ParsedType TrailingReturnType; 796ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor if (Tok.is(tok::arrow)) { 797ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor SourceRange Range; 798ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor TrailingReturnType = ParseTrailingReturnType(Range).get(); 799ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor if (Range.getEnd().isValid()) 800ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor DeclEndLoc = Range.getEnd(); 801ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor } 802ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor 803ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor PrototypeScope.Exit(); 804ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor 805ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor D.AddTypeInfo(DeclaratorChunk::getFunction(/*hasProto=*/true, 806ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor /*isVariadic=*/EllipsisLoc.isValid(), 807ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor EllipsisLoc, 808ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor ParamInfo.data(), ParamInfo.size(), 809ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor DS.getTypeQualifiers(), 810ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor /*RefQualifierIsLValueRef=*/true, 811ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor /*RefQualifierLoc=*/SourceLocation(), 81243f5103f8051bbac19022e6edaf7d9138b0f3c0fDouglas Gregor /*ConstQualifierLoc=*/SourceLocation(), 81343f5103f8051bbac19022e6edaf7d9138b0f3c0fDouglas Gregor /*VolatileQualifierLoc=*/SourceLocation(), 814ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor MutableLoc, 815ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor ESpecType, ESpecRange.getBegin(), 816ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor DynamicExceptions.data(), 817ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor DynamicExceptionRanges.data(), 818ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor DynamicExceptions.size(), 819ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor NoexceptExpr.isUsable() ? 820ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor NoexceptExpr.get() : 0, 821ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor DeclLoc, DeclEndLoc, D, 822ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor TrailingReturnType), 823ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor Attr, DeclEndLoc); 824c9ecec404fe28d53aa49b3c830d8353e97bea5f2Douglas Gregor } else if (Tok.is(tok::kw_mutable) || Tok.is(tok::arrow)) { 825c9ecec404fe28d53aa49b3c830d8353e97bea5f2Douglas Gregor // It's common to forget that one needs '()' before 'mutable' or the 826c9ecec404fe28d53aa49b3c830d8353e97bea5f2Douglas Gregor // result type. Deal with this. 827c9ecec404fe28d53aa49b3c830d8353e97bea5f2Douglas Gregor Diag(Tok, diag::err_lambda_missing_parens) 828c9ecec404fe28d53aa49b3c830d8353e97bea5f2Douglas Gregor << Tok.is(tok::arrow) 829c9ecec404fe28d53aa49b3c830d8353e97bea5f2Douglas Gregor << FixItHint::CreateInsertion(Tok.getLocation(), "() "); 830c9ecec404fe28d53aa49b3c830d8353e97bea5f2Douglas Gregor SourceLocation DeclLoc = Tok.getLocation(); 831c9ecec404fe28d53aa49b3c830d8353e97bea5f2Douglas Gregor SourceLocation DeclEndLoc = DeclLoc; 832c9ecec404fe28d53aa49b3c830d8353e97bea5f2Douglas Gregor 833c9ecec404fe28d53aa49b3c830d8353e97bea5f2Douglas Gregor // Parse 'mutable', if it's there. 834c9ecec404fe28d53aa49b3c830d8353e97bea5f2Douglas Gregor SourceLocation MutableLoc; 835c9ecec404fe28d53aa49b3c830d8353e97bea5f2Douglas Gregor if (Tok.is(tok::kw_mutable)) { 836c9ecec404fe28d53aa49b3c830d8353e97bea5f2Douglas Gregor MutableLoc = ConsumeToken(); 837c9ecec404fe28d53aa49b3c830d8353e97bea5f2Douglas Gregor DeclEndLoc = MutableLoc; 838c9ecec404fe28d53aa49b3c830d8353e97bea5f2Douglas Gregor } 839c9ecec404fe28d53aa49b3c830d8353e97bea5f2Douglas Gregor 840c9ecec404fe28d53aa49b3c830d8353e97bea5f2Douglas Gregor // Parse the return type, if there is one. 841c9ecec404fe28d53aa49b3c830d8353e97bea5f2Douglas Gregor ParsedType TrailingReturnType; 842c9ecec404fe28d53aa49b3c830d8353e97bea5f2Douglas Gregor if (Tok.is(tok::arrow)) { 843c9ecec404fe28d53aa49b3c830d8353e97bea5f2Douglas Gregor SourceRange Range; 844c9ecec404fe28d53aa49b3c830d8353e97bea5f2Douglas Gregor TrailingReturnType = ParseTrailingReturnType(Range).get(); 845c9ecec404fe28d53aa49b3c830d8353e97bea5f2Douglas Gregor if (Range.getEnd().isValid()) 846c9ecec404fe28d53aa49b3c830d8353e97bea5f2Douglas Gregor DeclEndLoc = Range.getEnd(); 847c9ecec404fe28d53aa49b3c830d8353e97bea5f2Douglas Gregor } 848c9ecec404fe28d53aa49b3c830d8353e97bea5f2Douglas Gregor 849c9ecec404fe28d53aa49b3c830d8353e97bea5f2Douglas Gregor ParsedAttributes Attr(AttrFactory); 850c9ecec404fe28d53aa49b3c830d8353e97bea5f2Douglas Gregor D.AddTypeInfo(DeclaratorChunk::getFunction(/*hasProto=*/true, 851c9ecec404fe28d53aa49b3c830d8353e97bea5f2Douglas Gregor /*isVariadic=*/false, 852c9ecec404fe28d53aa49b3c830d8353e97bea5f2Douglas Gregor /*EllipsisLoc=*/SourceLocation(), 853c9ecec404fe28d53aa49b3c830d8353e97bea5f2Douglas Gregor /*Params=*/0, /*NumParams=*/0, 854c9ecec404fe28d53aa49b3c830d8353e97bea5f2Douglas Gregor /*TypeQuals=*/0, 855c9ecec404fe28d53aa49b3c830d8353e97bea5f2Douglas Gregor /*RefQualifierIsLValueRef=*/true, 856c9ecec404fe28d53aa49b3c830d8353e97bea5f2Douglas Gregor /*RefQualifierLoc=*/SourceLocation(), 857c9ecec404fe28d53aa49b3c830d8353e97bea5f2Douglas Gregor /*ConstQualifierLoc=*/SourceLocation(), 858c9ecec404fe28d53aa49b3c830d8353e97bea5f2Douglas Gregor /*VolatileQualifierLoc=*/SourceLocation(), 859c9ecec404fe28d53aa49b3c830d8353e97bea5f2Douglas Gregor MutableLoc, 860c9ecec404fe28d53aa49b3c830d8353e97bea5f2Douglas Gregor EST_None, 861c9ecec404fe28d53aa49b3c830d8353e97bea5f2Douglas Gregor /*ESpecLoc=*/SourceLocation(), 862c9ecec404fe28d53aa49b3c830d8353e97bea5f2Douglas Gregor /*Exceptions=*/0, 863c9ecec404fe28d53aa49b3c830d8353e97bea5f2Douglas Gregor /*ExceptionRanges=*/0, 864c9ecec404fe28d53aa49b3c830d8353e97bea5f2Douglas Gregor /*NumExceptions=*/0, 865c9ecec404fe28d53aa49b3c830d8353e97bea5f2Douglas Gregor /*NoexceptExpr=*/0, 866c9ecec404fe28d53aa49b3c830d8353e97bea5f2Douglas Gregor DeclLoc, DeclEndLoc, D, 867c9ecec404fe28d53aa49b3c830d8353e97bea5f2Douglas Gregor TrailingReturnType), 868c9ecec404fe28d53aa49b3c830d8353e97bea5f2Douglas Gregor Attr, DeclEndLoc); 869ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor } 870c9ecec404fe28d53aa49b3c830d8353e97bea5f2Douglas Gregor 871ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor 872906a7e1c0f272f7e539c82dda01f4644031ce637Eli Friedman // FIXME: Rename BlockScope -> ClosureScope if we decide to continue using 873906a7e1c0f272f7e539c82dda01f4644031ce637Eli Friedman // it. 874fccfb625e3090e77da9b6a79edcab159c7006685Douglas Gregor unsigned ScopeFlags = Scope::BlockScope | Scope::FnScope | Scope::DeclScope; 875fccfb625e3090e77da9b6a79edcab159c7006685Douglas Gregor if (getCurScope()->getFlags() & Scope::ThisScope) 876fccfb625e3090e77da9b6a79edcab159c7006685Douglas Gregor ScopeFlags |= Scope::ThisScope; 877fccfb625e3090e77da9b6a79edcab159c7006685Douglas Gregor ParseScope BodyScope(this, ScopeFlags); 878906a7e1c0f272f7e539c82dda01f4644031ce637Eli Friedman 879ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman Actions.ActOnStartOfLambdaDefinition(Intro, D, getCurScope()); 880ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman 881ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor // Parse compound-statement. 882dc3b723d35067e5d13474247b94a10c869cc7e58Eli Friedman if (!Tok.is(tok::l_brace)) { 883ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor Diag(Tok, diag::err_expected_lambda_body); 884dc3b723d35067e5d13474247b94a10c869cc7e58Eli Friedman Actions.ActOnLambdaError(LambdaBeginLoc, getCurScope()); 885dc3b723d35067e5d13474247b94a10c869cc7e58Eli Friedman return ExprError(); 886ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor } 887ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor 888dc3b723d35067e5d13474247b94a10c869cc7e58Eli Friedman StmtResult Stmt(ParseCompoundStatementBody()); 889dc3b723d35067e5d13474247b94a10c869cc7e58Eli Friedman BodyScope.Exit(); 890dc3b723d35067e5d13474247b94a10c869cc7e58Eli Friedman 891deeab90783eb28d955add1062b616c030eb2b781Eli Friedman if (!Stmt.isInvalid()) 8929e8c92a9c9b949bbb0408fbbd9a58e34894b6efcDouglas Gregor return Actions.ActOnLambdaExpr(LambdaBeginLoc, Stmt.take(), getCurScope()); 893dc3b723d35067e5d13474247b94a10c869cc7e58Eli Friedman 894deeab90783eb28d955add1062b616c030eb2b781Eli Friedman Actions.ActOnLambdaError(LambdaBeginLoc, getCurScope()); 895deeab90783eb28d955add1062b616c030eb2b781Eli Friedman return ExprError(); 896ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor} 897ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor 8985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ParseCXXCasts - This handles the various ways to cast expressions to another 8995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// type. 9005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 9015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// postfix-expression: [C++ 5.2p1] 9025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 'dynamic_cast' '<' type-name '>' '(' expression ')' 9035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 'static_cast' '<' type-name '>' '(' expression ')' 9045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 'reinterpret_cast' '<' type-name '>' '(' expression ')' 9055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 'const_cast' '<' type-name '>' '(' expression ')' 9065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 90760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult Parser::ParseCXXCasts() { 9085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer tok::TokenKind Kind = Tok.getKind(); 9095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const char *CastName = 0; // For error messages 9105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer switch (Kind) { 912eb2d1f1c88836bd5382e5d7aa8f6b85148a88b27David Blaikie default: llvm_unreachable("Unknown C++ cast!"); 9135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case tok::kw_const_cast: CastName = "const_cast"; break; 9145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case tok::kw_dynamic_cast: CastName = "dynamic_cast"; break; 9155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case tok::kw_reinterpret_cast: CastName = "reinterpret_cast"; break; 9165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case tok::kw_static_cast: CastName = "static_cast"; break; 9175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 9185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation OpLoc = ConsumeToken(); 9205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation LAngleBracketLoc = Tok.getLocation(); 9215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 922ea698b3f6cad84f7f583282dce3e03e24fe80e98Richard Smith // Check for "<::" which is parsed as "[:". If found, fix token stream, 923ea698b3f6cad84f7f583282dce3e03e24fe80e98Richard Smith // diagnose error, suggest fix, and recover parsing. 924ea698b3f6cad84f7f583282dce3e03e24fe80e98Richard Smith Token Next = NextToken(); 925ea698b3f6cad84f7f583282dce3e03e24fe80e98Richard Smith if (Tok.is(tok::l_square) && Tok.getLength() == 2 && Next.is(tok::colon) && 926ea698b3f6cad84f7f583282dce3e03e24fe80e98Richard Smith AreTokensAdjacent(PP, Tok, Next)) 927ea698b3f6cad84f7f583282dce3e03e24fe80e98Richard Smith FixDigraph(*this, PP, Tok, Next, Kind, /*AtDigraph*/true); 928ea698b3f6cad84f7f583282dce3e03e24fe80e98Richard Smith 9295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (ExpectAndConsume(tok::less, diag::err_expected_less_after, CastName)) 93020df9b7ab9388b2a488c5b1293cd196b1e073b4eSebastian Redl return ExprError(); 9315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 93231862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis // Parse the common declaration-specifiers piece. 93331862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis DeclSpec DS(AttrFactory); 93431862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis ParseSpecifierQualifierList(DS); 93531862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis 93631862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis // Parse the abstract-declarator, if present. 93731862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis Declarator DeclaratorInfo(DS, Declarator::TypeNameContext); 93831862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis ParseDeclarator(DeclaratorInfo); 93931862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis 9405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation RAngleBracketLoc = Tok.getLocation(); 9415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9421ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner if (ExpectAndConsume(tok::greater, diag::err_expected_greater)) 94320df9b7ab9388b2a488c5b1293cd196b1e073b4eSebastian Redl return ExprError(Diag(LAngleBracketLoc, diag::note_matching) << "<"); 9445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9454a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor SourceLocation LParenLoc, RParenLoc; 9464a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor BalancedDelimiterTracker T(*this, tok::l_paren); 9475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9484a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor if (T.expectAndConsume(diag::err_expected_lparen_after, CastName)) 94921e7ad24099965acfa801e4abdd91e3d94106428Argyrios Kyrtzidis return ExprError(); 9505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 95160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result = ParseExpression(); 9521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 95321e7ad24099965acfa801e4abdd91e3d94106428Argyrios Kyrtzidis // Match the ')'. 9544a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor T.consumeClose(); 9555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 95631862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis if (!Result.isInvalid() && !DeclaratorInfo.isInvalidType()) 95749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor Result = Actions.ActOnCXXNamedCast(OpLoc, Kind, 95831862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis LAngleBracketLoc, DeclaratorInfo, 959809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor RAngleBracketLoc, 9604a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor T.getOpenLocation(), Result.take(), 9614a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor T.getCloseLocation()); 9625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 96320df9b7ab9388b2a488c5b1293cd196b1e073b4eSebastian Redl return move(Result); 9645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 9655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 966c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl/// ParseCXXTypeid - This handles the C++ typeid expression. 967c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl/// 968c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl/// postfix-expression: [C++ 5.2p1] 969c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl/// 'typeid' '(' expression ')' 970c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl/// 'typeid' '(' type-id ')' 971c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl/// 97260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult Parser::ParseCXXTypeid() { 973c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl assert(Tok.is(tok::kw_typeid) && "Not 'typeid'!"); 974c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl 975c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl SourceLocation OpLoc = ConsumeToken(); 9764a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor SourceLocation LParenLoc, RParenLoc; 9774a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor BalancedDelimiterTracker T(*this, tok::l_paren); 978c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl 979c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl // typeid expressions are always parenthesized. 9804a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor if (T.expectAndConsume(diag::err_expected_lparen_after, "typeid")) 98120df9b7ab9388b2a488c5b1293cd196b1e073b4eSebastian Redl return ExprError(); 9824a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor LParenLoc = T.getOpenLocation(); 983c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl 98460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result; 985c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl 986c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl if (isTypeIdInParens()) { 987809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor TypeResult Ty = ParseTypeName(); 988c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl 989c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl // Match the ')'. 9904a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor T.consumeClose(); 9914a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor RParenLoc = T.getCloseLocation(); 9924eb4f0f96289cbece50c1270e02af3caf8779705Douglas Gregor if (Ty.isInvalid() || RParenLoc.isInvalid()) 99320df9b7ab9388b2a488c5b1293cd196b1e073b4eSebastian Redl return ExprError(); 994c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl 995c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl Result = Actions.ActOnCXXTypeid(OpLoc, LParenLoc, /*isType=*/true, 996b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall Ty.get().getAsOpaquePtr(), RParenLoc); 997c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl } else { 998e0762c92110dfdcdd207db461a4ea17afd168f1eDouglas Gregor // C++0x [expr.typeid]p3: 9991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // When typeid is applied to an expression other than an lvalue of a 10001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // polymorphic class type [...] The expression is an unevaluated 1001e0762c92110dfdcdd207db461a4ea17afd168f1eDouglas Gregor // operand (Clause 5). 1002e0762c92110dfdcdd207db461a4ea17afd168f1eDouglas Gregor // 10031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // Note that we can't tell whether the expression is an lvalue of a 1004ef331b783bb96a0f0e34afdb7ef46677dc4764cbEli Friedman // polymorphic class type until after we've parsed the expression; we 1005ef331b783bb96a0f0e34afdb7ef46677dc4764cbEli Friedman // speculatively assume the subexpression is unevaluated, and fix it up 1006ef331b783bb96a0f0e34afdb7ef46677dc4764cbEli Friedman // later. 1007ef331b783bb96a0f0e34afdb7ef46677dc4764cbEli Friedman EnterExpressionEvaluationContext Unevaluated(Actions, Sema::Unevaluated); 1008c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl Result = ParseExpression(); 1009c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl 1010c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl // Match the ')'. 10110e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Result.isInvalid()) 1012c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl SkipUntil(tok::r_paren); 1013c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl else { 10144a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor T.consumeClose(); 10154a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor RParenLoc = T.getCloseLocation(); 10164eb4f0f96289cbece50c1270e02af3caf8779705Douglas Gregor if (RParenLoc.isInvalid()) 10174eb4f0f96289cbece50c1270e02af3caf8779705Douglas Gregor return ExprError(); 1018fadb53b351977ca7f99a9a613596cba6531979a3Douglas Gregor 1019c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl Result = Actions.ActOnCXXTypeid(OpLoc, LParenLoc, /*isType=*/false, 1020effa8d1c97b00a3f53e972b0e61d9aade5ea1c57Sebastian Redl Result.release(), RParenLoc); 1021c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl } 1022c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl } 1023c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl 102420df9b7ab9388b2a488c5b1293cd196b1e073b4eSebastian Redl return move(Result); 1025c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl} 1026c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl 102701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet/// ParseCXXUuidof - This handles the Microsoft C++ __uuidof expression. 102801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet/// 102901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet/// '__uuidof' '(' expression ')' 103001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet/// '__uuidof' '(' type-id ')' 103101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet/// 103201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois PichetExprResult Parser::ParseCXXUuidof() { 103301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet assert(Tok.is(tok::kw___uuidof) && "Not '__uuidof'!"); 103401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 103501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet SourceLocation OpLoc = ConsumeToken(); 10364a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor BalancedDelimiterTracker T(*this, tok::l_paren); 103701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 103801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet // __uuidof expressions are always parenthesized. 10394a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor if (T.expectAndConsume(diag::err_expected_lparen_after, "__uuidof")) 104001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet return ExprError(); 104101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 104201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet ExprResult Result; 104301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 104401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet if (isTypeIdInParens()) { 104501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet TypeResult Ty = ParseTypeName(); 104601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 104701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet // Match the ')'. 10484a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor T.consumeClose(); 104901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 105001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet if (Ty.isInvalid()) 105101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet return ExprError(); 105201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 10534a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor Result = Actions.ActOnCXXUuidof(OpLoc, T.getOpenLocation(), /*isType=*/true, 10544a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor Ty.get().getAsOpaquePtr(), 10554a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor T.getCloseLocation()); 105601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet } else { 105701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet EnterExpressionEvaluationContext Unevaluated(Actions, Sema::Unevaluated); 105801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet Result = ParseExpression(); 105901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 106001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet // Match the ')'. 106101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet if (Result.isInvalid()) 106201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet SkipUntil(tok::r_paren); 106301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet else { 10644a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor T.consumeClose(); 106501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 10664a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor Result = Actions.ActOnCXXUuidof(OpLoc, T.getOpenLocation(), 10674a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor /*isType=*/false, 10684a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor Result.release(), T.getCloseLocation()); 106901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet } 107001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet } 107101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 107201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet return move(Result); 107301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet} 107401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 1075d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor/// \brief Parse a C++ pseudo-destructor expression after the base, 1076d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor/// . or -> operator, and nested-name-specifier have already been 1077d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor/// parsed. 1078d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor/// 1079d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor/// postfix-expression: [C++ 5.2] 1080d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor/// postfix-expression . pseudo-destructor-name 1081d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor/// postfix-expression -> pseudo-destructor-name 1082d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor/// 1083d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor/// pseudo-destructor-name: 1084d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor/// ::[opt] nested-name-specifier[opt] type-name :: ~type-name 1085d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor/// ::[opt] nested-name-specifier template simple-template-id :: 1086d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor/// ~type-name 1087d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor/// ::[opt] nested-name-specifier[opt] ~type-name 1088d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor/// 108960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 1090d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas GregorParser::ParseCXXPseudoDestructor(ExprArg Base, SourceLocation OpLoc, 1091d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor tok::TokenKind OpKind, 1092d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor CXXScopeSpec &SS, 1093b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ObjectType) { 1094d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor // We're parsing either a pseudo-destructor-name or a dependent 1095d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor // member access that has the same form as a 1096d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor // pseudo-destructor-name. We parse both in the same way and let 1097d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor // the action model sort them out. 1098d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor // 1099d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor // Note that the ::[opt] nested-name-specifier[opt] has already 1100d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor // been parsed, and if there was a simple-template-id, it has 1101d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor // been coalesced into a template-id annotation token. 1102d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor UnqualifiedId FirstTypeName; 1103d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor SourceLocation CCLoc; 1104d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor if (Tok.is(tok::identifier)) { 1105d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor FirstTypeName.setIdentifier(Tok.getIdentifierInfo(), Tok.getLocation()); 1106d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor ConsumeToken(); 1107d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor assert(Tok.is(tok::coloncolon) &&"ParseOptionalCXXScopeSpecifier fail"); 1108d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor CCLoc = ConsumeToken(); 1109d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor } else if (Tok.is(tok::annot_template_id)) { 1110e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara // FIXME: retrieve TemplateKWLoc from template-id annotation and 1111e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara // store it in the pseudo-dtor node (to be used when instantiating it). 1112d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor FirstTypeName.setTemplateId( 1113d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor (TemplateIdAnnotation *)Tok.getAnnotationValue()); 1114d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor ConsumeToken(); 1115d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor assert(Tok.is(tok::coloncolon) &&"ParseOptionalCXXScopeSpecifier fail"); 1116d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor CCLoc = ConsumeToken(); 1117d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor } else { 1118d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor FirstTypeName.setIdentifier(0, SourceLocation()); 1119d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor } 1120d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor 1121d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor // Parse the tilde. 1122d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor assert(Tok.is(tok::tilde) && "ParseOptionalCXXScopeSpecifier fail"); 1123d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor SourceLocation TildeLoc = ConsumeToken(); 112491ec7894ec186dd36f509682f00486c98d8228edDavid Blaikie 112591ec7894ec186dd36f509682f00486c98d8228edDavid Blaikie if (Tok.is(tok::kw_decltype) && !FirstTypeName.isValid() && SS.isEmpty()) { 112691ec7894ec186dd36f509682f00486c98d8228edDavid Blaikie DeclSpec DS(AttrFactory); 112785c60db2131c6d210d4777c3d50bdaf0e69bb8bfBenjamin Kramer ParseDecltypeSpecifier(DS); 112891ec7894ec186dd36f509682f00486c98d8228edDavid Blaikie if (DS.getTypeSpecType() == TST_error) 112991ec7894ec186dd36f509682f00486c98d8228edDavid Blaikie return ExprError(); 113091ec7894ec186dd36f509682f00486c98d8228edDavid Blaikie return Actions.ActOnPseudoDestructorExpr(getCurScope(), Base, OpLoc, 113191ec7894ec186dd36f509682f00486c98d8228edDavid Blaikie OpKind, TildeLoc, DS, 113291ec7894ec186dd36f509682f00486c98d8228edDavid Blaikie Tok.is(tok::l_paren)); 113391ec7894ec186dd36f509682f00486c98d8228edDavid Blaikie } 113491ec7894ec186dd36f509682f00486c98d8228edDavid Blaikie 1135d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor if (!Tok.is(tok::identifier)) { 1136d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor Diag(Tok, diag::err_destructor_tilde_identifier); 1137d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor return ExprError(); 1138d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor } 1139d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor 1140d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor // Parse the second type. 1141d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor UnqualifiedId SecondTypeName; 1142d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor IdentifierInfo *Name = Tok.getIdentifierInfo(); 1143d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor SourceLocation NameLoc = ConsumeToken(); 1144d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor SecondTypeName.setIdentifier(Name, NameLoc); 1145d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor 1146d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor // If there is a '<', the second type name is a template-id. Parse 1147d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor // it as such. 1148d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor if (Tok.is(tok::less) && 1149e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara ParseUnqualifiedIdTemplateId(SS, SourceLocation(), 1150e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara Name, NameLoc, 1151e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara false, ObjectType, SecondTypeName, 1152e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /*AssumeTemplateName=*/true)) 1153d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor return ExprError(); 1154d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor 11559ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return Actions.ActOnPseudoDestructorExpr(getCurScope(), Base, 11569ae2f076ca5ab1feb3ba95629099ec2319833701John McCall OpLoc, OpKind, 1157d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor SS, FirstTypeName, CCLoc, 1158d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor TildeLoc, SecondTypeName, 1159d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor Tok.is(tok::l_paren)); 1160d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor} 1161d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor 11625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ParseCXXBoolLiteral - This handles the C++ Boolean literals. 11635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 11645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// boolean-literal: [C++ 2.13.5] 11655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 'true' 11665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 'false' 116760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult Parser::ParseCXXBoolLiteral() { 11685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer tok::TokenKind Kind = Tok.getKind(); 1169f53597fb16142bdb4a66901f8c0b768db4f2a548Sebastian Redl return Actions.ActOnCXXBoolLiteral(ConsumeToken(), Kind); 11705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 117150dd289f45738ed22b7583d52ed2525b927042ffChris Lattner 117250dd289f45738ed22b7583d52ed2525b927042ffChris Lattner/// ParseThrowExpression - This handles the C++ throw expression. 117350dd289f45738ed22b7583d52ed2525b927042ffChris Lattner/// 117450dd289f45738ed22b7583d52ed2525b927042ffChris Lattner/// throw-expression: [C++ 15] 117550dd289f45738ed22b7583d52ed2525b927042ffChris Lattner/// 'throw' assignment-expression[opt] 117660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult Parser::ParseThrowExpression() { 117750dd289f45738ed22b7583d52ed2525b927042ffChris Lattner assert(Tok.is(tok::kw_throw) && "Not throw!"); 117850dd289f45738ed22b7583d52ed2525b927042ffChris Lattner SourceLocation ThrowLoc = ConsumeToken(); // Eat the throw token. 117920df9b7ab9388b2a488c5b1293cd196b1e073b4eSebastian Redl 11802a2819a0a8e114bfa5a3c4fc4c97fa173155bae9Chris Lattner // If the current token isn't the start of an assignment-expression, 11812a2819a0a8e114bfa5a3c4fc4c97fa173155bae9Chris Lattner // then the expression is not present. This handles things like: 11822a2819a0a8e114bfa5a3c4fc4c97fa173155bae9Chris Lattner // "C ? throw : (void)42", which is crazy but legal. 11832a2819a0a8e114bfa5a3c4fc4c97fa173155bae9Chris Lattner switch (Tok.getKind()) { // FIXME: move this predicate somewhere common. 11842a2819a0a8e114bfa5a3c4fc4c97fa173155bae9Chris Lattner case tok::semi: 11852a2819a0a8e114bfa5a3c4fc4c97fa173155bae9Chris Lattner case tok::r_paren: 11862a2819a0a8e114bfa5a3c4fc4c97fa173155bae9Chris Lattner case tok::r_square: 11872a2819a0a8e114bfa5a3c4fc4c97fa173155bae9Chris Lattner case tok::r_brace: 11882a2819a0a8e114bfa5a3c4fc4c97fa173155bae9Chris Lattner case tok::colon: 11892a2819a0a8e114bfa5a3c4fc4c97fa173155bae9Chris Lattner case tok::comma: 1190bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor return Actions.ActOnCXXThrow(getCurScope(), ThrowLoc, 0); 119150dd289f45738ed22b7583d52ed2525b927042ffChris Lattner 11922a2819a0a8e114bfa5a3c4fc4c97fa173155bae9Chris Lattner default: 119360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Expr(ParseAssignmentExpression()); 119420df9b7ab9388b2a488c5b1293cd196b1e073b4eSebastian Redl if (Expr.isInvalid()) return move(Expr); 1195bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor return Actions.ActOnCXXThrow(getCurScope(), ThrowLoc, Expr.take()); 11962a2819a0a8e114bfa5a3c4fc4c97fa173155bae9Chris Lattner } 119750dd289f45738ed22b7583d52ed2525b927042ffChris Lattner} 11984cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 11994cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis/// ParseCXXThis - This handles the C++ 'this' pointer. 12004cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis/// 12014cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis/// C++ 9.3.2: In the body of a non-static member function, the keyword this is 12024cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis/// a non-lvalue expression whose value is the address of the object for which 12034cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis/// the function is called. 120460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult Parser::ParseCXXThis() { 12054cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis assert(Tok.is(tok::kw_this) && "Not 'this'!"); 12064cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis SourceLocation ThisLoc = ConsumeToken(); 1207f53597fb16142bdb4a66901f8c0b768db4f2a548Sebastian Redl return Actions.ActOnCXXThis(ThisLoc); 12084cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis} 1209987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis 1210987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis/// ParseCXXTypeConstructExpression - Parse construction of a specified type. 1211987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis/// Can be interpreted either as function-style casting ("int(x)") 1212987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis/// or class type construction ("ClassType(x,y,z)") 1213987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis/// or creation of a value-initialized type ("int()"). 1214dbef1bb8a8118b7b73e184e08fccfe0eaf914ddaSebastian Redl/// See [C++ 5.2.3]. 1215987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis/// 1216987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis/// postfix-expression: [C++ 5.2p1] 1217dbef1bb8a8118b7b73e184e08fccfe0eaf914ddaSebastian Redl/// simple-type-specifier '(' expression-list[opt] ')' 1218dbef1bb8a8118b7b73e184e08fccfe0eaf914ddaSebastian Redl/// [C++0x] simple-type-specifier braced-init-list 1219dbef1bb8a8118b7b73e184e08fccfe0eaf914ddaSebastian Redl/// typename-specifier '(' expression-list[opt] ')' 1220dbef1bb8a8118b7b73e184e08fccfe0eaf914ddaSebastian Redl/// [C++0x] typename-specifier braced-init-list 1221987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis/// 122260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 122320df9b7ab9388b2a488c5b1293cd196b1e073b4eSebastian RedlParser::ParseCXXTypeConstructExpression(const DeclSpec &DS) { 1224987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis Declarator DeclaratorInfo(DS, Declarator::TypeNameContext); 1225b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType TypeRep = Actions.ActOnTypeName(getCurScope(), DeclaratorInfo).get(); 1226987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis 1227dbef1bb8a8118b7b73e184e08fccfe0eaf914ddaSebastian Redl assert((Tok.is(tok::l_paren) || 12284e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie (getLangOpts().CPlusPlus0x && Tok.is(tok::l_brace))) 1229dbef1bb8a8118b7b73e184e08fccfe0eaf914ddaSebastian Redl && "Expected '(' or '{'!"); 1230bc61bd8109d9accf8f966b59e3f16a1497e72adfDouglas Gregor 1231dbef1bb8a8118b7b73e184e08fccfe0eaf914ddaSebastian Redl if (Tok.is(tok::l_brace)) { 12326dc00f6e98a00bd1c332927c3e04918d7e8b0d4fSebastian Redl ExprResult Init = ParseBraceInitializer(); 12336dc00f6e98a00bd1c332927c3e04918d7e8b0d4fSebastian Redl if (Init.isInvalid()) 12346dc00f6e98a00bd1c332927c3e04918d7e8b0d4fSebastian Redl return Init; 12356dc00f6e98a00bd1c332927c3e04918d7e8b0d4fSebastian Redl Expr *InitList = Init.take(); 12366dc00f6e98a00bd1c332927c3e04918d7e8b0d4fSebastian Redl return Actions.ActOnCXXTypeConstructExpr(TypeRep, SourceLocation(), 12376dc00f6e98a00bd1c332927c3e04918d7e8b0d4fSebastian Redl MultiExprArg(&InitList, 1), 12386dc00f6e98a00bd1c332927c3e04918d7e8b0d4fSebastian Redl SourceLocation()); 1239dbef1bb8a8118b7b73e184e08fccfe0eaf914ddaSebastian Redl } else { 1240dbef1bb8a8118b7b73e184e08fccfe0eaf914ddaSebastian Redl GreaterThanIsOperatorScope G(GreaterThanIsOperator, true); 1241dbef1bb8a8118b7b73e184e08fccfe0eaf914ddaSebastian Redl 12424a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor BalancedDelimiterTracker T(*this, tok::l_paren); 12434a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor T.consumeOpen(); 1244dbef1bb8a8118b7b73e184e08fccfe0eaf914ddaSebastian Redl 1245dbef1bb8a8118b7b73e184e08fccfe0eaf914ddaSebastian Redl ExprVector Exprs(Actions); 1246dbef1bb8a8118b7b73e184e08fccfe0eaf914ddaSebastian Redl CommaLocsTy CommaLocs; 1247dbef1bb8a8118b7b73e184e08fccfe0eaf914ddaSebastian Redl 1248dbef1bb8a8118b7b73e184e08fccfe0eaf914ddaSebastian Redl if (Tok.isNot(tok::r_paren)) { 1249dbef1bb8a8118b7b73e184e08fccfe0eaf914ddaSebastian Redl if (ParseExpressionList(Exprs, CommaLocs)) { 1250dbef1bb8a8118b7b73e184e08fccfe0eaf914ddaSebastian Redl SkipUntil(tok::r_paren); 1251dbef1bb8a8118b7b73e184e08fccfe0eaf914ddaSebastian Redl return ExprError(); 1252dbef1bb8a8118b7b73e184e08fccfe0eaf914ddaSebastian Redl } 1253987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis } 1254987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis 1255dbef1bb8a8118b7b73e184e08fccfe0eaf914ddaSebastian Redl // Match the ')'. 12564a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor T.consumeClose(); 1257987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis 1258dbef1bb8a8118b7b73e184e08fccfe0eaf914ddaSebastian Redl // TypeRep could be null, if it references an invalid typedef. 1259dbef1bb8a8118b7b73e184e08fccfe0eaf914ddaSebastian Redl if (!TypeRep) 1260dbef1bb8a8118b7b73e184e08fccfe0eaf914ddaSebastian Redl return ExprError(); 1261ef0cb8e62d090ad88a01ca9fa89e48d7416f0ac7Sebastian Redl 1262dbef1bb8a8118b7b73e184e08fccfe0eaf914ddaSebastian Redl assert((Exprs.size() == 0 || Exprs.size()-1 == CommaLocs.size())&& 1263dbef1bb8a8118b7b73e184e08fccfe0eaf914ddaSebastian Redl "Unexpected number of commas!"); 12644a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor return Actions.ActOnCXXTypeConstructExpr(TypeRep, T.getOpenLocation(), 12654a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor move_arg(Exprs), 12664a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor T.getCloseLocation()); 1267dbef1bb8a8118b7b73e184e08fccfe0eaf914ddaSebastian Redl } 1268987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis} 1269987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis 127099e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor/// ParseCXXCondition - if/switch/while condition expression. 127171b914b999d9c4b6df11068fc5a3291ac4770492Argyrios Kyrtzidis/// 127271b914b999d9c4b6df11068fc5a3291ac4770492Argyrios Kyrtzidis/// condition: 127371b914b999d9c4b6df11068fc5a3291ac4770492Argyrios Kyrtzidis/// expression 127471b914b999d9c4b6df11068fc5a3291ac4770492Argyrios Kyrtzidis/// type-specifier-seq declarator '=' assignment-expression 12750635aa75ab48c9c3b4269d266305aba77b6ec58eRichard Smith/// [C++11] type-specifier-seq declarator '=' initializer-clause 12760635aa75ab48c9c3b4269d266305aba77b6ec58eRichard Smith/// [C++11] type-specifier-seq declarator braced-init-list 127771b914b999d9c4b6df11068fc5a3291ac4770492Argyrios Kyrtzidis/// [GNU] type-specifier-seq declarator simple-asm-expr[opt] attributes[opt] 127871b914b999d9c4b6df11068fc5a3291ac4770492Argyrios Kyrtzidis/// '=' assignment-expression 127971b914b999d9c4b6df11068fc5a3291ac4770492Argyrios Kyrtzidis/// 128099e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor/// \param ExprResult if the condition was parsed as an expression, the 128199e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor/// parsed expression. 128299e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor/// 128399e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor/// \param DeclResult if the condition was parsed as a declaration, the 128499e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor/// parsed declaration. 128599e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor/// 1286586596fd7f7a336a2847b300c80614dcf39ab6d5Douglas Gregor/// \param Loc The location of the start of the statement that requires this 1287586596fd7f7a336a2847b300c80614dcf39ab6d5Douglas Gregor/// condition, e.g., the "for" in a for loop. 1288586596fd7f7a336a2847b300c80614dcf39ab6d5Douglas Gregor/// 1289586596fd7f7a336a2847b300c80614dcf39ab6d5Douglas Gregor/// \param ConvertToBoolean Whether the condition expression should be 1290586596fd7f7a336a2847b300c80614dcf39ab6d5Douglas Gregor/// converted to a boolean value. 1291586596fd7f7a336a2847b300c80614dcf39ab6d5Douglas Gregor/// 129299e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor/// \returns true if there was a parsing, false otherwise. 129360d7b3a319d84d688752be3870615ac0f111fb16John McCallbool Parser::ParseCXXCondition(ExprResult &ExprOut, 129460d7b3a319d84d688752be3870615ac0f111fb16John McCall Decl *&DeclOut, 1295586596fd7f7a336a2847b300c80614dcf39ab6d5Douglas Gregor SourceLocation Loc, 1296586596fd7f7a336a2847b300c80614dcf39ab6d5Douglas Gregor bool ConvertToBoolean) { 129701dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor if (Tok.is(tok::code_completion)) { 1298f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Actions.CodeCompleteOrdinaryName(getCurScope(), Sema::PCC_Condition); 12997d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis cutOffParsing(); 13007d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis return true; 130101dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor } 130201dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor 130399e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor if (!isCXXConditionDeclaration()) { 1304586596fd7f7a336a2847b300c80614dcf39ab6d5Douglas Gregor // Parse the expression. 130560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprOut = ParseExpression(); // expression 130660d7b3a319d84d688752be3870615ac0f111fb16John McCall DeclOut = 0; 130760d7b3a319d84d688752be3870615ac0f111fb16John McCall if (ExprOut.isInvalid()) 1308586596fd7f7a336a2847b300c80614dcf39ab6d5Douglas Gregor return true; 1309586596fd7f7a336a2847b300c80614dcf39ab6d5Douglas Gregor 1310586596fd7f7a336a2847b300c80614dcf39ab6d5Douglas Gregor // If required, convert to a boolean value. 1311586596fd7f7a336a2847b300c80614dcf39ab6d5Douglas Gregor if (ConvertToBoolean) 131260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprOut 131360d7b3a319d84d688752be3870615ac0f111fb16John McCall = Actions.ActOnBooleanCondition(getCurScope(), Loc, ExprOut.get()); 131460d7b3a319d84d688752be3870615ac0f111fb16John McCall return ExprOut.isInvalid(); 131599e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor } 131671b914b999d9c4b6df11068fc5a3291ac4770492Argyrios Kyrtzidis 131771b914b999d9c4b6df11068fc5a3291ac4770492Argyrios Kyrtzidis // type-specifier-seq 13180b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall DeclSpec DS(AttrFactory); 131971b914b999d9c4b6df11068fc5a3291ac4770492Argyrios Kyrtzidis ParseSpecifierQualifierList(DS); 132071b914b999d9c4b6df11068fc5a3291ac4770492Argyrios Kyrtzidis 132171b914b999d9c4b6df11068fc5a3291ac4770492Argyrios Kyrtzidis // declarator 132271b914b999d9c4b6df11068fc5a3291ac4770492Argyrios Kyrtzidis Declarator DeclaratorInfo(DS, Declarator::ConditionContext); 132371b914b999d9c4b6df11068fc5a3291ac4770492Argyrios Kyrtzidis ParseDeclarator(DeclaratorInfo); 132471b914b999d9c4b6df11068fc5a3291ac4770492Argyrios Kyrtzidis 132571b914b999d9c4b6df11068fc5a3291ac4770492Argyrios Kyrtzidis // simple-asm-expr[opt] 132671b914b999d9c4b6df11068fc5a3291ac4770492Argyrios Kyrtzidis if (Tok.is(tok::kw_asm)) { 1327ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl SourceLocation Loc; 132860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult AsmLabel(ParseSimpleAsm(&Loc)); 13290e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (AsmLabel.isInvalid()) { 133071b914b999d9c4b6df11068fc5a3291ac4770492Argyrios Kyrtzidis SkipUntil(tok::semi); 133199e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor return true; 133271b914b999d9c4b6df11068fc5a3291ac4770492Argyrios Kyrtzidis } 1333effa8d1c97b00a3f53e972b0e61d9aade5ea1c57Sebastian Redl DeclaratorInfo.setAsmLabel(AsmLabel.release()); 1334ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl DeclaratorInfo.SetRangeEnd(Loc); 133571b914b999d9c4b6df11068fc5a3291ac4770492Argyrios Kyrtzidis } 133671b914b999d9c4b6df11068fc5a3291ac4770492Argyrios Kyrtzidis 133771b914b999d9c4b6df11068fc5a3291ac4770492Argyrios Kyrtzidis // If attributes are present, parse them. 13387f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall MaybeParseGNUAttributes(DeclaratorInfo); 133971b914b999d9c4b6df11068fc5a3291ac4770492Argyrios Kyrtzidis 134099e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor // Type-check the declaration itself. 134160d7b3a319d84d688752be3870615ac0f111fb16John McCall DeclResult Dcl = Actions.ActOnCXXConditionDeclaration(getCurScope(), 13427f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall DeclaratorInfo); 134360d7b3a319d84d688752be3870615ac0f111fb16John McCall DeclOut = Dcl.get(); 134460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprOut = ExprError(); 1345a6eb5f81d13bacac01faff70a947047725b4413fArgyrios Kyrtzidis 134671b914b999d9c4b6df11068fc5a3291ac4770492Argyrios Kyrtzidis // '=' assignment-expression 1347d6c7c67313634b317a0d63c32be0511a121bb33dRichard Trieu // If a '==' or '+=' is found, suggest a fixit to '='. 13480635aa75ab48c9c3b4269d266305aba77b6ec58eRichard Smith bool CopyInitialization = isTokenEqualOrEqualTypo(); 13490635aa75ab48c9c3b4269d266305aba77b6ec58eRichard Smith if (CopyInitialization) 1350dec0984fce504a39a7f085774fb67cfd9957be58Jeffrey Yasskin ConsumeToken(); 13510635aa75ab48c9c3b4269d266305aba77b6ec58eRichard Smith 13520635aa75ab48c9c3b4269d266305aba77b6ec58eRichard Smith ExprResult InitExpr = ExprError(); 13534e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (getLangOpts().CPlusPlus0x && Tok.is(tok::l_brace)) { 13540635aa75ab48c9c3b4269d266305aba77b6ec58eRichard Smith Diag(Tok.getLocation(), 13550635aa75ab48c9c3b4269d266305aba77b6ec58eRichard Smith diag::warn_cxx98_compat_generalized_initializer_lists); 13560635aa75ab48c9c3b4269d266305aba77b6ec58eRichard Smith InitExpr = ParseBraceInitializer(); 13570635aa75ab48c9c3b4269d266305aba77b6ec58eRichard Smith } else if (CopyInitialization) { 13580635aa75ab48c9c3b4269d266305aba77b6ec58eRichard Smith InitExpr = ParseAssignmentExpression(); 13590635aa75ab48c9c3b4269d266305aba77b6ec58eRichard Smith } else if (Tok.is(tok::l_paren)) { 13600635aa75ab48c9c3b4269d266305aba77b6ec58eRichard Smith // This was probably an attempt to initialize the variable. 13610635aa75ab48c9c3b4269d266305aba77b6ec58eRichard Smith SourceLocation LParen = ConsumeParen(), RParen = LParen; 13620635aa75ab48c9c3b4269d266305aba77b6ec58eRichard Smith if (SkipUntil(tok::r_paren, true, /*DontConsume=*/true)) 13630635aa75ab48c9c3b4269d266305aba77b6ec58eRichard Smith RParen = ConsumeParen(); 13640635aa75ab48c9c3b4269d266305aba77b6ec58eRichard Smith Diag(DeclOut ? DeclOut->getLocation() : LParen, 13650635aa75ab48c9c3b4269d266305aba77b6ec58eRichard Smith diag::err_expected_init_in_condition_lparen) 13660635aa75ab48c9c3b4269d266305aba77b6ec58eRichard Smith << SourceRange(LParen, RParen); 136799e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor } else { 13680635aa75ab48c9c3b4269d266305aba77b6ec58eRichard Smith Diag(DeclOut ? DeclOut->getLocation() : Tok.getLocation(), 13690635aa75ab48c9c3b4269d266305aba77b6ec58eRichard Smith diag::err_expected_init_in_condition); 137099e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor } 13710635aa75ab48c9c3b4269d266305aba77b6ec58eRichard Smith 13720635aa75ab48c9c3b4269d266305aba77b6ec58eRichard Smith if (!InitExpr.isInvalid()) 13730635aa75ab48c9c3b4269d266305aba77b6ec58eRichard Smith Actions.AddInitializerToDecl(DeclOut, InitExpr.take(), !CopyInitialization, 13740635aa75ab48c9c3b4269d266305aba77b6ec58eRichard Smith DS.getTypeSpecType() == DeclSpec::TST_auto); 13750635aa75ab48c9c3b4269d266305aba77b6ec58eRichard Smith 1376586596fd7f7a336a2847b300c80614dcf39ab6d5Douglas Gregor // FIXME: Build a reference to this declaration? Convert it to bool? 1377586596fd7f7a336a2847b300c80614dcf39ab6d5Douglas Gregor // (This is currently handled by Sema). 1378483b9f3bc05c5409e2c6643f1c9d91e21c8ff9d2Richard Smith 1379483b9f3bc05c5409e2c6643f1c9d91e21c8ff9d2Richard Smith Actions.FinalizeDeclaration(DeclOut); 1380586596fd7f7a336a2847b300c80614dcf39ab6d5Douglas Gregor 138199e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor return false; 138271b914b999d9c4b6df11068fc5a3291ac4770492Argyrios Kyrtzidis} 138371b914b999d9c4b6df11068fc5a3291ac4770492Argyrios Kyrtzidis 13846aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// \brief Determine whether the current token starts a C++ 13856aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// simple-type-specifier. 13866aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregorbool Parser::isCXXSimpleTypeSpecifier() const { 13876aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor switch (Tok.getKind()) { 13886aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor case tok::annot_typename: 13896aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor case tok::kw_short: 13906aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor case tok::kw_long: 1391338d7f7362d18fa9c39c6bb5282b4e20574a9309Francois Pichet case tok::kw___int64: 13925a5a971908a1fd064454db44c42333a3aecf3d5bRichard Smith case tok::kw___int128: 13936aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor case tok::kw_signed: 13946aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor case tok::kw_unsigned: 13956aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor case tok::kw_void: 13966aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor case tok::kw_char: 13976aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor case tok::kw_int: 1398aa4a99b4a62615db243f7a5c433169f2fc704420Anton Korobeynikov case tok::kw_half: 13996aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor case tok::kw_float: 14006aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor case tok::kw_double: 14016aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor case tok::kw_wchar_t: 14026aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor case tok::kw_char16_t: 14036aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor case tok::kw_char32_t: 14046aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor case tok::kw_bool: 1405d9d75e57dfa22366c0379c92beac1db82db34e9aDouglas Gregor case tok::kw_decltype: 14066aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor case tok::kw_typeof: 1407db5d44b775c60166074acd184ca9f1981c10c2a7Sean Hunt case tok::kw___underlying_type: 14086aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor return true; 14096aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 14106aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor default: 14116aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor break; 14126aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor } 14136aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 14146aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor return false; 14156aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor} 14166aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 1417987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis/// ParseCXXSimpleTypeSpecifier - [C++ 7.1.5.2] Simple type specifiers. 1418987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis/// This should only be called when the current token is known to be part of 1419987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis/// simple-type-specifier. 1420987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis/// 1421987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis/// simple-type-specifier: 1422eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis/// '::'[opt] nested-name-specifier[opt] type-name 1423987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis/// '::'[opt] nested-name-specifier 'template' simple-template-id [TODO] 1424987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis/// char 1425987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis/// wchar_t 1426987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis/// bool 1427987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis/// short 1428987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis/// int 1429987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis/// long 1430987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis/// signed 1431987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis/// unsigned 1432987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis/// float 1433987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis/// double 1434987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis/// void 1435987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis/// [GNU] typeof-specifier 1436987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis/// [C++0x] auto [TODO] 1437987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis/// 1438987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis/// type-name: 1439987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis/// class-name 1440987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis/// enum-name 1441987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis/// typedef-name 1442987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis/// 1443987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidisvoid Parser::ParseCXXSimpleTypeSpecifier(DeclSpec &DS) { 1444987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis DS.SetRangeStart(Tok.getLocation()); 1445987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis const char *PrevSpec; 1446fec54013fcd0eb72642741584ca04c1bc292bef8John McCall unsigned DiagID; 1447987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis SourceLocation Loc = Tok.getLocation(); 14481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1449987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis switch (Tok.getKind()) { 145055a7cefc846765ac7d142a63f773747a20518d71Chris Lattner case tok::identifier: // foo::bar 145155a7cefc846765ac7d142a63f773747a20518d71Chris Lattner case tok::coloncolon: // ::foo::bar 1452b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie llvm_unreachable("Annotation token should already be formed!"); 14531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump default: 1454b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie llvm_unreachable("Not a simple-type-specifier token!"); 145555a7cefc846765ac7d142a63f773747a20518d71Chris Lattner 1456987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis // type-name 1457b31757b68afe06ba442a05775d08fe7aa0f6f889Chris Lattner case tok::annot_typename: { 14586952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor if (getTypeAnnotation(Tok)) 14596952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor DS.SetTypeSpecType(DeclSpec::TST_typename, Loc, PrevSpec, DiagID, 14606952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor getTypeAnnotation(Tok)); 14616952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor else 14626952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor DS.SetTypeSpecError(); 14639bd1d8d174a9d15ae343246c8322299248b9e92aDouglas Gregor 14649bd1d8d174a9d15ae343246c8322299248b9e92aDouglas Gregor DS.SetRangeEnd(Tok.getAnnotationEndLoc()); 14659bd1d8d174a9d15ae343246c8322299248b9e92aDouglas Gregor ConsumeToken(); 14669bd1d8d174a9d15ae343246c8322299248b9e92aDouglas Gregor 14679bd1d8d174a9d15ae343246c8322299248b9e92aDouglas Gregor // Objective-C supports syntax of the form 'id<proto1,proto2>' where 'id' 14689bd1d8d174a9d15ae343246c8322299248b9e92aDouglas Gregor // is a specific typedef and 'itf<proto1,proto2>' where 'itf' is an 14699bd1d8d174a9d15ae343246c8322299248b9e92aDouglas Gregor // Objective-C interface. If we don't have Objective-C or a '<', this is 14709bd1d8d174a9d15ae343246c8322299248b9e92aDouglas Gregor // just a normal reference to a typedef name. 14714e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (Tok.is(tok::less) && getLangOpts().ObjC1) 14729bd1d8d174a9d15ae343246c8322299248b9e92aDouglas Gregor ParseObjCProtocolQualifiers(DS); 14739bd1d8d174a9d15ae343246c8322299248b9e92aDouglas Gregor 14749bd1d8d174a9d15ae343246c8322299248b9e92aDouglas Gregor DS.Finish(Diags, PP); 14759bd1d8d174a9d15ae343246c8322299248b9e92aDouglas Gregor return; 1476987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis } 14771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1478987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis // builtin types 1479987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis case tok::kw_short: 1480fec54013fcd0eb72642741584ca04c1bc292bef8John McCall DS.SetTypeSpecWidth(DeclSpec::TSW_short, Loc, PrevSpec, DiagID); 1481987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis break; 1482987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis case tok::kw_long: 1483fec54013fcd0eb72642741584ca04c1bc292bef8John McCall DS.SetTypeSpecWidth(DeclSpec::TSW_long, Loc, PrevSpec, DiagID); 1484338d7f7362d18fa9c39c6bb5282b4e20574a9309Francois Pichet break; 1485338d7f7362d18fa9c39c6bb5282b4e20574a9309Francois Pichet case tok::kw___int64: 1486338d7f7362d18fa9c39c6bb5282b4e20574a9309Francois Pichet DS.SetTypeSpecWidth(DeclSpec::TSW_longlong, Loc, PrevSpec, DiagID); 1487987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis break; 1488987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis case tok::kw_signed: 1489fec54013fcd0eb72642741584ca04c1bc292bef8John McCall DS.SetTypeSpecSign(DeclSpec::TSS_signed, Loc, PrevSpec, DiagID); 1490987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis break; 1491987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis case tok::kw_unsigned: 1492fec54013fcd0eb72642741584ca04c1bc292bef8John McCall DS.SetTypeSpecSign(DeclSpec::TSS_unsigned, Loc, PrevSpec, DiagID); 1493987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis break; 1494987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis case tok::kw_void: 1495fec54013fcd0eb72642741584ca04c1bc292bef8John McCall DS.SetTypeSpecType(DeclSpec::TST_void, Loc, PrevSpec, DiagID); 1496987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis break; 1497987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis case tok::kw_char: 1498fec54013fcd0eb72642741584ca04c1bc292bef8John McCall DS.SetTypeSpecType(DeclSpec::TST_char, Loc, PrevSpec, DiagID); 1499987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis break; 1500987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis case tok::kw_int: 1501fec54013fcd0eb72642741584ca04c1bc292bef8John McCall DS.SetTypeSpecType(DeclSpec::TST_int, Loc, PrevSpec, DiagID); 1502987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis break; 15035a5a971908a1fd064454db44c42333a3aecf3d5bRichard Smith case tok::kw___int128: 15045a5a971908a1fd064454db44c42333a3aecf3d5bRichard Smith DS.SetTypeSpecType(DeclSpec::TST_int128, Loc, PrevSpec, DiagID); 15055a5a971908a1fd064454db44c42333a3aecf3d5bRichard Smith break; 1506aa4a99b4a62615db243f7a5c433169f2fc704420Anton Korobeynikov case tok::kw_half: 1507aa4a99b4a62615db243f7a5c433169f2fc704420Anton Korobeynikov DS.SetTypeSpecType(DeclSpec::TST_half, Loc, PrevSpec, DiagID); 1508aa4a99b4a62615db243f7a5c433169f2fc704420Anton Korobeynikov break; 1509987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis case tok::kw_float: 1510fec54013fcd0eb72642741584ca04c1bc292bef8John McCall DS.SetTypeSpecType(DeclSpec::TST_float, Loc, PrevSpec, DiagID); 1511987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis break; 1512987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis case tok::kw_double: 1513fec54013fcd0eb72642741584ca04c1bc292bef8John McCall DS.SetTypeSpecType(DeclSpec::TST_double, Loc, PrevSpec, DiagID); 1514987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis break; 1515987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis case tok::kw_wchar_t: 1516fec54013fcd0eb72642741584ca04c1bc292bef8John McCall DS.SetTypeSpecType(DeclSpec::TST_wchar, Loc, PrevSpec, DiagID); 1517987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis break; 1518f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith case tok::kw_char16_t: 1519fec54013fcd0eb72642741584ca04c1bc292bef8John McCall DS.SetTypeSpecType(DeclSpec::TST_char16, Loc, PrevSpec, DiagID); 1520f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith break; 1521f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith case tok::kw_char32_t: 1522fec54013fcd0eb72642741584ca04c1bc292bef8John McCall DS.SetTypeSpecType(DeclSpec::TST_char32, Loc, PrevSpec, DiagID); 1523f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith break; 1524987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis case tok::kw_bool: 1525fec54013fcd0eb72642741584ca04c1bc292bef8John McCall DS.SetTypeSpecType(DeclSpec::TST_bool, Loc, PrevSpec, DiagID); 1526987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis break; 15275e089fe1affb63d670ea02010b104bd9fa3477a1David Blaikie case tok::annot_decltype: 15285e089fe1affb63d670ea02010b104bd9fa3477a1David Blaikie case tok::kw_decltype: 15295e089fe1affb63d670ea02010b104bd9fa3477a1David Blaikie DS.SetRangeEnd(ParseDecltypeSpecifier(DS)); 15305e089fe1affb63d670ea02010b104bd9fa3477a1David Blaikie return DS.Finish(Diags, PP); 15311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1532987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis // GNU typeof support. 1533987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis case tok::kw_typeof: 1534987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis ParseTypeofSpecifier(DS); 15359b3064b55f3c858923734e8b1c9831777fc22554Douglas Gregor DS.Finish(Diags, PP); 1536987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis return; 1537987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis } 1538b31757b68afe06ba442a05775d08fe7aa0f6f889Chris Lattner if (Tok.is(tok::annot_typename)) 1539eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis DS.SetRangeEnd(Tok.getAnnotationEndLoc()); 1540eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis else 1541eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis DS.SetRangeEnd(Tok.getLocation()); 1542987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis ConsumeToken(); 15439b3064b55f3c858923734e8b1c9831777fc22554Douglas Gregor DS.Finish(Diags, PP); 1544987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis} 15451cd1b1e987f5e2f060d7972b13d83239b36d77d6Douglas Gregor 15462f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregor/// ParseCXXTypeSpecifierSeq - Parse a C++ type-specifier-seq (C++ 15472f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregor/// [dcl.name]), which is a non-empty sequence of type-specifiers, 15482f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregor/// e.g., "const short int". Note that the DeclSpec is *not* finished 15492f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregor/// by parsing the type-specifier-seq, because these sequences are 15502f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregor/// typically followed by some form of declarator. Returns true and 15512f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregor/// emits diagnostics if this is not a type-specifier-seq, false 15522f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregor/// otherwise. 15532f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregor/// 15542f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregor/// type-specifier-seq: [C++ 8.1] 15552f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregor/// type-specifier type-specifier-seq[opt] 15562f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregor/// 15572f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregorbool Parser::ParseCXXTypeSpecifierSeq(DeclSpec &DS) { 155869730c115c2d0fec2f20609d905d920a5a41b29bRichard Smith ParseSpecifierQualifierList(DS, AS_none, DSC_type_specifier); 1559396a9f235e160093b5f803f7a6a18fad7b68bdbeDouglas Gregor DS.Finish(Diags, PP); 15602f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregor return false; 15612f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregor} 15622f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregor 15633f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor/// \brief Finish parsing a C++ unqualified-id that is a template-id of 15643f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor/// some form. 15653f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor/// 15663f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor/// This routine is invoked when a '<' is encountered after an identifier or 15673f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor/// operator-function-id is parsed by \c ParseUnqualifiedId() to determine 15683f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor/// whether the unqualified-id is actually a template-id. This routine will 15693f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor/// then parse the template arguments and form the appropriate template-id to 15703f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor/// return to the caller. 15713f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor/// 15723f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor/// \param SS the nested-name-specifier that precedes this template-id, if 15733f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor/// we're actually parsing a qualified-id. 15743f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor/// 15753f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor/// \param Name for constructor and destructor names, this is the actual 15763f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor/// identifier that may be a template-name. 15773f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor/// 15783f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor/// \param NameLoc the location of the class-name in a constructor or 15793f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor/// destructor. 15803f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor/// 15813f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor/// \param EnteringContext whether we're entering the scope of the 15823f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor/// nested-name-specifier. 15833f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor/// 158446df8cc349096f141c841dbffaa72641ff1dd94bDouglas Gregor/// \param ObjectType if this unqualified-id occurs within a member access 158546df8cc349096f141c841dbffaa72641ff1dd94bDouglas Gregor/// expression, the type of the base object whose member is being accessed. 158646df8cc349096f141c841dbffaa72641ff1dd94bDouglas Gregor/// 15873f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor/// \param Id as input, describes the template-name or operator-function-id 15883f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor/// that precedes the '<'. If template arguments were parsed successfully, 15893f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor/// will be updated with the template-id. 15903f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor/// 1591d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor/// \param AssumeTemplateId When true, this routine will assume that the name 1592d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor/// refers to a template without performing name lookup to verify. 1593d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor/// 15943f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor/// \returns true if a parse error occurred, false otherwise. 15953f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregorbool Parser::ParseUnqualifiedIdTemplateId(CXXScopeSpec &SS, 1596e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 15973f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor IdentifierInfo *Name, 15983f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor SourceLocation NameLoc, 15993f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor bool EnteringContext, 1600b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ObjectType, 1601d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor UnqualifiedId &Id, 1602e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara bool AssumeTemplateId) { 16030278e123b4606ea15dbfa717e9c5a76a5ef2bc7dDouglas Gregor assert((AssumeTemplateId || Tok.is(tok::less)) && 16040278e123b4606ea15dbfa717e9c5a76a5ef2bc7dDouglas Gregor "Expected '<' to finish parsing a template-id"); 16053f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 16063f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor TemplateTy Template; 16073f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor TemplateNameKind TNK = TNK_Non_template; 16083f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor switch (Id.getKind()) { 16093f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor case UnqualifiedId::IK_Identifier: 1610014e88d94ff83e3aad4e33b16413a2d1817ec208Douglas Gregor case UnqualifiedId::IK_OperatorFunctionId: 1611e6252d1587f98dbac704178e7b2ce53116048310Sean Hunt case UnqualifiedId::IK_LiteralOperatorId: 1612d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor if (AssumeTemplateId) { 1613e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara TNK = Actions.ActOnDependentTemplateName(getCurScope(), SS, TemplateKWLoc, 1614d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor Id, ObjectType, EnteringContext, 1615d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor Template); 1616d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor if (TNK == TNK_Non_template) 1617d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor return true; 16181fd6d44d7ca97631497551bbf98866263143d706Douglas Gregor } else { 16191fd6d44d7ca97631497551bbf98866263143d706Douglas Gregor bool MemberOfUnknownSpecialization; 16207c15353ccaed24f2df932571166bf305c1b98b6dAbramo Bagnara TNK = Actions.isTemplateName(getCurScope(), SS, 16217c15353ccaed24f2df932571166bf305c1b98b6dAbramo Bagnara TemplateKWLoc.isValid(), Id, 16227c15353ccaed24f2df932571166bf305c1b98b6dAbramo Bagnara ObjectType, EnteringContext, Template, 16231fd6d44d7ca97631497551bbf98866263143d706Douglas Gregor MemberOfUnknownSpecialization); 16241fd6d44d7ca97631497551bbf98866263143d706Douglas Gregor 16251fd6d44d7ca97631497551bbf98866263143d706Douglas Gregor if (TNK == TNK_Non_template && MemberOfUnknownSpecialization && 16261fd6d44d7ca97631497551bbf98866263143d706Douglas Gregor ObjectType && IsTemplateArgumentList()) { 16271fd6d44d7ca97631497551bbf98866263143d706Douglas Gregor // We have something like t->getAs<T>(), where getAs is a 16281fd6d44d7ca97631497551bbf98866263143d706Douglas Gregor // member of an unknown specialization. However, this will only 16291fd6d44d7ca97631497551bbf98866263143d706Douglas Gregor // parse correctly as a template, so suggest the keyword 'template' 16301fd6d44d7ca97631497551bbf98866263143d706Douglas Gregor // before 'getAs' and treat this as a dependent template name. 16311fd6d44d7ca97631497551bbf98866263143d706Douglas Gregor std::string Name; 16321fd6d44d7ca97631497551bbf98866263143d706Douglas Gregor if (Id.getKind() == UnqualifiedId::IK_Identifier) 16331fd6d44d7ca97631497551bbf98866263143d706Douglas Gregor Name = Id.Identifier->getName(); 16341fd6d44d7ca97631497551bbf98866263143d706Douglas Gregor else { 16351fd6d44d7ca97631497551bbf98866263143d706Douglas Gregor Name = "operator "; 16361fd6d44d7ca97631497551bbf98866263143d706Douglas Gregor if (Id.getKind() == UnqualifiedId::IK_OperatorFunctionId) 16371fd6d44d7ca97631497551bbf98866263143d706Douglas Gregor Name += getOperatorSpelling(Id.OperatorFunctionId.Operator); 16381fd6d44d7ca97631497551bbf98866263143d706Douglas Gregor else 16391fd6d44d7ca97631497551bbf98866263143d706Douglas Gregor Name += Id.Identifier->getName(); 16401fd6d44d7ca97631497551bbf98866263143d706Douglas Gregor } 16411fd6d44d7ca97631497551bbf98866263143d706Douglas Gregor Diag(Id.StartLocation, diag::err_missing_dependent_template_keyword) 16421fd6d44d7ca97631497551bbf98866263143d706Douglas Gregor << Name 16431fd6d44d7ca97631497551bbf98866263143d706Douglas Gregor << FixItHint::CreateInsertion(Id.StartLocation, "template "); 1644e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara TNK = Actions.ActOnDependentTemplateName(getCurScope(), 1645e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SS, TemplateKWLoc, Id, 1646e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara ObjectType, EnteringContext, 1647e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara Template); 1648d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor if (TNK == TNK_Non_template) 16491fd6d44d7ca97631497551bbf98866263143d706Douglas Gregor return true; 16501fd6d44d7ca97631497551bbf98866263143d706Douglas Gregor } 16511fd6d44d7ca97631497551bbf98866263143d706Douglas Gregor } 16523f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor break; 16533f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 1654014e88d94ff83e3aad4e33b16413a2d1817ec208Douglas Gregor case UnqualifiedId::IK_ConstructorName: { 1655014e88d94ff83e3aad4e33b16413a2d1817ec208Douglas Gregor UnqualifiedId TemplateName; 16561fd6d44d7ca97631497551bbf98866263143d706Douglas Gregor bool MemberOfUnknownSpecialization; 1657014e88d94ff83e3aad4e33b16413a2d1817ec208Douglas Gregor TemplateName.setIdentifier(Name, NameLoc); 16587c15353ccaed24f2df932571166bf305c1b98b6dAbramo Bagnara TNK = Actions.isTemplateName(getCurScope(), SS, TemplateKWLoc.isValid(), 16597c15353ccaed24f2df932571166bf305c1b98b6dAbramo Bagnara TemplateName, ObjectType, 16601fd6d44d7ca97631497551bbf98866263143d706Douglas Gregor EnteringContext, Template, 16611fd6d44d7ca97631497551bbf98866263143d706Douglas Gregor MemberOfUnknownSpecialization); 16623f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor break; 1663014e88d94ff83e3aad4e33b16413a2d1817ec208Douglas Gregor } 16643f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 1665014e88d94ff83e3aad4e33b16413a2d1817ec208Douglas Gregor case UnqualifiedId::IK_DestructorName: { 1666014e88d94ff83e3aad4e33b16413a2d1817ec208Douglas Gregor UnqualifiedId TemplateName; 16671fd6d44d7ca97631497551bbf98866263143d706Douglas Gregor bool MemberOfUnknownSpecialization; 1668014e88d94ff83e3aad4e33b16413a2d1817ec208Douglas Gregor TemplateName.setIdentifier(Name, NameLoc); 16692d1c21414199a7452f122598189363a3922605b1Douglas Gregor if (ObjectType) { 1670e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara TNK = Actions.ActOnDependentTemplateName(getCurScope(), 1671e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SS, TemplateKWLoc, TemplateName, 1672e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara ObjectType, EnteringContext, 1673e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara Template); 1674d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor if (TNK == TNK_Non_template) 16752d1c21414199a7452f122598189363a3922605b1Douglas Gregor return true; 16762d1c21414199a7452f122598189363a3922605b1Douglas Gregor } else { 16777c15353ccaed24f2df932571166bf305c1b98b6dAbramo Bagnara TNK = Actions.isTemplateName(getCurScope(), SS, TemplateKWLoc.isValid(), 16787c15353ccaed24f2df932571166bf305c1b98b6dAbramo Bagnara TemplateName, ObjectType, 16791fd6d44d7ca97631497551bbf98866263143d706Douglas Gregor EnteringContext, Template, 16801fd6d44d7ca97631497551bbf98866263143d706Douglas Gregor MemberOfUnknownSpecialization); 16812d1c21414199a7452f122598189363a3922605b1Douglas Gregor 1682b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall if (TNK == TNK_Non_template && !Id.DestructorName.get()) { 1683124b878dba5007df0a268ea128a6ad8dc5dd2c5eDouglas Gregor Diag(NameLoc, diag::err_destructor_template_id) 1684124b878dba5007df0a268ea128a6ad8dc5dd2c5eDouglas Gregor << Name << SS.getRange(); 16852d1c21414199a7452f122598189363a3922605b1Douglas Gregor return true; 16862d1c21414199a7452f122598189363a3922605b1Douglas Gregor } 16872d1c21414199a7452f122598189363a3922605b1Douglas Gregor } 16883f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor break; 1689014e88d94ff83e3aad4e33b16413a2d1817ec208Douglas Gregor } 16903f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 16913f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor default: 16923f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor return false; 16933f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor } 16943f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 16953f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor if (TNK == TNK_Non_template) 16963f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor return false; 16973f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 16983f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor // Parse the enclosed template argument list. 16993f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor SourceLocation LAngleLoc, RAngleLoc; 17003f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor TemplateArgList TemplateArgs; 17010278e123b4606ea15dbfa717e9c5a76a5ef2bc7dDouglas Gregor if (Tok.is(tok::less) && 17020278e123b4606ea15dbfa717e9c5a76a5ef2bc7dDouglas Gregor ParseTemplateIdAfterTemplateName(Template, Id.StartLocation, 1703059101f922de6eb765601459925f4c8914420b23Douglas Gregor SS, true, LAngleLoc, 17043f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor TemplateArgs, 17053f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor RAngleLoc)) 17063f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor return true; 17073f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 17083f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor if (Id.getKind() == UnqualifiedId::IK_Identifier || 1709e6252d1587f98dbac704178e7b2ce53116048310Sean Hunt Id.getKind() == UnqualifiedId::IK_OperatorFunctionId || 1710e6252d1587f98dbac704178e7b2ce53116048310Sean Hunt Id.getKind() == UnqualifiedId::IK_LiteralOperatorId) { 17113f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor // Form a parsed representation of the template-id to be stored in the 17123f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor // UnqualifiedId. 17133f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor TemplateIdAnnotation *TemplateId 17143f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor = TemplateIdAnnotation::Allocate(TemplateArgs.size()); 17153f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 17163f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor if (Id.getKind() == UnqualifiedId::IK_Identifier) { 17173f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor TemplateId->Name = Id.Identifier; 1718014e88d94ff83e3aad4e33b16413a2d1817ec208Douglas Gregor TemplateId->Operator = OO_None; 17193f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor TemplateId->TemplateNameLoc = Id.StartLocation; 17203f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor } else { 1721014e88d94ff83e3aad4e33b16413a2d1817ec208Douglas Gregor TemplateId->Name = 0; 1722014e88d94ff83e3aad4e33b16413a2d1817ec208Douglas Gregor TemplateId->Operator = Id.OperatorFunctionId.Operator; 1723014e88d94ff83e3aad4e33b16413a2d1817ec208Douglas Gregor TemplateId->TemplateNameLoc = Id.StartLocation; 17243f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor } 17253f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 1726059101f922de6eb765601459925f4c8914420b23Douglas Gregor TemplateId->SS = SS; 17272b28bf1a8fa6e1c598805374f29e4fbf45e751feBenjamin Kramer TemplateId->TemplateKWLoc = TemplateKWLoc; 17282b5289b6fd7e3d9899868410a498c081c9595662John McCall TemplateId->Template = Template; 17293f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor TemplateId->Kind = TNK; 17303f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor TemplateId->LAngleLoc = LAngleLoc; 17313f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor TemplateId->RAngleLoc = RAngleLoc; 1732314b97f8c564b465af605efaee23f91ec18a982bDouglas Gregor ParsedTemplateArgument *Args = TemplateId->getTemplateArgs(); 17333f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor for (unsigned Arg = 0, ArgEnd = TemplateArgs.size(); 1734314b97f8c564b465af605efaee23f91ec18a982bDouglas Gregor Arg != ArgEnd; ++Arg) 17353f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor Args[Arg] = TemplateArgs[Arg]; 17363f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 17373f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor Id.setTemplateId(TemplateId); 17383f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor return false; 17393f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor } 17403f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 17413f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor // Bundle the template arguments together. 17423f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor ASTTemplateArgsPtr TemplateArgsPtr(Actions, TemplateArgs.data(), 17433f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor TemplateArgs.size()); 1744fad03b75e0297546c5d12ec420b5b79d5b7baa2aAbramo Bagnara 17453f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor // Constructor and destructor names. 1746f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall TypeResult Type 174755d23c925b058be29b792008ddb7d68f6c4fa9a0Abramo Bagnara = Actions.ActOnTemplateIdType(SS, TemplateKWLoc, 174855d23c925b058be29b792008ddb7d68f6c4fa9a0Abramo Bagnara Template, NameLoc, 1749fad03b75e0297546c5d12ec420b5b79d5b7baa2aAbramo Bagnara LAngleLoc, TemplateArgsPtr, RAngleLoc, 1750fad03b75e0297546c5d12ec420b5b79d5b7baa2aAbramo Bagnara /*IsCtorOrDtorName=*/true); 17513f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor if (Type.isInvalid()) 17523f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor return true; 17533f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 17543f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor if (Id.getKind() == UnqualifiedId::IK_ConstructorName) 17553f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor Id.setConstructorName(Type.get(), NameLoc, RAngleLoc); 17563f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor else 17573f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor Id.setDestructorName(Id.StartLocation, Type.get(), RAngleLoc); 17583f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 17593f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor return false; 17603f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor} 17613f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 1762ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor/// \brief Parse an operator-function-id or conversion-function-id as part 1763ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor/// of a C++ unqualified-id. 17643f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor/// 1765ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor/// This routine is responsible only for parsing the operator-function-id or 1766ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor/// conversion-function-id; it does not handle template arguments in any way. 17673f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor/// 1768ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor/// \code 17693f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor/// operator-function-id: [C++ 13.5] 17703f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor/// 'operator' operator 17713f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor/// 1772ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor/// operator: one of 17733f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor/// new delete new[] delete[] 17743f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor/// + - * / % ^ & | ~ 17753f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor/// ! = < > += -= *= /= %= 17763f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor/// ^= &= |= << >> >>= <<= == != 17773f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor/// <= >= && || ++ -- , ->* -> 17783f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor/// () [] 17793f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor/// 17803f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor/// conversion-function-id: [C++ 12.3.2] 17813f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor/// operator conversion-type-id 17823f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor/// 17833f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor/// conversion-type-id: 17843f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor/// type-specifier-seq conversion-declarator[opt] 17853f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor/// 17863f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor/// conversion-declarator: 17873f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor/// ptr-operator conversion-declarator[opt] 17883f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor/// \endcode 17893f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor/// 17903f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor/// \param The nested-name-specifier that preceded this unqualified-id. If 17913f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor/// non-empty, then we are parsing the unqualified-id of a qualified-id. 17923f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor/// 17933f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor/// \param EnteringContext whether we are entering the scope of the 17943f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor/// nested-name-specifier. 17953f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor/// 1796ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor/// \param ObjectType if this unqualified-id occurs within a member access 1797ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor/// expression, the type of the base object whose member is being accessed. 1798ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor/// 1799ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor/// \param Result on a successful parse, contains the parsed unqualified-id. 1800ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor/// 1801ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor/// \returns true if parsing fails, false otherwise. 1802ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregorbool Parser::ParseUnqualifiedIdOperator(CXXScopeSpec &SS, bool EnteringContext, 1803b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ObjectType, 1804ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor UnqualifiedId &Result) { 1805ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor assert(Tok.is(tok::kw_operator) && "Expected 'operator' keyword"); 1806ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor 1807ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor // Consume the 'operator' keyword. 1808ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor SourceLocation KeywordLoc = ConsumeToken(); 1809ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor 1810ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor // Determine what kind of operator name we have. 1811ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor unsigned SymbolIdx = 0; 1812ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor SourceLocation SymbolLocations[3]; 1813ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor OverloadedOperatorKind Op = OO_None; 1814ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor switch (Tok.getKind()) { 1815ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor case tok::kw_new: 1816ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor case tok::kw_delete: { 1817ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor bool isNew = Tok.getKind() == tok::kw_new; 1818ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor // Consume the 'new' or 'delete'. 1819ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor SymbolLocations[SymbolIdx++] = ConsumeToken(); 18206ee326af4e77e6f05973486097884d7431f2108dRichard Smith // Check for array new/delete. 18216ee326af4e77e6f05973486097884d7431f2108dRichard Smith if (Tok.is(tok::l_square) && 18226ee326af4e77e6f05973486097884d7431f2108dRichard Smith (!getLangOpts().CPlusPlus0x || NextToken().isNot(tok::l_square))) { 18234a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor // Consume the '[' and ']'. 18244a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor BalancedDelimiterTracker T(*this, tok::l_square); 18254a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor T.consumeOpen(); 18264a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor T.consumeClose(); 18274a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor if (T.getCloseLocation().isInvalid()) 1828ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor return true; 1829ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor 18304a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor SymbolLocations[SymbolIdx++] = T.getOpenLocation(); 18314a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor SymbolLocations[SymbolIdx++] = T.getCloseLocation(); 1832ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor Op = isNew? OO_Array_New : OO_Array_Delete; 1833ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor } else { 1834ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor Op = isNew? OO_New : OO_Delete; 1835ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor } 1836ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor break; 1837ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor } 1838ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor 1839ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ 1840ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor case tok::Token: \ 1841ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor SymbolLocations[SymbolIdx++] = ConsumeToken(); \ 1842ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor Op = OO_##Name; \ 1843ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor break; 1844ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly) 1845ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor#include "clang/Basic/OperatorKinds.def" 1846ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor 1847ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor case tok::l_paren: { 18484a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor // Consume the '(' and ')'. 18494a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor BalancedDelimiterTracker T(*this, tok::l_paren); 18504a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor T.consumeOpen(); 18514a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor T.consumeClose(); 18524a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor if (T.getCloseLocation().isInvalid()) 1853ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor return true; 1854ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor 18554a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor SymbolLocations[SymbolIdx++] = T.getOpenLocation(); 18564a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor SymbolLocations[SymbolIdx++] = T.getCloseLocation(); 1857ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor Op = OO_Call; 1858ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor break; 1859ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor } 1860ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor 1861ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor case tok::l_square: { 18624a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor // Consume the '[' and ']'. 18634a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor BalancedDelimiterTracker T(*this, tok::l_square); 18644a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor T.consumeOpen(); 18654a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor T.consumeClose(); 18664a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor if (T.getCloseLocation().isInvalid()) 1867ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor return true; 1868ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor 18694a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor SymbolLocations[SymbolIdx++] = T.getOpenLocation(); 18704a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor SymbolLocations[SymbolIdx++] = T.getCloseLocation(); 1871ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor Op = OO_Subscript; 1872ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor break; 1873ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor } 1874ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor 1875ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor case tok::code_completion: { 1876ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor // Code completion for the operator name. 187723c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteOperatorName(getCurScope()); 18787d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis cutOffParsing(); 1879ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor // Don't try to parse any further. 1880ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor return true; 1881ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor } 1882ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor 1883ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor default: 1884ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor break; 1885ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor } 1886ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor 1887ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor if (Op != OO_None) { 1888ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor // We have parsed an operator-function-id. 1889ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor Result.setOperatorFunctionId(KeywordLoc, Op, SymbolLocations); 1890ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor return false; 1891ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor } 18920486d746019f8310589b1f0d92edcc4bb3916b33Sean Hunt 18930486d746019f8310589b1f0d92edcc4bb3916b33Sean Hunt // Parse a literal-operator-id. 18940486d746019f8310589b1f0d92edcc4bb3916b33Sean Hunt // 18950486d746019f8310589b1f0d92edcc4bb3916b33Sean Hunt // literal-operator-id: [C++0x 13.5.8] 18960486d746019f8310589b1f0d92edcc4bb3916b33Sean Hunt // operator "" identifier 18970486d746019f8310589b1f0d92edcc4bb3916b33Sean Hunt 18984e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (getLangOpts().CPlusPlus0x && isTokenStringLiteral()) { 18997fe6208c3fa91f835813bb78236ef5c2bbf81053Richard Smith Diag(Tok.getLocation(), diag::warn_cxx98_compat_literal_operator); 190033762775706e81c17ca774102ceda36049ecc593Richard Smith 190133762775706e81c17ca774102ceda36049ecc593Richard Smith SourceLocation DiagLoc; 190233762775706e81c17ca774102ceda36049ecc593Richard Smith unsigned DiagId = 0; 190333762775706e81c17ca774102ceda36049ecc593Richard Smith 190433762775706e81c17ca774102ceda36049ecc593Richard Smith // We're past translation phase 6, so perform string literal concatenation 190533762775706e81c17ca774102ceda36049ecc593Richard Smith // before checking for "". 190633762775706e81c17ca774102ceda36049ecc593Richard Smith llvm::SmallVector<Token, 4> Toks; 190733762775706e81c17ca774102ceda36049ecc593Richard Smith llvm::SmallVector<SourceLocation, 4> TokLocs; 190833762775706e81c17ca774102ceda36049ecc593Richard Smith while (isTokenStringLiteral()) { 190933762775706e81c17ca774102ceda36049ecc593Richard Smith if (!Tok.is(tok::string_literal) && !DiagId) { 191033762775706e81c17ca774102ceda36049ecc593Richard Smith DiagLoc = Tok.getLocation(); 191133762775706e81c17ca774102ceda36049ecc593Richard Smith DiagId = diag::err_literal_operator_string_prefix; 191233762775706e81c17ca774102ceda36049ecc593Richard Smith } 191333762775706e81c17ca774102ceda36049ecc593Richard Smith Toks.push_back(Tok); 191433762775706e81c17ca774102ceda36049ecc593Richard Smith TokLocs.push_back(ConsumeStringToken()); 191599831e4677a7e2e051af636221694d60ba31fcdbRichard Smith } 19160486d746019f8310589b1f0d92edcc4bb3916b33Sean Hunt 191733762775706e81c17ca774102ceda36049ecc593Richard Smith StringLiteralParser Literal(Toks.data(), Toks.size(), PP); 191833762775706e81c17ca774102ceda36049ecc593Richard Smith if (Literal.hadError) 191933762775706e81c17ca774102ceda36049ecc593Richard Smith return true; 192033762775706e81c17ca774102ceda36049ecc593Richard Smith 192133762775706e81c17ca774102ceda36049ecc593Richard Smith // Grab the literal operator's suffix, which will be either the next token 192233762775706e81c17ca774102ceda36049ecc593Richard Smith // or a ud-suffix from the string literal. 192333762775706e81c17ca774102ceda36049ecc593Richard Smith IdentifierInfo *II = 0; 192433762775706e81c17ca774102ceda36049ecc593Richard Smith SourceLocation SuffixLoc; 192533762775706e81c17ca774102ceda36049ecc593Richard Smith if (!Literal.getUDSuffix().empty()) { 192633762775706e81c17ca774102ceda36049ecc593Richard Smith II = &PP.getIdentifierTable().get(Literal.getUDSuffix()); 192733762775706e81c17ca774102ceda36049ecc593Richard Smith SuffixLoc = 192833762775706e81c17ca774102ceda36049ecc593Richard Smith Lexer::AdvanceToTokenCharacter(TokLocs[Literal.getUDSuffixToken()], 192933762775706e81c17ca774102ceda36049ecc593Richard Smith Literal.getUDSuffixOffset(), 19304e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie PP.getSourceManager(), getLangOpts()); 193133762775706e81c17ca774102ceda36049ecc593Richard Smith // This form is not permitted by the standard (yet). 193233762775706e81c17ca774102ceda36049ecc593Richard Smith DiagLoc = SuffixLoc; 193333762775706e81c17ca774102ceda36049ecc593Richard Smith DiagId = diag::err_literal_operator_missing_space; 193433762775706e81c17ca774102ceda36049ecc593Richard Smith } else if (Tok.is(tok::identifier)) { 193533762775706e81c17ca774102ceda36049ecc593Richard Smith II = Tok.getIdentifierInfo(); 193633762775706e81c17ca774102ceda36049ecc593Richard Smith SuffixLoc = ConsumeToken(); 193733762775706e81c17ca774102ceda36049ecc593Richard Smith TokLocs.push_back(SuffixLoc); 193833762775706e81c17ca774102ceda36049ecc593Richard Smith } else { 19390486d746019f8310589b1f0d92edcc4bb3916b33Sean Hunt Diag(Tok.getLocation(), diag::err_expected_ident); 19400486d746019f8310589b1f0d92edcc4bb3916b33Sean Hunt return true; 19410486d746019f8310589b1f0d92edcc4bb3916b33Sean Hunt } 19420486d746019f8310589b1f0d92edcc4bb3916b33Sean Hunt 194333762775706e81c17ca774102ceda36049ecc593Richard Smith // The string literal must be empty. 194433762775706e81c17ca774102ceda36049ecc593Richard Smith if (!Literal.GetString().empty() || Literal.Pascal) { 194533762775706e81c17ca774102ceda36049ecc593Richard Smith DiagLoc = TokLocs.front(); 194633762775706e81c17ca774102ceda36049ecc593Richard Smith DiagId = diag::err_literal_operator_string_not_empty; 194733762775706e81c17ca774102ceda36049ecc593Richard Smith } 194833762775706e81c17ca774102ceda36049ecc593Richard Smith 194933762775706e81c17ca774102ceda36049ecc593Richard Smith if (DiagId) { 195033762775706e81c17ca774102ceda36049ecc593Richard Smith // This isn't a valid literal-operator-id, but we think we know 195133762775706e81c17ca774102ceda36049ecc593Richard Smith // what the user meant. Tell them what they should have written. 195233762775706e81c17ca774102ceda36049ecc593Richard Smith llvm::SmallString<32> Str; 195333762775706e81c17ca774102ceda36049ecc593Richard Smith Str += "\"\" "; 195433762775706e81c17ca774102ceda36049ecc593Richard Smith Str += II->getName(); 195533762775706e81c17ca774102ceda36049ecc593Richard Smith Diag(DiagLoc, DiagId) << FixItHint::CreateReplacement( 195633762775706e81c17ca774102ceda36049ecc593Richard Smith SourceRange(TokLocs.front(), TokLocs.back()), Str); 195733762775706e81c17ca774102ceda36049ecc593Richard Smith } 195833762775706e81c17ca774102ceda36049ecc593Richard Smith 195933762775706e81c17ca774102ceda36049ecc593Richard Smith Result.setLiteralOperatorId(II, KeywordLoc, SuffixLoc); 19603e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt return false; 19610486d746019f8310589b1f0d92edcc4bb3916b33Sean Hunt } 1962ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor 1963ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor // Parse a conversion-function-id. 1964ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor // 1965ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor // conversion-function-id: [C++ 12.3.2] 1966ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor // operator conversion-type-id 1967ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor // 1968ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor // conversion-type-id: 1969ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor // type-specifier-seq conversion-declarator[opt] 1970ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor // 1971ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor // conversion-declarator: 1972ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor // ptr-operator conversion-declarator[opt] 1973ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor 1974ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor // Parse the type-specifier-seq. 19750b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall DeclSpec DS(AttrFactory); 1976f6e6fc801c700c7b8ac202ddbe550d9843a816fcDouglas Gregor if (ParseCXXTypeSpecifierSeq(DS)) // FIXME: ObjectType? 1977ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor return true; 1978ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor 1979ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor // Parse the conversion-declarator, which is merely a sequence of 1980ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor // ptr-operators. 1981ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor Declarator D(DS, Declarator::TypeNameContext); 1982ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor ParseDeclaratorInternal(D, /*DirectDeclParser=*/0); 1983ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor 1984ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor // Finish up the type. 1985f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall TypeResult Ty = Actions.ActOnTypeName(getCurScope(), D); 1986ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor if (Ty.isInvalid()) 1987ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor return true; 1988ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor 1989ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor // Note that this is a conversion-function-id. 1990ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor Result.setConversionFunctionId(KeywordLoc, Ty.get(), 1991ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor D.getSourceRange().getEnd()); 1992ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor return false; 1993ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor} 1994ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor 1995ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor/// \brief Parse a C++ unqualified-id (or a C identifier), which describes the 1996ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor/// name of an entity. 1997ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor/// 1998ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor/// \code 1999ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor/// unqualified-id: [C++ expr.prim.general] 2000ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor/// identifier 2001ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor/// operator-function-id 2002ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor/// conversion-function-id 2003ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor/// [C++0x] literal-operator-id [TODO] 2004ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor/// ~ class-name 2005ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor/// template-id 2006ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor/// 2007ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor/// \endcode 2008ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor/// 2009ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor/// \param The nested-name-specifier that preceded this unqualified-id. If 2010ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor/// non-empty, then we are parsing the unqualified-id of a qualified-id. 2011ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor/// 2012ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor/// \param EnteringContext whether we are entering the scope of the 2013ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor/// nested-name-specifier. 2014ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor/// 20153f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor/// \param AllowDestructorName whether we allow parsing of a destructor name. 20163f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor/// 20173f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor/// \param AllowConstructorName whether we allow parsing a constructor name. 20183f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor/// 201946df8cc349096f141c841dbffaa72641ff1dd94bDouglas Gregor/// \param ObjectType if this unqualified-id occurs within a member access 202046df8cc349096f141c841dbffaa72641ff1dd94bDouglas Gregor/// expression, the type of the base object whose member is being accessed. 202146df8cc349096f141c841dbffaa72641ff1dd94bDouglas Gregor/// 20223f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor/// \param Result on a successful parse, contains the parsed unqualified-id. 20233f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor/// 20243f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor/// \returns true if parsing fails, false otherwise. 20253f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregorbool Parser::ParseUnqualifiedId(CXXScopeSpec &SS, bool EnteringContext, 20263f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor bool AllowDestructorName, 20273f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor bool AllowConstructorName, 2028b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ObjectType, 2029e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation& TemplateKWLoc, 20303f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor UnqualifiedId &Result) { 20310278e123b4606ea15dbfa717e9c5a76a5ef2bc7dDouglas Gregor 20320278e123b4606ea15dbfa717e9c5a76a5ef2bc7dDouglas Gregor // Handle 'A::template B'. This is for template-ids which have not 20330278e123b4606ea15dbfa717e9c5a76a5ef2bc7dDouglas Gregor // already been annotated by ParseOptionalCXXScopeSpecifier(). 20340278e123b4606ea15dbfa717e9c5a76a5ef2bc7dDouglas Gregor bool TemplateSpecified = false; 20354e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (getLangOpts().CPlusPlus && Tok.is(tok::kw_template) && 20360278e123b4606ea15dbfa717e9c5a76a5ef2bc7dDouglas Gregor (ObjectType || SS.isSet())) { 20370278e123b4606ea15dbfa717e9c5a76a5ef2bc7dDouglas Gregor TemplateSpecified = true; 20380278e123b4606ea15dbfa717e9c5a76a5ef2bc7dDouglas Gregor TemplateKWLoc = ConsumeToken(); 20390278e123b4606ea15dbfa717e9c5a76a5ef2bc7dDouglas Gregor } 20400278e123b4606ea15dbfa717e9c5a76a5ef2bc7dDouglas Gregor 20413f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor // unqualified-id: 20423f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor // identifier 20433f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor // template-id (when it hasn't already been annotated) 20443f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor if (Tok.is(tok::identifier)) { 20453f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor // Consume the identifier. 20463f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor IdentifierInfo *Id = Tok.getIdentifierInfo(); 20473f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor SourceLocation IdLoc = ConsumeToken(); 20483f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 20494e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (!getLangOpts().CPlusPlus) { 2050b862b8f93424a583fc912ab37bbbac1c231e852eDouglas Gregor // If we're not in C++, only identifiers matter. Record the 2051b862b8f93424a583fc912ab37bbbac1c231e852eDouglas Gregor // identifier and return. 2052b862b8f93424a583fc912ab37bbbac1c231e852eDouglas Gregor Result.setIdentifier(Id, IdLoc); 2053b862b8f93424a583fc912ab37bbbac1c231e852eDouglas Gregor return false; 2054b862b8f93424a583fc912ab37bbbac1c231e852eDouglas Gregor } 2055b862b8f93424a583fc912ab37bbbac1c231e852eDouglas Gregor 20563f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor if (AllowConstructorName && 205723c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.isCurrentClassName(*Id, getCurScope(), &SS)) { 20583f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor // We have parsed a constructor name. 2059fad03b75e0297546c5d12ec420b5b79d5b7baa2aAbramo Bagnara ParsedType Ty = Actions.getTypeName(*Id, IdLoc, getCurScope(), 2060fad03b75e0297546c5d12ec420b5b79d5b7baa2aAbramo Bagnara &SS, false, false, 2061fad03b75e0297546c5d12ec420b5b79d5b7baa2aAbramo Bagnara ParsedType(), 2062fad03b75e0297546c5d12ec420b5b79d5b7baa2aAbramo Bagnara /*IsCtorOrDtorName=*/true, 2063fad03b75e0297546c5d12ec420b5b79d5b7baa2aAbramo Bagnara /*NonTrivialTypeSourceInfo=*/true); 2064fad03b75e0297546c5d12ec420b5b79d5b7baa2aAbramo Bagnara Result.setConstructorName(Ty, IdLoc, IdLoc); 20653f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor } else { 20663f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor // We have parsed an identifier. 20673f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor Result.setIdentifier(Id, IdLoc); 20683f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor } 20693f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 20703f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor // If the next token is a '<', we may have a template. 20710278e123b4606ea15dbfa717e9c5a76a5ef2bc7dDouglas Gregor if (TemplateSpecified || Tok.is(tok::less)) 2072e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return ParseUnqualifiedIdTemplateId(SS, TemplateKWLoc, Id, IdLoc, 2073e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara EnteringContext, ObjectType, 2074e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara Result, TemplateSpecified); 20753f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 20763f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor return false; 20773f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor } 20783f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 20793f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor // unqualified-id: 20803f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor // template-id (already parsed and annotated) 20813f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor if (Tok.is(tok::annot_template_id)) { 208225a767651d14db87aa03dd5fe3e011d877dd4100Argyrios Kyrtzidis TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Tok); 20830efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor 20840efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor // If the template-name names the current class, then this is a constructor 20850efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor if (AllowConstructorName && TemplateId->Name && 208623c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.isCurrentClassName(*TemplateId->Name, getCurScope(), &SS)) { 20870efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor if (SS.isSet()) { 20880efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor // C++ [class.qual]p2 specifies that a qualified template-name 20890efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor // is taken as the constructor name where a constructor can be 20900efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor // declared. Thus, the template arguments are extraneous, so 20910efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor // complain about them and remove them entirely. 20920efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor Diag(TemplateId->TemplateNameLoc, 20930efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor diag::err_out_of_line_constructor_template_id) 20940efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor << TemplateId->Name 2095849b243d4065f56742a4677d6dc8277609a151f8Douglas Gregor << FixItHint::CreateRemoval( 20960efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor SourceRange(TemplateId->LAngleLoc, TemplateId->RAngleLoc)); 2097fad03b75e0297546c5d12ec420b5b79d5b7baa2aAbramo Bagnara ParsedType Ty = Actions.getTypeName(*TemplateId->Name, 2098fad03b75e0297546c5d12ec420b5b79d5b7baa2aAbramo Bagnara TemplateId->TemplateNameLoc, 2099fad03b75e0297546c5d12ec420b5b79d5b7baa2aAbramo Bagnara getCurScope(), 2100fad03b75e0297546c5d12ec420b5b79d5b7baa2aAbramo Bagnara &SS, false, false, 2101fad03b75e0297546c5d12ec420b5b79d5b7baa2aAbramo Bagnara ParsedType(), 2102fad03b75e0297546c5d12ec420b5b79d5b7baa2aAbramo Bagnara /*IsCtorOrDtorName=*/true, 2103fad03b75e0297546c5d12ec420b5b79d5b7baa2aAbramo Bagnara /*NontrivialTypeSourceInfo=*/true); 2104fad03b75e0297546c5d12ec420b5b79d5b7baa2aAbramo Bagnara Result.setConstructorName(Ty, TemplateId->TemplateNameLoc, 21050efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor TemplateId->RAngleLoc); 21060efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor ConsumeToken(); 21070efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor return false; 21080efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor } 21090efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor 21100efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor Result.setConstructorTemplateId(TemplateId); 21110efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor ConsumeToken(); 21120efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor return false; 21130efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor } 21140efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor 21153f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor // We have already parsed a template-id; consume the annotation token as 21163f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor // our unqualified-id. 21170efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor Result.setTemplateId(TemplateId); 2118e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara TemplateKWLoc = TemplateId->TemplateKWLoc; 21193f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor ConsumeToken(); 21203f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor return false; 21213f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor } 21223f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 21233f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor // unqualified-id: 21243f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor // operator-function-id 21253f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor // conversion-function-id 21263f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor if (Tok.is(tok::kw_operator)) { 2127ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor if (ParseUnqualifiedIdOperator(SS, EnteringContext, ObjectType, Result)) 21283f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor return true; 21293f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 2130e6252d1587f98dbac704178e7b2ce53116048310Sean Hunt // If we have an operator-function-id or a literal-operator-id and the next 2131e6252d1587f98dbac704178e7b2ce53116048310Sean Hunt // token is a '<', we may have a 2132ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor // 2133ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor // template-id: 2134ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor // operator-function-id < template-argument-list[opt] > 2135e6252d1587f98dbac704178e7b2ce53116048310Sean Hunt if ((Result.getKind() == UnqualifiedId::IK_OperatorFunctionId || 2136e6252d1587f98dbac704178e7b2ce53116048310Sean Hunt Result.getKind() == UnqualifiedId::IK_LiteralOperatorId) && 21370278e123b4606ea15dbfa717e9c5a76a5ef2bc7dDouglas Gregor (TemplateSpecified || Tok.is(tok::less))) 2138e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return ParseUnqualifiedIdTemplateId(SS, TemplateKWLoc, 2139e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 0, SourceLocation(), 2140e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara EnteringContext, ObjectType, 2141e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara Result, TemplateSpecified); 21423f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 21433f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor return false; 21443f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor } 21453f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 21464e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (getLangOpts().CPlusPlus && 2147b862b8f93424a583fc912ab37bbbac1c231e852eDouglas Gregor (AllowDestructorName || SS.isSet()) && Tok.is(tok::tilde)) { 21483f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor // C++ [expr.unary.op]p10: 21493f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor // There is an ambiguity in the unary-expression ~X(), where X is a 21503f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor // class-name. The ambiguity is resolved in favor of treating ~ as a 21513f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor // unary complement rather than treating ~X as referring to a destructor. 21523f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 21533f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor // Parse the '~'. 21543f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor SourceLocation TildeLoc = ConsumeToken(); 215553a75c07dbe79b3dd5dd88a0378aefa18f793083David Blaikie 215653a75c07dbe79b3dd5dd88a0378aefa18f793083David Blaikie if (SS.isEmpty() && Tok.is(tok::kw_decltype)) { 215753a75c07dbe79b3dd5dd88a0378aefa18f793083David Blaikie DeclSpec DS(AttrFactory); 215853a75c07dbe79b3dd5dd88a0378aefa18f793083David Blaikie SourceLocation EndLoc = ParseDecltypeSpecifier(DS); 215953a75c07dbe79b3dd5dd88a0378aefa18f793083David Blaikie if (ParsedType Type = Actions.getDestructorType(DS, ObjectType)) { 216053a75c07dbe79b3dd5dd88a0378aefa18f793083David Blaikie Result.setDestructorName(TildeLoc, Type, EndLoc); 216153a75c07dbe79b3dd5dd88a0378aefa18f793083David Blaikie return false; 216253a75c07dbe79b3dd5dd88a0378aefa18f793083David Blaikie } 216353a75c07dbe79b3dd5dd88a0378aefa18f793083David Blaikie return true; 216453a75c07dbe79b3dd5dd88a0378aefa18f793083David Blaikie } 21653f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 21663f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor // Parse the class-name. 21673f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor if (Tok.isNot(tok::identifier)) { 2168124b878dba5007df0a268ea128a6ad8dc5dd2c5eDouglas Gregor Diag(Tok, diag::err_destructor_tilde_identifier); 21693f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor return true; 21703f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor } 21713f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 21723f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor // Parse the class-name (or template-name in a simple-template-id). 21733f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor IdentifierInfo *ClassName = Tok.getIdentifierInfo(); 21743f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor SourceLocation ClassNameLoc = ConsumeToken(); 21753f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 21760278e123b4606ea15dbfa717e9c5a76a5ef2bc7dDouglas Gregor if (TemplateSpecified || Tok.is(tok::less)) { 2177b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall Result.setDestructorName(TildeLoc, ParsedType(), ClassNameLoc); 2178e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return ParseUnqualifiedIdTemplateId(SS, TemplateKWLoc, 2179e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara ClassName, ClassNameLoc, 2180e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara EnteringContext, ObjectType, 2181e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara Result, TemplateSpecified); 21822d1c21414199a7452f122598189363a3922605b1Douglas Gregor } 21832d1c21414199a7452f122598189363a3922605b1Douglas Gregor 21843f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor // Note that this is a destructor name. 2185b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType Ty = Actions.getDestructorName(TildeLoc, *ClassName, 2186b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ClassNameLoc, getCurScope(), 2187b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall SS, ObjectType, 2188b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall EnteringContext); 2189124b878dba5007df0a268ea128a6ad8dc5dd2c5eDouglas Gregor if (!Ty) 21903f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor return true; 2191124b878dba5007df0a268ea128a6ad8dc5dd2c5eDouglas Gregor 21923f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor Result.setDestructorName(TildeLoc, Ty, ClassNameLoc); 21933f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor return false; 21943f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor } 21953f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 21962d1c21414199a7452f122598189363a3922605b1Douglas Gregor Diag(Tok, diag::err_expected_unqualified_id) 21974e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie << getLangOpts().CPlusPlus; 21983f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor return true; 21993f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor} 22003f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 22014c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl/// ParseCXXNewExpression - Parse a C++ new-expression. New is used to allocate 22024c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl/// memory in a typesafe manner and call constructors. 22031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 220459232d35f5820e334b6c8b007ae8006f4390055dChris Lattner/// This method is called to parse the new expression after the optional :: has 220559232d35f5820e334b6c8b007ae8006f4390055dChris Lattner/// been already parsed. If the :: was present, "UseGlobal" is true and "Start" 220659232d35f5820e334b6c8b007ae8006f4390055dChris Lattner/// is its location. Otherwise, "Start" is the location of the 'new' token. 22074c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl/// 22084c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl/// new-expression: 22094c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl/// '::'[opt] 'new' new-placement[opt] new-type-id 22104c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl/// new-initializer[opt] 22114c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl/// '::'[opt] 'new' new-placement[opt] '(' type-id ')' 22124c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl/// new-initializer[opt] 22134c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl/// 22144c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl/// new-placement: 22154c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl/// '(' expression-list ')' 22164c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl/// 2217cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl/// new-type-id: 2218cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl/// type-specifier-seq new-declarator[opt] 2219893e1cc13ab17e96ada5019df6978af1668fee26Douglas Gregor/// [GNU] attributes type-specifier-seq new-declarator[opt] 2220cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl/// 2221cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl/// new-declarator: 2222cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl/// ptr-operator new-declarator[opt] 2223cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl/// direct-new-declarator 2224cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl/// 22254c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl/// new-initializer: 22264c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl/// '(' expression-list[opt] ')' 2227dbef1bb8a8118b7b73e184e08fccfe0eaf914ddaSebastian Redl/// [C++0x] braced-init-list 22284c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl/// 222960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 223059232d35f5820e334b6c8b007ae8006f4390055dChris LattnerParser::ParseCXXNewExpression(bool UseGlobal, SourceLocation Start) { 223159232d35f5820e334b6c8b007ae8006f4390055dChris Lattner assert(Tok.is(tok::kw_new) && "expected 'new' token"); 223259232d35f5820e334b6c8b007ae8006f4390055dChris Lattner ConsumeToken(); // Consume 'new' 22334c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 22344c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl // A '(' now can be a new-placement or the '(' wrapping the type-id in the 22354c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl // second form of new-expression. It can't be a new-type-id. 22364c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 2237a55e52c0802cae3b7c366a05c461d3d15074c1a3Sebastian Redl ExprVector PlacementArgs(Actions); 22384c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl SourceLocation PlacementLParen, PlacementRParen; 22394c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 22404bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor SourceRange TypeIdParens; 22410b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall DeclSpec DS(AttrFactory); 22420b8c98f3ddf83adcb9e9d98b68ce38e970cdee73Argyrios Kyrtzidis Declarator DeclaratorInfo(DS, Declarator::CXXNewContext); 22434c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl if (Tok.is(tok::l_paren)) { 22444c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl // If it turns out to be a placement, we change the type location. 22454a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor BalancedDelimiterTracker T(*this, tok::l_paren); 22464a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor T.consumeOpen(); 22474a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor PlacementLParen = T.getOpenLocation(); 2248cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl if (ParseExpressionListOrTypeId(PlacementArgs, DeclaratorInfo)) { 2249cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl SkipUntil(tok::semi, /*StopAtSemi=*/true, /*DontConsume=*/true); 225020df9b7ab9388b2a488c5b1293cd196b1e073b4eSebastian Redl return ExprError(); 2251cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl } 22524c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 22534a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor T.consumeClose(); 22544a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor PlacementRParen = T.getCloseLocation(); 2255cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl if (PlacementRParen.isInvalid()) { 2256cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl SkipUntil(tok::semi, /*StopAtSemi=*/true, /*DontConsume=*/true); 225720df9b7ab9388b2a488c5b1293cd196b1e073b4eSebastian Redl return ExprError(); 2258cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl } 22594c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 2260cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl if (PlacementArgs.empty()) { 22614c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl // Reset the placement locations. There was no placement. 22624a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor TypeIdParens = T.getRange(); 22634c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl PlacementLParen = PlacementRParen = SourceLocation(); 22644c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl } else { 22654c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl // We still need the type. 22664c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl if (Tok.is(tok::l_paren)) { 22674a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor BalancedDelimiterTracker T(*this, tok::l_paren); 22684a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor T.consumeOpen(); 2269893e1cc13ab17e96ada5019df6978af1668fee26Douglas Gregor MaybeParseGNUAttributes(DeclaratorInfo); 2270cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl ParseSpecifierQualifierList(DS); 2271ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl DeclaratorInfo.SetSourceRange(DS.getSourceRange()); 2272cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl ParseDeclarator(DeclaratorInfo); 22734a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor T.consumeClose(); 22744a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor TypeIdParens = T.getRange(); 22754c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl } else { 2276893e1cc13ab17e96ada5019df6978af1668fee26Douglas Gregor MaybeParseGNUAttributes(DeclaratorInfo); 2277cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl if (ParseCXXTypeSpecifierSeq(DS)) 2278cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl DeclaratorInfo.setInvalidType(true); 2279ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl else { 2280ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl DeclaratorInfo.SetSourceRange(DS.getSourceRange()); 2281cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl ParseDeclaratorInternal(DeclaratorInfo, 2282cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl &Parser::ParseDirectNewDeclarator); 2283ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl } 22844c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl } 22854c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl } 22864c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl } else { 2287cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl // A new-type-id is a simplified type-id, where essentially the 2288cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl // direct-declarator is replaced by a direct-new-declarator. 2289893e1cc13ab17e96ada5019df6978af1668fee26Douglas Gregor MaybeParseGNUAttributes(DeclaratorInfo); 2290cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl if (ParseCXXTypeSpecifierSeq(DS)) 2291cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl DeclaratorInfo.setInvalidType(true); 2292ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl else { 2293ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl DeclaratorInfo.SetSourceRange(DS.getSourceRange()); 2294cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl ParseDeclaratorInternal(DeclaratorInfo, 2295cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl &Parser::ParseDirectNewDeclarator); 2296ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl } 22974c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl } 2298eaaebc7cf10dc1a2016183a262ad3256bc468759Chris Lattner if (DeclaratorInfo.isInvalidType()) { 2299cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl SkipUntil(tok::semi, /*StopAtSemi=*/true, /*DontConsume=*/true); 230020df9b7ab9388b2a488c5b1293cd196b1e073b4eSebastian Redl return ExprError(); 2301cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl } 23024c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 23032aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl ExprResult Initializer; 23044c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 23054c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl if (Tok.is(tok::l_paren)) { 23062aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl SourceLocation ConstructorLParen, ConstructorRParen; 23072aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl ExprVector ConstructorArgs(Actions); 23084a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor BalancedDelimiterTracker T(*this, tok::l_paren); 23094a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor T.consumeOpen(); 23104a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor ConstructorLParen = T.getOpenLocation(); 23114c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl if (Tok.isNot(tok::r_paren)) { 23124c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl CommaLocsTy CommaLocs; 2313cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl if (ParseExpressionList(ConstructorArgs, CommaLocs)) { 2314cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl SkipUntil(tok::semi, /*StopAtSemi=*/true, /*DontConsume=*/true); 231520df9b7ab9388b2a488c5b1293cd196b1e073b4eSebastian Redl return ExprError(); 2316cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl } 23174c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl } 23184a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor T.consumeClose(); 23194a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor ConstructorRParen = T.getCloseLocation(); 2320cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl if (ConstructorRParen.isInvalid()) { 2321cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl SkipUntil(tok::semi, /*StopAtSemi=*/true, /*DontConsume=*/true); 232220df9b7ab9388b2a488c5b1293cd196b1e073b4eSebastian Redl return ExprError(); 2323cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl } 23242aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl Initializer = Actions.ActOnParenListExpr(ConstructorLParen, 23252aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl ConstructorRParen, 23262aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl move_arg(ConstructorArgs)); 23274e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie } else if (Tok.is(tok::l_brace) && getLangOpts().CPlusPlus0x) { 23287fe6208c3fa91f835813bb78236ef5c2bbf81053Richard Smith Diag(Tok.getLocation(), 23297fe6208c3fa91f835813bb78236ef5c2bbf81053Richard Smith diag::warn_cxx98_compat_generalized_initializer_lists); 23302aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl Initializer = ParseBraceInitializer(); 23314c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl } 23322aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl if (Initializer.isInvalid()) 23332aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl return Initializer; 23344c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 2335f53597fb16142bdb4a66901f8c0b768db4f2a548Sebastian Redl return Actions.ActOnCXXNew(Start, UseGlobal, PlacementLParen, 2336f53597fb16142bdb4a66901f8c0b768db4f2a548Sebastian Redl move_arg(PlacementArgs), PlacementRParen, 23372aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl TypeIdParens, DeclaratorInfo, Initializer.take()); 23384c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl} 23394c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 23404c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl/// ParseDirectNewDeclarator - Parses a direct-new-declarator. Intended to be 23414c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl/// passed to ParseDeclaratorInternal. 23424c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl/// 23434c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl/// direct-new-declarator: 23444c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl/// '[' expression ']' 23454c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl/// direct-new-declarator '[' constant-expression ']' 23464c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl/// 234759232d35f5820e334b6c8b007ae8006f4390055dChris Lattnervoid Parser::ParseDirectNewDeclarator(Declarator &D) { 23484c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl // Parse the array dimensions. 23494c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl bool first = true; 23504c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl while (Tok.is(tok::l_square)) { 23516ee326af4e77e6f05973486097884d7431f2108dRichard Smith // An array-size expression can't start with a lambda. 23526ee326af4e77e6f05973486097884d7431f2108dRichard Smith if (CheckProhibitedCXX11Attribute()) 23536ee326af4e77e6f05973486097884d7431f2108dRichard Smith continue; 23546ee326af4e77e6f05973486097884d7431f2108dRichard Smith 23554a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor BalancedDelimiterTracker T(*this, tok::l_square); 23564a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor T.consumeOpen(); 23574a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor 235860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Size(first ? ParseExpression() 23592f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl : ParseConstantExpression()); 23600e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Size.isInvalid()) { 23614c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl // Recover 23624c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl SkipUntil(tok::r_square); 23634c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl return; 23644c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl } 23654c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl first = false; 23664c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 23674a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor T.consumeClose(); 23680b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall 23696ee326af4e77e6f05973486097884d7431f2108dRichard Smith // Attributes here appertain to the array type. C++11 [expr.new]p5. 23706ee326af4e77e6f05973486097884d7431f2108dRichard Smith ParsedAttributes Attrs(AttrFactory); 23716ee326af4e77e6f05973486097884d7431f2108dRichard Smith MaybeParseCXX0XAttributes(Attrs); 23726ee326af4e77e6f05973486097884d7431f2108dRichard Smith 23730b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall D.AddTypeInfo(DeclaratorChunk::getArray(0, 23747f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall /*static=*/false, /*star=*/false, 23754a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor Size.release(), 23764a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor T.getOpenLocation(), 23774a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor T.getCloseLocation()), 23786ee326af4e77e6f05973486097884d7431f2108dRichard Smith Attrs, T.getCloseLocation()); 23794c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 23804a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor if (T.getCloseLocation().isInvalid()) 23814c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl return; 23824c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl } 23834c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl} 23844c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 23854c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl/// ParseExpressionListOrTypeId - Parse either an expression-list or a type-id. 23864c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl/// This ambiguity appears in the syntax of the C++ new operator. 23874c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl/// 23884c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl/// new-expression: 23894c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl/// '::'[opt] 'new' new-placement[opt] '(' type-id ')' 23904c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl/// new-initializer[opt] 23914c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl/// 23924c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl/// new-placement: 23934c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl/// '(' expression-list ')' 23944c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl/// 2395ca0408fb49c1370430672acf2d770b7151cf71deJohn McCallbool Parser::ParseExpressionListOrTypeId( 23965f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVectorImpl<Expr*> &PlacementArgs, 239759232d35f5820e334b6c8b007ae8006f4390055dChris Lattner Declarator &D) { 23984c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl // The '(' was already consumed. 23994c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl if (isTypeIdInParens()) { 2400cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl ParseSpecifierQualifierList(D.getMutableDeclSpec()); 2401ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl D.SetSourceRange(D.getDeclSpec().getSourceRange()); 2402cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl ParseDeclarator(D); 2403eaaebc7cf10dc1a2016183a262ad3256bc468759Chris Lattner return D.isInvalidType(); 24044c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl } 24054c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 24064c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl // It's not a type, it has to be an expression list. 24074c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl // Discard the comma locations - ActOnCXXNew has enough parameters. 24084c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl CommaLocsTy CommaLocs; 24094c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl return ParseExpressionList(PlacementArgs, CommaLocs); 24104c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl} 24114c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 24124c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl/// ParseCXXDeleteExpression - Parse a C++ delete-expression. Delete is used 24134c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl/// to free memory allocated by new. 24144c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl/// 241559232d35f5820e334b6c8b007ae8006f4390055dChris Lattner/// This method is called to parse the 'delete' expression after the optional 241659232d35f5820e334b6c8b007ae8006f4390055dChris Lattner/// '::' has been already parsed. If the '::' was present, "UseGlobal" is true 241759232d35f5820e334b6c8b007ae8006f4390055dChris Lattner/// and "Start" is its location. Otherwise, "Start" is the location of the 241859232d35f5820e334b6c8b007ae8006f4390055dChris Lattner/// 'delete' token. 241959232d35f5820e334b6c8b007ae8006f4390055dChris Lattner/// 24204c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl/// delete-expression: 24214c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl/// '::'[opt] 'delete' cast-expression 24224c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl/// '::'[opt] 'delete' '[' ']' cast-expression 242360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 242459232d35f5820e334b6c8b007ae8006f4390055dChris LattnerParser::ParseCXXDeleteExpression(bool UseGlobal, SourceLocation Start) { 242559232d35f5820e334b6c8b007ae8006f4390055dChris Lattner assert(Tok.is(tok::kw_delete) && "Expected 'delete' keyword"); 242659232d35f5820e334b6c8b007ae8006f4390055dChris Lattner ConsumeToken(); // Consume 'delete' 24274c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 24284c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl // Array delete? 24294c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl bool ArrayDelete = false; 24306ee326af4e77e6f05973486097884d7431f2108dRichard Smith if (Tok.is(tok::l_square) && NextToken().is(tok::r_square)) { 24316ee326af4e77e6f05973486097884d7431f2108dRichard Smith // FIXME: This could be the start of a lambda-expression. We should 24326ee326af4e77e6f05973486097884d7431f2108dRichard Smith // disambiguate this, but that will require arbitrary lookahead if 24336ee326af4e77e6f05973486097884d7431f2108dRichard Smith // the next token is '(': 24346ee326af4e77e6f05973486097884d7431f2108dRichard Smith // delete [](int*){ /* ... */ 24354c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl ArrayDelete = true; 24364a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor BalancedDelimiterTracker T(*this, tok::l_square); 24374a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor 24384a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor T.consumeOpen(); 24394a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor T.consumeClose(); 24404a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor if (T.getCloseLocation().isInvalid()) 244120df9b7ab9388b2a488c5b1293cd196b1e073b4eSebastian Redl return ExprError(); 24424c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl } 24434c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 244460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Operand(ParseCastExpression(false)); 24450e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (Operand.isInvalid()) 244620df9b7ab9388b2a488c5b1293cd196b1e073b4eSebastian Redl return move(Operand); 24474c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 24489ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return Actions.ActOnCXXDelete(Start, UseGlobal, ArrayDelete, Operand.take()); 24494c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl} 245064b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 24511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpstatic UnaryTypeTrait UnaryTypeTraitFromTokKind(tok::TokenKind kind) { 245264b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl switch(kind) { 2453b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie default: llvm_unreachable("Not a known unary type trait."); 245464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl case tok::kw___has_nothrow_assign: return UTT_HasNothrowAssign; 245564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl case tok::kw___has_nothrow_constructor: return UTT_HasNothrowConstructor; 245620c0da7787c9a7d2529e42a4a91d777778595d74John Wiegley case tok::kw___has_nothrow_copy: return UTT_HasNothrowCopy; 245764b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl case tok::kw___has_trivial_assign: return UTT_HasTrivialAssign; 2458023df37c27ee8035664fb62f206ca58f4e2a169dSean Hunt case tok::kw___has_trivial_constructor: 2459023df37c27ee8035664fb62f206ca58f4e2a169dSean Hunt return UTT_HasTrivialDefaultConstructor; 246020c0da7787c9a7d2529e42a4a91d777778595d74John Wiegley case tok::kw___has_trivial_copy: return UTT_HasTrivialCopy; 246164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl case tok::kw___has_trivial_destructor: return UTT_HasTrivialDestructor; 246264b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl case tok::kw___has_virtual_destructor: return UTT_HasVirtualDestructor; 246364b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl case tok::kw___is_abstract: return UTT_IsAbstract; 246420c0da7787c9a7d2529e42a4a91d777778595d74John Wiegley case tok::kw___is_arithmetic: return UTT_IsArithmetic; 246520c0da7787c9a7d2529e42a4a91d777778595d74John Wiegley case tok::kw___is_array: return UTT_IsArray; 246664b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl case tok::kw___is_class: return UTT_IsClass; 246720c0da7787c9a7d2529e42a4a91d777778595d74John Wiegley case tok::kw___is_complete_type: return UTT_IsCompleteType; 246820c0da7787c9a7d2529e42a4a91d777778595d74John Wiegley case tok::kw___is_compound: return UTT_IsCompound; 246920c0da7787c9a7d2529e42a4a91d777778595d74John Wiegley case tok::kw___is_const: return UTT_IsConst; 247064b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl case tok::kw___is_empty: return UTT_IsEmpty; 247164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl case tok::kw___is_enum: return UTT_IsEnum; 24725e9392ba18f5925e26cc5714d1412eda0d219826Douglas Gregor case tok::kw___is_final: return UTT_IsFinal; 247320c0da7787c9a7d2529e42a4a91d777778595d74John Wiegley case tok::kw___is_floating_point: return UTT_IsFloatingPoint; 247420c0da7787c9a7d2529e42a4a91d777778595d74John Wiegley case tok::kw___is_function: return UTT_IsFunction; 247520c0da7787c9a7d2529e42a4a91d777778595d74John Wiegley case tok::kw___is_fundamental: return UTT_IsFundamental; 247620c0da7787c9a7d2529e42a4a91d777778595d74John Wiegley case tok::kw___is_integral: return UTT_IsIntegral; 247720c0da7787c9a7d2529e42a4a91d777778595d74John Wiegley case tok::kw___is_lvalue_reference: return UTT_IsLvalueReference; 247820c0da7787c9a7d2529e42a4a91d777778595d74John Wiegley case tok::kw___is_member_function_pointer: return UTT_IsMemberFunctionPointer; 247920c0da7787c9a7d2529e42a4a91d777778595d74John Wiegley case tok::kw___is_member_object_pointer: return UTT_IsMemberObjectPointer; 248020c0da7787c9a7d2529e42a4a91d777778595d74John Wiegley case tok::kw___is_member_pointer: return UTT_IsMemberPointer; 248120c0da7787c9a7d2529e42a4a91d777778595d74John Wiegley case tok::kw___is_object: return UTT_IsObject; 24824e61ddd644e9c6293697a966d98d7c1905cf63a8Chandler Carruth case tok::kw___is_literal: return UTT_IsLiteral; 24833840281126e7d10552c55f6fd8b1ec9483898906Chandler Carruth case tok::kw___is_literal_type: return UTT_IsLiteral; 248464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl case tok::kw___is_pod: return UTT_IsPOD; 248520c0da7787c9a7d2529e42a4a91d777778595d74John Wiegley case tok::kw___is_pointer: return UTT_IsPointer; 248664b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl case tok::kw___is_polymorphic: return UTT_IsPolymorphic; 248720c0da7787c9a7d2529e42a4a91d777778595d74John Wiegley case tok::kw___is_reference: return UTT_IsReference; 248820c0da7787c9a7d2529e42a4a91d777778595d74John Wiegley case tok::kw___is_rvalue_reference: return UTT_IsRvalueReference; 248920c0da7787c9a7d2529e42a4a91d777778595d74John Wiegley case tok::kw___is_scalar: return UTT_IsScalar; 249020c0da7787c9a7d2529e42a4a91d777778595d74John Wiegley case tok::kw___is_signed: return UTT_IsSigned; 249120c0da7787c9a7d2529e42a4a91d777778595d74John Wiegley case tok::kw___is_standard_layout: return UTT_IsStandardLayout; 249220c0da7787c9a7d2529e42a4a91d777778595d74John Wiegley case tok::kw___is_trivial: return UTT_IsTrivial; 2493feb375d31b7e9108b04a9f55b721d5e0c793a558Sean Hunt case tok::kw___is_trivially_copyable: return UTT_IsTriviallyCopyable; 249464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl case tok::kw___is_union: return UTT_IsUnion; 249520c0da7787c9a7d2529e42a4a91d777778595d74John Wiegley case tok::kw___is_unsigned: return UTT_IsUnsigned; 249620c0da7787c9a7d2529e42a4a91d777778595d74John Wiegley case tok::kw___is_void: return UTT_IsVoid; 249720c0da7787c9a7d2529e42a4a91d777778595d74John Wiegley case tok::kw___is_volatile: return UTT_IsVolatile; 249864b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl } 24996ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet} 25006ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 25016ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichetstatic BinaryTypeTrait BinaryTypeTraitFromTokKind(tok::TokenKind kind) { 25026ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet switch(kind) { 250338c2b730a8553fa1cf369d0c5567f8b5d0a3dda8Francois Pichet default: llvm_unreachable("Not a known binary type trait"); 2504f187237d916afa97c491ac32fe98be7d335c5b63Francois Pichet case tok::kw___is_base_of: return BTT_IsBaseOf; 250520c0da7787c9a7d2529e42a4a91d777778595d74John Wiegley case tok::kw___is_convertible: return BTT_IsConvertible; 250620c0da7787c9a7d2529e42a4a91d777778595d74John Wiegley case tok::kw___is_same: return BTT_IsSame; 2507f187237d916afa97c491ac32fe98be7d335c5b63Francois Pichet case tok::kw___builtin_types_compatible_p: return BTT_TypeCompatible; 25089f3611365d0f2297a910cf246e056708726ed10aDouglas Gregor case tok::kw___is_convertible_to: return BTT_IsConvertibleTo; 250925d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor case tok::kw___is_trivially_assignable: return BTT_IsTriviallyAssignable; 25106ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet } 251164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl} 251264b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 25134ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregorstatic TypeTrait TypeTraitFromTokKind(tok::TokenKind kind) { 25144ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor switch (kind) { 25154ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor default: llvm_unreachable("Not a known type trait"); 25164ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor case tok::kw___is_trivially_constructible: 25174ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor return TT_IsTriviallyConstructible; 25184ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor } 25194ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor} 25204ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 252121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegleystatic ArrayTypeTrait ArrayTypeTraitFromTokKind(tok::TokenKind kind) { 252221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley switch(kind) { 252321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley default: llvm_unreachable("Not a known binary type trait"); 252421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley case tok::kw___array_rank: return ATT_ArrayRank; 252521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley case tok::kw___array_extent: return ATT_ArrayExtent; 252621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley } 252721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley} 252821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 2529552622067dc45013d240f73952fece703f5e63bdJohn Wiegleystatic ExpressionTrait ExpressionTraitFromTokKind(tok::TokenKind kind) { 2530552622067dc45013d240f73952fece703f5e63bdJohn Wiegley switch(kind) { 2531b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie default: llvm_unreachable("Not a known unary expression trait."); 2532552622067dc45013d240f73952fece703f5e63bdJohn Wiegley case tok::kw___is_lvalue_expr: return ET_IsLValueExpr; 2533552622067dc45013d240f73952fece703f5e63bdJohn Wiegley case tok::kw___is_rvalue_expr: return ET_IsRValueExpr; 2534552622067dc45013d240f73952fece703f5e63bdJohn Wiegley } 2535552622067dc45013d240f73952fece703f5e63bdJohn Wiegley} 2536552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 253764b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl/// ParseUnaryTypeTrait - Parse the built-in unary type-trait 253864b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl/// pseudo-functions that allow implementation of the TR1/C++0x type traits 253964b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl/// templates. 254064b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl/// 254164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl/// primary-expression: 254264b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl/// [GNU] unary-type-trait '(' type-id ')' 254364b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl/// 254460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult Parser::ParseUnaryTypeTrait() { 254564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl UnaryTypeTrait UTT = UnaryTypeTraitFromTokKind(Tok.getKind()); 254664b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl SourceLocation Loc = ConsumeToken(); 254764b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 25484a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor BalancedDelimiterTracker T(*this, tok::l_paren); 25494a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor if (T.expectAndConsume(diag::err_expected_lparen)) 255064b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl return ExprError(); 255164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 255264b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl // FIXME: Error reporting absolutely sucks! If the this fails to parse a type 255364b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl // there will be cryptic errors about mismatched parentheses and missing 255464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl // specifiers. 2555809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor TypeResult Ty = ParseTypeName(); 255664b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 25574a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor T.consumeClose(); 255864b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 2559809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor if (Ty.isInvalid()) 2560809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor return ExprError(); 2561809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor 25624a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor return Actions.ActOnUnaryTypeTrait(UTT, Loc, Ty.get(), T.getCloseLocation()); 256364b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl} 2564f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis 25656ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet/// ParseBinaryTypeTrait - Parse the built-in binary type-trait 25666ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet/// pseudo-functions that allow implementation of the TR1/C++0x type traits 25676ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet/// templates. 25686ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet/// 25696ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet/// primary-expression: 25706ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet/// [GNU] binary-type-trait '(' type-id ',' type-id ')' 25716ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet/// 25726ad6f2848d7652ab2991286eb48be440d3493b28Francois PichetExprResult Parser::ParseBinaryTypeTrait() { 25736ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet BinaryTypeTrait BTT = BinaryTypeTraitFromTokKind(Tok.getKind()); 25746ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet SourceLocation Loc = ConsumeToken(); 25756ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 25764a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor BalancedDelimiterTracker T(*this, tok::l_paren); 25774a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor if (T.expectAndConsume(diag::err_expected_lparen)) 25786ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet return ExprError(); 25796ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 25806ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet TypeResult LhsTy = ParseTypeName(); 25816ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet if (LhsTy.isInvalid()) { 25826ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet SkipUntil(tok::r_paren); 25836ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet return ExprError(); 25846ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet } 25856ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 25866ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet if (ExpectAndConsume(tok::comma, diag::err_expected_comma)) { 25876ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet SkipUntil(tok::r_paren); 25886ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet return ExprError(); 25896ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet } 25906ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 25916ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet TypeResult RhsTy = ParseTypeName(); 25926ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet if (RhsTy.isInvalid()) { 25936ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet SkipUntil(tok::r_paren); 25946ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet return ExprError(); 25956ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet } 25966ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 25974a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor T.consumeClose(); 25986ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 25994a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor return Actions.ActOnBinaryTypeTrait(BTT, Loc, LhsTy.get(), RhsTy.get(), 26004a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor T.getCloseLocation()); 26016ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet} 26026ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 26034ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor/// \brief Parse the built-in type-trait pseudo-functions that allow 26044ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor/// implementation of the TR1/C++11 type traits templates. 26054ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor/// 26064ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor/// primary-expression: 26074ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor/// type-trait '(' type-id-seq ')' 26084ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor/// 26094ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor/// type-id-seq: 26104ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor/// type-id ...[opt] type-id-seq[opt] 26114ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor/// 26124ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas GregorExprResult Parser::ParseTypeTrait() { 26134ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor TypeTrait Kind = TypeTraitFromTokKind(Tok.getKind()); 26144ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor SourceLocation Loc = ConsumeToken(); 26154ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 26164ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor BalancedDelimiterTracker Parens(*this, tok::l_paren); 26174ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor if (Parens.expectAndConsume(diag::err_expected_lparen)) 26184ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor return ExprError(); 26194ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 26204ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor llvm::SmallVector<ParsedType, 2> Args; 26214ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor do { 26224ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor // Parse the next type. 26234ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor TypeResult Ty = ParseTypeName(); 26244ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor if (Ty.isInvalid()) { 26254ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor Parens.skipToEnd(); 26264ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor return ExprError(); 26274ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor } 26284ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 26294ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor // Parse the ellipsis, if present. 26304ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor if (Tok.is(tok::ellipsis)) { 26314ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor Ty = Actions.ActOnPackExpansion(Ty.get(), ConsumeToken()); 26324ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor if (Ty.isInvalid()) { 26334ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor Parens.skipToEnd(); 26344ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor return ExprError(); 26354ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor } 26364ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor } 26374ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 26384ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor // Add this type to the list of arguments. 26394ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor Args.push_back(Ty.get()); 26404ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 26414ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor if (Tok.is(tok::comma)) { 26424ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor ConsumeToken(); 26434ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor continue; 26444ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor } 26454ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 26464ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor break; 26474ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor } while (true); 26484ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 26494ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor if (Parens.consumeClose()) 26504ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor return ExprError(); 26514ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 26524ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor return Actions.ActOnTypeTrait(Kind, Loc, Args, Parens.getCloseLocation()); 26534ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor} 26544ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 265521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley/// ParseArrayTypeTrait - Parse the built-in array type-trait 265621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley/// pseudo-functions. 265721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley/// 265821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley/// primary-expression: 265921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley/// [Embarcadero] '__array_rank' '(' type-id ')' 266021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley/// [Embarcadero] '__array_extent' '(' type-id ',' expression ')' 266121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley/// 266221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John WiegleyExprResult Parser::ParseArrayTypeTrait() { 266321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley ArrayTypeTrait ATT = ArrayTypeTraitFromTokKind(Tok.getKind()); 266421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley SourceLocation Loc = ConsumeToken(); 266521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 26664a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor BalancedDelimiterTracker T(*this, tok::l_paren); 26674a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor if (T.expectAndConsume(diag::err_expected_lparen)) 266821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley return ExprError(); 266921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 267021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley TypeResult Ty = ParseTypeName(); 267121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley if (Ty.isInvalid()) { 267221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley SkipUntil(tok::comma); 267321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley SkipUntil(tok::r_paren); 267421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley return ExprError(); 267521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley } 267621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 267721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley switch (ATT) { 267821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley case ATT_ArrayRank: { 26794a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor T.consumeClose(); 26804a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor return Actions.ActOnArrayTypeTrait(ATT, Loc, Ty.get(), NULL, 26814a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor T.getCloseLocation()); 268221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley } 268321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley case ATT_ArrayExtent: { 268421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley if (ExpectAndConsume(tok::comma, diag::err_expected_comma)) { 268521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley SkipUntil(tok::r_paren); 268621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley return ExprError(); 268721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley } 268821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 268921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley ExprResult DimExpr = ParseExpression(); 26904a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor T.consumeClose(); 269121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 26924a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor return Actions.ActOnArrayTypeTrait(ATT, Loc, Ty.get(), DimExpr.get(), 26934a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor T.getCloseLocation()); 269421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley } 269521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley } 26963026348bd4c13a0f83b59839f64065e0fcbea253David Blaikie llvm_unreachable("Invalid ArrayTypeTrait!"); 269721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley} 269821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 2699552622067dc45013d240f73952fece703f5e63bdJohn Wiegley/// ParseExpressionTrait - Parse built-in expression-trait 2700552622067dc45013d240f73952fece703f5e63bdJohn Wiegley/// pseudo-functions like __is_lvalue_expr( xxx ). 2701552622067dc45013d240f73952fece703f5e63bdJohn Wiegley/// 2702552622067dc45013d240f73952fece703f5e63bdJohn Wiegley/// primary-expression: 2703552622067dc45013d240f73952fece703f5e63bdJohn Wiegley/// [Embarcadero] expression-trait '(' expression ')' 2704552622067dc45013d240f73952fece703f5e63bdJohn Wiegley/// 2705552622067dc45013d240f73952fece703f5e63bdJohn WiegleyExprResult Parser::ParseExpressionTrait() { 2706552622067dc45013d240f73952fece703f5e63bdJohn Wiegley ExpressionTrait ET = ExpressionTraitFromTokKind(Tok.getKind()); 2707552622067dc45013d240f73952fece703f5e63bdJohn Wiegley SourceLocation Loc = ConsumeToken(); 2708552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 27094a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor BalancedDelimiterTracker T(*this, tok::l_paren); 27104a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor if (T.expectAndConsume(diag::err_expected_lparen)) 2711552622067dc45013d240f73952fece703f5e63bdJohn Wiegley return ExprError(); 2712552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 2713552622067dc45013d240f73952fece703f5e63bdJohn Wiegley ExprResult Expr = ParseExpression(); 2714552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 27154a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor T.consumeClose(); 2716552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 27174a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor return Actions.ActOnExpressionTrait(ET, Loc, Expr.get(), 27184a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor T.getCloseLocation()); 2719552622067dc45013d240f73952fece703f5e63bdJohn Wiegley} 2720552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 2721552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 2722f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis/// ParseCXXAmbiguousParenExpression - We have parsed the left paren of a 2723f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis/// parenthesized ambiguous type-id. This uses tentative parsing to disambiguate 2724f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis/// based on the context past the parens. 272560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 2726f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios KyrtzidisParser::ParseCXXAmbiguousParenExpression(ParenParseOption &ExprType, 2727b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType &CastTy, 27284a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor BalancedDelimiterTracker &Tracker) { 27294e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie assert(getLangOpts().CPlusPlus && "Should only be called for C++!"); 2730f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis assert(ExprType == CastExpr && "Compound literals are not ambiguous!"); 2731f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis assert(isTypeIdInParens() && "Not a type-id!"); 2732f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis 273360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result(true); 2734b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall CastTy = ParsedType(); 2735f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis 2736f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis // We need to disambiguate a very ugly part of the C++ syntax: 2737f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis // 2738f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis // (T())x; - type-id 2739f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis // (T())*x; - type-id 2740f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis // (T())/x; - expression 2741f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis // (T()); - expression 2742f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis // 2743f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis // The bad news is that we cannot use the specialized tentative parser, since 2744f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis // it can only verify that the thing inside the parens can be parsed as 2745f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis // type-id, it is not useful for determining the context past the parens. 2746f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis // 2747f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis // The good news is that the parser can disambiguate this part without 2748a558a897cbe83a21914058348ffbdcf827530ad4Argyrios Kyrtzidis // making any unnecessary Action calls. 2749f40882a38baf258fa10e362003f6939a590074bbArgyrios Kyrtzidis // 2750f40882a38baf258fa10e362003f6939a590074bbArgyrios Kyrtzidis // It uses a scheme similar to parsing inline methods. The parenthesized 2751f40882a38baf258fa10e362003f6939a590074bbArgyrios Kyrtzidis // tokens are cached, the context that follows is determined (possibly by 2752f40882a38baf258fa10e362003f6939a590074bbArgyrios Kyrtzidis // parsing a cast-expression), and then we re-introduce the cached tokens 2753f40882a38baf258fa10e362003f6939a590074bbArgyrios Kyrtzidis // into the token stream and parse them appropriately. 2754f40882a38baf258fa10e362003f6939a590074bbArgyrios Kyrtzidis 27551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ParenParseOption ParseAs; 2756f40882a38baf258fa10e362003f6939a590074bbArgyrios Kyrtzidis CachedTokens Toks; 2757f40882a38baf258fa10e362003f6939a590074bbArgyrios Kyrtzidis 2758f40882a38baf258fa10e362003f6939a590074bbArgyrios Kyrtzidis // Store the tokens of the parentheses. We will parse them after we determine 2759f40882a38baf258fa10e362003f6939a590074bbArgyrios Kyrtzidis // the context that follows them. 276014b91628961ab50cc6e724bbcd408fdee100662dArgyrios Kyrtzidis if (!ConsumeAndStoreUntil(tok::r_paren, Toks)) { 2761f40882a38baf258fa10e362003f6939a590074bbArgyrios Kyrtzidis // We didn't find the ')' we expected. 27624a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor Tracker.consumeClose(); 2763f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis return ExprError(); 2764f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis } 2765f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis 2766f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis if (Tok.is(tok::l_brace)) { 2767f40882a38baf258fa10e362003f6939a590074bbArgyrios Kyrtzidis ParseAs = CompoundLiteral; 2768f40882a38baf258fa10e362003f6939a590074bbArgyrios Kyrtzidis } else { 2769f40882a38baf258fa10e362003f6939a590074bbArgyrios Kyrtzidis bool NotCastExpr; 2770b53f08ac87f1e1f4bc2fbfa4560c2183a82020eeEli Friedman // FIXME: Special-case ++ and --: "(S())++;" is not a cast-expression 2771b53f08ac87f1e1f4bc2fbfa4560c2183a82020eeEli Friedman if (Tok.is(tok::l_paren) && NextToken().is(tok::r_paren)) { 2772b53f08ac87f1e1f4bc2fbfa4560c2183a82020eeEli Friedman NotCastExpr = true; 2773b53f08ac87f1e1f4bc2fbfa4560c2183a82020eeEli Friedman } else { 2774b53f08ac87f1e1f4bc2fbfa4560c2183a82020eeEli Friedman // Try parsing the cast-expression that may follow. 2775b53f08ac87f1e1f4bc2fbfa4560c2183a82020eeEli Friedman // If it is not a cast-expression, NotCastExpr will be true and no token 2776b53f08ac87f1e1f4bc2fbfa4560c2183a82020eeEli Friedman // will be consumed. 2777b53f08ac87f1e1f4bc2fbfa4560c2183a82020eeEli Friedman Result = ParseCastExpression(false/*isUnaryExpression*/, 2778b53f08ac87f1e1f4bc2fbfa4560c2183a82020eeEli Friedman false/*isAddressofOperand*/, 2779b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall NotCastExpr, 27800a85183be6930571f3af8e5a976d24c3f95e5b25Argyrios Kyrtzidis // type-id has priority. 2781cd78e612d6fa8e214e6a6bb0e739a0c3e419df91Kaelyn Uhrain IsTypeCast); 2782b53f08ac87f1e1f4bc2fbfa4560c2183a82020eeEli Friedman } 2783f40882a38baf258fa10e362003f6939a590074bbArgyrios Kyrtzidis 2784f40882a38baf258fa10e362003f6939a590074bbArgyrios Kyrtzidis // If we parsed a cast-expression, it's really a type-id, otherwise it's 2785f40882a38baf258fa10e362003f6939a590074bbArgyrios Kyrtzidis // an expression. 2786f40882a38baf258fa10e362003f6939a590074bbArgyrios Kyrtzidis ParseAs = NotCastExpr ? SimpleExpr : CastExpr; 2787f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis } 2788f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis 27891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // The current token should go after the cached tokens. 2790f40882a38baf258fa10e362003f6939a590074bbArgyrios Kyrtzidis Toks.push_back(Tok); 2791f40882a38baf258fa10e362003f6939a590074bbArgyrios Kyrtzidis // Re-enter the stored parenthesized tokens into the token stream, so we may 2792f40882a38baf258fa10e362003f6939a590074bbArgyrios Kyrtzidis // parse them now. 2793f40882a38baf258fa10e362003f6939a590074bbArgyrios Kyrtzidis PP.EnterTokenStream(Toks.data(), Toks.size(), 2794f40882a38baf258fa10e362003f6939a590074bbArgyrios Kyrtzidis true/*DisableMacroExpansion*/, false/*OwnsTokens*/); 2795f40882a38baf258fa10e362003f6939a590074bbArgyrios Kyrtzidis // Drop the current token and bring the first cached one. It's the same token 2796f40882a38baf258fa10e362003f6939a590074bbArgyrios Kyrtzidis // as when we entered this function. 2797f40882a38baf258fa10e362003f6939a590074bbArgyrios Kyrtzidis ConsumeAnyToken(); 2798f40882a38baf258fa10e362003f6939a590074bbArgyrios Kyrtzidis 2799f40882a38baf258fa10e362003f6939a590074bbArgyrios Kyrtzidis if (ParseAs >= CompoundLiteral) { 28000a85183be6930571f3af8e5a976d24c3f95e5b25Argyrios Kyrtzidis // Parse the type declarator. 28010a85183be6930571f3af8e5a976d24c3f95e5b25Argyrios Kyrtzidis DeclSpec DS(AttrFactory); 28020a85183be6930571f3af8e5a976d24c3f95e5b25Argyrios Kyrtzidis ParseSpecifierQualifierList(DS); 28030a85183be6930571f3af8e5a976d24c3f95e5b25Argyrios Kyrtzidis Declarator DeclaratorInfo(DS, Declarator::TypeNameContext); 28040a85183be6930571f3af8e5a976d24c3f95e5b25Argyrios Kyrtzidis ParseDeclarator(DeclaratorInfo); 2805f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis 2806f40882a38baf258fa10e362003f6939a590074bbArgyrios Kyrtzidis // Match the ')'. 28074a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor Tracker.consumeClose(); 2808f40882a38baf258fa10e362003f6939a590074bbArgyrios Kyrtzidis 2809f40882a38baf258fa10e362003f6939a590074bbArgyrios Kyrtzidis if (ParseAs == CompoundLiteral) { 2810f40882a38baf258fa10e362003f6939a590074bbArgyrios Kyrtzidis ExprType = CompoundLiteral; 28110a85183be6930571f3af8e5a976d24c3f95e5b25Argyrios Kyrtzidis TypeResult Ty = ParseTypeName(); 28124a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor return ParseCompoundLiteralExpression(Ty.get(), 28134a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor Tracker.getOpenLocation(), 28144a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor Tracker.getCloseLocation()); 2815f40882a38baf258fa10e362003f6939a590074bbArgyrios Kyrtzidis } 28161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2817f40882a38baf258fa10e362003f6939a590074bbArgyrios Kyrtzidis // We parsed '(' type-id ')' and the thing after it wasn't a '{'. 2818f40882a38baf258fa10e362003f6939a590074bbArgyrios Kyrtzidis assert(ParseAs == CastExpr); 2819f40882a38baf258fa10e362003f6939a590074bbArgyrios Kyrtzidis 28200a85183be6930571f3af8e5a976d24c3f95e5b25Argyrios Kyrtzidis if (DeclaratorInfo.isInvalidType()) 2821f40882a38baf258fa10e362003f6939a590074bbArgyrios Kyrtzidis return ExprError(); 2822f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis 2823f40882a38baf258fa10e362003f6939a590074bbArgyrios Kyrtzidis // Result is what ParseCastExpression returned earlier. 2824f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis if (!Result.isInvalid()) 28254a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor Result = Actions.ActOnCastExpr(getCurScope(), Tracker.getOpenLocation(), 28264a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor DeclaratorInfo, CastTy, 28274a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor Tracker.getCloseLocation(), Result.take()); 2828f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis return move(Result); 2829f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis } 28301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2831f40882a38baf258fa10e362003f6939a590074bbArgyrios Kyrtzidis // Not a compound literal, and not followed by a cast-expression. 2832f40882a38baf258fa10e362003f6939a590074bbArgyrios Kyrtzidis assert(ParseAs == SimpleExpr); 2833f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis 2834f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis ExprType = SimpleExpr; 2835f40882a38baf258fa10e362003f6939a590074bbArgyrios Kyrtzidis Result = ParseExpression(); 2836f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis if (!Result.isInvalid() && Tok.is(tok::r_paren)) 28374a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor Result = Actions.ActOnParenExpr(Tracker.getOpenLocation(), 28384a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor Tok.getLocation(), Result.take()); 2839f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis 2840f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis // Match the ')'. 2841f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis if (Result.isInvalid()) { 2842f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis SkipUntil(tok::r_paren); 2843f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis return ExprError(); 2844f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis } 28451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 28464a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor Tracker.consumeClose(); 2847f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis return move(Result); 2848f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis} 2849