2006-12-05 02:06:35 +08:00
|
|
|
//===--- ParseExprCXX.cpp - C++ Expression Parsing ------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-30 03:59:25 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2006-12-05 02:06:35 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the Expression parsing implementation for C++.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2014-01-15 17:15:43 +08:00
|
|
|
#include "clang/AST/ASTContext.h"
|
2011-01-11 08:33:19 +08:00
|
|
|
#include "RAIIObjectsForParser.h"
|
2014-03-04 18:05:20 +08:00
|
|
|
#include "clang/AST/DeclTemplate.h"
|
2012-01-04 10:40:39 +08:00
|
|
|
#include "clang/Basic/PrettyStackTrace.h"
|
2012-03-09 07:06:02 +08:00
|
|
|
#include "clang/Lex/LiteralSupport.h"
|
2012-12-04 17:13:33 +08:00
|
|
|
#include "clang/Parse/ParseDiagnostic.h"
|
2014-01-07 19:51:46 +08:00
|
|
|
#include "clang/Parse/Parser.h"
|
2010-08-21 02:27:03 +08:00
|
|
|
#include "clang/Sema/DeclSpec.h"
|
|
|
|
#include "clang/Sema/ParsedTemplate.h"
|
2012-12-04 17:13:33 +08:00
|
|
|
#include "clang/Sema/Scope.h"
|
2009-11-03 09:35:08 +08:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
|
|
|
|
Implement a rudimentary form of generic lambdas.
Specifically, the following features are not included in this commit:
- any sort of capturing within generic lambdas
- generic lambdas within template functions and nested
within other generic lambdas
- conversion operator for captureless lambdas
- ensuring all visitors are generic lambda aware
(Although I have gotten some useful feedback on my patches of the above and will be incorporating that as I submit those patches for commit)
As an example of what compiles through this commit:
template <class F1, class F2>
struct overload : F1, F2 {
using F1::operator();
using F2::operator();
overload(F1 f1, F2 f2) : F1(f1), F2(f2) { }
};
auto Recursive = [](auto Self, auto h, auto ... rest) {
return 1 + Self(Self, rest...);
};
auto Base = [](auto Self, auto h) {
return 1;
};
overload<decltype(Base), decltype(Recursive)> O(Base, Recursive);
int num_params = O(O, 5, 3, "abc", 3.14, 'a');
Please see attached tests for more examples.
This patch has been reviewed by Doug and Richard. Minor changes (non-functionality affecting) have been made since both of them formally looked at it, but the changes involve removal of supernumerary return type deduction changes (since they are now redundant, with richard having committed a recent patch to address return type deduction for C++11 lambdas using C++14 semantics).
Some implementation notes:
- Add a new Declarator context => LambdaExprParameterContext to
clang::Declarator to allow the use of 'auto' in declaring generic
lambda parameters
- Add various helpers to CXXRecordDecl to facilitate identifying
and querying a closure class
- LambdaScopeInfo (which maintains the current lambda's Sema state)
was augmented to house the current depth of the template being
parsed (id est the Parser calls Sema::RecordParsingTemplateParameterDepth)
so that SemaType.cpp::ConvertDeclSpecToType may use it to immediately
generate a template-parameter-type when 'auto' is parsed in a generic
lambda parameter context. (i.e we do NOT use AutoType deduced to
a template parameter type - Richard seemed ok with this approach).
We encode that this template type was generated from an auto by simply
adding $auto to the name which can be used for better diagnostics if needed.
- SemaLambda.h was added to hold some common lambda utility
functions (this file is likely to grow ...)
- Teach Sema::ActOnStartOfFunctionDef to check whether it
is being called to instantiate a generic lambda's call
operator, and if so, push an appropriately prepared
LambdaScopeInfo object on the stack.
- various tests were added - but much more will be needed.
There is obviously more work to be done, and both Richard (weakly) and Doug (strongly)
have requested that LambdaExpr be removed form the CXXRecordDecl LambdaDefinitionaData
in a future patch which is forthcoming.
A greatful thanks to all reviewers including Eli Friedman, James Dennett,
and especially the two gracious wizards (Richard Smith and Doug Gregor)
who spent hours providing feedback (in person in Chicago and on the mailing lists).
And yet I am certain that I have allowed unidentified bugs to creep in; bugs, that I will do my best to slay, once identified!
Thanks!
llvm-svn: 191453
2013-09-27 03:54:12 +08:00
|
|
|
|
2006-12-05 02:06:35 +08:00
|
|
|
using namespace clang;
|
|
|
|
|
2014-01-07 10:35:33 +08:00
|
|
|
static int SelectDigraphErrorMessage(tok::TokenKind Kind) {
|
|
|
|
switch (Kind) {
|
|
|
|
// template name
|
|
|
|
case tok::unknown: return 0;
|
|
|
|
// casts
|
|
|
|
case tok::kw_const_cast: return 1;
|
|
|
|
case tok::kw_dynamic_cast: return 2;
|
|
|
|
case tok::kw_reinterpret_cast: return 3;
|
|
|
|
case tok::kw_static_cast: return 4;
|
|
|
|
default:
|
|
|
|
llvm_unreachable("Unknown type for digraph error message.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-15 05:45:45 +08:00
|
|
|
// Are the two tokens adjacent in the same source file?
|
2012-06-18 14:11:04 +08:00
|
|
|
bool Parser::areTokensAdjacent(const Token &First, const Token &Second) {
|
2011-04-15 05:45:45 +08:00
|
|
|
SourceManager &SM = PP.getSourceManager();
|
|
|
|
SourceLocation FirstLoc = SM.getSpellingLoc(First.getLocation());
|
2011-09-20 04:40:19 +08:00
|
|
|
SourceLocation FirstEnd = FirstLoc.getLocWithOffset(First.getLength());
|
2011-04-15 05:45:45 +08:00
|
|
|
return FirstEnd == SM.getSpellingLoc(Second.getLocation());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Suggest fixit for "<::" after a cast.
|
|
|
|
static void FixDigraph(Parser &P, Preprocessor &PP, Token &DigraphToken,
|
|
|
|
Token &ColonToken, tok::TokenKind Kind, bool AtDigraph) {
|
|
|
|
// Pull '<:' and ':' off token stream.
|
|
|
|
if (!AtDigraph)
|
|
|
|
PP.Lex(DigraphToken);
|
|
|
|
PP.Lex(ColonToken);
|
|
|
|
|
|
|
|
SourceRange Range;
|
|
|
|
Range.setBegin(DigraphToken.getLocation());
|
|
|
|
Range.setEnd(ColonToken.getLocation());
|
|
|
|
P.Diag(DigraphToken.getLocation(), diag::err_missing_whitespace_digraph)
|
2014-01-07 10:35:33 +08:00
|
|
|
<< SelectDigraphErrorMessage(Kind)
|
|
|
|
<< FixItHint::CreateReplacement(Range, "< ::");
|
2011-04-15 05:45:45 +08:00
|
|
|
|
|
|
|
// Update token information to reflect their change in token type.
|
|
|
|
ColonToken.setKind(tok::coloncolon);
|
2011-09-20 04:40:19 +08:00
|
|
|
ColonToken.setLocation(ColonToken.getLocation().getLocWithOffset(-1));
|
2011-04-15 05:45:45 +08:00
|
|
|
ColonToken.setLength(2);
|
|
|
|
DigraphToken.setKind(tok::less);
|
|
|
|
DigraphToken.setLength(1);
|
|
|
|
|
|
|
|
// Push new tokens back to token stream.
|
|
|
|
PP.EnterToken(ColonToken);
|
|
|
|
if (!AtDigraph)
|
|
|
|
PP.EnterToken(DigraphToken);
|
|
|
|
}
|
|
|
|
|
2011-09-20 03:01:00 +08:00
|
|
|
// Check for '<::' which should be '< ::' instead of '[:' when following
|
|
|
|
// a template name.
|
|
|
|
void Parser::CheckForTemplateAndDigraph(Token &Next, ParsedType ObjectType,
|
|
|
|
bool EnteringContext,
|
|
|
|
IdentifierInfo &II, CXXScopeSpec &SS) {
|
2011-09-21 04:03:50 +08:00
|
|
|
if (!Next.is(tok::l_square) || Next.getLength() != 2)
|
2011-09-20 03:01:00 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
Token SecondToken = GetLookAheadToken(2);
|
2012-06-18 14:11:04 +08:00
|
|
|
if (!SecondToken.is(tok::colon) || !areTokensAdjacent(Next, SecondToken))
|
2011-09-20 03:01:00 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
TemplateTy Template;
|
|
|
|
UnqualifiedId TemplateName;
|
|
|
|
TemplateName.setIdentifier(&II, Tok.getLocation());
|
|
|
|
bool MemberOfUnknownSpecialization;
|
|
|
|
if (!Actions.isTemplateName(getCurScope(), SS, /*hasTemplateKeyword=*/false,
|
|
|
|
TemplateName, ObjectType, EnteringContext,
|
|
|
|
Template, MemberOfUnknownSpecialization))
|
|
|
|
return;
|
|
|
|
|
2014-01-07 10:35:33 +08:00
|
|
|
FixDigraph(*this, PP, Next, SecondToken, tok::unknown,
|
|
|
|
/*AtDigraph*/false);
|
2011-09-20 03:01:00 +08:00
|
|
|
}
|
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
/// \brief Parse global scope or nested-name-specifier if present.
|
2009-09-03 06:59:36 +08:00
|
|
|
///
|
|
|
|
/// Parses a C++ global scope specifier ('::') or nested-name-specifier (which
|
2009-09-09 23:08:12 +08:00
|
|
|
/// may be preceded by '::'). Note that this routine will not parse ::new or
|
2009-09-03 06:59:36 +08:00
|
|
|
/// ::delete; it will just leave them in the token stream.
|
2008-11-09 00:45:02 +08:00
|
|
|
///
|
|
|
|
/// '::'[opt] nested-name-specifier
|
|
|
|
/// '::'
|
|
|
|
///
|
|
|
|
/// nested-name-specifier:
|
|
|
|
/// type-name '::'
|
|
|
|
/// namespace-name '::'
|
|
|
|
/// nested-name-specifier identifier '::'
|
2009-09-03 06:59:36 +08:00
|
|
|
/// nested-name-specifier 'template'[opt] simple-template-id '::'
|
|
|
|
///
|
|
|
|
///
|
2009-09-09 23:08:12 +08:00
|
|
|
/// \param SS the scope specifier that will be set to the parsed
|
2009-09-03 06:59:36 +08:00
|
|
|
/// nested-name-specifier (or empty)
|
|
|
|
///
|
2009-09-09 23:08:12 +08:00
|
|
|
/// \param ObjectType if this nested-name-specifier is being parsed following
|
2009-09-03 06:59:36 +08:00
|
|
|
/// the "." or "->" of a member access expression, this parameter provides the
|
|
|
|
/// type of the object whose members are being accessed.
|
2008-11-09 00:45:02 +08:00
|
|
|
///
|
2009-09-03 06:59:36 +08:00
|
|
|
/// \param EnteringContext whether we will be entering into the context of
|
|
|
|
/// the nested-name-specifier after parsing it.
|
|
|
|
///
|
Rework parsing of pseudo-destructor expressions and explicit
destructor calls, e.g.,
p->T::~T
We now detect when the member access that we've parsed, e.g.,
p-> or x.
may be a pseudo-destructor expression, either because the type of p or
x is a scalar or because it is dependent (and, therefore, may become a
scalar at template instantiation time).
We then parse the pseudo-destructor grammar specifically:
::[opt] nested-name-specifier[opt] type-name :: ∼ type-name
and hand those results to a new action, ActOnPseudoDestructorExpr,
which will cope with both dependent member accesses of destructors and
with pseudo-destructor expressions.
This commit affects the parsing of pseudo-destructors, only; the
semantic actions still go through the semantic actions for member
access expressions. That will change soon.
llvm-svn: 97045
2010-02-25 02:44:31 +08:00
|
|
|
/// \param MayBePseudoDestructor When non-NULL, points to a flag that
|
|
|
|
/// indicates whether this nested-name-specifier may be part of a
|
|
|
|
/// pseudo-destructor name. In this case, the flag will be set false
|
|
|
|
/// if we don't actually end up parsing a destructor name. Moreorover,
|
|
|
|
/// if we do end up determining that we are parsing a destructor name,
|
|
|
|
/// the last component of the nested-name-specifier is not parsed as
|
|
|
|
/// part of the scope specifier.
|
2013-03-26 09:15:19 +08:00
|
|
|
///
|
|
|
|
/// \param IsTypename If \c true, this nested-name-specifier is known to be
|
|
|
|
/// part of a type name. This is used to improve error recovery.
|
|
|
|
///
|
|
|
|
/// \param LastII When non-NULL, points to an IdentifierInfo* that will be
|
|
|
|
/// filled in with the leading identifier in the last component of the
|
|
|
|
/// nested-name-specifier, if any.
|
2010-02-22 02:36:56 +08:00
|
|
|
///
|
2010-02-26 16:45:28 +08:00
|
|
|
/// \returns true if there was an error parsing a scope specifier
|
Improve support for out-of-line definitions of nested templates and
their members, including member class template, member function
templates, and member classes and functions of member templates.
To actually parse the nested-name-specifiers that qualify the name of
an out-of-line definition of a member template, e.g.,
template<typename X> template<typename Y>
X Outer<X>::Inner1<Y>::foo(Y) {
return X();
}
we need to look for the template names (e.g., "Inner1") as a member of
the current instantiation (Outer<X>), even before we have entered the
scope of the current instantiation. Since we can't do this in general
(i.e., we should not be looking into all dependent
nested-name-specifiers as if they were the current instantiation), we
rely on the parser to tell us when it is parsing a declaration
specifier sequence, and, therefore, when we should consider the
current scope specifier to be a current instantiation.
Printing of complicated, dependent nested-name-specifiers may be
somewhat broken by this commit; I'll add tests for this issue and fix
the problem (if it still exists) in a subsequent commit.
llvm-svn: 80044
2009-08-26 06:51:20 +08:00
|
|
|
bool Parser::ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS,
|
2010-08-24 13:47:05 +08:00
|
|
|
ParsedType ObjectType,
|
2010-02-22 02:36:56 +08:00
|
|
|
bool EnteringContext,
|
2011-03-28 03:41:34 +08:00
|
|
|
bool *MayBePseudoDestructor,
|
2013-03-26 09:15:19 +08:00
|
|
|
bool IsTypename,
|
|
|
|
IdentifierInfo **LastII) {
|
2012-03-11 15:00:24 +08:00
|
|
|
assert(getLangOpts().CPlusPlus &&
|
2009-01-05 09:24:05 +08:00
|
|
|
"Call sites of this function should be guarded by checking for C++");
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-11-09 00:45:02 +08:00
|
|
|
if (Tok.is(tok::annot_cxxscope)) {
|
2013-03-26 09:15:19 +08:00
|
|
|
assert(!LastII && "want last identifier but have already annotated scope");
|
2015-02-17 06:32:46 +08:00
|
|
|
assert(!MayBePseudoDestructor && "unexpected annot_cxxscope");
|
2011-02-25 01:54:50 +08:00
|
|
|
Actions.RestoreNestedNameSpecifierAnnotation(Tok.getAnnotationValue(),
|
|
|
|
Tok.getAnnotationRange(),
|
|
|
|
SS);
|
2008-11-09 00:45:02 +08:00
|
|
|
ConsumeToken();
|
2010-02-26 16:45:28 +08:00
|
|
|
return false;
|
2008-11-09 00:45:02 +08:00
|
|
|
}
|
2009-01-05 05:14:15 +08:00
|
|
|
|
2013-08-06 13:49:26 +08:00
|
|
|
if (Tok.is(tok::annot_template_id)) {
|
|
|
|
// If the current token is an annotated template id, it may already have
|
|
|
|
// a scope specifier. Restore it.
|
|
|
|
TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Tok);
|
|
|
|
SS = TemplateId->SS;
|
|
|
|
}
|
|
|
|
|
2015-02-17 06:32:46 +08:00
|
|
|
// Has to happen before any "return false"s in this function.
|
|
|
|
bool CheckForDestructor = false;
|
|
|
|
if (MayBePseudoDestructor && *MayBePseudoDestructor) {
|
|
|
|
CheckForDestructor = true;
|
|
|
|
*MayBePseudoDestructor = false;
|
|
|
|
}
|
|
|
|
|
2013-03-26 09:15:19 +08:00
|
|
|
if (LastII)
|
2014-05-21 14:02:52 +08:00
|
|
|
*LastII = nullptr;
|
2013-03-26 09:15:19 +08:00
|
|
|
|
Implement parsing of nested-name-specifiers that involve template-ids, e.g.,
std::vector<int>::allocator_type
When we parse a template-id that names a type, it will become either a
template-id annotation (which is a parsed representation of a
template-id that has not yet been through semantic analysis) or a
typename annotation (where semantic analysis has resolved the
template-id to an actual type), depending on the context. We only
produce a type in contexts where we know that we only need type
information, e.g., in a type specifier. Otherwise, we create a
template-id annotation that can later be "upgraded" by transforming it
into a typename annotation when the parser needs a type. This occurs,
for example, when we've parsed "std::vector<int>" above and then see
the '::' after it. However, it means that when writing something like
this:
template<> class Outer::Inner<int> { ... };
We have two tokens to represent Outer::Inner<int>: one token for the
nested name specifier Outer::, and one template-id annotation token
for Inner<int>, which will be passed to semantic analysis to define
the class template specialization.
Most of the churn in the template tests in this patch come from an
improvement in our error recovery from ill-formed template-ids.
llvm-svn: 65467
2009-02-26 03:37:18 +08:00
|
|
|
bool HasScopeSpecifier = false;
|
|
|
|
|
2009-01-05 11:55:46 +08:00
|
|
|
if (Tok.is(tok::coloncolon)) {
|
|
|
|
// ::new and ::delete aren't nested-name-specifiers.
|
|
|
|
tok::TokenKind NextKind = NextToken().getKind();
|
|
|
|
if (NextKind == tok::kw_new || NextKind == tok::kw_delete)
|
|
|
|
return false;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2014-12-30 03:19:18 +08:00
|
|
|
if (NextKind == tok::l_brace) {
|
|
|
|
// It is invalid to have :: {, consume the scope qualifier and pretend
|
|
|
|
// like we never saw it.
|
|
|
|
Diag(ConsumeToken(), diag::err_expected) << tok::identifier;
|
|
|
|
} else {
|
|
|
|
// '::' - Global scope qualifier.
|
|
|
|
if (Actions.ActOnCXXGlobalScopeSpecifier(ConsumeToken(), SS))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
HasScopeSpecifier = true;
|
|
|
|
}
|
2008-11-09 00:45:02 +08:00
|
|
|
}
|
|
|
|
|
2014-09-26 08:28:20 +08:00
|
|
|
if (Tok.is(tok::kw___super)) {
|
|
|
|
SourceLocation SuperLoc = ConsumeToken();
|
|
|
|
if (!Tok.is(tok::coloncolon)) {
|
|
|
|
Diag(Tok.getLocation(), diag::err_expected_coloncolon_after_super);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Actions.ActOnSuperScopeSpecifier(SuperLoc, ConsumeToken(), SS);
|
|
|
|
}
|
|
|
|
|
2014-10-04 09:57:39 +08:00
|
|
|
if (!HasScopeSpecifier &&
|
2015-06-18 18:59:26 +08:00
|
|
|
Tok.isOneOf(tok::kw_decltype, tok::annot_decltype)) {
|
2011-12-04 13:04:18 +08:00
|
|
|
DeclSpec DS(AttrFactory);
|
|
|
|
SourceLocation DeclLoc = Tok.getLocation();
|
|
|
|
SourceLocation EndLoc = ParseDecltypeSpecifier(DS);
|
2013-12-17 22:12:37 +08:00
|
|
|
|
|
|
|
SourceLocation CCLoc;
|
|
|
|
if (!TryConsumeToken(tok::coloncolon, CCLoc)) {
|
2011-12-04 13:04:18 +08:00
|
|
|
AnnotateExistingDecltypeSpecifier(DS, DeclLoc, EndLoc);
|
|
|
|
return false;
|
|
|
|
}
|
2013-12-17 22:12:37 +08:00
|
|
|
|
2011-12-04 13:04:18 +08:00
|
|
|
if (Actions.ActOnCXXNestedNameSpecifierDecltype(SS, DS, CCLoc))
|
|
|
|
SS.SetInvalid(SourceRange(DeclLoc, CCLoc));
|
|
|
|
|
|
|
|
HasScopeSpecifier = true;
|
|
|
|
}
|
|
|
|
|
Implement parsing of nested-name-specifiers that involve template-ids, e.g.,
std::vector<int>::allocator_type
When we parse a template-id that names a type, it will become either a
template-id annotation (which is a parsed representation of a
template-id that has not yet been through semantic analysis) or a
typename annotation (where semantic analysis has resolved the
template-id to an actual type), depending on the context. We only
produce a type in contexts where we know that we only need type
information, e.g., in a type specifier. Otherwise, we create a
template-id annotation that can later be "upgraded" by transforming it
into a typename annotation when the parser needs a type. This occurs,
for example, when we've parsed "std::vector<int>" above and then see
the '::' after it. However, it means that when writing something like
this:
template<> class Outer::Inner<int> { ... };
We have two tokens to represent Outer::Inner<int>: one token for the
nested name specifier Outer::, and one template-id annotation token
for Inner<int>, which will be passed to semantic analysis to define
the class template specialization.
Most of the churn in the template tests in this patch come from an
improvement in our error recovery from ill-formed template-ids.
llvm-svn: 65467
2009-02-26 03:37:18 +08:00
|
|
|
while (true) {
|
2009-09-03 06:59:36 +08:00
|
|
|
if (HasScopeSpecifier) {
|
|
|
|
// C++ [basic.lookup.classref]p5:
|
|
|
|
// If the qualified-id has the form
|
2009-09-09 08:23:06 +08:00
|
|
|
//
|
2009-09-03 06:59:36 +08:00
|
|
|
// ::class-name-or-namespace-name::...
|
2009-09-09 08:23:06 +08:00
|
|
|
//
|
2009-09-03 06:59:36 +08:00
|
|
|
// the class-name-or-namespace-name is looked up in global scope as a
|
|
|
|
// class-name or namespace-name.
|
|
|
|
//
|
|
|
|
// To implement this, we clear out the object type as soon as we've
|
|
|
|
// seen a leading '::' or part of a nested-name-specifier.
|
2016-01-16 07:43:34 +08:00
|
|
|
ObjectType = nullptr;
|
|
|
|
|
Initial implementation of a code-completion interface in Clang. In
essence, code completion is triggered by a magic "code completion"
token produced by the lexer [*], which the parser recognizes at
certain points in the grammar. The parser then calls into the Action
object with the appropriate CodeCompletionXXX action.
Sema implements the CodeCompletionXXX callbacks by performing minimal
translation, then forwarding them to a CodeCompletionConsumer
subclass, which uses the results of semantic analysis to provide
code-completion results. At present, only a single, "printing" code
completion consumer is available, for regression testing and
debugging. However, the design is meant to permit other
code-completion consumers.
This initial commit contains two code-completion actions: one for
member access, e.g., "x." or "p->", and one for
nested-name-specifiers, e.g., "std::". More code-completion actions
will follow, along with improved gathering of code-completion results
for the various contexts.
[*] In the current -code-completion-dump testing/debugging mode, the
file is truncated at the completion point and EOF is translated into
"code completion".
llvm-svn: 82166
2009-09-18 05:32:03 +08:00
|
|
|
if (Tok.is(tok::code_completion)) {
|
|
|
|
// Code completion for a nested-name-specifier, where the code
|
|
|
|
// code completion token follows the '::'.
|
2010-07-03 01:43:08 +08:00
|
|
|
Actions.CodeCompleteQualifiedId(getCurScope(), SS, EnteringContext);
|
2011-04-23 09:04:12 +08:00
|
|
|
// Include code completion token into the range of the scope otherwise
|
|
|
|
// when we try to annotate the scope tokens the dangling code completion
|
|
|
|
// token will cause assertion in
|
|
|
|
// Preprocessor::AnnotatePreviousCachedTokens.
|
2011-09-04 11:32:15 +08:00
|
|
|
SS.setEndLoc(Tok.getLocation());
|
|
|
|
cutOffParsing();
|
|
|
|
return true;
|
Initial implementation of a code-completion interface in Clang. In
essence, code completion is triggered by a magic "code completion"
token produced by the lexer [*], which the parser recognizes at
certain points in the grammar. The parser then calls into the Action
object with the appropriate CodeCompletionXXX action.
Sema implements the CodeCompletionXXX callbacks by performing minimal
translation, then forwarding them to a CodeCompletionConsumer
subclass, which uses the results of semantic analysis to provide
code-completion results. At present, only a single, "printing" code
completion consumer is available, for regression testing and
debugging. However, the design is meant to permit other
code-completion consumers.
This initial commit contains two code-completion actions: one for
member access, e.g., "x." or "p->", and one for
nested-name-specifiers, e.g., "std::". More code-completion actions
will follow, along with improved gathering of code-completion results
for the various contexts.
[*] In the current -code-completion-dump testing/debugging mode, the
file is truncated at the completion point and EOF is translated into
"code completion".
llvm-svn: 82166
2009-09-18 05:32:03 +08:00
|
|
|
}
|
2009-09-03 06:59:36 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-06-26 11:47:46 +08:00
|
|
|
// nested-name-specifier:
|
|
|
|
// nested-name-specifier 'template'[opt] simple-template-id '::'
|
|
|
|
|
|
|
|
// Parse the optional 'template' keyword, then make sure we have
|
|
|
|
// 'identifier <' after it.
|
|
|
|
if (Tok.is(tok::kw_template)) {
|
2009-09-03 06:59:36 +08:00
|
|
|
// If we don't have a scope specifier or an object type, this isn't a
|
2009-08-29 12:08:08 +08:00
|
|
|
// nested-name-specifier, since they aren't allowed to start with
|
|
|
|
// 'template'.
|
2009-09-03 06:59:36 +08:00
|
|
|
if (!HasScopeSpecifier && !ObjectType)
|
2009-08-29 12:08:08 +08:00
|
|
|
break;
|
|
|
|
|
2009-11-12 00:39:34 +08:00
|
|
|
TentativeParsingAction TPA(*this);
|
2009-06-26 11:47:46 +08:00
|
|
|
SourceLocation TemplateKWLoc = ConsumeToken();
|
2013-12-05 08:58:33 +08:00
|
|
|
|
2009-11-04 08:56:37 +08:00
|
|
|
UnqualifiedId TemplateName;
|
|
|
|
if (Tok.is(tok::identifier)) {
|
|
|
|
// Consume the identifier.
|
2009-11-12 00:39:34 +08:00
|
|
|
TemplateName.setIdentifier(Tok.getIdentifierInfo(), Tok.getLocation());
|
2009-11-04 08:56:37 +08:00
|
|
|
ConsumeToken();
|
|
|
|
} else if (Tok.is(tok::kw_operator)) {
|
2013-12-05 08:58:33 +08:00
|
|
|
// We don't need to actually parse the unqualified-id in this case,
|
|
|
|
// because a simple-template-id cannot start with 'operator', but
|
|
|
|
// go ahead and parse it anyway for consistency with the case where
|
|
|
|
// we already annotated the template-id.
|
|
|
|
if (ParseUnqualifiedIdOperator(SS, EnteringContext, ObjectType,
|
2009-11-12 00:39:34 +08:00
|
|
|
TemplateName)) {
|
|
|
|
TPA.Commit();
|
2009-11-04 08:56:37 +08:00
|
|
|
break;
|
2009-11-12 00:39:34 +08:00
|
|
|
}
|
2013-12-05 08:58:33 +08:00
|
|
|
|
2009-11-28 16:58:14 +08:00
|
|
|
if (TemplateName.getKind() != UnqualifiedId::IK_OperatorFunctionId &&
|
|
|
|
TemplateName.getKind() != UnqualifiedId::IK_LiteralOperatorId) {
|
2009-11-04 08:56:37 +08:00
|
|
|
Diag(TemplateName.getSourceRange().getBegin(),
|
|
|
|
diag::err_id_after_template_in_nested_name_spec)
|
|
|
|
<< TemplateName.getSourceRange();
|
2009-11-12 00:39:34 +08:00
|
|
|
TPA.Commit();
|
2009-11-04 08:56:37 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
2009-11-12 00:39:34 +08:00
|
|
|
TPA.Revert();
|
2009-06-26 11:47:46 +08:00
|
|
|
break;
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-11-12 00:39:34 +08:00
|
|
|
// If the next token is not '<', we have a qualified-id that refers
|
|
|
|
// to a template name, such as T::template apply, but is not a
|
|
|
|
// template-id.
|
|
|
|
if (Tok.isNot(tok::less)) {
|
|
|
|
TPA.Revert();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Commit to parsing the template-id.
|
|
|
|
TPA.Commit();
|
2010-06-17 07:00:59 +08:00
|
|
|
TemplateTy Template;
|
2012-01-27 17:46:47 +08:00
|
|
|
if (TemplateNameKind TNK
|
|
|
|
= Actions.ActOnDependentTemplateName(getCurScope(),
|
|
|
|
SS, TemplateKWLoc, TemplateName,
|
|
|
|
ObjectType, EnteringContext,
|
|
|
|
Template)) {
|
|
|
|
if (AnnotateTemplateIdToken(Template, TNK, SS, TemplateKWLoc,
|
|
|
|
TemplateName, false))
|
2010-06-17 07:00:59 +08:00
|
|
|
return true;
|
|
|
|
} else
|
2010-02-26 16:45:28 +08:00
|
|
|
return true;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-06-26 11:47:46 +08:00
|
|
|
continue;
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
Implement parsing of nested-name-specifiers that involve template-ids, e.g.,
std::vector<int>::allocator_type
When we parse a template-id that names a type, it will become either a
template-id annotation (which is a parsed representation of a
template-id that has not yet been through semantic analysis) or a
typename annotation (where semantic analysis has resolved the
template-id to an actual type), depending on the context. We only
produce a type in contexts where we know that we only need type
information, e.g., in a type specifier. Otherwise, we create a
template-id annotation that can later be "upgraded" by transforming it
into a typename annotation when the parser needs a type. This occurs,
for example, when we've parsed "std::vector<int>" above and then see
the '::' after it. However, it means that when writing something like
this:
template<> class Outer::Inner<int> { ... };
We have two tokens to represent Outer::Inner<int>: one token for the
nested name specifier Outer::, and one template-id annotation token
for Inner<int>, which will be passed to semantic analysis to define
the class template specialization.
Most of the churn in the template tests in this patch come from an
improvement in our error recovery from ill-formed template-ids.
llvm-svn: 65467
2009-02-26 03:37:18 +08:00
|
|
|
if (Tok.is(tok::annot_template_id) && NextToken().is(tok::coloncolon)) {
|
2009-09-09 23:08:12 +08:00
|
|
|
// We have
|
Implement parsing of nested-name-specifiers that involve template-ids, e.g.,
std::vector<int>::allocator_type
When we parse a template-id that names a type, it will become either a
template-id annotation (which is a parsed representation of a
template-id that has not yet been through semantic analysis) or a
typename annotation (where semantic analysis has resolved the
template-id to an actual type), depending on the context. We only
produce a type in contexts where we know that we only need type
information, e.g., in a type specifier. Otherwise, we create a
template-id annotation that can later be "upgraded" by transforming it
into a typename annotation when the parser needs a type. This occurs,
for example, when we've parsed "std::vector<int>" above and then see
the '::' after it. However, it means that when writing something like
this:
template<> class Outer::Inner<int> { ... };
We have two tokens to represent Outer::Inner<int>: one token for the
nested name specifier Outer::, and one template-id annotation token
for Inner<int>, which will be passed to semantic analysis to define
the class template specialization.
Most of the churn in the template tests in this patch come from an
improvement in our error recovery from ill-formed template-ids.
llvm-svn: 65467
2009-02-26 03:37:18 +08:00
|
|
|
//
|
2013-12-04 08:28:23 +08:00
|
|
|
// template-id '::'
|
Implement parsing of nested-name-specifiers that involve template-ids, e.g.,
std::vector<int>::allocator_type
When we parse a template-id that names a type, it will become either a
template-id annotation (which is a parsed representation of a
template-id that has not yet been through semantic analysis) or a
typename annotation (where semantic analysis has resolved the
template-id to an actual type), depending on the context. We only
produce a type in contexts where we know that we only need type
information, e.g., in a type specifier. Otherwise, we create a
template-id annotation that can later be "upgraded" by transforming it
into a typename annotation when the parser needs a type. This occurs,
for example, when we've parsed "std::vector<int>" above and then see
the '::' after it. However, it means that when writing something like
this:
template<> class Outer::Inner<int> { ... };
We have two tokens to represent Outer::Inner<int>: one token for the
nested name specifier Outer::, and one template-id annotation token
for Inner<int>, which will be passed to semantic analysis to define
the class template specialization.
Most of the churn in the template tests in this patch come from an
improvement in our error recovery from ill-formed template-ids.
llvm-svn: 65467
2009-02-26 03:37:18 +08:00
|
|
|
//
|
2013-12-04 08:28:23 +08:00
|
|
|
// So we need to check whether the template-id is a simple-template-id of
|
|
|
|
// the right kind (it should name a type or be dependent), and then
|
2009-03-31 08:43:58 +08:00
|
|
|
// convert it into a type within the nested-name-specifier.
|
2011-06-22 14:09:49 +08:00
|
|
|
TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Tok);
|
Rework parsing of pseudo-destructor expressions and explicit
destructor calls, e.g.,
p->T::~T
We now detect when the member access that we've parsed, e.g.,
p-> or x.
may be a pseudo-destructor expression, either because the type of p or
x is a scalar or because it is dependent (and, therefore, may become a
scalar at template instantiation time).
We then parse the pseudo-destructor grammar specifically:
::[opt] nested-name-specifier[opt] type-name :: ∼ type-name
and hand those results to a new action, ActOnPseudoDestructorExpr,
which will cope with both dependent member accesses of destructors and
with pseudo-destructor expressions.
This commit affects the parsing of pseudo-destructors, only; the
semantic actions still go through the semantic actions for member
access expressions. That will change soon.
llvm-svn: 97045
2010-02-25 02:44:31 +08:00
|
|
|
if (CheckForDestructor && GetLookAheadToken(2).is(tok::tilde)) {
|
|
|
|
*MayBePseudoDestructor = true;
|
2010-02-26 16:45:28 +08:00
|
|
|
return false;
|
Rework parsing of pseudo-destructor expressions and explicit
destructor calls, e.g.,
p->T::~T
We now detect when the member access that we've parsed, e.g.,
p-> or x.
may be a pseudo-destructor expression, either because the type of p or
x is a scalar or because it is dependent (and, therefore, may become a
scalar at template instantiation time).
We then parse the pseudo-destructor grammar specifically:
::[opt] nested-name-specifier[opt] type-name :: ∼ type-name
and hand those results to a new action, ActOnPseudoDestructorExpr,
which will cope with both dependent member accesses of destructors and
with pseudo-destructor expressions.
This commit affects the parsing of pseudo-destructors, only; the
semantic actions still go through the semantic actions for member
access expressions. That will change soon.
llvm-svn: 97045
2010-02-25 02:44:31 +08:00
|
|
|
}
|
|
|
|
|
2013-03-26 09:15:19 +08:00
|
|
|
if (LastII)
|
|
|
|
*LastII = TemplateId->Name;
|
|
|
|
|
2011-03-05 05:37:14 +08:00
|
|
|
// Consume the template-id token.
|
|
|
|
ConsumeToken();
|
2014-04-14 00:52:03 +08:00
|
|
|
|
2011-03-05 05:37:14 +08:00
|
|
|
assert(Tok.is(tok::coloncolon) && "NextToken() not working properly!");
|
|
|
|
SourceLocation CCLoc = ConsumeToken();
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-11-07 11:30:03 +08:00
|
|
|
HasScopeSpecifier = true;
|
2014-04-14 00:52:03 +08:00
|
|
|
|
2012-08-24 07:38:35 +08:00
|
|
|
ASTTemplateArgsPtr TemplateArgsPtr(TemplateId->getTemplateArgs(),
|
2011-03-05 05:37:14 +08:00
|
|
|
TemplateId->NumArgs);
|
2014-04-14 00:52:03 +08:00
|
|
|
|
2011-03-05 05:37:14 +08:00
|
|
|
if (Actions.ActOnCXXNestedNameSpecifier(getCurScope(),
|
2012-01-27 17:46:47 +08:00
|
|
|
SS,
|
|
|
|
TemplateId->TemplateKWLoc,
|
2011-03-05 05:37:14 +08:00
|
|
|
TemplateId->Template,
|
|
|
|
TemplateId->TemplateNameLoc,
|
|
|
|
TemplateId->LAngleLoc,
|
|
|
|
TemplateArgsPtr,
|
|
|
|
TemplateId->RAngleLoc,
|
|
|
|
CCLoc,
|
|
|
|
EnteringContext)) {
|
|
|
|
SourceLocation StartLoc
|
|
|
|
= SS.getBeginLoc().isValid()? SS.getBeginLoc()
|
|
|
|
: TemplateId->TemplateNameLoc;
|
|
|
|
SS.SetInvalid(SourceRange(StartLoc, CCLoc));
|
2009-06-26 11:45:46 +08:00
|
|
|
}
|
2011-05-04 02:45:38 +08:00
|
|
|
|
2011-03-05 05:37:14 +08:00
|
|
|
continue;
|
Implement parsing of nested-name-specifiers that involve template-ids, e.g.,
std::vector<int>::allocator_type
When we parse a template-id that names a type, it will become either a
template-id annotation (which is a parsed representation of a
template-id that has not yet been through semantic analysis) or a
typename annotation (where semantic analysis has resolved the
template-id to an actual type), depending on the context. We only
produce a type in contexts where we know that we only need type
information, e.g., in a type specifier. Otherwise, we create a
template-id annotation that can later be "upgraded" by transforming it
into a typename annotation when the parser needs a type. This occurs,
for example, when we've parsed "std::vector<int>" above and then see
the '::' after it. However, it means that when writing something like
this:
template<> class Outer::Inner<int> { ... };
We have two tokens to represent Outer::Inner<int>: one token for the
nested name specifier Outer::, and one template-id annotation token
for Inner<int>, which will be passed to semantic analysis to define
the class template specialization.
Most of the churn in the template tests in this patch come from an
improvement in our error recovery from ill-formed template-ids.
llvm-svn: 65467
2009-02-26 03:37:18 +08:00
|
|
|
}
|
|
|
|
|
2009-06-26 11:52:38 +08:00
|
|
|
// The rest of the nested-name-specifier possibilities start with
|
|
|
|
// tok::identifier.
|
|
|
|
if (Tok.isNot(tok::identifier))
|
|
|
|
break;
|
|
|
|
|
|
|
|
IdentifierInfo &II = *Tok.getIdentifierInfo();
|
|
|
|
|
|
|
|
// nested-name-specifier:
|
|
|
|
// type-name '::'
|
|
|
|
// namespace-name '::'
|
|
|
|
// nested-name-specifier identifier '::'
|
|
|
|
Token Next = NextToken();
|
2016-08-08 12:02:15 +08:00
|
|
|
Sema::NestedNameSpecInfo IdInfo(&II, Tok.getLocation(), Next.getLocation(),
|
|
|
|
ObjectType);
|
|
|
|
|
2009-12-07 09:36:53 +08:00
|
|
|
// If we get foo:bar, this is almost certainly a typo for foo::bar. Recover
|
|
|
|
// and emit a fixit hint for it.
|
2010-02-22 02:36:56 +08:00
|
|
|
if (Next.is(tok::colon) && !ColonIsSacred) {
|
2016-08-08 12:02:15 +08:00
|
|
|
if (Actions.IsInvalidUnlessNestedName(getCurScope(), SS, IdInfo,
|
2010-02-22 02:36:56 +08:00
|
|
|
EnteringContext) &&
|
|
|
|
// If the token after the colon isn't an identifier, it's still an
|
|
|
|
// error, but they probably meant something else strange so don't
|
|
|
|
// recover like this.
|
|
|
|
PP.LookAhead(1).is(tok::identifier)) {
|
2014-04-14 00:52:03 +08:00
|
|
|
Diag(Next, diag::err_unexpected_colon_in_nested_name_spec)
|
2010-04-01 01:46:05 +08:00
|
|
|
<< FixItHint::CreateReplacement(Next.getLocation(), "::");
|
2010-02-22 02:36:56 +08:00
|
|
|
// Recover as if the user wrote '::'.
|
|
|
|
Next.setKind(tok::coloncolon);
|
|
|
|
}
|
2009-12-07 09:36:53 +08:00
|
|
|
}
|
2014-12-30 07:12:23 +08:00
|
|
|
|
|
|
|
if (Next.is(tok::coloncolon) && GetLookAheadToken(2).is(tok::l_brace)) {
|
|
|
|
// It is invalid to have :: {, consume the scope qualifier and pretend
|
|
|
|
// like we never saw it.
|
|
|
|
Token Identifier = Tok; // Stash away the identifier.
|
|
|
|
ConsumeToken(); // Eat the identifier, current token is now '::'.
|
2014-12-30 07:24:27 +08:00
|
|
|
Diag(PP.getLocForEndOfToken(ConsumeToken()), diag::err_expected)
|
|
|
|
<< tok::identifier;
|
2014-12-30 07:12:23 +08:00
|
|
|
UnconsumeToken(Identifier); // Stick the identifier back.
|
|
|
|
Next = NextToken(); // Point Next at the '{' token.
|
|
|
|
}
|
|
|
|
|
2009-06-26 11:52:38 +08:00
|
|
|
if (Next.is(tok::coloncolon)) {
|
2010-02-25 05:29:12 +08:00
|
|
|
if (CheckForDestructor && GetLookAheadToken(2).is(tok::tilde) &&
|
2016-08-08 12:02:15 +08:00
|
|
|
!Actions.isNonTypeNestedNameSpecifier(getCurScope(), SS, IdInfo)) {
|
Rework parsing of pseudo-destructor expressions and explicit
destructor calls, e.g.,
p->T::~T
We now detect when the member access that we've parsed, e.g.,
p-> or x.
may be a pseudo-destructor expression, either because the type of p or
x is a scalar or because it is dependent (and, therefore, may become a
scalar at template instantiation time).
We then parse the pseudo-destructor grammar specifically:
::[opt] nested-name-specifier[opt] type-name :: ∼ type-name
and hand those results to a new action, ActOnPseudoDestructorExpr,
which will cope with both dependent member accesses of destructors and
with pseudo-destructor expressions.
This commit affects the parsing of pseudo-destructors, only; the
semantic actions still go through the semantic actions for member
access expressions. That will change soon.
llvm-svn: 97045
2010-02-25 02:44:31 +08:00
|
|
|
*MayBePseudoDestructor = true;
|
2010-02-26 16:45:28 +08:00
|
|
|
return false;
|
Rework parsing of pseudo-destructor expressions and explicit
destructor calls, e.g.,
p->T::~T
We now detect when the member access that we've parsed, e.g.,
p-> or x.
may be a pseudo-destructor expression, either because the type of p or
x is a scalar or because it is dependent (and, therefore, may become a
scalar at template instantiation time).
We then parse the pseudo-destructor grammar specifically:
::[opt] nested-name-specifier[opt] type-name :: ∼ type-name
and hand those results to a new action, ActOnPseudoDestructorExpr,
which will cope with both dependent member accesses of destructors and
with pseudo-destructor expressions.
This commit affects the parsing of pseudo-destructors, only; the
semantic actions still go through the semantic actions for member
access expressions. That will change soon.
llvm-svn: 97045
2010-02-25 02:44:31 +08:00
|
|
|
}
|
|
|
|
|
2014-04-14 00:52:03 +08:00
|
|
|
if (ColonIsSacred) {
|
|
|
|
const Token &Next2 = GetLookAheadToken(2);
|
|
|
|
if (Next2.is(tok::kw_private) || Next2.is(tok::kw_protected) ||
|
|
|
|
Next2.is(tok::kw_public) || Next2.is(tok::kw_virtual)) {
|
|
|
|
Diag(Next2, diag::err_unexpected_token_in_nested_name_spec)
|
|
|
|
<< Next2.getName()
|
|
|
|
<< FixItHint::CreateReplacement(Next.getLocation(), ":");
|
|
|
|
Token ColonColon;
|
|
|
|
PP.Lex(ColonColon);
|
|
|
|
ColonColon.setKind(tok::colon);
|
|
|
|
PP.EnterToken(ColonColon);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-26 09:15:19 +08:00
|
|
|
if (LastII)
|
|
|
|
*LastII = &II;
|
|
|
|
|
2009-06-26 11:52:38 +08:00
|
|
|
// We have an identifier followed by a '::'. Lookup this name
|
|
|
|
// as the name in a nested-name-specifier.
|
2014-04-14 00:52:03 +08:00
|
|
|
Token Identifier = Tok;
|
2009-06-26 11:52:38 +08:00
|
|
|
SourceLocation IdLoc = ConsumeToken();
|
2015-06-18 18:59:26 +08:00
|
|
|
assert(Tok.isOneOf(tok::coloncolon, tok::colon) &&
|
2009-12-07 09:36:53 +08:00
|
|
|
"NextToken() not working properly!");
|
2014-04-14 00:52:03 +08:00
|
|
|
Token ColonColon = Tok;
|
2009-06-26 11:52:38 +08:00
|
|
|
SourceLocation CCLoc = ConsumeToken();
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2014-04-14 00:52:03 +08:00
|
|
|
bool IsCorrectedToColon = false;
|
2014-05-21 14:02:52 +08:00
|
|
|
bool *CorrectionFlagPtr = ColonIsSacred ? &IsCorrectedToColon : nullptr;
|
2016-08-08 12:02:15 +08:00
|
|
|
if (Actions.ActOnCXXNestedNameSpecifier(getCurScope(), IdInfo,
|
|
|
|
EnteringContext, SS,
|
2014-04-14 00:52:03 +08:00
|
|
|
false, CorrectionFlagPtr)) {
|
|
|
|
// Identifier is not recognized as a nested name, but we can have
|
|
|
|
// mistyped '::' instead of ':'.
|
|
|
|
if (CorrectionFlagPtr && IsCorrectedToColon) {
|
|
|
|
ColonColon.setKind(tok::colon);
|
|
|
|
PP.EnterToken(Tok);
|
|
|
|
PP.EnterToken(ColonColon);
|
|
|
|
Tok = Identifier;
|
|
|
|
break;
|
|
|
|
}
|
2011-02-24 08:17:56 +08:00
|
|
|
SS.SetInvalid(SourceRange(IdLoc, CCLoc));
|
2014-04-14 00:52:03 +08:00
|
|
|
}
|
|
|
|
HasScopeSpecifier = true;
|
2009-06-26 11:52:38 +08:00
|
|
|
continue;
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-09-20 03:01:00 +08:00
|
|
|
CheckForTemplateAndDigraph(Next, ObjectType, EnteringContext, II, SS);
|
2011-04-15 05:45:45 +08:00
|
|
|
|
2009-06-26 11:52:38 +08:00
|
|
|
// nested-name-specifier:
|
|
|
|
// type-name '<'
|
|
|
|
if (Next.is(tok::less)) {
|
|
|
|
TemplateTy Template;
|
2009-11-04 07:16:33 +08:00
|
|
|
UnqualifiedId TemplateName;
|
|
|
|
TemplateName.setIdentifier(&II, Tok.getLocation());
|
2010-05-22 07:18:07 +08:00
|
|
|
bool MemberOfUnknownSpecialization;
|
2010-07-03 01:43:08 +08:00
|
|
|
if (TemplateNameKind TNK = Actions.isTemplateName(getCurScope(), SS,
|
2010-08-06 20:11:11 +08:00
|
|
|
/*hasTemplateKeyword=*/false,
|
2009-11-04 07:16:33 +08:00
|
|
|
TemplateName,
|
2009-09-03 06:59:36 +08:00
|
|
|
ObjectType,
|
Improve support for out-of-line definitions of nested templates and
their members, including member class template, member function
templates, and member classes and functions of member templates.
To actually parse the nested-name-specifiers that qualify the name of
an out-of-line definition of a member template, e.g.,
template<typename X> template<typename Y>
X Outer<X>::Inner1<Y>::foo(Y) {
return X();
}
we need to look for the template names (e.g., "Inner1") as a member of
the current instantiation (Outer<X>), even before we have entered the
scope of the current instantiation. Since we can't do this in general
(i.e., we should not be looking into all dependent
nested-name-specifiers as if they were the current instantiation), we
rely on the parser to tell us when it is parsing a declaration
specifier sequence, and, therefore, when we should consider the
current scope specifier to be a current instantiation.
Printing of complicated, dependent nested-name-specifiers may be
somewhat broken by this commit; I'll add tests for this issue and fix
the problem (if it still exists) in a subsequent commit.
llvm-svn: 80044
2009-08-26 06:51:20 +08:00
|
|
|
EnteringContext,
|
2010-05-22 07:18:07 +08:00
|
|
|
Template,
|
|
|
|
MemberOfUnknownSpecialization)) {
|
2011-11-07 11:30:03 +08:00
|
|
|
// We have found a template name, so annotate this token
|
2009-06-26 11:52:38 +08:00
|
|
|
// with a template-id annotation. We do not permit the
|
|
|
|
// template-id to be translated into a type annotation,
|
|
|
|
// because some clients (e.g., the parsing of class template
|
|
|
|
// specializations) still want to see the original template-id
|
|
|
|
// token.
|
2009-11-04 08:56:37 +08:00
|
|
|
ConsumeToken();
|
2012-01-27 17:46:47 +08:00
|
|
|
if (AnnotateTemplateIdToken(Template, TNK, SS, SourceLocation(),
|
|
|
|
TemplateName, false))
|
2010-02-26 16:45:28 +08:00
|
|
|
return true;
|
2009-06-26 11:52:38 +08:00
|
|
|
continue;
|
2013-08-06 09:03:05 +08:00
|
|
|
}
|
|
|
|
|
2010-05-22 07:43:39 +08:00
|
|
|
if (MemberOfUnknownSpecialization && (ObjectType || SS.isSet()) &&
|
2011-03-28 03:41:34 +08:00
|
|
|
(IsTypename || IsTemplateArgumentList(1))) {
|
2010-05-22 07:43:39 +08:00
|
|
|
// We have something like t::getAs<T>, where getAs is a
|
|
|
|
// member of an unknown specialization. However, this will only
|
|
|
|
// parse correctly as a template, so suggest the keyword 'template'
|
|
|
|
// before 'getAs' and treat this as a dependent template name.
|
2011-03-28 03:41:34 +08:00
|
|
|
unsigned DiagID = diag::err_missing_dependent_template_keyword;
|
2012-03-11 15:00:24 +08:00
|
|
|
if (getLangOpts().MicrosoftExt)
|
2011-04-22 16:25:24 +08:00
|
|
|
DiagID = diag::warn_missing_dependent_template_keyword;
|
2011-03-28 03:41:34 +08:00
|
|
|
|
|
|
|
Diag(Tok.getLocation(), DiagID)
|
2010-05-22 07:43:39 +08:00
|
|
|
<< II.getName()
|
|
|
|
<< FixItHint::CreateInsertion(Tok.getLocation(), "template ");
|
|
|
|
|
2010-06-17 07:00:59 +08:00
|
|
|
if (TemplateNameKind TNK
|
2010-07-03 01:43:08 +08:00
|
|
|
= Actions.ActOnDependentTemplateName(getCurScope(),
|
2012-01-27 17:46:47 +08:00
|
|
|
SS, SourceLocation(),
|
2010-06-17 07:00:59 +08:00
|
|
|
TemplateName, ObjectType,
|
|
|
|
EnteringContext, Template)) {
|
|
|
|
// Consume the identifier.
|
|
|
|
ConsumeToken();
|
2012-01-27 17:46:47 +08:00
|
|
|
if (AnnotateTemplateIdToken(Template, TNK, SS, SourceLocation(),
|
|
|
|
TemplateName, false))
|
|
|
|
return true;
|
2010-06-17 07:00:59 +08:00
|
|
|
}
|
|
|
|
else
|
2010-05-22 07:43:39 +08:00
|
|
|
return true;
|
2010-06-17 07:00:59 +08:00
|
|
|
|
2010-05-22 07:43:39 +08:00
|
|
|
continue;
|
2009-06-26 11:52:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Implement parsing of nested-name-specifiers that involve template-ids, e.g.,
std::vector<int>::allocator_type
When we parse a template-id that names a type, it will become either a
template-id annotation (which is a parsed representation of a
template-id that has not yet been through semantic analysis) or a
typename annotation (where semantic analysis has resolved the
template-id to an actual type), depending on the context. We only
produce a type in contexts where we know that we only need type
information, e.g., in a type specifier. Otherwise, we create a
template-id annotation that can later be "upgraded" by transforming it
into a typename annotation when the parser needs a type. This occurs,
for example, when we've parsed "std::vector<int>" above and then see
the '::' after it. However, it means that when writing something like
this:
template<> class Outer::Inner<int> { ... };
We have two tokens to represent Outer::Inner<int>: one token for the
nested name specifier Outer::, and one template-id annotation token
for Inner<int>, which will be passed to semantic analysis to define
the class template specialization.
Most of the churn in the template tests in this patch come from an
improvement in our error recovery from ill-formed template-ids.
llvm-svn: 65467
2009-02-26 03:37:18 +08:00
|
|
|
// We don't have any tokens that form the beginning of a
|
|
|
|
// nested-name-specifier, so we're done.
|
|
|
|
break;
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
Rework parsing of pseudo-destructor expressions and explicit
destructor calls, e.g.,
p->T::~T
We now detect when the member access that we've parsed, e.g.,
p-> or x.
may be a pseudo-destructor expression, either because the type of p or
x is a scalar or because it is dependent (and, therefore, may become a
scalar at template instantiation time).
We then parse the pseudo-destructor grammar specifically:
::[opt] nested-name-specifier[opt] type-name :: ∼ type-name
and hand those results to a new action, ActOnPseudoDestructorExpr,
which will cope with both dependent member accesses of destructors and
with pseudo-destructor expressions.
This commit affects the parsing of pseudo-destructors, only; the
semantic actions still go through the semantic actions for member
access expressions. That will change soon.
llvm-svn: 97045
2010-02-25 02:44:31 +08:00
|
|
|
// Even if we didn't see any pieces of a nested-name-specifier, we
|
|
|
|
// still check whether there is a tilde in this position, which
|
|
|
|
// indicates a potential pseudo-destructor.
|
|
|
|
if (CheckForDestructor && Tok.is(tok::tilde))
|
|
|
|
*MayBePseudoDestructor = true;
|
|
|
|
|
2010-02-26 16:45:28 +08:00
|
|
|
return false;
|
2008-11-09 00:45:02 +08:00
|
|
|
}
|
|
|
|
|
2014-11-21 06:06:40 +08:00
|
|
|
ExprResult Parser::tryParseCXXIdExpression(CXXScopeSpec &SS, bool isAddressOfOperand,
|
|
|
|
Token &Replacement) {
|
|
|
|
SourceLocation TemplateKWLoc;
|
|
|
|
UnqualifiedId Name;
|
|
|
|
if (ParseUnqualifiedId(SS,
|
|
|
|
/*EnteringContext=*/false,
|
|
|
|
/*AllowDestructorName=*/false,
|
|
|
|
/*AllowConstructorName=*/false,
|
2016-01-16 07:43:34 +08:00
|
|
|
/*ObjectType=*/nullptr, TemplateKWLoc, Name))
|
2014-11-21 06:06:40 +08:00
|
|
|
return ExprError();
|
|
|
|
|
|
|
|
// This is only the direct operand of an & operator if it is not
|
|
|
|
// followed by a postfix-expression suffix.
|
|
|
|
if (isAddressOfOperand && isPostfixExpressionSuffixStart())
|
|
|
|
isAddressOfOperand = false;
|
|
|
|
|
|
|
|
return Actions.ActOnIdExpression(getCurScope(), SS, TemplateKWLoc, Name,
|
|
|
|
Tok.is(tok::l_paren), isAddressOfOperand,
|
|
|
|
nullptr, /*IsInlineAsmIdentifier=*/false,
|
|
|
|
&Replacement);
|
|
|
|
}
|
|
|
|
|
2008-11-09 00:45:02 +08:00
|
|
|
/// ParseCXXIdExpression - Handle id-expression.
|
|
|
|
///
|
|
|
|
/// id-expression:
|
|
|
|
/// unqualified-id
|
|
|
|
/// qualified-id
|
|
|
|
///
|
|
|
|
/// qualified-id:
|
|
|
|
/// '::'[opt] nested-name-specifier 'template'[opt] unqualified-id
|
|
|
|
/// '::' identifier
|
|
|
|
/// '::' operator-function-id
|
2009-07-01 06:34:41 +08:00
|
|
|
/// '::' template-id
|
2008-11-09 00:45:02 +08:00
|
|
|
///
|
|
|
|
/// NOTE: The standard specifies that, for qualified-id, the parser does not
|
|
|
|
/// expect:
|
|
|
|
///
|
|
|
|
/// '::' conversion-function-id
|
|
|
|
/// '::' '~' class-name
|
|
|
|
///
|
|
|
|
/// This may cause a slight inconsistency on diagnostics:
|
|
|
|
///
|
|
|
|
/// class C {};
|
|
|
|
/// namespace A {}
|
|
|
|
/// void f() {
|
|
|
|
/// :: A :: ~ C(); // Some Sema error about using destructor with a
|
|
|
|
/// // namespace.
|
|
|
|
/// :: ~ C(); // Some Parser error like 'unexpected ~'.
|
|
|
|
/// }
|
|
|
|
///
|
|
|
|
/// We simplify the parser a bit and make it work like:
|
|
|
|
///
|
|
|
|
/// qualified-id:
|
|
|
|
/// '::'[opt] nested-name-specifier 'template'[opt] unqualified-id
|
|
|
|
/// '::' unqualified-id
|
|
|
|
///
|
|
|
|
/// That way Sema can handle and report similar errors for namespaces and the
|
|
|
|
/// global scope.
|
|
|
|
///
|
2009-02-04 04:19:35 +08:00
|
|
|
/// The isAddressOfOperand parameter indicates that this id-expression is a
|
|
|
|
/// direct operand of the address-of operator. This is, besides member contexts,
|
|
|
|
/// the only place where a qualified-id naming a non-static class member may
|
|
|
|
/// appear.
|
|
|
|
///
|
2010-08-24 14:29:42 +08:00
|
|
|
ExprResult Parser::ParseCXXIdExpression(bool isAddressOfOperand) {
|
2008-11-09 00:45:02 +08:00
|
|
|
// qualified-id:
|
|
|
|
// '::'[opt] nested-name-specifier 'template'[opt] unqualified-id
|
|
|
|
// '::' unqualified-id
|
|
|
|
//
|
|
|
|
CXXScopeSpec SS;
|
2016-01-16 07:43:34 +08:00
|
|
|
ParseOptionalCXXScopeSpecifier(SS, nullptr, /*EnteringContext=*/false);
|
2012-01-27 17:46:47 +08:00
|
|
|
|
2014-11-21 06:06:40 +08:00
|
|
|
Token Replacement;
|
2015-02-15 14:15:40 +08:00
|
|
|
ExprResult Result =
|
|
|
|
tryParseCXXIdExpression(SS, isAddressOfOperand, Replacement);
|
2014-11-21 06:06:40 +08:00
|
|
|
if (Result.isUnset()) {
|
|
|
|
// If the ExprResult is valid but null, then typo correction suggested a
|
|
|
|
// keyword replacement that needs to be reparsed.
|
|
|
|
UnconsumeToken(Replacement);
|
|
|
|
Result = tryParseCXXIdExpression(SS, isAddressOfOperand, Replacement);
|
|
|
|
}
|
|
|
|
assert(!Result.isUnset() && "Typo correction suggested a keyword replacement "
|
|
|
|
"for a previous keyword suggestion");
|
|
|
|
return Result;
|
2008-11-09 00:45:02 +08:00
|
|
|
}
|
|
|
|
|
2013-05-10 05:36:41 +08:00
|
|
|
/// ParseLambdaExpression - Parse a C++11 lambda expression.
|
2011-08-04 23:30:47 +08:00
|
|
|
///
|
|
|
|
/// lambda-expression:
|
|
|
|
/// lambda-introducer lambda-declarator[opt] compound-statement
|
|
|
|
///
|
|
|
|
/// lambda-introducer:
|
|
|
|
/// '[' lambda-capture[opt] ']'
|
|
|
|
///
|
|
|
|
/// lambda-capture:
|
|
|
|
/// capture-default
|
|
|
|
/// capture-list
|
|
|
|
/// capture-default ',' capture-list
|
|
|
|
///
|
|
|
|
/// capture-default:
|
|
|
|
/// '&'
|
|
|
|
/// '='
|
|
|
|
///
|
|
|
|
/// capture-list:
|
|
|
|
/// capture
|
|
|
|
/// capture-list ',' capture
|
|
|
|
///
|
|
|
|
/// capture:
|
2013-05-10 05:36:41 +08:00
|
|
|
/// simple-capture
|
|
|
|
/// init-capture [C++1y]
|
|
|
|
///
|
|
|
|
/// simple-capture:
|
2011-08-04 23:30:47 +08:00
|
|
|
/// identifier
|
|
|
|
/// '&' identifier
|
|
|
|
/// 'this'
|
|
|
|
///
|
2013-05-10 05:36:41 +08:00
|
|
|
/// init-capture: [C++1y]
|
|
|
|
/// identifier initializer
|
|
|
|
/// '&' identifier initializer
|
|
|
|
///
|
2011-08-04 23:30:47 +08:00
|
|
|
/// lambda-declarator:
|
|
|
|
/// '(' parameter-declaration-clause ')' attribute-specifier[opt]
|
|
|
|
/// 'mutable'[opt] exception-specification[opt]
|
|
|
|
/// trailing-return-type[opt]
|
|
|
|
///
|
|
|
|
ExprResult Parser::ParseLambdaExpression() {
|
|
|
|
// Parse lambda-introducer.
|
|
|
|
LambdaIntroducer Intro;
|
2013-12-05 09:40:41 +08:00
|
|
|
Optional<unsigned> DiagID = ParseLambdaIntroducer(Intro);
|
2011-08-04 23:30:47 +08:00
|
|
|
if (DiagID) {
|
|
|
|
Diag(Tok, DiagID.getValue());
|
2015-01-12 11:36:37 +08:00
|
|
|
SkipUntil(tok::r_square, StopAtSemi);
|
|
|
|
SkipUntil(tok::l_brace, StopAtSemi);
|
|
|
|
SkipUntil(tok::r_brace, StopAtSemi);
|
2012-01-04 10:40:39 +08:00
|
|
|
return ExprError();
|
2011-08-04 23:30:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return ParseLambdaExpressionAfterIntroducer(Intro);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// TryParseLambdaExpression - Use lookahead and potentially tentative
|
|
|
|
/// parsing to determine if we are looking at a C++0x lambda expression, and parse
|
|
|
|
/// it if we are.
|
|
|
|
///
|
|
|
|
/// If we are not looking at a lambda expression, returns ExprError().
|
|
|
|
ExprResult Parser::TryParseLambdaExpression() {
|
2013-01-02 19:42:31 +08:00
|
|
|
assert(getLangOpts().CPlusPlus11
|
2011-08-04 23:30:47 +08:00
|
|
|
&& Tok.is(tok::l_square)
|
|
|
|
&& "Not at the start of a possible lambda expression.");
|
|
|
|
|
2016-06-01 02:46:31 +08:00
|
|
|
const Token Next = NextToken();
|
|
|
|
if (Next.is(tok::eof)) // Nothing else to lookup here...
|
|
|
|
return ExprEmpty();
|
2011-08-04 23:30:47 +08:00
|
|
|
|
2016-06-01 02:46:31 +08:00
|
|
|
const Token After = GetLookAheadToken(2);
|
2011-08-04 23:30:47 +08:00
|
|
|
// If lookahead indicates this is a lambda...
|
|
|
|
if (Next.is(tok::r_square) || // []
|
|
|
|
Next.is(tok::equal) || // [=
|
|
|
|
(Next.is(tok::amp) && // [&] or [&,
|
|
|
|
(After.is(tok::r_square) ||
|
|
|
|
After.is(tok::comma))) ||
|
|
|
|
(Next.is(tok::identifier) && // [identifier]
|
|
|
|
After.is(tok::r_square))) {
|
|
|
|
return ParseLambdaExpression();
|
|
|
|
}
|
|
|
|
|
2012-01-04 10:40:39 +08:00
|
|
|
// If lookahead indicates an ObjC message send...
|
|
|
|
// [identifier identifier
|
2011-08-04 23:30:47 +08:00
|
|
|
if (Next.is(tok::identifier) && After.is(tok::identifier)) {
|
2012-01-04 10:40:39 +08:00
|
|
|
return ExprEmpty();
|
2011-08-04 23:30:47 +08:00
|
|
|
}
|
2013-12-05 09:40:41 +08:00
|
|
|
|
2012-01-04 10:40:39 +08:00
|
|
|
// Here, we're stuck: lambda introducers and Objective-C message sends are
|
|
|
|
// unambiguous, but it requires arbitrary lookhead. [a,b,c,d,e,f,g] is a
|
|
|
|
// lambda, and [a,b,c,d,e,f,g h] is a Objective-C message send. Instead of
|
|
|
|
// writing two routines to parse a lambda introducer, just try to parse
|
|
|
|
// a lambda introducer first, and fall back if that fails.
|
|
|
|
// (TryParseLambdaIntroducer never produces any diagnostic output.)
|
2011-08-04 23:30:47 +08:00
|
|
|
LambdaIntroducer Intro;
|
|
|
|
if (TryParseLambdaIntroducer(Intro))
|
2012-01-04 10:40:39 +08:00
|
|
|
return ExprEmpty();
|
2013-12-05 09:40:41 +08:00
|
|
|
|
2011-08-04 23:30:47 +08:00
|
|
|
return ParseLambdaExpressionAfterIntroducer(Intro);
|
|
|
|
}
|
|
|
|
|
2013-05-22 06:21:19 +08:00
|
|
|
/// \brief Parse a lambda introducer.
|
|
|
|
/// \param Intro A LambdaIntroducer filled in with information about the
|
|
|
|
/// contents of the lambda-introducer.
|
|
|
|
/// \param SkippedInits If non-null, we are disambiguating between an Obj-C
|
|
|
|
/// message send and a lambda expression. In this mode, we will
|
|
|
|
/// sometimes skip the initializers for init-captures and not fully
|
|
|
|
/// populate \p Intro. This flag will be set to \c true if we do so.
|
|
|
|
/// \return A DiagnosticID if it hit something unexpected. The location for
|
2017-01-11 19:23:22 +08:00
|
|
|
/// the diagnostic is that of the current token.
|
2013-05-22 06:21:19 +08:00
|
|
|
Optional<unsigned> Parser::ParseLambdaIntroducer(LambdaIntroducer &Intro,
|
|
|
|
bool *SkippedInits) {
|
2013-02-21 06:23:23 +08:00
|
|
|
typedef Optional<unsigned> DiagResult;
|
2011-08-04 23:30:47 +08:00
|
|
|
|
|
|
|
assert(Tok.is(tok::l_square) && "Lambda expressions begin with '['.");
|
2011-10-13 00:37:45 +08:00
|
|
|
BalancedDelimiterTracker T(*this, tok::l_square);
|
|
|
|
T.consumeOpen();
|
|
|
|
|
|
|
|
Intro.Range.setBegin(T.getOpenLocation());
|
2011-08-04 23:30:47 +08:00
|
|
|
|
|
|
|
bool first = true;
|
|
|
|
|
|
|
|
// Parse capture-default.
|
|
|
|
if (Tok.is(tok::amp) &&
|
|
|
|
(NextToken().is(tok::comma) || NextToken().is(tok::r_square))) {
|
|
|
|
Intro.Default = LCD_ByRef;
|
2012-02-11 01:46:20 +08:00
|
|
|
Intro.DefaultLoc = ConsumeToken();
|
2011-08-04 23:30:47 +08:00
|
|
|
first = false;
|
|
|
|
} else if (Tok.is(tok::equal)) {
|
|
|
|
Intro.Default = LCD_ByCopy;
|
2012-02-11 01:46:20 +08:00
|
|
|
Intro.DefaultLoc = ConsumeToken();
|
2011-08-04 23:30:47 +08:00
|
|
|
first = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (Tok.isNot(tok::r_square)) {
|
|
|
|
if (!first) {
|
2012-02-15 23:34:24 +08:00
|
|
|
if (Tok.isNot(tok::comma)) {
|
2012-07-31 08:50:07 +08:00
|
|
|
// Provide a completion for a lambda introducer here. Except
|
|
|
|
// in Objective-C, where this is Almost Surely meant to be a message
|
|
|
|
// send. In that case, fail here and let the ObjC message
|
|
|
|
// expression parser perform the completion.
|
2012-07-31 23:27:48 +08:00
|
|
|
if (Tok.is(tok::code_completion) &&
|
|
|
|
!(getLangOpts().ObjC1 && Intro.Default == LCD_None &&
|
|
|
|
!Intro.Captures.empty())) {
|
2012-02-15 23:34:24 +08:00
|
|
|
Actions.CodeCompleteLambdaIntroducer(getCurScope(), Intro,
|
|
|
|
/*AfterAmpersand=*/false);
|
2014-05-02 11:43:14 +08:00
|
|
|
cutOffParsing();
|
2012-02-15 23:34:24 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-08-04 23:30:47 +08:00
|
|
|
return DiagResult(diag::err_expected_comma_or_rsquare);
|
2012-02-15 23:34:24 +08:00
|
|
|
}
|
2011-08-04 23:30:47 +08:00
|
|
|
ConsumeToken();
|
|
|
|
}
|
|
|
|
|
2012-02-15 23:34:24 +08:00
|
|
|
if (Tok.is(tok::code_completion)) {
|
|
|
|
// If we're in Objective-C++ and we have a bare '[', then this is more
|
|
|
|
// likely to be a message receiver.
|
2012-03-11 15:00:24 +08:00
|
|
|
if (getLangOpts().ObjC1 && first)
|
2012-02-15 23:34:24 +08:00
|
|
|
Actions.CodeCompleteObjCMessageReceiver(getCurScope());
|
|
|
|
else
|
|
|
|
Actions.CodeCompleteLambdaIntroducer(getCurScope(), Intro,
|
|
|
|
/*AfterAmpersand=*/false);
|
2014-05-02 11:43:14 +08:00
|
|
|
cutOffParsing();
|
2012-02-15 23:34:24 +08:00
|
|
|
break;
|
|
|
|
}
|
2011-08-04 23:30:47 +08:00
|
|
|
|
2012-02-15 23:34:24 +08:00
|
|
|
first = false;
|
|
|
|
|
2011-08-04 23:30:47 +08:00
|
|
|
// Parse capture.
|
|
|
|
LambdaCaptureKind Kind = LCK_ByCopy;
|
2015-11-11 09:36:17 +08:00
|
|
|
LambdaCaptureInitKind InitKind = LambdaCaptureInitKind::NoInit;
|
2011-08-04 23:30:47 +08:00
|
|
|
SourceLocation Loc;
|
2014-05-21 14:02:52 +08:00
|
|
|
IdentifierInfo *Id = nullptr;
|
2012-02-15 03:27:52 +08:00
|
|
|
SourceLocation EllipsisLoc;
|
2013-05-10 05:36:41 +08:00
|
|
|
ExprResult Init;
|
[Cxx1z] Implement Lambda Capture of *this by Value as [=,*this] (P0018R3)
Implement lambda capture of *this by copy.
For e.g.:
struct A {
int d = 10;
auto foo() { return [*this] (auto a) mutable { d+=a; return d; }; }
};
auto L = A{}.foo(); // A{}'s lifetime is gone.
// Below is still ok, because *this was captured by value.
assert(L(10) == 20);
assert(L(100) == 120);
If the capture was implicit, or [this] (i.e. *this was captured by reference), this code would be otherwise undefined.
Implementation Strategy:
- amend the parser to accept *this in the lambda introducer
- add a new king of capture LCK_StarThis
- teach Sema::CheckCXXThisCapture to handle by copy captures of the
enclosing object (i.e. *this)
- when CheckCXXThisCapture does capture by copy, the corresponding
initializer expression for the closure's data member
direct-initializes it thus making a copy of '*this'.
- in codegen, when assigning to CXXThisValue, if *this was captured by
copy, make sure it points to the corresponding field member, and
not, unlike when captured by reference, what the field member points
to.
- mark feature as implemented in svn
Much gratitude to Richard Smith for his carefully illuminating reviews!
llvm-svn: 263921
2016-03-21 17:25:37 +08:00
|
|
|
|
|
|
|
if (Tok.is(tok::star)) {
|
|
|
|
Loc = ConsumeToken();
|
|
|
|
if (Tok.is(tok::kw_this)) {
|
|
|
|
ConsumeToken();
|
|
|
|
Kind = LCK_StarThis;
|
|
|
|
} else {
|
|
|
|
return DiagResult(diag::err_expected_star_this_capture);
|
|
|
|
}
|
|
|
|
} else if (Tok.is(tok::kw_this)) {
|
2011-08-04 23:30:47 +08:00
|
|
|
Kind = LCK_This;
|
|
|
|
Loc = ConsumeToken();
|
|
|
|
} else {
|
|
|
|
if (Tok.is(tok::amp)) {
|
|
|
|
Kind = LCK_ByRef;
|
|
|
|
ConsumeToken();
|
2012-02-15 23:34:24 +08:00
|
|
|
|
|
|
|
if (Tok.is(tok::code_completion)) {
|
|
|
|
Actions.CodeCompleteLambdaIntroducer(getCurScope(), Intro,
|
|
|
|
/*AfterAmpersand=*/true);
|
2014-05-02 11:43:14 +08:00
|
|
|
cutOffParsing();
|
2012-02-15 23:34:24 +08:00
|
|
|
break;
|
|
|
|
}
|
2011-08-04 23:30:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (Tok.is(tok::identifier)) {
|
|
|
|
Id = Tok.getIdentifierInfo();
|
|
|
|
Loc = ConsumeToken();
|
|
|
|
} else if (Tok.is(tok::kw_this)) {
|
|
|
|
// FIXME: If we want to suggest a fixit here, will need to return more
|
|
|
|
// than just DiagnosticID. Perhaps full DiagnosticBuilder that can be
|
|
|
|
// Clear()ed to prevent emission in case of tentative parsing?
|
|
|
|
return DiagResult(diag::err_this_captured_by_reference);
|
|
|
|
} else {
|
|
|
|
return DiagResult(diag::err_expected_capture);
|
|
|
|
}
|
2013-05-10 05:36:41 +08:00
|
|
|
|
|
|
|
if (Tok.is(tok::l_paren)) {
|
|
|
|
BalancedDelimiterTracker Parens(*this, tok::l_paren);
|
|
|
|
Parens.consumeOpen();
|
|
|
|
|
2015-11-11 09:36:17 +08:00
|
|
|
InitKind = LambdaCaptureInitKind::DirectInit;
|
|
|
|
|
2013-05-10 05:36:41 +08:00
|
|
|
ExprVector Exprs;
|
|
|
|
CommaLocsTy Commas;
|
2013-05-22 06:21:19 +08:00
|
|
|
if (SkippedInits) {
|
|
|
|
Parens.skipToEnd();
|
|
|
|
*SkippedInits = true;
|
|
|
|
} else if (ParseExpressionList(Exprs, Commas)) {
|
2013-05-10 05:36:41 +08:00
|
|
|
Parens.skipToEnd();
|
|
|
|
Init = ExprError();
|
|
|
|
} else {
|
|
|
|
Parens.consumeClose();
|
|
|
|
Init = Actions.ActOnParenListExpr(Parens.getOpenLocation(),
|
|
|
|
Parens.getCloseLocation(),
|
|
|
|
Exprs);
|
|
|
|
}
|
2015-06-18 18:59:26 +08:00
|
|
|
} else if (Tok.isOneOf(tok::l_brace, tok::equal)) {
|
2013-12-05 09:40:41 +08:00
|
|
|
// Each lambda init-capture forms its own full expression, which clears
|
|
|
|
// Actions.MaybeODRUseExprs. So create an expression evaluation context
|
|
|
|
// to save the necessary state, and restore it later.
|
|
|
|
EnterExpressionEvaluationContext EC(Actions,
|
|
|
|
Sema::PotentiallyEvaluated);
|
2015-11-11 09:36:17 +08:00
|
|
|
|
|
|
|
if (TryConsumeToken(tok::equal))
|
|
|
|
InitKind = LambdaCaptureInitKind::CopyInit;
|
|
|
|
else
|
|
|
|
InitKind = LambdaCaptureInitKind::ListInit;
|
2015-02-11 10:41:33 +08:00
|
|
|
|
|
|
|
if (!SkippedInits) {
|
2013-05-22 06:21:19 +08:00
|
|
|
Init = ParseInitializer();
|
2015-02-11 10:41:33 +08:00
|
|
|
} else if (Tok.is(tok::l_brace)) {
|
2013-05-22 06:21:19 +08:00
|
|
|
BalancedDelimiterTracker Braces(*this, tok::l_brace);
|
|
|
|
Braces.consumeOpen();
|
|
|
|
Braces.skipToEnd();
|
|
|
|
*SkippedInits = true;
|
|
|
|
} else {
|
|
|
|
// We're disambiguating this:
|
|
|
|
//
|
|
|
|
// [..., x = expr
|
|
|
|
//
|
|
|
|
// We need to find the end of the following expression in order to
|
2014-04-13 12:31:48 +08:00
|
|
|
// determine whether this is an Obj-C message send's receiver, a
|
|
|
|
// C99 designator, or a lambda init-capture.
|
2013-05-22 06:21:19 +08:00
|
|
|
//
|
|
|
|
// Parse the expression to find where it ends, and annotate it back
|
|
|
|
// onto the tokens. We would have parsed this expression the same way
|
|
|
|
// in either case: both the RHS of an init-capture and the RHS of an
|
|
|
|
// assignment expression are parsed as an initializer-clause, and in
|
|
|
|
// neither case can anything be added to the scope between the '[' and
|
|
|
|
// here.
|
|
|
|
//
|
|
|
|
// FIXME: This is horrible. Adding a mechanism to skip an expression
|
|
|
|
// would be much cleaner.
|
|
|
|
// FIXME: If there is a ',' before the next ']' or ':', we can skip to
|
|
|
|
// that instead. (And if we see a ':' with no matching '?', we can
|
|
|
|
// classify this as an Obj-C message send.)
|
|
|
|
SourceLocation StartLoc = Tok.getLocation();
|
|
|
|
InMessageExpressionRAIIObject MaybeInMessageExpression(*this, true);
|
|
|
|
Init = ParseInitializer();
|
2016-12-20 10:11:29 +08:00
|
|
|
if (!Init.isInvalid())
|
|
|
|
Init = Actions.CorrectDelayedTyposInExpr(Init.get());
|
2013-05-22 06:21:19 +08:00
|
|
|
|
|
|
|
if (Tok.getLocation() != StartLoc) {
|
|
|
|
// Back out the lexing of the token after the initializer.
|
|
|
|
PP.RevertCachedTokens(1);
|
|
|
|
|
|
|
|
// Replace the consumed tokens with an appropriate annotation.
|
|
|
|
Tok.setLocation(StartLoc);
|
|
|
|
Tok.setKind(tok::annot_primary_expr);
|
|
|
|
setExprAnnotation(Tok, Init);
|
|
|
|
Tok.setAnnotationEndLoc(PP.getLastCachedTokenLocation());
|
|
|
|
PP.AnnotateCachedTokens(Tok);
|
|
|
|
|
|
|
|
// Consume the annotated initializer.
|
|
|
|
ConsumeToken();
|
|
|
|
}
|
|
|
|
}
|
2013-12-17 22:12:37 +08:00
|
|
|
} else
|
|
|
|
TryConsumeToken(tok::ellipsis, EllipsisLoc);
|
2011-08-04 23:30:47 +08:00
|
|
|
}
|
2013-12-05 09:40:41 +08:00
|
|
|
// If this is an init capture, process the initialization expression
|
|
|
|
// right away. For lambda init-captures such as the following:
|
|
|
|
// const int x = 10;
|
|
|
|
// auto L = [i = x+1](int a) {
|
|
|
|
// return [j = x+2,
|
|
|
|
// &k = x](char b) { };
|
|
|
|
// };
|
|
|
|
// keep in mind that each lambda init-capture has to have:
|
|
|
|
// - its initialization expression executed in the context
|
|
|
|
// of the enclosing/parent decl-context.
|
|
|
|
// - but the variable itself has to be 'injected' into the
|
|
|
|
// decl-context of its lambda's call-operator (which has
|
|
|
|
// not yet been created).
|
|
|
|
// Each init-expression is a full-expression that has to get
|
|
|
|
// Sema-analyzed (for capturing etc.) before its lambda's
|
|
|
|
// call-operator's decl-context, scope & scopeinfo are pushed on their
|
|
|
|
// respective stacks. Thus if any variable is odr-used in the init-capture
|
|
|
|
// it will correctly get captured in the enclosing lambda, if one exists.
|
|
|
|
// The init-variables above are created later once the lambdascope and
|
|
|
|
// call-operators decl-context is pushed onto its respective stack.
|
|
|
|
|
|
|
|
// Since the lambda init-capture's initializer expression occurs in the
|
|
|
|
// context of the enclosing function or lambda, therefore we can not wait
|
|
|
|
// till a lambda scope has been pushed on before deciding whether the
|
|
|
|
// variable needs to be captured. We also need to process all
|
|
|
|
// lvalue-to-rvalue conversions and discarded-value conversions,
|
|
|
|
// so that we can avoid capturing certain constant variables.
|
|
|
|
// For e.g.,
|
|
|
|
// void test() {
|
|
|
|
// const int x = 10;
|
|
|
|
// auto L = [&z = x](char a) { <-- don't capture by the current lambda
|
|
|
|
// return [y = x](int i) { <-- don't capture by enclosing lambda
|
|
|
|
// return y;
|
|
|
|
// }
|
|
|
|
// };
|
2016-07-23 07:36:59 +08:00
|
|
|
// }
|
2013-12-05 09:40:41 +08:00
|
|
|
// If x was not const, the second use would require 'L' to capture, and
|
|
|
|
// that would be an error.
|
|
|
|
|
2015-11-11 09:36:17 +08:00
|
|
|
ParsedType InitCaptureType;
|
2013-12-05 09:40:41 +08:00
|
|
|
if (Init.isUsable()) {
|
|
|
|
// Get the pointer and store it in an lvalue, so we can use it as an
|
|
|
|
// out argument.
|
|
|
|
Expr *InitExpr = Init.get();
|
|
|
|
// This performs any lvalue-to-rvalue conversions if necessary, which
|
|
|
|
// can affect what gets captured in the containing decl-context.
|
2015-11-11 09:36:17 +08:00
|
|
|
InitCaptureType = Actions.actOnLambdaInitCaptureInitialization(
|
|
|
|
Loc, Kind == LCK_ByRef, Id, InitKind, InitExpr);
|
2013-12-05 09:40:41 +08:00
|
|
|
Init = InitExpr;
|
|
|
|
}
|
2015-11-11 09:36:17 +08:00
|
|
|
Intro.addCapture(Kind, Loc, Id, EllipsisLoc, InitKind, Init,
|
|
|
|
InitCaptureType);
|
2011-08-04 23:30:47 +08:00
|
|
|
}
|
|
|
|
|
2011-10-13 00:37:45 +08:00
|
|
|
T.consumeClose();
|
|
|
|
Intro.Range.setEnd(T.getCloseLocation());
|
2011-08-04 23:30:47 +08:00
|
|
|
return DiagResult();
|
|
|
|
}
|
|
|
|
|
2012-02-15 23:34:24 +08:00
|
|
|
/// TryParseLambdaIntroducer - Tentatively parse a lambda introducer.
|
2011-08-04 23:30:47 +08:00
|
|
|
///
|
|
|
|
/// Returns true if it hit something unexpected.
|
|
|
|
bool Parser::TryParseLambdaIntroducer(LambdaIntroducer &Intro) {
|
|
|
|
TentativeParsingAction PA(*this);
|
|
|
|
|
2013-05-22 06:21:19 +08:00
|
|
|
bool SkippedInits = false;
|
|
|
|
Optional<unsigned> DiagID(ParseLambdaIntroducer(Intro, &SkippedInits));
|
2011-08-04 23:30:47 +08:00
|
|
|
|
|
|
|
if (DiagID) {
|
|
|
|
PA.Revert();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-05-22 06:21:19 +08:00
|
|
|
if (SkippedInits) {
|
|
|
|
// Parse it again, but this time parse the init-captures too.
|
|
|
|
PA.Revert();
|
|
|
|
Intro = LambdaIntroducer();
|
|
|
|
DiagID = ParseLambdaIntroducer(Intro);
|
|
|
|
assert(!DiagID && "parsing lambda-introducer failed on reparse");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-08-04 23:30:47 +08:00
|
|
|
PA.Commit();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-03-27 00:11:37 +08:00
|
|
|
static void
|
|
|
|
tryConsumeMutableOrConstexprToken(Parser &P, SourceLocation &MutableLoc,
|
|
|
|
SourceLocation &ConstexprLoc,
|
|
|
|
SourceLocation &DeclEndLoc) {
|
|
|
|
assert(MutableLoc.isInvalid());
|
|
|
|
assert(ConstexprLoc.isInvalid());
|
|
|
|
// Consume constexpr-opt mutable-opt in any sequence, and set the DeclEndLoc
|
|
|
|
// to the final of those locations. Emit an error if we have multiple
|
|
|
|
// copies of those keywords and recover.
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
switch (P.getCurToken().getKind()) {
|
|
|
|
case tok::kw_mutable: {
|
|
|
|
if (MutableLoc.isValid()) {
|
|
|
|
P.Diag(P.getCurToken().getLocation(),
|
|
|
|
diag::err_lambda_decl_specifier_repeated)
|
|
|
|
<< 0 << FixItHint::CreateRemoval(P.getCurToken().getLocation());
|
|
|
|
}
|
|
|
|
MutableLoc = P.ConsumeToken();
|
|
|
|
DeclEndLoc = MutableLoc;
|
|
|
|
break /*switch*/;
|
|
|
|
}
|
|
|
|
case tok::kw_constexpr:
|
|
|
|
if (ConstexprLoc.isValid()) {
|
|
|
|
P.Diag(P.getCurToken().getLocation(),
|
|
|
|
diag::err_lambda_decl_specifier_repeated)
|
|
|
|
<< 1 << FixItHint::CreateRemoval(P.getCurToken().getLocation());
|
|
|
|
}
|
|
|
|
ConstexprLoc = P.ConsumeToken();
|
|
|
|
DeclEndLoc = ConstexprLoc;
|
|
|
|
break /*switch*/;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
addConstexprToLambdaDeclSpecifier(Parser &P, SourceLocation ConstexprLoc,
|
|
|
|
DeclSpec &DS) {
|
|
|
|
if (ConstexprLoc.isValid()) {
|
|
|
|
P.Diag(ConstexprLoc, !P.getLangOpts().CPlusPlus1z
|
|
|
|
? diag::ext_constexpr_on_lambda_cxx1z
|
|
|
|
: diag::warn_cxx14_compat_constexpr_on_lambda);
|
|
|
|
const char *PrevSpec = nullptr;
|
|
|
|
unsigned DiagID = 0;
|
|
|
|
DS.SetConstexprSpec(ConstexprLoc, PrevSpec, DiagID);
|
|
|
|
assert(PrevSpec == nullptr && DiagID == 0 &&
|
|
|
|
"Constexpr cannot have been set previously!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-04 23:30:47 +08:00
|
|
|
/// ParseLambdaExpressionAfterIntroducer - Parse the rest of a lambda
|
|
|
|
/// expression.
|
|
|
|
ExprResult Parser::ParseLambdaExpressionAfterIntroducer(
|
|
|
|
LambdaIntroducer &Intro) {
|
2012-01-04 10:40:39 +08:00
|
|
|
SourceLocation LambdaBeginLoc = Intro.Range.getBegin();
|
|
|
|
Diag(LambdaBeginLoc, diag::warn_cxx98_compat_lambda);
|
|
|
|
|
|
|
|
PrettyStackTraceLoc CrashInfo(PP.getSourceManager(), LambdaBeginLoc,
|
|
|
|
"lambda expression parsing");
|
|
|
|
|
Implement a rudimentary form of generic lambdas.
Specifically, the following features are not included in this commit:
- any sort of capturing within generic lambdas
- generic lambdas within template functions and nested
within other generic lambdas
- conversion operator for captureless lambdas
- ensuring all visitors are generic lambda aware
(Although I have gotten some useful feedback on my patches of the above and will be incorporating that as I submit those patches for commit)
As an example of what compiles through this commit:
template <class F1, class F2>
struct overload : F1, F2 {
using F1::operator();
using F2::operator();
overload(F1 f1, F2 f2) : F1(f1), F2(f2) { }
};
auto Recursive = [](auto Self, auto h, auto ... rest) {
return 1 + Self(Self, rest...);
};
auto Base = [](auto Self, auto h) {
return 1;
};
overload<decltype(Base), decltype(Recursive)> O(Base, Recursive);
int num_params = O(O, 5, 3, "abc", 3.14, 'a');
Please see attached tests for more examples.
This patch has been reviewed by Doug and Richard. Minor changes (non-functionality affecting) have been made since both of them formally looked at it, but the changes involve removal of supernumerary return type deduction changes (since they are now redundant, with richard having committed a recent patch to address return type deduction for C++11 lambdas using C++14 semantics).
Some implementation notes:
- Add a new Declarator context => LambdaExprParameterContext to
clang::Declarator to allow the use of 'auto' in declaring generic
lambda parameters
- Add various helpers to CXXRecordDecl to facilitate identifying
and querying a closure class
- LambdaScopeInfo (which maintains the current lambda's Sema state)
was augmented to house the current depth of the template being
parsed (id est the Parser calls Sema::RecordParsingTemplateParameterDepth)
so that SemaType.cpp::ConvertDeclSpecToType may use it to immediately
generate a template-parameter-type when 'auto' is parsed in a generic
lambda parameter context. (i.e we do NOT use AutoType deduced to
a template parameter type - Richard seemed ok with this approach).
We encode that this template type was generated from an auto by simply
adding $auto to the name which can be used for better diagnostics if needed.
- SemaLambda.h was added to hold some common lambda utility
functions (this file is likely to grow ...)
- Teach Sema::ActOnStartOfFunctionDef to check whether it
is being called to instantiate a generic lambda's call
operator, and if so, push an appropriately prepared
LambdaScopeInfo object on the stack.
- various tests were added - but much more will be needed.
There is obviously more work to be done, and both Richard (weakly) and Doug (strongly)
have requested that LambdaExpr be removed form the CXXRecordDecl LambdaDefinitionaData
in a future patch which is forthcoming.
A greatful thanks to all reviewers including Eli Friedman, James Dennett,
and especially the two gracious wizards (Richard Smith and Doug Gregor)
who spent hours providing feedback (in person in Chicago and on the mailing lists).
And yet I am certain that I have allowed unidentified bugs to creep in; bugs, that I will do my best to slay, once identified!
Thanks!
llvm-svn: 191453
2013-09-27 03:54:12 +08:00
|
|
|
|
|
|
|
|
2013-05-10 05:36:41 +08:00
|
|
|
// FIXME: Call into Actions to add any init-capture declarations to the
|
|
|
|
// scope while parsing the lambda-declarator and compound-statement.
|
|
|
|
|
2011-08-04 23:30:47 +08:00
|
|
|
// Parse lambda-declarator[opt].
|
|
|
|
DeclSpec DS(AttrFactory);
|
2012-01-04 12:41:38 +08:00
|
|
|
Declarator D(DS, Declarator::LambdaExprContext);
|
Implement a rudimentary form of generic lambdas.
Specifically, the following features are not included in this commit:
- any sort of capturing within generic lambdas
- generic lambdas within template functions and nested
within other generic lambdas
- conversion operator for captureless lambdas
- ensuring all visitors are generic lambda aware
(Although I have gotten some useful feedback on my patches of the above and will be incorporating that as I submit those patches for commit)
As an example of what compiles through this commit:
template <class F1, class F2>
struct overload : F1, F2 {
using F1::operator();
using F2::operator();
overload(F1 f1, F2 f2) : F1(f1), F2(f2) { }
};
auto Recursive = [](auto Self, auto h, auto ... rest) {
return 1 + Self(Self, rest...);
};
auto Base = [](auto Self, auto h) {
return 1;
};
overload<decltype(Base), decltype(Recursive)> O(Base, Recursive);
int num_params = O(O, 5, 3, "abc", 3.14, 'a');
Please see attached tests for more examples.
This patch has been reviewed by Doug and Richard. Minor changes (non-functionality affecting) have been made since both of them formally looked at it, but the changes involve removal of supernumerary return type deduction changes (since they are now redundant, with richard having committed a recent patch to address return type deduction for C++11 lambdas using C++14 semantics).
Some implementation notes:
- Add a new Declarator context => LambdaExprParameterContext to
clang::Declarator to allow the use of 'auto' in declaring generic
lambda parameters
- Add various helpers to CXXRecordDecl to facilitate identifying
and querying a closure class
- LambdaScopeInfo (which maintains the current lambda's Sema state)
was augmented to house the current depth of the template being
parsed (id est the Parser calls Sema::RecordParsingTemplateParameterDepth)
so that SemaType.cpp::ConvertDeclSpecToType may use it to immediately
generate a template-parameter-type when 'auto' is parsed in a generic
lambda parameter context. (i.e we do NOT use AutoType deduced to
a template parameter type - Richard seemed ok with this approach).
We encode that this template type was generated from an auto by simply
adding $auto to the name which can be used for better diagnostics if needed.
- SemaLambda.h was added to hold some common lambda utility
functions (this file is likely to grow ...)
- Teach Sema::ActOnStartOfFunctionDef to check whether it
is being called to instantiate a generic lambda's call
operator, and if so, push an appropriately prepared
LambdaScopeInfo object on the stack.
- various tests were added - but much more will be needed.
There is obviously more work to be done, and both Richard (weakly) and Doug (strongly)
have requested that LambdaExpr be removed form the CXXRecordDecl LambdaDefinitionaData
in a future patch which is forthcoming.
A greatful thanks to all reviewers including Eli Friedman, James Dennett,
and especially the two gracious wizards (Richard Smith and Doug Gregor)
who spent hours providing feedback (in person in Chicago and on the mailing lists).
And yet I am certain that I have allowed unidentified bugs to creep in; bugs, that I will do my best to slay, once identified!
Thanks!
llvm-svn: 191453
2013-09-27 03:54:12 +08:00
|
|
|
TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth);
|
2016-10-01 01:14:48 +08:00
|
|
|
Actions.PushLambdaScope();
|
|
|
|
|
|
|
|
ParsedAttributes Attr(AttrFactory);
|
|
|
|
SourceLocation DeclLoc = Tok.getLocation();
|
|
|
|
if (getLangOpts().CUDA) {
|
|
|
|
// In CUDA code, GNU attributes are allowed to appear immediately after the
|
|
|
|
// "[...]", even if there is no "(...)" before the lambda body.
|
2016-10-01 03:55:48 +08:00
|
|
|
MaybeParseGNUAttributes(D);
|
2016-10-01 01:14:48 +08:00
|
|
|
}
|
2011-08-04 23:30:47 +08:00
|
|
|
|
2016-10-01 03:55:55 +08:00
|
|
|
// Helper to emit a warning if we see a CUDA host/device/global attribute
|
|
|
|
// after '(...)'. nvcc doesn't accept this.
|
|
|
|
auto WarnIfHasCUDATargetAttr = [&] {
|
|
|
|
if (getLangOpts().CUDA)
|
|
|
|
for (auto *A = Attr.getList(); A != nullptr; A = A->getNext())
|
|
|
|
if (A->getKind() == AttributeList::AT_CUDADevice ||
|
|
|
|
A->getKind() == AttributeList::AT_CUDAHost ||
|
|
|
|
A->getKind() == AttributeList::AT_CUDAGlobal)
|
|
|
|
Diag(A->getLoc(), diag::warn_cuda_attr_lambda_position)
|
|
|
|
<< A->getName()->getName();
|
|
|
|
};
|
|
|
|
|
2015-01-09 13:10:55 +08:00
|
|
|
TypeResult TrailingReturnType;
|
2011-08-04 23:30:47 +08:00
|
|
|
if (Tok.is(tok::l_paren)) {
|
|
|
|
ParseScope PrototypeScope(this,
|
|
|
|
Scope::FunctionPrototypeScope |
|
2013-01-29 06:42:45 +08:00
|
|
|
Scope::FunctionDeclarationScope |
|
2011-08-04 23:30:47 +08:00
|
|
|
Scope::DeclScope);
|
|
|
|
|
2011-10-13 00:37:45 +08:00
|
|
|
BalancedDelimiterTracker T(*this, tok::l_paren);
|
|
|
|
T.consumeOpen();
|
2012-10-05 05:42:10 +08:00
|
|
|
SourceLocation LParenLoc = T.getOpenLocation();
|
2011-08-04 23:30:47 +08:00
|
|
|
|
|
|
|
// Parse parameter-declaration-clause.
|
2013-01-13 03:30:44 +08:00
|
|
|
SmallVector<DeclaratorChunk::ParamInfo, 16> ParamInfo;
|
2011-08-04 23:30:47 +08:00
|
|
|
SourceLocation EllipsisLoc;
|
Implement a rudimentary form of generic lambdas.
Specifically, the following features are not included in this commit:
- any sort of capturing within generic lambdas
- generic lambdas within template functions and nested
within other generic lambdas
- conversion operator for captureless lambdas
- ensuring all visitors are generic lambda aware
(Although I have gotten some useful feedback on my patches of the above and will be incorporating that as I submit those patches for commit)
As an example of what compiles through this commit:
template <class F1, class F2>
struct overload : F1, F2 {
using F1::operator();
using F2::operator();
overload(F1 f1, F2 f2) : F1(f1), F2(f2) { }
};
auto Recursive = [](auto Self, auto h, auto ... rest) {
return 1 + Self(Self, rest...);
};
auto Base = [](auto Self, auto h) {
return 1;
};
overload<decltype(Base), decltype(Recursive)> O(Base, Recursive);
int num_params = O(O, 5, 3, "abc", 3.14, 'a');
Please see attached tests for more examples.
This patch has been reviewed by Doug and Richard. Minor changes (non-functionality affecting) have been made since both of them formally looked at it, but the changes involve removal of supernumerary return type deduction changes (since they are now redundant, with richard having committed a recent patch to address return type deduction for C++11 lambdas using C++14 semantics).
Some implementation notes:
- Add a new Declarator context => LambdaExprParameterContext to
clang::Declarator to allow the use of 'auto' in declaring generic
lambda parameters
- Add various helpers to CXXRecordDecl to facilitate identifying
and querying a closure class
- LambdaScopeInfo (which maintains the current lambda's Sema state)
was augmented to house the current depth of the template being
parsed (id est the Parser calls Sema::RecordParsingTemplateParameterDepth)
so that SemaType.cpp::ConvertDeclSpecToType may use it to immediately
generate a template-parameter-type when 'auto' is parsed in a generic
lambda parameter context. (i.e we do NOT use AutoType deduced to
a template parameter type - Richard seemed ok with this approach).
We encode that this template type was generated from an auto by simply
adding $auto to the name which can be used for better diagnostics if needed.
- SemaLambda.h was added to hold some common lambda utility
functions (this file is likely to grow ...)
- Teach Sema::ActOnStartOfFunctionDef to check whether it
is being called to instantiate a generic lambda's call
operator, and if so, push an appropriately prepared
LambdaScopeInfo object on the stack.
- various tests were added - but much more will be needed.
There is obviously more work to be done, and both Richard (weakly) and Doug (strongly)
have requested that LambdaExpr be removed form the CXXRecordDecl LambdaDefinitionaData
in a future patch which is forthcoming.
A greatful thanks to all reviewers including Eli Friedman, James Dennett,
and especially the two gracious wizards (Richard Smith and Doug Gregor)
who spent hours providing feedback (in person in Chicago and on the mailing lists).
And yet I am certain that I have allowed unidentified bugs to creep in; bugs, that I will do my best to slay, once identified!
Thanks!
llvm-svn: 191453
2013-09-27 03:54:12 +08:00
|
|
|
|
|
|
|
if (Tok.isNot(tok::r_paren)) {
|
|
|
|
Actions.RecordParsingTemplateParameterDepth(TemplateParameterDepth);
|
2011-08-04 23:30:47 +08:00
|
|
|
ParseParameterDeclarationClause(D, Attr, ParamInfo, EllipsisLoc);
|
Implement a rudimentary form of generic lambdas.
Specifically, the following features are not included in this commit:
- any sort of capturing within generic lambdas
- generic lambdas within template functions and nested
within other generic lambdas
- conversion operator for captureless lambdas
- ensuring all visitors are generic lambda aware
(Although I have gotten some useful feedback on my patches of the above and will be incorporating that as I submit those patches for commit)
As an example of what compiles through this commit:
template <class F1, class F2>
struct overload : F1, F2 {
using F1::operator();
using F2::operator();
overload(F1 f1, F2 f2) : F1(f1), F2(f2) { }
};
auto Recursive = [](auto Self, auto h, auto ... rest) {
return 1 + Self(Self, rest...);
};
auto Base = [](auto Self, auto h) {
return 1;
};
overload<decltype(Base), decltype(Recursive)> O(Base, Recursive);
int num_params = O(O, 5, 3, "abc", 3.14, 'a');
Please see attached tests for more examples.
This patch has been reviewed by Doug and Richard. Minor changes (non-functionality affecting) have been made since both of them formally looked at it, but the changes involve removal of supernumerary return type deduction changes (since they are now redundant, with richard having committed a recent patch to address return type deduction for C++11 lambdas using C++14 semantics).
Some implementation notes:
- Add a new Declarator context => LambdaExprParameterContext to
clang::Declarator to allow the use of 'auto' in declaring generic
lambda parameters
- Add various helpers to CXXRecordDecl to facilitate identifying
and querying a closure class
- LambdaScopeInfo (which maintains the current lambda's Sema state)
was augmented to house the current depth of the template being
parsed (id est the Parser calls Sema::RecordParsingTemplateParameterDepth)
so that SemaType.cpp::ConvertDeclSpecToType may use it to immediately
generate a template-parameter-type when 'auto' is parsed in a generic
lambda parameter context. (i.e we do NOT use AutoType deduced to
a template parameter type - Richard seemed ok with this approach).
We encode that this template type was generated from an auto by simply
adding $auto to the name which can be used for better diagnostics if needed.
- SemaLambda.h was added to hold some common lambda utility
functions (this file is likely to grow ...)
- Teach Sema::ActOnStartOfFunctionDef to check whether it
is being called to instantiate a generic lambda's call
operator, and if so, push an appropriately prepared
LambdaScopeInfo object on the stack.
- various tests were added - but much more will be needed.
There is obviously more work to be done, and both Richard (weakly) and Doug (strongly)
have requested that LambdaExpr be removed form the CXXRecordDecl LambdaDefinitionaData
in a future patch which is forthcoming.
A greatful thanks to all reviewers including Eli Friedman, James Dennett,
and especially the two gracious wizards (Richard Smith and Doug Gregor)
who spent hours providing feedback (in person in Chicago and on the mailing lists).
And yet I am certain that I have allowed unidentified bugs to creep in; bugs, that I will do my best to slay, once identified!
Thanks!
llvm-svn: 191453
2013-09-27 03:54:12 +08:00
|
|
|
// For a generic lambda, each 'auto' within the parameter declaration
|
|
|
|
// clause creates a template type parameter, so increment the depth.
|
|
|
|
if (Actions.getCurGenericLambda())
|
|
|
|
++CurTemplateDepthTracker;
|
|
|
|
}
|
2011-10-13 00:37:45 +08:00
|
|
|
T.consumeClose();
|
2012-10-05 05:42:10 +08:00
|
|
|
SourceLocation RParenLoc = T.getCloseLocation();
|
2016-10-01 03:55:48 +08:00
|
|
|
SourceLocation DeclEndLoc = RParenLoc;
|
2011-08-04 23:30:47 +08:00
|
|
|
|
2014-03-12 08:01:07 +08:00
|
|
|
// GNU-style attributes must be parsed before the mutable specifier to be
|
|
|
|
// compatible with GCC.
|
|
|
|
MaybeParseGNUAttributes(Attr, &DeclEndLoc);
|
|
|
|
|
2015-02-04 16:22:46 +08:00
|
|
|
// MSVC-style attributes must be parsed before the mutable specifier to be
|
|
|
|
// compatible with MSVC.
|
2015-05-21 04:58:33 +08:00
|
|
|
MaybeParseMicrosoftDeclSpecs(Attr, &DeclEndLoc);
|
2015-02-04 16:22:46 +08:00
|
|
|
|
2016-03-27 00:11:37 +08:00
|
|
|
// Parse mutable-opt and/or constexpr-opt, and update the DeclEndLoc.
|
2011-08-04 23:30:47 +08:00
|
|
|
SourceLocation MutableLoc;
|
2016-03-27 00:11:37 +08:00
|
|
|
SourceLocation ConstexprLoc;
|
|
|
|
tryConsumeMutableOrConstexprToken(*this, MutableLoc, ConstexprLoc,
|
|
|
|
DeclEndLoc);
|
|
|
|
|
|
|
|
addConstexprToLambdaDeclSpecifier(*this, ConstexprLoc, DS);
|
2011-08-04 23:30:47 +08:00
|
|
|
|
|
|
|
// Parse exception-specification[opt].
|
|
|
|
ExceptionSpecificationType ESpecType = EST_None;
|
|
|
|
SourceRange ESpecRange;
|
2013-01-13 03:30:44 +08:00
|
|
|
SmallVector<ParsedType, 2> DynamicExceptions;
|
|
|
|
SmallVector<SourceRange, 2> DynamicExceptionRanges;
|
2011-08-04 23:30:47 +08:00
|
|
|
ExprResult NoexceptExpr;
|
2014-11-14 04:01:57 +08:00
|
|
|
CachedTokens *ExceptionSpecTokens;
|
|
|
|
ESpecType = tryParseExceptionSpecification(/*Delayed=*/false,
|
|
|
|
ESpecRange,
|
2012-04-17 02:27:27 +08:00
|
|
|
DynamicExceptions,
|
|
|
|
DynamicExceptionRanges,
|
2014-11-14 04:01:57 +08:00
|
|
|
NoexceptExpr,
|
|
|
|
ExceptionSpecTokens);
|
2011-08-04 23:30:47 +08:00
|
|
|
|
|
|
|
if (ESpecType != EST_None)
|
|
|
|
DeclEndLoc = ESpecRange.getEnd();
|
|
|
|
|
|
|
|
// Parse attribute-specifier[opt].
|
2013-01-02 20:01:23 +08:00
|
|
|
MaybeParseCXX11Attributes(Attr, &DeclEndLoc);
|
2011-08-04 23:30:47 +08:00
|
|
|
|
2012-10-05 05:42:10 +08:00
|
|
|
SourceLocation FunLocalRangeEnd = DeclEndLoc;
|
|
|
|
|
2011-08-04 23:30:47 +08:00
|
|
|
// Parse trailing-return-type[opt].
|
|
|
|
if (Tok.is(tok::arrow)) {
|
2012-10-05 05:42:10 +08:00
|
|
|
FunLocalRangeEnd = Tok.getLocation();
|
2011-08-04 23:30:47 +08:00
|
|
|
SourceRange Range;
|
2012-06-12 09:51:59 +08:00
|
|
|
TrailingReturnType = ParseTrailingReturnType(Range);
|
2011-08-04 23:30:47 +08:00
|
|
|
if (Range.getEnd().isValid())
|
|
|
|
DeclEndLoc = Range.getEnd();
|
|
|
|
}
|
|
|
|
|
|
|
|
PrototypeScope.Exit();
|
|
|
|
|
2016-10-01 03:55:55 +08:00
|
|
|
WarnIfHasCUDATargetAttr();
|
|
|
|
|
2012-10-05 05:42:10 +08:00
|
|
|
SourceLocation NoLoc;
|
2011-08-04 23:30:47 +08:00
|
|
|
D.AddTypeInfo(DeclaratorChunk::getFunction(/*hasProto=*/true,
|
2012-10-05 05:42:10 +08:00
|
|
|
/*isAmbiguous=*/false,
|
|
|
|
LParenLoc,
|
2011-08-04 23:30:47 +08:00
|
|
|
ParamInfo.data(), ParamInfo.size(),
|
2012-10-05 05:42:10 +08:00
|
|
|
EllipsisLoc, RParenLoc,
|
2011-08-04 23:30:47 +08:00
|
|
|
DS.getTypeQualifiers(),
|
|
|
|
/*RefQualifierIsLValueRef=*/true,
|
2012-10-05 05:42:10 +08:00
|
|
|
/*RefQualifierLoc=*/NoLoc,
|
|
|
|
/*ConstQualifierLoc=*/NoLoc,
|
|
|
|
/*VolatileQualifierLoc=*/NoLoc,
|
2014-10-21 01:32:04 +08:00
|
|
|
/*RestrictQualifierLoc=*/NoLoc,
|
2011-08-04 23:30:47 +08:00
|
|
|
MutableLoc,
|
2015-08-26 12:19:36 +08:00
|
|
|
ESpecType, ESpecRange,
|
2011-08-04 23:30:47 +08:00
|
|
|
DynamicExceptions.data(),
|
|
|
|
DynamicExceptionRanges.data(),
|
|
|
|
DynamicExceptions.size(),
|
|
|
|
NoexceptExpr.isUsable() ?
|
2014-05-21 14:02:52 +08:00
|
|
|
NoexceptExpr.get() : nullptr,
|
2014-11-14 04:01:57 +08:00
|
|
|
/*ExceptionSpecTokens*/nullptr,
|
Store decls in prototypes on the declarator instead of in the AST
This saves two pointers from FunctionDecl that were being used for some
rare and questionable C-only functionality. The DeclsInPrototypeScope
ArrayRef was added in r151712 in order to parse this kind of C code:
enum e {x, y};
int f(enum {y, x} n) {
return x; // should return 1, not 0
}
The challenge is that we parse 'int f(enum {y, x} n)' it its own
function prototype scope that gets popped before we build the
FunctionDecl for 'f'. The original change was doing two questionable
things:
1. Saving all tag decls introduced in prototype scope on a TU-global
Sema variable. This is problematic when you have cases like this, where
'x' and 'y' shouldn't be visible in 'f':
void f(void (*fp)(enum { x, y } e)) { /* no x */ }
This patch fixes that, so now 'f' can't see 'x', which is consistent
with GCC.
2. Storing the decls in FunctionDecl in ActOnFunctionDeclarator so that
they could be used in ActOnStartOfFunctionDef. This is just an
inefficient way to move information around. The AST lives forever, but
the list of non-parameter decls in prototype scope is short lived.
Moving these things to the Declarator solves both of these issues.
Reviewers: rsmith
Subscribers: jmolloy, cfe-commits
Differential Revision: https://reviews.llvm.org/D27279
llvm-svn: 289225
2016-12-10 01:14:05 +08:00
|
|
|
/*DeclsInPrototype=*/None,
|
2012-10-05 05:42:10 +08:00
|
|
|
LParenLoc, FunLocalRangeEnd, D,
|
2011-08-04 23:30:47 +08:00
|
|
|
TrailingReturnType),
|
|
|
|
Attr, DeclEndLoc);
|
2016-03-27 00:11:37 +08:00
|
|
|
} else if (Tok.isOneOf(tok::kw_mutable, tok::arrow, tok::kw___attribute,
|
|
|
|
tok::kw_constexpr) ||
|
2014-03-11 21:03:15 +08:00
|
|
|
(Tok.is(tok::l_square) && NextToken().is(tok::l_square))) {
|
|
|
|
// It's common to forget that one needs '()' before 'mutable', an attribute
|
|
|
|
// specifier, or the result type. Deal with this.
|
|
|
|
unsigned TokKind = 0;
|
|
|
|
switch (Tok.getKind()) {
|
|
|
|
case tok::kw_mutable: TokKind = 0; break;
|
|
|
|
case tok::arrow: TokKind = 1; break;
|
2014-03-12 08:01:07 +08:00
|
|
|
case tok::kw___attribute:
|
2014-03-11 21:03:15 +08:00
|
|
|
case tok::l_square: TokKind = 2; break;
|
2016-03-27 00:11:37 +08:00
|
|
|
case tok::kw_constexpr: TokKind = 3; break;
|
2014-03-11 21:03:15 +08:00
|
|
|
default: llvm_unreachable("Unknown token kind");
|
|
|
|
}
|
|
|
|
|
2012-02-17 05:53:36 +08:00
|
|
|
Diag(Tok, diag::err_lambda_missing_parens)
|
2014-03-11 21:03:15 +08:00
|
|
|
<< TokKind
|
2012-02-17 05:53:36 +08:00
|
|
|
<< FixItHint::CreateInsertion(Tok.getLocation(), "() ");
|
2016-10-01 03:55:48 +08:00
|
|
|
SourceLocation DeclEndLoc = DeclLoc;
|
2014-03-12 08:01:07 +08:00
|
|
|
|
|
|
|
// GNU-style attributes must be parsed before the mutable specifier to be
|
|
|
|
// compatible with GCC.
|
|
|
|
MaybeParseGNUAttributes(Attr, &DeclEndLoc);
|
|
|
|
|
2012-02-17 05:53:36 +08:00
|
|
|
// Parse 'mutable', if it's there.
|
|
|
|
SourceLocation MutableLoc;
|
|
|
|
if (Tok.is(tok::kw_mutable)) {
|
|
|
|
MutableLoc = ConsumeToken();
|
|
|
|
DeclEndLoc = MutableLoc;
|
|
|
|
}
|
2014-03-11 21:03:15 +08:00
|
|
|
|
|
|
|
// Parse attribute-specifier[opt].
|
|
|
|
MaybeParseCXX11Attributes(Attr, &DeclEndLoc);
|
|
|
|
|
2012-02-17 05:53:36 +08:00
|
|
|
// Parse the return type, if there is one.
|
|
|
|
if (Tok.is(tok::arrow)) {
|
|
|
|
SourceRange Range;
|
2012-06-12 09:51:59 +08:00
|
|
|
TrailingReturnType = ParseTrailingReturnType(Range);
|
2012-02-17 05:53:36 +08:00
|
|
|
if (Range.getEnd().isValid())
|
2015-01-09 13:10:55 +08:00
|
|
|
DeclEndLoc = Range.getEnd();
|
2012-02-17 05:53:36 +08:00
|
|
|
}
|
|
|
|
|
2016-10-01 03:55:55 +08:00
|
|
|
WarnIfHasCUDATargetAttr();
|
|
|
|
|
2012-10-05 05:42:10 +08:00
|
|
|
SourceLocation NoLoc;
|
2012-02-17 05:53:36 +08:00
|
|
|
D.AddTypeInfo(DeclaratorChunk::getFunction(/*hasProto=*/true,
|
2012-10-05 05:42:10 +08:00
|
|
|
/*isAmbiguous=*/false,
|
|
|
|
/*LParenLoc=*/NoLoc,
|
2014-05-21 14:02:52 +08:00
|
|
|
/*Params=*/nullptr,
|
2012-10-05 05:42:10 +08:00
|
|
|
/*NumParams=*/0,
|
|
|
|
/*EllipsisLoc=*/NoLoc,
|
|
|
|
/*RParenLoc=*/NoLoc,
|
|
|
|
/*TypeQuals=*/0,
|
|
|
|
/*RefQualifierIsLValueRef=*/true,
|
|
|
|
/*RefQualifierLoc=*/NoLoc,
|
|
|
|
/*ConstQualifierLoc=*/NoLoc,
|
|
|
|
/*VolatileQualifierLoc=*/NoLoc,
|
2014-10-21 01:32:04 +08:00
|
|
|
/*RestrictQualifierLoc=*/NoLoc,
|
2012-10-05 05:42:10 +08:00
|
|
|
MutableLoc,
|
|
|
|
EST_None,
|
2015-08-26 12:19:36 +08:00
|
|
|
/*ESpecRange=*/SourceRange(),
|
2014-05-21 14:02:52 +08:00
|
|
|
/*Exceptions=*/nullptr,
|
|
|
|
/*ExceptionRanges=*/nullptr,
|
2012-10-05 05:42:10 +08:00
|
|
|
/*NumExceptions=*/0,
|
2014-05-21 14:02:52 +08:00
|
|
|
/*NoexceptExpr=*/nullptr,
|
2014-11-14 04:01:57 +08:00
|
|
|
/*ExceptionSpecTokens=*/nullptr,
|
Store decls in prototypes on the declarator instead of in the AST
This saves two pointers from FunctionDecl that were being used for some
rare and questionable C-only functionality. The DeclsInPrototypeScope
ArrayRef was added in r151712 in order to parse this kind of C code:
enum e {x, y};
int f(enum {y, x} n) {
return x; // should return 1, not 0
}
The challenge is that we parse 'int f(enum {y, x} n)' it its own
function prototype scope that gets popped before we build the
FunctionDecl for 'f'. The original change was doing two questionable
things:
1. Saving all tag decls introduced in prototype scope on a TU-global
Sema variable. This is problematic when you have cases like this, where
'x' and 'y' shouldn't be visible in 'f':
void f(void (*fp)(enum { x, y } e)) { /* no x */ }
This patch fixes that, so now 'f' can't see 'x', which is consistent
with GCC.
2. Storing the decls in FunctionDecl in ActOnFunctionDeclarator so that
they could be used in ActOnStartOfFunctionDef. This is just an
inefficient way to move information around. The AST lives forever, but
the list of non-parameter decls in prototype scope is short lived.
Moving these things to the Declarator solves both of these issues.
Reviewers: rsmith
Subscribers: jmolloy, cfe-commits
Differential Revision: https://reviews.llvm.org/D27279
llvm-svn: 289225
2016-12-10 01:14:05 +08:00
|
|
|
/*DeclsInPrototype=*/None,
|
2012-10-05 05:42:10 +08:00
|
|
|
DeclLoc, DeclEndLoc, D,
|
|
|
|
TrailingReturnType),
|
2012-02-17 05:53:36 +08:00
|
|
|
Attr, DeclEndLoc);
|
2011-08-04 23:30:47 +08:00
|
|
|
}
|
|
|
|
|
2012-01-06 11:05:34 +08:00
|
|
|
// FIXME: Rename BlockScope -> ClosureScope if we decide to continue using
|
|
|
|
// it.
|
2012-02-22 06:51:27 +08:00
|
|
|
unsigned ScopeFlags = Scope::BlockScope | Scope::FnScope | Scope::DeclScope;
|
|
|
|
ParseScope BodyScope(this, ScopeFlags);
|
2012-01-06 11:05:34 +08:00
|
|
|
|
2012-01-05 11:35:19 +08:00
|
|
|
Actions.ActOnStartOfLambdaDefinition(Intro, D, getCurScope());
|
|
|
|
|
2011-08-04 23:30:47 +08:00
|
|
|
// Parse compound-statement.
|
2012-01-04 10:40:39 +08:00
|
|
|
if (!Tok.is(tok::l_brace)) {
|
2011-08-04 23:30:47 +08:00
|
|
|
Diag(Tok, diag::err_expected_lambda_body);
|
2012-01-04 10:40:39 +08:00
|
|
|
Actions.ActOnLambdaError(LambdaBeginLoc, getCurScope());
|
|
|
|
return ExprError();
|
2011-08-04 23:30:47 +08:00
|
|
|
}
|
|
|
|
|
2012-01-04 10:40:39 +08:00
|
|
|
StmtResult Stmt(ParseCompoundStatementBody());
|
|
|
|
BodyScope.Exit();
|
|
|
|
|
2015-01-09 13:10:55 +08:00
|
|
|
if (!Stmt.isInvalid() && !TrailingReturnType.isInvalid())
|
2014-05-29 18:55:11 +08:00
|
|
|
return Actions.ActOnLambdaExpr(LambdaBeginLoc, Stmt.get(), getCurScope());
|
2015-01-09 13:10:55 +08:00
|
|
|
|
2012-01-04 10:46:53 +08:00
|
|
|
Actions.ActOnLambdaError(LambdaBeginLoc, getCurScope());
|
|
|
|
return ExprError();
|
2011-08-04 23:30:47 +08:00
|
|
|
}
|
|
|
|
|
2006-12-05 02:06:35 +08:00
|
|
|
/// ParseCXXCasts - This handles the various ways to cast expressions to another
|
|
|
|
/// type.
|
|
|
|
///
|
|
|
|
/// postfix-expression: [C++ 5.2p1]
|
|
|
|
/// 'dynamic_cast' '<' type-name '>' '(' expression ')'
|
|
|
|
/// 'static_cast' '<' type-name '>' '(' expression ')'
|
|
|
|
/// 'reinterpret_cast' '<' type-name '>' '(' expression ')'
|
|
|
|
/// 'const_cast' '<' type-name '>' '(' expression ')'
|
|
|
|
///
|
2010-08-24 14:29:42 +08:00
|
|
|
ExprResult Parser::ParseCXXCasts() {
|
2006-12-05 02:06:35 +08:00
|
|
|
tok::TokenKind Kind = Tok.getKind();
|
2014-05-21 14:02:52 +08:00
|
|
|
const char *CastName = nullptr; // For error messages
|
2006-12-05 02:06:35 +08:00
|
|
|
|
|
|
|
switch (Kind) {
|
2011-09-24 04:26:49 +08:00
|
|
|
default: llvm_unreachable("Unknown C++ cast!");
|
2006-12-05 02:06:35 +08:00
|
|
|
case tok::kw_const_cast: CastName = "const_cast"; break;
|
|
|
|
case tok::kw_dynamic_cast: CastName = "dynamic_cast"; break;
|
|
|
|
case tok::kw_reinterpret_cast: CastName = "reinterpret_cast"; break;
|
|
|
|
case tok::kw_static_cast: CastName = "static_cast"; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
SourceLocation OpLoc = ConsumeToken();
|
|
|
|
SourceLocation LAngleBracketLoc = Tok.getLocation();
|
|
|
|
|
2011-04-15 05:45:45 +08:00
|
|
|
// Check for "<::" which is parsed as "[:". If found, fix token stream,
|
|
|
|
// diagnose error, suggest fix, and recover parsing.
|
2012-08-21 01:37:52 +08:00
|
|
|
if (Tok.is(tok::l_square) && Tok.getLength() == 2) {
|
|
|
|
Token Next = NextToken();
|
|
|
|
if (Next.is(tok::colon) && areTokensAdjacent(Tok, Next))
|
|
|
|
FixDigraph(*this, PP, Tok, Next, Kind, /*AtDigraph*/true);
|
|
|
|
}
|
2011-04-15 05:45:45 +08:00
|
|
|
|
2006-12-05 02:06:35 +08:00
|
|
|
if (ExpectAndConsume(tok::less, diag::err_expected_less_after, CastName))
|
2008-12-12 06:51:44 +08:00
|
|
|
return ExprError();
|
2006-12-05 02:06:35 +08:00
|
|
|
|
2011-07-02 06:22:50 +08:00
|
|
|
// Parse the common declaration-specifiers piece.
|
|
|
|
DeclSpec DS(AttrFactory);
|
|
|
|
ParseSpecifierQualifierList(DS);
|
|
|
|
|
|
|
|
// Parse the abstract-declarator, if present.
|
|
|
|
Declarator DeclaratorInfo(DS, Declarator::TypeNameContext);
|
|
|
|
ParseDeclarator(DeclaratorInfo);
|
|
|
|
|
2006-12-05 02:06:35 +08:00
|
|
|
SourceLocation RAngleBracketLoc = Tok.getLocation();
|
|
|
|
|
2014-01-01 11:08:43 +08:00
|
|
|
if (ExpectAndConsume(tok::greater))
|
2013-12-24 17:48:30 +08:00
|
|
|
return ExprError(Diag(LAngleBracketLoc, diag::note_matching) << tok::less);
|
2006-12-05 02:06:35 +08:00
|
|
|
|
2011-10-13 00:37:45 +08:00
|
|
|
SourceLocation LParenLoc, RParenLoc;
|
|
|
|
BalancedDelimiterTracker T(*this, tok::l_paren);
|
2006-12-05 02:06:35 +08:00
|
|
|
|
2011-10-13 00:37:45 +08:00
|
|
|
if (T.expectAndConsume(diag::err_expected_lparen_after, CastName))
|
2009-05-22 18:23:16 +08:00
|
|
|
return ExprError();
|
2006-12-05 02:06:35 +08:00
|
|
|
|
2010-08-24 14:29:42 +08:00
|
|
|
ExprResult Result = ParseExpression();
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-05-22 18:23:16 +08:00
|
|
|
// Match the ')'.
|
2011-10-13 00:37:45 +08:00
|
|
|
T.consumeClose();
|
2006-12-05 02:06:35 +08:00
|
|
|
|
2011-07-02 06:22:50 +08:00
|
|
|
if (!Result.isInvalid() && !DeclaratorInfo.isInvalidType())
|
2008-10-28 03:41:14 +08:00
|
|
|
Result = Actions.ActOnCXXNamedCast(OpLoc, Kind,
|
2011-07-02 06:22:50 +08:00
|
|
|
LAngleBracketLoc, DeclaratorInfo,
|
2009-02-19 01:45:20 +08:00
|
|
|
RAngleBracketLoc,
|
2014-05-29 18:55:11 +08:00
|
|
|
T.getOpenLocation(), Result.get(),
|
2011-10-13 00:37:45 +08:00
|
|
|
T.getCloseLocation());
|
2006-12-05 02:06:35 +08:00
|
|
|
|
2012-08-24 05:35:17 +08:00
|
|
|
return Result;
|
2006-12-05 02:06:35 +08:00
|
|
|
}
|
2007-02-13 09:51:42 +08:00
|
|
|
|
2008-11-11 19:37:55 +08:00
|
|
|
/// ParseCXXTypeid - This handles the C++ typeid expression.
|
|
|
|
///
|
|
|
|
/// postfix-expression: [C++ 5.2p1]
|
|
|
|
/// 'typeid' '(' expression ')'
|
|
|
|
/// 'typeid' '(' type-id ')'
|
|
|
|
///
|
2010-08-24 14:29:42 +08:00
|
|
|
ExprResult Parser::ParseCXXTypeid() {
|
2008-11-11 19:37:55 +08:00
|
|
|
assert(Tok.is(tok::kw_typeid) && "Not 'typeid'!");
|
|
|
|
|
|
|
|
SourceLocation OpLoc = ConsumeToken();
|
2011-10-13 00:37:45 +08:00
|
|
|
SourceLocation LParenLoc, RParenLoc;
|
|
|
|
BalancedDelimiterTracker T(*this, tok::l_paren);
|
2008-11-11 19:37:55 +08:00
|
|
|
|
|
|
|
// typeid expressions are always parenthesized.
|
2011-10-13 00:37:45 +08:00
|
|
|
if (T.expectAndConsume(diag::err_expected_lparen_after, "typeid"))
|
2008-12-12 06:51:44 +08:00
|
|
|
return ExprError();
|
2011-10-13 00:37:45 +08:00
|
|
|
LParenLoc = T.getOpenLocation();
|
2008-11-11 19:37:55 +08:00
|
|
|
|
2010-08-24 14:29:42 +08:00
|
|
|
ExprResult Result;
|
2008-11-11 19:37:55 +08:00
|
|
|
|
2012-08-18 08:55:03 +08:00
|
|
|
// C++0x [expr.typeid]p3:
|
|
|
|
// When typeid is applied to an expression other than an lvalue of a
|
|
|
|
// polymorphic class type [...] The expression is an unevaluated
|
|
|
|
// operand (Clause 5).
|
|
|
|
//
|
|
|
|
// Note that we can't tell whether the expression is an lvalue of a
|
|
|
|
// polymorphic class type until after we've parsed the expression; we
|
|
|
|
// speculatively assume the subexpression is unevaluated, and fix it up
|
|
|
|
// later.
|
|
|
|
//
|
|
|
|
// We enter the unevaluated context before trying to determine whether we
|
|
|
|
// have a type-id, because the tentative parse logic will try to resolve
|
|
|
|
// names, and must treat them as unevaluated.
|
2012-09-26 12:34:21 +08:00
|
|
|
EnterExpressionEvaluationContext Unevaluated(Actions, Sema::Unevaluated,
|
|
|
|
Sema::ReuseLambdaContextDecl);
|
2012-08-18 08:55:03 +08:00
|
|
|
|
2008-11-11 19:37:55 +08:00
|
|
|
if (isTypeIdInParens()) {
|
2009-02-19 01:45:20 +08:00
|
|
|
TypeResult Ty = ParseTypeName();
|
2008-11-11 19:37:55 +08:00
|
|
|
|
|
|
|
// Match the ')'.
|
2011-10-13 00:37:45 +08:00
|
|
|
T.consumeClose();
|
|
|
|
RParenLoc = T.getCloseLocation();
|
2010-09-09 07:14:30 +08:00
|
|
|
if (Ty.isInvalid() || RParenLoc.isInvalid())
|
2008-12-12 06:51:44 +08:00
|
|
|
return ExprError();
|
2008-11-11 19:37:55 +08:00
|
|
|
|
|
|
|
Result = Actions.ActOnCXXTypeid(OpLoc, LParenLoc, /*isType=*/true,
|
2010-08-24 13:47:05 +08:00
|
|
|
Ty.get().getAsOpaquePtr(), RParenLoc);
|
2008-11-11 19:37:55 +08:00
|
|
|
} else {
|
|
|
|
Result = ParseExpression();
|
|
|
|
|
|
|
|
// Match the ')'.
|
2008-12-09 21:15:23 +08:00
|
|
|
if (Result.isInvalid())
|
2013-11-18 16:17:37 +08:00
|
|
|
SkipUntil(tok::r_paren, StopAtSemi);
|
2008-11-11 19:37:55 +08:00
|
|
|
else {
|
2011-10-13 00:37:45 +08:00
|
|
|
T.consumeClose();
|
|
|
|
RParenLoc = T.getCloseLocation();
|
2010-09-09 07:14:30 +08:00
|
|
|
if (RParenLoc.isInvalid())
|
|
|
|
return ExprError();
|
2011-03-12 09:48:56 +08:00
|
|
|
|
2008-11-11 19:37:55 +08:00
|
|
|
Result = Actions.ActOnCXXTypeid(OpLoc, LParenLoc, /*isType=*/false,
|
2014-05-29 18:55:11 +08:00
|
|
|
Result.get(), RParenLoc);
|
2008-11-11 19:37:55 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-24 05:35:17 +08:00
|
|
|
return Result;
|
2008-11-11 19:37:55 +08:00
|
|
|
}
|
|
|
|
|
2010-09-08 20:20:18 +08:00
|
|
|
/// ParseCXXUuidof - This handles the Microsoft C++ __uuidof expression.
|
|
|
|
///
|
|
|
|
/// '__uuidof' '(' expression ')'
|
|
|
|
/// '__uuidof' '(' type-id ')'
|
|
|
|
///
|
|
|
|
ExprResult Parser::ParseCXXUuidof() {
|
|
|
|
assert(Tok.is(tok::kw___uuidof) && "Not '__uuidof'!");
|
|
|
|
|
|
|
|
SourceLocation OpLoc = ConsumeToken();
|
2011-10-13 00:37:45 +08:00
|
|
|
BalancedDelimiterTracker T(*this, tok::l_paren);
|
2010-09-08 20:20:18 +08:00
|
|
|
|
|
|
|
// __uuidof expressions are always parenthesized.
|
2011-10-13 00:37:45 +08:00
|
|
|
if (T.expectAndConsume(diag::err_expected_lparen_after, "__uuidof"))
|
2010-09-08 20:20:18 +08:00
|
|
|
return ExprError();
|
|
|
|
|
|
|
|
ExprResult Result;
|
|
|
|
|
|
|
|
if (isTypeIdInParens()) {
|
|
|
|
TypeResult Ty = ParseTypeName();
|
|
|
|
|
|
|
|
// Match the ')'.
|
2011-10-13 00:37:45 +08:00
|
|
|
T.consumeClose();
|
2010-09-08 20:20:18 +08:00
|
|
|
|
|
|
|
if (Ty.isInvalid())
|
|
|
|
return ExprError();
|
|
|
|
|
2011-10-13 00:37:45 +08:00
|
|
|
Result = Actions.ActOnCXXUuidof(OpLoc, T.getOpenLocation(), /*isType=*/true,
|
|
|
|
Ty.get().getAsOpaquePtr(),
|
|
|
|
T.getCloseLocation());
|
2010-09-08 20:20:18 +08:00
|
|
|
} else {
|
|
|
|
EnterExpressionEvaluationContext Unevaluated(Actions, Sema::Unevaluated);
|
|
|
|
Result = ParseExpression();
|
|
|
|
|
|
|
|
// Match the ')'.
|
|
|
|
if (Result.isInvalid())
|
2013-11-18 16:17:37 +08:00
|
|
|
SkipUntil(tok::r_paren, StopAtSemi);
|
2010-09-08 20:20:18 +08:00
|
|
|
else {
|
2011-10-13 00:37:45 +08:00
|
|
|
T.consumeClose();
|
2010-09-08 20:20:18 +08:00
|
|
|
|
2011-10-13 00:37:45 +08:00
|
|
|
Result = Actions.ActOnCXXUuidof(OpLoc, T.getOpenLocation(),
|
|
|
|
/*isType=*/false,
|
2014-05-29 18:55:11 +08:00
|
|
|
Result.get(), T.getCloseLocation());
|
2010-09-08 20:20:18 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-24 05:35:17 +08:00
|
|
|
return Result;
|
2010-09-08 20:20:18 +08:00
|
|
|
}
|
|
|
|
|
Rework parsing of pseudo-destructor expressions and explicit
destructor calls, e.g.,
p->T::~T
We now detect when the member access that we've parsed, e.g.,
p-> or x.
may be a pseudo-destructor expression, either because the type of p or
x is a scalar or because it is dependent (and, therefore, may become a
scalar at template instantiation time).
We then parse the pseudo-destructor grammar specifically:
::[opt] nested-name-specifier[opt] type-name :: ∼ type-name
and hand those results to a new action, ActOnPseudoDestructorExpr,
which will cope with both dependent member accesses of destructors and
with pseudo-destructor expressions.
This commit affects the parsing of pseudo-destructors, only; the
semantic actions still go through the semantic actions for member
access expressions. That will change soon.
llvm-svn: 97045
2010-02-25 02:44:31 +08:00
|
|
|
/// \brief Parse a C++ pseudo-destructor expression after the base,
|
|
|
|
/// . or -> operator, and nested-name-specifier have already been
|
|
|
|
/// parsed.
|
|
|
|
///
|
|
|
|
/// postfix-expression: [C++ 5.2]
|
|
|
|
/// postfix-expression . pseudo-destructor-name
|
|
|
|
/// postfix-expression -> pseudo-destructor-name
|
|
|
|
///
|
|
|
|
/// pseudo-destructor-name:
|
|
|
|
/// ::[opt] nested-name-specifier[opt] type-name :: ~type-name
|
|
|
|
/// ::[opt] nested-name-specifier template simple-template-id ::
|
|
|
|
/// ~type-name
|
|
|
|
/// ::[opt] nested-name-specifier[opt] ~type-name
|
|
|
|
///
|
2010-08-24 14:29:42 +08:00
|
|
|
ExprResult
|
2014-10-30 13:30:05 +08:00
|
|
|
Parser::ParseCXXPseudoDestructor(Expr *Base, SourceLocation OpLoc,
|
Rework parsing of pseudo-destructor expressions and explicit
destructor calls, e.g.,
p->T::~T
We now detect when the member access that we've parsed, e.g.,
p-> or x.
may be a pseudo-destructor expression, either because the type of p or
x is a scalar or because it is dependent (and, therefore, may become a
scalar at template instantiation time).
We then parse the pseudo-destructor grammar specifically:
::[opt] nested-name-specifier[opt] type-name :: ∼ type-name
and hand those results to a new action, ActOnPseudoDestructorExpr,
which will cope with both dependent member accesses of destructors and
with pseudo-destructor expressions.
This commit affects the parsing of pseudo-destructors, only; the
semantic actions still go through the semantic actions for member
access expressions. That will change soon.
llvm-svn: 97045
2010-02-25 02:44:31 +08:00
|
|
|
tok::TokenKind OpKind,
|
|
|
|
CXXScopeSpec &SS,
|
2010-08-24 13:47:05 +08:00
|
|
|
ParsedType ObjectType) {
|
Rework parsing of pseudo-destructor expressions and explicit
destructor calls, e.g.,
p->T::~T
We now detect when the member access that we've parsed, e.g.,
p-> or x.
may be a pseudo-destructor expression, either because the type of p or
x is a scalar or because it is dependent (and, therefore, may become a
scalar at template instantiation time).
We then parse the pseudo-destructor grammar specifically:
::[opt] nested-name-specifier[opt] type-name :: ∼ type-name
and hand those results to a new action, ActOnPseudoDestructorExpr,
which will cope with both dependent member accesses of destructors and
with pseudo-destructor expressions.
This commit affects the parsing of pseudo-destructors, only; the
semantic actions still go through the semantic actions for member
access expressions. That will change soon.
llvm-svn: 97045
2010-02-25 02:44:31 +08:00
|
|
|
// We're parsing either a pseudo-destructor-name or a dependent
|
|
|
|
// member access that has the same form as a
|
|
|
|
// pseudo-destructor-name. We parse both in the same way and let
|
|
|
|
// the action model sort them out.
|
|
|
|
//
|
|
|
|
// Note that the ::[opt] nested-name-specifier[opt] has already
|
|
|
|
// been parsed, and if there was a simple-template-id, it has
|
|
|
|
// been coalesced into a template-id annotation token.
|
|
|
|
UnqualifiedId FirstTypeName;
|
|
|
|
SourceLocation CCLoc;
|
|
|
|
if (Tok.is(tok::identifier)) {
|
|
|
|
FirstTypeName.setIdentifier(Tok.getIdentifierInfo(), Tok.getLocation());
|
|
|
|
ConsumeToken();
|
|
|
|
assert(Tok.is(tok::coloncolon) &&"ParseOptionalCXXScopeSpecifier fail");
|
|
|
|
CCLoc = ConsumeToken();
|
|
|
|
} else if (Tok.is(tok::annot_template_id)) {
|
2012-01-27 17:46:47 +08:00
|
|
|
// FIXME: retrieve TemplateKWLoc from template-id annotation and
|
|
|
|
// store it in the pseudo-dtor node (to be used when instantiating it).
|
Rework parsing of pseudo-destructor expressions and explicit
destructor calls, e.g.,
p->T::~T
We now detect when the member access that we've parsed, e.g.,
p-> or x.
may be a pseudo-destructor expression, either because the type of p or
x is a scalar or because it is dependent (and, therefore, may become a
scalar at template instantiation time).
We then parse the pseudo-destructor grammar specifically:
::[opt] nested-name-specifier[opt] type-name :: ∼ type-name
and hand those results to a new action, ActOnPseudoDestructorExpr,
which will cope with both dependent member accesses of destructors and
with pseudo-destructor expressions.
This commit affects the parsing of pseudo-destructors, only; the
semantic actions still go through the semantic actions for member
access expressions. That will change soon.
llvm-svn: 97045
2010-02-25 02:44:31 +08:00
|
|
|
FirstTypeName.setTemplateId(
|
|
|
|
(TemplateIdAnnotation *)Tok.getAnnotationValue());
|
|
|
|
ConsumeToken();
|
|
|
|
assert(Tok.is(tok::coloncolon) &&"ParseOptionalCXXScopeSpecifier fail");
|
|
|
|
CCLoc = ConsumeToken();
|
|
|
|
} else {
|
2014-05-21 14:02:52 +08:00
|
|
|
FirstTypeName.setIdentifier(nullptr, SourceLocation());
|
Rework parsing of pseudo-destructor expressions and explicit
destructor calls, e.g.,
p->T::~T
We now detect when the member access that we've parsed, e.g.,
p-> or x.
may be a pseudo-destructor expression, either because the type of p or
x is a scalar or because it is dependent (and, therefore, may become a
scalar at template instantiation time).
We then parse the pseudo-destructor grammar specifically:
::[opt] nested-name-specifier[opt] type-name :: ∼ type-name
and hand those results to a new action, ActOnPseudoDestructorExpr,
which will cope with both dependent member accesses of destructors and
with pseudo-destructor expressions.
This commit affects the parsing of pseudo-destructors, only; the
semantic actions still go through the semantic actions for member
access expressions. That will change soon.
llvm-svn: 97045
2010-02-25 02:44:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Parse the tilde.
|
|
|
|
assert(Tok.is(tok::tilde) && "ParseOptionalCXXScopeSpecifier fail");
|
|
|
|
SourceLocation TildeLoc = ConsumeToken();
|
2011-12-17 00:03:09 +08:00
|
|
|
|
|
|
|
if (Tok.is(tok::kw_decltype) && !FirstTypeName.isValid() && SS.isEmpty()) {
|
|
|
|
DeclSpec DS(AttrFactory);
|
2011-12-18 20:18:02 +08:00
|
|
|
ParseDecltypeSpecifier(DS);
|
2011-12-17 00:03:09 +08:00
|
|
|
if (DS.getTypeSpecType() == TST_error)
|
|
|
|
return ExprError();
|
2015-02-26 01:36:15 +08:00
|
|
|
return Actions.ActOnPseudoDestructorExpr(getCurScope(), Base, OpLoc, OpKind,
|
|
|
|
TildeLoc, DS);
|
2011-12-17 00:03:09 +08:00
|
|
|
}
|
|
|
|
|
Rework parsing of pseudo-destructor expressions and explicit
destructor calls, e.g.,
p->T::~T
We now detect when the member access that we've parsed, e.g.,
p-> or x.
may be a pseudo-destructor expression, either because the type of p or
x is a scalar or because it is dependent (and, therefore, may become a
scalar at template instantiation time).
We then parse the pseudo-destructor grammar specifically:
::[opt] nested-name-specifier[opt] type-name :: ∼ type-name
and hand those results to a new action, ActOnPseudoDestructorExpr,
which will cope with both dependent member accesses of destructors and
with pseudo-destructor expressions.
This commit affects the parsing of pseudo-destructors, only; the
semantic actions still go through the semantic actions for member
access expressions. That will change soon.
llvm-svn: 97045
2010-02-25 02:44:31 +08:00
|
|
|
if (!Tok.is(tok::identifier)) {
|
|
|
|
Diag(Tok, diag::err_destructor_tilde_identifier);
|
|
|
|
return ExprError();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Parse the second type.
|
|
|
|
UnqualifiedId SecondTypeName;
|
|
|
|
IdentifierInfo *Name = Tok.getIdentifierInfo();
|
|
|
|
SourceLocation NameLoc = ConsumeToken();
|
|
|
|
SecondTypeName.setIdentifier(Name, NameLoc);
|
|
|
|
|
|
|
|
// If there is a '<', the second type name is a template-id. Parse
|
|
|
|
// it as such.
|
|
|
|
if (Tok.is(tok::less) &&
|
2012-01-27 17:46:47 +08:00
|
|
|
ParseUnqualifiedIdTemplateId(SS, SourceLocation(),
|
|
|
|
Name, NameLoc,
|
|
|
|
false, ObjectType, SecondTypeName,
|
|
|
|
/*AssumeTemplateName=*/true))
|
Rework parsing of pseudo-destructor expressions and explicit
destructor calls, e.g.,
p->T::~T
We now detect when the member access that we've parsed, e.g.,
p-> or x.
may be a pseudo-destructor expression, either because the type of p or
x is a scalar or because it is dependent (and, therefore, may become a
scalar at template instantiation time).
We then parse the pseudo-destructor grammar specifically:
::[opt] nested-name-specifier[opt] type-name :: ∼ type-name
and hand those results to a new action, ActOnPseudoDestructorExpr,
which will cope with both dependent member accesses of destructors and
with pseudo-destructor expressions.
This commit affects the parsing of pseudo-destructors, only; the
semantic actions still go through the semantic actions for member
access expressions. That will change soon.
llvm-svn: 97045
2010-02-25 02:44:31 +08:00
|
|
|
return ExprError();
|
|
|
|
|
2015-02-26 01:36:15 +08:00
|
|
|
return Actions.ActOnPseudoDestructorExpr(getCurScope(), Base, OpLoc, OpKind,
|
|
|
|
SS, FirstTypeName, CCLoc, TildeLoc,
|
|
|
|
SecondTypeName);
|
Rework parsing of pseudo-destructor expressions and explicit
destructor calls, e.g.,
p->T::~T
We now detect when the member access that we've parsed, e.g.,
p-> or x.
may be a pseudo-destructor expression, either because the type of p or
x is a scalar or because it is dependent (and, therefore, may become a
scalar at template instantiation time).
We then parse the pseudo-destructor grammar specifically:
::[opt] nested-name-specifier[opt] type-name :: ∼ type-name
and hand those results to a new action, ActOnPseudoDestructorExpr,
which will cope with both dependent member accesses of destructors and
with pseudo-destructor expressions.
This commit affects the parsing of pseudo-destructors, only; the
semantic actions still go through the semantic actions for member
access expressions. That will change soon.
llvm-svn: 97045
2010-02-25 02:44:31 +08:00
|
|
|
}
|
|
|
|
|
2007-02-13 09:51:42 +08:00
|
|
|
/// ParseCXXBoolLiteral - This handles the C++ Boolean literals.
|
|
|
|
///
|
|
|
|
/// boolean-literal: [C++ 2.13.5]
|
|
|
|
/// 'true'
|
|
|
|
/// 'false'
|
2010-08-24 14:29:42 +08:00
|
|
|
ExprResult Parser::ParseCXXBoolLiteral() {
|
2007-02-13 09:51:42 +08:00
|
|
|
tok::TokenKind Kind = Tok.getKind();
|
2009-03-16 01:47:39 +08:00
|
|
|
return Actions.ActOnCXXBoolLiteral(ConsumeToken(), Kind);
|
2007-02-13 09:51:42 +08:00
|
|
|
}
|
2008-02-26 08:51:44 +08:00
|
|
|
|
|
|
|
/// ParseThrowExpression - This handles the C++ throw expression.
|
|
|
|
///
|
|
|
|
/// throw-expression: [C++ 15]
|
|
|
|
/// 'throw' assignment-expression[opt]
|
2010-08-24 14:29:42 +08:00
|
|
|
ExprResult Parser::ParseThrowExpression() {
|
2008-02-26 08:51:44 +08:00
|
|
|
assert(Tok.is(tok::kw_throw) && "Not throw!");
|
|
|
|
SourceLocation ThrowLoc = ConsumeToken(); // Eat the throw token.
|
2008-12-12 06:51:44 +08:00
|
|
|
|
2008-04-06 14:02:23 +08:00
|
|
|
// If the current token isn't the start of an assignment-expression,
|
|
|
|
// then the expression is not present. This handles things like:
|
|
|
|
// "C ? throw : (void)42", which is crazy but legal.
|
|
|
|
switch (Tok.getKind()) { // FIXME: move this predicate somewhere common.
|
|
|
|
case tok::semi:
|
|
|
|
case tok::r_paren:
|
|
|
|
case tok::r_square:
|
|
|
|
case tok::r_brace:
|
|
|
|
case tok::colon:
|
|
|
|
case tok::comma:
|
2014-05-21 14:02:52 +08:00
|
|
|
return Actions.ActOnCXXThrow(getCurScope(), ThrowLoc, nullptr);
|
2008-02-26 08:51:44 +08:00
|
|
|
|
2008-04-06 14:02:23 +08:00
|
|
|
default:
|
2010-08-24 14:29:42 +08:00
|
|
|
ExprResult Expr(ParseAssignmentExpression());
|
2012-08-24 05:35:17 +08:00
|
|
|
if (Expr.isInvalid()) return Expr;
|
2014-05-29 18:55:11 +08:00
|
|
|
return Actions.ActOnCXXThrow(getCurScope(), ThrowLoc, Expr.get());
|
2008-04-06 14:02:23 +08:00
|
|
|
}
|
2008-02-26 08:51:44 +08:00
|
|
|
}
|
2008-06-25 06:12:16 +08:00
|
|
|
|
2015-10-22 12:46:14 +08:00
|
|
|
/// \brief Parse the C++ Coroutines co_yield expression.
|
|
|
|
///
|
|
|
|
/// co_yield-expression:
|
|
|
|
/// 'co_yield' assignment-expression[opt]
|
|
|
|
ExprResult Parser::ParseCoyieldExpression() {
|
|
|
|
assert(Tok.is(tok::kw_co_yield) && "Not co_yield!");
|
|
|
|
|
|
|
|
SourceLocation Loc = ConsumeToken();
|
2015-11-21 06:47:10 +08:00
|
|
|
ExprResult Expr = Tok.is(tok::l_brace) ? ParseBraceInitializer()
|
|
|
|
: ParseAssignmentExpression();
|
2015-10-22 14:13:50 +08:00
|
|
|
if (!Expr.isInvalid())
|
2015-10-27 14:02:45 +08:00
|
|
|
Expr = Actions.ActOnCoyieldExpr(getCurScope(), Loc, Expr.get());
|
2015-10-22 12:46:14 +08:00
|
|
|
return Expr;
|
|
|
|
}
|
|
|
|
|
2008-06-25 06:12:16 +08:00
|
|
|
/// ParseCXXThis - This handles the C++ 'this' pointer.
|
|
|
|
///
|
|
|
|
/// C++ 9.3.2: In the body of a non-static member function, the keyword this is
|
|
|
|
/// a non-lvalue expression whose value is the address of the object for which
|
|
|
|
/// the function is called.
|
2010-08-24 14:29:42 +08:00
|
|
|
ExprResult Parser::ParseCXXThis() {
|
2008-06-25 06:12:16 +08:00
|
|
|
assert(Tok.is(tok::kw_this) && "Not 'this'!");
|
|
|
|
SourceLocation ThisLoc = ConsumeToken();
|
2009-03-16 01:47:39 +08:00
|
|
|
return Actions.ActOnCXXThis(ThisLoc);
|
2008-06-25 06:12:16 +08:00
|
|
|
}
|
2008-08-22 23:38:55 +08:00
|
|
|
|
|
|
|
/// ParseCXXTypeConstructExpression - Parse construction of a specified type.
|
|
|
|
/// Can be interpreted either as function-style casting ("int(x)")
|
|
|
|
/// or class type construction ("ClassType(x,y,z)")
|
|
|
|
/// or creation of a value-initialized type ("int()").
|
2011-06-05 20:23:16 +08:00
|
|
|
/// See [C++ 5.2.3].
|
2008-08-22 23:38:55 +08:00
|
|
|
///
|
|
|
|
/// postfix-expression: [C++ 5.2p1]
|
2011-06-05 20:23:16 +08:00
|
|
|
/// simple-type-specifier '(' expression-list[opt] ')'
|
|
|
|
/// [C++0x] simple-type-specifier braced-init-list
|
|
|
|
/// typename-specifier '(' expression-list[opt] ')'
|
|
|
|
/// [C++0x] typename-specifier braced-init-list
|
2008-08-22 23:38:55 +08:00
|
|
|
///
|
2010-08-24 14:29:42 +08:00
|
|
|
ExprResult
|
2008-12-12 06:51:44 +08:00
|
|
|
Parser::ParseCXXTypeConstructExpression(const DeclSpec &DS) {
|
2008-08-22 23:38:55 +08:00
|
|
|
Declarator DeclaratorInfo(DS, Declarator::TypeNameContext);
|
2010-08-24 13:47:05 +08:00
|
|
|
ParsedType TypeRep = Actions.ActOnTypeName(getCurScope(), DeclaratorInfo).get();
|
2008-08-22 23:38:55 +08:00
|
|
|
|
2011-06-05 20:23:16 +08:00
|
|
|
assert((Tok.is(tok::l_paren) ||
|
2013-01-02 19:42:31 +08:00
|
|
|
(getLangOpts().CPlusPlus11 && Tok.is(tok::l_brace)))
|
2011-06-05 20:23:16 +08:00
|
|
|
&& "Expected '(' or '{'!");
|
2011-01-11 08:33:19 +08:00
|
|
|
|
2011-06-05 20:23:16 +08:00
|
|
|
if (Tok.is(tok::l_brace)) {
|
2012-02-13 02:41:05 +08:00
|
|
|
ExprResult Init = ParseBraceInitializer();
|
|
|
|
if (Init.isInvalid())
|
|
|
|
return Init;
|
2014-05-29 18:55:11 +08:00
|
|
|
Expr *InitList = Init.get();
|
2012-02-13 02:41:05 +08:00
|
|
|
return Actions.ActOnCXXTypeConstructExpr(TypeRep, SourceLocation(),
|
|
|
|
MultiExprArg(&InitList, 1),
|
|
|
|
SourceLocation());
|
2011-06-05 20:23:16 +08:00
|
|
|
} else {
|
2011-10-13 00:37:45 +08:00
|
|
|
BalancedDelimiterTracker T(*this, tok::l_paren);
|
|
|
|
T.consumeOpen();
|
2011-06-05 20:23:16 +08:00
|
|
|
|
2012-08-24 06:51:59 +08:00
|
|
|
ExprVector Exprs;
|
2011-06-05 20:23:16 +08:00
|
|
|
CommaLocsTy CommaLocs;
|
|
|
|
|
|
|
|
if (Tok.isNot(tok::r_paren)) {
|
2015-01-22 00:24:11 +08:00
|
|
|
if (ParseExpressionList(Exprs, CommaLocs, [&] {
|
|
|
|
Actions.CodeCompleteConstructor(getCurScope(),
|
|
|
|
TypeRep.get()->getCanonicalTypeInternal(),
|
|
|
|
DS.getLocEnd(), Exprs);
|
|
|
|
})) {
|
2013-11-18 16:17:37 +08:00
|
|
|
SkipUntil(tok::r_paren, StopAtSemi);
|
2011-06-05 20:23:16 +08:00
|
|
|
return ExprError();
|
|
|
|
}
|
2008-08-22 23:38:55 +08:00
|
|
|
}
|
|
|
|
|
2011-06-05 20:23:16 +08:00
|
|
|
// Match the ')'.
|
2011-10-13 00:37:45 +08:00
|
|
|
T.consumeClose();
|
2008-08-22 23:38:55 +08:00
|
|
|
|
2011-06-05 20:23:16 +08:00
|
|
|
// TypeRep could be null, if it references an invalid typedef.
|
|
|
|
if (!TypeRep)
|
|
|
|
return ExprError();
|
2009-07-29 21:50:23 +08:00
|
|
|
|
2011-06-05 20:23:16 +08:00
|
|
|
assert((Exprs.size() == 0 || Exprs.size()-1 == CommaLocs.size())&&
|
|
|
|
"Unexpected number of commas!");
|
2011-10-13 00:37:45 +08:00
|
|
|
return Actions.ActOnCXXTypeConstructExpr(TypeRep, T.getOpenLocation(),
|
2012-08-24 05:35:17 +08:00
|
|
|
Exprs,
|
2011-10-13 00:37:45 +08:00
|
|
|
T.getCloseLocation());
|
2011-06-05 20:23:16 +08:00
|
|
|
}
|
2008-08-22 23:38:55 +08:00
|
|
|
}
|
|
|
|
|
2009-11-25 08:27:52 +08:00
|
|
|
/// ParseCXXCondition - if/switch/while condition expression.
|
2008-09-10 04:38:47 +08:00
|
|
|
///
|
|
|
|
/// condition:
|
|
|
|
/// expression
|
|
|
|
/// type-specifier-seq declarator '=' assignment-expression
|
2012-02-22 14:49:09 +08:00
|
|
|
/// [C++11] type-specifier-seq declarator '=' initializer-clause
|
|
|
|
/// [C++11] type-specifier-seq declarator braced-init-list
|
2008-09-10 04:38:47 +08:00
|
|
|
/// [GNU] type-specifier-seq declarator simple-asm-expr[opt] attributes[opt]
|
|
|
|
/// '=' assignment-expression
|
|
|
|
///
|
2016-06-30 05:17:59 +08:00
|
|
|
/// In C++1z, a condition may in some contexts be preceded by an
|
|
|
|
/// optional init-statement. This function will parse that too.
|
|
|
|
///
|
|
|
|
/// \param InitStmt If non-null, an init-statement is permitted, and if present
|
|
|
|
/// will be parsed and stored here.
|
|
|
|
///
|
2010-05-07 01:25:47 +08:00
|
|
|
/// \param Loc The location of the start of the statement that requires this
|
|
|
|
/// condition, e.g., the "for" in a for loop.
|
|
|
|
///
|
2016-06-24 03:02:52 +08:00
|
|
|
/// \returns The parsed condition.
|
2016-06-30 05:17:59 +08:00
|
|
|
Sema::ConditionResult Parser::ParseCXXCondition(StmtResult *InitStmt,
|
|
|
|
SourceLocation Loc,
|
2016-06-24 03:02:52 +08:00
|
|
|
Sema::ConditionKind CK) {
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
if (Tok.is(tok::code_completion)) {
|
2010-08-27 07:41:50 +08:00
|
|
|
Actions.CodeCompleteOrdinaryName(getCurScope(), Sema::PCC_Condition);
|
2011-09-04 11:32:15 +08:00
|
|
|
cutOffParsing();
|
2016-06-24 03:02:52 +08:00
|
|
|
return Sema::ConditionError();
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
}
|
|
|
|
|
2012-06-23 13:07:58 +08:00
|
|
|
ParsedAttributesWithRange attrs(AttrFactory);
|
2013-01-02 20:01:23 +08:00
|
|
|
MaybeParseCXX11Attributes(attrs);
|
2012-06-23 13:07:58 +08:00
|
|
|
|
2016-06-30 05:17:59 +08:00
|
|
|
// Determine what kind of thing we have.
|
|
|
|
switch (isCXXConditionDeclarationOrInitStatement(InitStmt)) {
|
|
|
|
case ConditionOrInitStatement::Expression: {
|
2012-06-23 13:07:58 +08:00
|
|
|
ProhibitAttributes(attrs);
|
|
|
|
|
2010-05-07 01:25:47 +08:00
|
|
|
// Parse the expression.
|
2016-06-24 03:02:52 +08:00
|
|
|
ExprResult Expr = ParseExpression(); // expression
|
|
|
|
if (Expr.isInvalid())
|
|
|
|
return Sema::ConditionError();
|
2010-05-07 01:25:47 +08:00
|
|
|
|
2016-06-30 05:17:59 +08:00
|
|
|
if (InitStmt && Tok.is(tok::semi)) {
|
|
|
|
*InitStmt = Actions.ActOnExprStmt(Expr.get());
|
|
|
|
ConsumeToken();
|
|
|
|
return ParseCXXCondition(nullptr, Loc, CK);
|
|
|
|
}
|
|
|
|
|
2016-06-24 03:02:52 +08:00
|
|
|
return Actions.ActOnCondition(getCurScope(), Loc, Expr.get(), CK);
|
2009-11-25 08:27:52 +08:00
|
|
|
}
|
2008-09-10 04:38:47 +08:00
|
|
|
|
2016-06-30 05:17:59 +08:00
|
|
|
case ConditionOrInitStatement::InitStmtDecl: {
|
2016-10-19 04:27:16 +08:00
|
|
|
Diag(Tok.getLocation(), getLangOpts().CPlusPlus1z
|
|
|
|
? diag::warn_cxx14_compat_init_statement
|
|
|
|
: diag::ext_init_statement)
|
|
|
|
<< (CK == Sema::ConditionKind::Switch);
|
2016-06-30 05:17:59 +08:00
|
|
|
SourceLocation DeclStart = Tok.getLocation(), DeclEnd;
|
|
|
|
DeclGroupPtrTy DG = ParseSimpleDeclaration(
|
|
|
|
Declarator::InitStmtContext, DeclEnd, attrs, /*RequireSemi=*/true);
|
|
|
|
*InitStmt = Actions.ActOnDeclStmt(DG, DeclStart, DeclEnd);
|
|
|
|
return ParseCXXCondition(nullptr, Loc, CK);
|
|
|
|
}
|
|
|
|
|
|
|
|
case ConditionOrInitStatement::ConditionDecl:
|
|
|
|
case ConditionOrInitStatement::Error:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-09-10 04:38:47 +08:00
|
|
|
// type-specifier-seq
|
2011-03-24 19:26:52 +08:00
|
|
|
DeclSpec DS(AttrFactory);
|
2013-02-21 03:22:51 +08:00
|
|
|
DS.takeAttributesFrom(attrs);
|
2015-06-26 06:06:40 +08:00
|
|
|
ParseSpecifierQualifierList(DS, AS_none, DSC_condition);
|
2008-09-10 04:38:47 +08:00
|
|
|
|
|
|
|
// declarator
|
|
|
|
Declarator DeclaratorInfo(DS, Declarator::ConditionContext);
|
|
|
|
ParseDeclarator(DeclaratorInfo);
|
|
|
|
|
|
|
|
// simple-asm-expr[opt]
|
|
|
|
if (Tok.is(tok::kw_asm)) {
|
2009-02-10 02:23:29 +08:00
|
|
|
SourceLocation Loc;
|
2010-08-24 14:29:42 +08:00
|
|
|
ExprResult AsmLabel(ParseSimpleAsm(&Loc));
|
2008-12-09 21:15:23 +08:00
|
|
|
if (AsmLabel.isInvalid()) {
|
2013-11-18 16:17:37 +08:00
|
|
|
SkipUntil(tok::semi, StopAtSemi);
|
2016-06-24 03:02:52 +08:00
|
|
|
return Sema::ConditionError();
|
2008-09-10 04:38:47 +08:00
|
|
|
}
|
2014-05-29 18:55:11 +08:00
|
|
|
DeclaratorInfo.setAsmLabel(AsmLabel.get());
|
2009-02-10 02:23:29 +08:00
|
|
|
DeclaratorInfo.SetRangeEnd(Loc);
|
2008-09-10 04:38:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// If attributes are present, parse them.
|
2010-12-24 10:08:15 +08:00
|
|
|
MaybeParseGNUAttributes(DeclaratorInfo);
|
2008-09-10 04:38:47 +08:00
|
|
|
|
2009-11-25 08:27:52 +08:00
|
|
|
// Type-check the declaration itself.
|
2010-08-24 14:29:42 +08:00
|
|
|
DeclResult Dcl = Actions.ActOnCXXConditionDeclaration(getCurScope(),
|
2010-12-24 10:08:15 +08:00
|
|
|
DeclaratorInfo);
|
2016-06-24 03:02:52 +08:00
|
|
|
if (Dcl.isInvalid())
|
|
|
|
return Sema::ConditionError();
|
|
|
|
Decl *DeclOut = Dcl.get();
|
2010-10-08 10:39:23 +08:00
|
|
|
|
2008-09-10 04:38:47 +08:00
|
|
|
// '=' assignment-expression
|
2012-01-19 06:54:52 +08:00
|
|
|
// If a '==' or '+=' is found, suggest a fixit to '='.
|
2012-02-22 14:49:09 +08:00
|
|
|
bool CopyInitialization = isTokenEqualOrEqualTypo();
|
|
|
|
if (CopyInitialization)
|
2011-01-18 10:00:16 +08:00
|
|
|
ConsumeToken();
|
2012-02-22 14:49:09 +08:00
|
|
|
|
|
|
|
ExprResult InitExpr = ExprError();
|
2013-01-02 19:42:31 +08:00
|
|
|
if (getLangOpts().CPlusPlus11 && Tok.is(tok::l_brace)) {
|
2012-02-22 14:49:09 +08:00
|
|
|
Diag(Tok.getLocation(),
|
|
|
|
diag::warn_cxx98_compat_generalized_initializer_lists);
|
|
|
|
InitExpr = ParseBraceInitializer();
|
|
|
|
} else if (CopyInitialization) {
|
|
|
|
InitExpr = ParseAssignmentExpression();
|
|
|
|
} else if (Tok.is(tok::l_paren)) {
|
|
|
|
// This was probably an attempt to initialize the variable.
|
|
|
|
SourceLocation LParen = ConsumeParen(), RParen = LParen;
|
2013-11-18 16:17:37 +08:00
|
|
|
if (SkipUntil(tok::r_paren, StopAtSemi | StopBeforeMatch))
|
2012-02-22 14:49:09 +08:00
|
|
|
RParen = ConsumeParen();
|
2016-06-24 03:02:52 +08:00
|
|
|
Diag(DeclOut->getLocation(),
|
2012-02-22 14:49:09 +08:00
|
|
|
diag::err_expected_init_in_condition_lparen)
|
|
|
|
<< SourceRange(LParen, RParen);
|
2009-11-25 08:27:52 +08:00
|
|
|
} else {
|
2016-06-24 03:02:52 +08:00
|
|
|
Diag(DeclOut->getLocation(), diag::err_expected_init_in_condition);
|
2009-11-25 08:27:52 +08:00
|
|
|
}
|
2012-02-22 14:49:09 +08:00
|
|
|
|
|
|
|
if (!InitExpr.isInvalid())
|
2017-01-12 10:27:38 +08:00
|
|
|
Actions.AddInitializerToDecl(DeclOut, InitExpr.get(), !CopyInitialization);
|
2013-04-30 21:56:41 +08:00
|
|
|
else
|
|
|
|
Actions.ActOnInitializerError(DeclOut);
|
2012-02-22 14:49:09 +08:00
|
|
|
|
2011-02-22 04:05:19 +08:00
|
|
|
Actions.FinalizeDeclaration(DeclOut);
|
2016-06-24 03:02:52 +08:00
|
|
|
return Actions.ActOnConditionVariable(DeclOut, Loc, CK);
|
2008-09-10 04:38:47 +08:00
|
|
|
}
|
|
|
|
|
2008-08-22 23:38:55 +08:00
|
|
|
/// ParseCXXSimpleTypeSpecifier - [C++ 7.1.5.2] Simple type specifiers.
|
|
|
|
/// This should only be called when the current token is known to be part of
|
|
|
|
/// simple-type-specifier.
|
|
|
|
///
|
|
|
|
/// simple-type-specifier:
|
2008-11-09 00:45:02 +08:00
|
|
|
/// '::'[opt] nested-name-specifier[opt] type-name
|
2008-08-22 23:38:55 +08:00
|
|
|
/// '::'[opt] nested-name-specifier 'template' simple-template-id [TODO]
|
|
|
|
/// char
|
|
|
|
/// wchar_t
|
|
|
|
/// bool
|
|
|
|
/// short
|
|
|
|
/// int
|
|
|
|
/// long
|
|
|
|
/// signed
|
|
|
|
/// unsigned
|
|
|
|
/// float
|
|
|
|
/// double
|
|
|
|
/// void
|
|
|
|
/// [GNU] typeof-specifier
|
|
|
|
/// [C++0x] auto [TODO]
|
|
|
|
///
|
|
|
|
/// type-name:
|
|
|
|
/// class-name
|
|
|
|
/// enum-name
|
|
|
|
/// typedef-name
|
|
|
|
///
|
|
|
|
void Parser::ParseCXXSimpleTypeSpecifier(DeclSpec &DS) {
|
|
|
|
DS.SetRangeStart(Tok.getLocation());
|
|
|
|
const char *PrevSpec;
|
2009-08-04 04:12:06 +08:00
|
|
|
unsigned DiagID;
|
2008-08-22 23:38:55 +08:00
|
|
|
SourceLocation Loc = Tok.getLocation();
|
2014-01-15 17:15:43 +08:00
|
|
|
const clang::PrintingPolicy &Policy =
|
|
|
|
Actions.getASTContext().getPrintingPolicy();
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-08-22 23:38:55 +08:00
|
|
|
switch (Tok.getKind()) {
|
2009-01-05 08:13:00 +08:00
|
|
|
case tok::identifier: // foo::bar
|
|
|
|
case tok::coloncolon: // ::foo::bar
|
2011-09-23 13:06:16 +08:00
|
|
|
llvm_unreachable("Annotation token should already be formed!");
|
2009-09-09 23:08:12 +08:00
|
|
|
default:
|
2011-09-23 13:06:16 +08:00
|
|
|
llvm_unreachable("Not a simple-type-specifier token!");
|
2009-01-05 08:13:00 +08:00
|
|
|
|
2008-08-22 23:38:55 +08:00
|
|
|
// type-name
|
2009-01-06 13:06:21 +08:00
|
|
|
case tok::annot_typename: {
|
2011-01-20 04:10:05 +08:00
|
|
|
if (getTypeAnnotation(Tok))
|
|
|
|
DS.SetTypeSpecType(DeclSpec::TST_typename, Loc, PrevSpec, DiagID,
|
2014-01-15 17:15:43 +08:00
|
|
|
getTypeAnnotation(Tok), Policy);
|
2011-01-20 04:10:05 +08:00
|
|
|
else
|
|
|
|
DS.SetTypeSpecError();
|
2010-10-22 07:17:00 +08:00
|
|
|
|
|
|
|
DS.SetRangeEnd(Tok.getAnnotationEndLoc());
|
|
|
|
ConsumeToken();
|
|
|
|
|
2015-11-15 11:32:11 +08:00
|
|
|
DS.Finish(Actions, Policy);
|
2010-10-22 07:17:00 +08:00
|
|
|
return;
|
2008-08-22 23:38:55 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-08-22 23:38:55 +08:00
|
|
|
// builtin types
|
|
|
|
case tok::kw_short:
|
2014-01-15 17:15:43 +08:00
|
|
|
DS.SetTypeSpecWidth(DeclSpec::TSW_short, Loc, PrevSpec, DiagID, Policy);
|
2008-08-22 23:38:55 +08:00
|
|
|
break;
|
|
|
|
case tok::kw_long:
|
2014-01-15 17:15:43 +08:00
|
|
|
DS.SetTypeSpecWidth(DeclSpec::TSW_long, Loc, PrevSpec, DiagID, Policy);
|
2011-04-28 09:59:37 +08:00
|
|
|
break;
|
|
|
|
case tok::kw___int64:
|
2014-01-15 17:15:43 +08:00
|
|
|
DS.SetTypeSpecWidth(DeclSpec::TSW_longlong, Loc, PrevSpec, DiagID, Policy);
|
2008-08-22 23:38:55 +08:00
|
|
|
break;
|
|
|
|
case tok::kw_signed:
|
2009-08-04 04:12:06 +08:00
|
|
|
DS.SetTypeSpecSign(DeclSpec::TSS_signed, Loc, PrevSpec, DiagID);
|
2008-08-22 23:38:55 +08:00
|
|
|
break;
|
|
|
|
case tok::kw_unsigned:
|
2009-08-04 04:12:06 +08:00
|
|
|
DS.SetTypeSpecSign(DeclSpec::TSS_unsigned, Loc, PrevSpec, DiagID);
|
2008-08-22 23:38:55 +08:00
|
|
|
break;
|
|
|
|
case tok::kw_void:
|
2014-01-15 17:15:43 +08:00
|
|
|
DS.SetTypeSpecType(DeclSpec::TST_void, Loc, PrevSpec, DiagID, Policy);
|
2008-08-22 23:38:55 +08:00
|
|
|
break;
|
|
|
|
case tok::kw_char:
|
2014-01-15 17:15:43 +08:00
|
|
|
DS.SetTypeSpecType(DeclSpec::TST_char, Loc, PrevSpec, DiagID, Policy);
|
2008-08-22 23:38:55 +08:00
|
|
|
break;
|
|
|
|
case tok::kw_int:
|
2014-01-15 17:15:43 +08:00
|
|
|
DS.SetTypeSpecType(DeclSpec::TST_int, Loc, PrevSpec, DiagID, Policy);
|
2008-08-22 23:38:55 +08:00
|
|
|
break;
|
2012-04-04 14:24:32 +08:00
|
|
|
case tok::kw___int128:
|
2014-01-15 17:15:43 +08:00
|
|
|
DS.SetTypeSpecType(DeclSpec::TST_int128, Loc, PrevSpec, DiagID, Policy);
|
2012-04-04 14:24:32 +08:00
|
|
|
break;
|
2011-10-15 07:23:15 +08:00
|
|
|
case tok::kw_half:
|
2014-01-15 17:15:43 +08:00
|
|
|
DS.SetTypeSpecType(DeclSpec::TST_half, Loc, PrevSpec, DiagID, Policy);
|
2011-10-15 07:23:15 +08:00
|
|
|
break;
|
2008-08-22 23:38:55 +08:00
|
|
|
case tok::kw_float:
|
2014-01-15 17:15:43 +08:00
|
|
|
DS.SetTypeSpecType(DeclSpec::TST_float, Loc, PrevSpec, DiagID, Policy);
|
2008-08-22 23:38:55 +08:00
|
|
|
break;
|
|
|
|
case tok::kw_double:
|
2014-01-15 17:15:43 +08:00
|
|
|
DS.SetTypeSpecType(DeclSpec::TST_double, Loc, PrevSpec, DiagID, Policy);
|
2008-08-22 23:38:55 +08:00
|
|
|
break;
|
2016-05-09 16:52:33 +08:00
|
|
|
case tok::kw___float128:
|
|
|
|
DS.SetTypeSpecType(DeclSpec::TST_float128, Loc, PrevSpec, DiagID, Policy);
|
|
|
|
break;
|
2008-08-22 23:38:55 +08:00
|
|
|
case tok::kw_wchar_t:
|
2014-01-15 17:15:43 +08:00
|
|
|
DS.SetTypeSpecType(DeclSpec::TST_wchar, Loc, PrevSpec, DiagID, Policy);
|
2008-08-22 23:38:55 +08:00
|
|
|
break;
|
2009-07-14 14:30:34 +08:00
|
|
|
case tok::kw_char16_t:
|
2014-01-15 17:15:43 +08:00
|
|
|
DS.SetTypeSpecType(DeclSpec::TST_char16, Loc, PrevSpec, DiagID, Policy);
|
2009-07-14 14:30:34 +08:00
|
|
|
break;
|
|
|
|
case tok::kw_char32_t:
|
2014-01-15 17:15:43 +08:00
|
|
|
DS.SetTypeSpecType(DeclSpec::TST_char32, Loc, PrevSpec, DiagID, Policy);
|
2009-07-14 14:30:34 +08:00
|
|
|
break;
|
2008-08-22 23:38:55 +08:00
|
|
|
case tok::kw_bool:
|
2014-01-15 17:15:43 +08:00
|
|
|
DS.SetTypeSpecType(DeclSpec::TST_bool, Loc, PrevSpec, DiagID, Policy);
|
2008-08-22 23:38:55 +08:00
|
|
|
break;
|
2012-01-24 13:47:35 +08:00
|
|
|
case tok::annot_decltype:
|
|
|
|
case tok::kw_decltype:
|
|
|
|
DS.SetRangeEnd(ParseDecltypeSpecifier(DS));
|
2015-11-15 11:32:11 +08:00
|
|
|
return DS.Finish(Actions, Policy);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-08-22 23:38:55 +08:00
|
|
|
// GNU typeof support.
|
|
|
|
case tok::kw_typeof:
|
|
|
|
ParseTypeofSpecifier(DS);
|
2015-11-15 11:32:11 +08:00
|
|
|
DS.Finish(Actions, Policy);
|
2008-08-22 23:38:55 +08:00
|
|
|
return;
|
|
|
|
}
|
2009-01-06 13:06:21 +08:00
|
|
|
if (Tok.is(tok::annot_typename))
|
2008-11-09 00:45:02 +08:00
|
|
|
DS.SetRangeEnd(Tok.getAnnotationEndLoc());
|
|
|
|
else
|
|
|
|
DS.SetRangeEnd(Tok.getLocation());
|
2008-08-22 23:38:55 +08:00
|
|
|
ConsumeToken();
|
2015-11-15 11:32:11 +08:00
|
|
|
DS.Finish(Actions, Policy);
|
2008-08-22 23:38:55 +08:00
|
|
|
}
|
2008-11-07 06:13:31 +08:00
|
|
|
|
2008-11-08 04:08:42 +08:00
|
|
|
/// ParseCXXTypeSpecifierSeq - Parse a C++ type-specifier-seq (C++
|
|
|
|
/// [dcl.name]), which is a non-empty sequence of type-specifiers,
|
|
|
|
/// e.g., "const short int". Note that the DeclSpec is *not* finished
|
|
|
|
/// by parsing the type-specifier-seq, because these sequences are
|
|
|
|
/// typically followed by some form of declarator. Returns true and
|
|
|
|
/// emits diagnostics if this is not a type-specifier-seq, false
|
|
|
|
/// otherwise.
|
|
|
|
///
|
|
|
|
/// type-specifier-seq: [C++ 8.1]
|
|
|
|
/// type-specifier type-specifier-seq[opt]
|
|
|
|
///
|
|
|
|
bool Parser::ParseCXXTypeSpecifierSeq(DeclSpec &DS) {
|
2012-03-12 15:56:15 +08:00
|
|
|
ParseSpecifierQualifierList(DS, AS_none, DSC_type_specifier);
|
2015-11-15 11:32:11 +08:00
|
|
|
DS.Finish(Actions, Actions.getASTContext().getPrintingPolicy());
|
2008-11-08 04:08:42 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-11-03 09:35:08 +08:00
|
|
|
/// \brief Finish parsing a C++ unqualified-id that is a template-id of
|
|
|
|
/// some form.
|
|
|
|
///
|
|
|
|
/// This routine is invoked when a '<' is encountered after an identifier or
|
|
|
|
/// operator-function-id is parsed by \c ParseUnqualifiedId() to determine
|
|
|
|
/// whether the unqualified-id is actually a template-id. This routine will
|
|
|
|
/// then parse the template arguments and form the appropriate template-id to
|
|
|
|
/// return to the caller.
|
|
|
|
///
|
|
|
|
/// \param SS the nested-name-specifier that precedes this template-id, if
|
|
|
|
/// we're actually parsing a qualified-id.
|
|
|
|
///
|
|
|
|
/// \param Name for constructor and destructor names, this is the actual
|
|
|
|
/// identifier that may be a template-name.
|
|
|
|
///
|
|
|
|
/// \param NameLoc the location of the class-name in a constructor or
|
|
|
|
/// destructor.
|
|
|
|
///
|
|
|
|
/// \param EnteringContext whether we're entering the scope of the
|
|
|
|
/// nested-name-specifier.
|
|
|
|
///
|
2009-11-04 05:24:04 +08:00
|
|
|
/// \param ObjectType if this unqualified-id occurs within a member access
|
|
|
|
/// expression, the type of the base object whose member is being accessed.
|
|
|
|
///
|
2009-11-03 09:35:08 +08:00
|
|
|
/// \param Id as input, describes the template-name or operator-function-id
|
|
|
|
/// that precedes the '<'. If template arguments were parsed successfully,
|
|
|
|
/// will be updated with the template-id.
|
|
|
|
///
|
Rework parsing of pseudo-destructor expressions and explicit
destructor calls, e.g.,
p->T::~T
We now detect when the member access that we've parsed, e.g.,
p-> or x.
may be a pseudo-destructor expression, either because the type of p or
x is a scalar or because it is dependent (and, therefore, may become a
scalar at template instantiation time).
We then parse the pseudo-destructor grammar specifically:
::[opt] nested-name-specifier[opt] type-name :: ∼ type-name
and hand those results to a new action, ActOnPseudoDestructorExpr,
which will cope with both dependent member accesses of destructors and
with pseudo-destructor expressions.
This commit affects the parsing of pseudo-destructors, only; the
semantic actions still go through the semantic actions for member
access expressions. That will change soon.
llvm-svn: 97045
2010-02-25 02:44:31 +08:00
|
|
|
/// \param AssumeTemplateId When true, this routine will assume that the name
|
|
|
|
/// refers to a template without performing name lookup to verify.
|
|
|
|
///
|
2009-11-03 09:35:08 +08:00
|
|
|
/// \returns true if a parse error occurred, false otherwise.
|
|
|
|
bool Parser::ParseUnqualifiedIdTemplateId(CXXScopeSpec &SS,
|
2012-01-27 17:46:47 +08:00
|
|
|
SourceLocation TemplateKWLoc,
|
2009-11-03 09:35:08 +08:00
|
|
|
IdentifierInfo *Name,
|
|
|
|
SourceLocation NameLoc,
|
|
|
|
bool EnteringContext,
|
2010-08-24 13:47:05 +08:00
|
|
|
ParsedType ObjectType,
|
Rework parsing of pseudo-destructor expressions and explicit
destructor calls, e.g.,
p->T::~T
We now detect when the member access that we've parsed, e.g.,
p-> or x.
may be a pseudo-destructor expression, either because the type of p or
x is a scalar or because it is dependent (and, therefore, may become a
scalar at template instantiation time).
We then parse the pseudo-destructor grammar specifically:
::[opt] nested-name-specifier[opt] type-name :: ∼ type-name
and hand those results to a new action, ActOnPseudoDestructorExpr,
which will cope with both dependent member accesses of destructors and
with pseudo-destructor expressions.
This commit affects the parsing of pseudo-destructors, only; the
semantic actions still go through the semantic actions for member
access expressions. That will change soon.
llvm-svn: 97045
2010-02-25 02:44:31 +08:00
|
|
|
UnqualifiedId &Id,
|
2012-01-27 17:46:47 +08:00
|
|
|
bool AssumeTemplateId) {
|
2010-05-05 13:58:24 +08:00
|
|
|
assert((AssumeTemplateId || Tok.is(tok::less)) &&
|
|
|
|
"Expected '<' to finish parsing a template-id");
|
2009-11-03 09:35:08 +08:00
|
|
|
|
|
|
|
TemplateTy Template;
|
|
|
|
TemplateNameKind TNK = TNK_Non_template;
|
|
|
|
switch (Id.getKind()) {
|
|
|
|
case UnqualifiedId::IK_Identifier:
|
2009-11-04 07:16:33 +08:00
|
|
|
case UnqualifiedId::IK_OperatorFunctionId:
|
2009-11-28 16:58:14 +08:00
|
|
|
case UnqualifiedId::IK_LiteralOperatorId:
|
Rework parsing of pseudo-destructor expressions and explicit
destructor calls, e.g.,
p->T::~T
We now detect when the member access that we've parsed, e.g.,
p-> or x.
may be a pseudo-destructor expression, either because the type of p or
x is a scalar or because it is dependent (and, therefore, may become a
scalar at template instantiation time).
We then parse the pseudo-destructor grammar specifically:
::[opt] nested-name-specifier[opt] type-name :: ∼ type-name
and hand those results to a new action, ActOnPseudoDestructorExpr,
which will cope with both dependent member accesses of destructors and
with pseudo-destructor expressions.
This commit affects the parsing of pseudo-destructors, only; the
semantic actions still go through the semantic actions for member
access expressions. That will change soon.
llvm-svn: 97045
2010-02-25 02:44:31 +08:00
|
|
|
if (AssumeTemplateId) {
|
2012-01-27 17:46:47 +08:00
|
|
|
TNK = Actions.ActOnDependentTemplateName(getCurScope(), SS, TemplateKWLoc,
|
2010-06-17 07:00:59 +08:00
|
|
|
Id, ObjectType, EnteringContext,
|
|
|
|
Template);
|
|
|
|
if (TNK == TNK_Non_template)
|
|
|
|
return true;
|
2010-05-22 07:18:07 +08:00
|
|
|
} else {
|
|
|
|
bool MemberOfUnknownSpecialization;
|
2010-08-06 20:11:11 +08:00
|
|
|
TNK = Actions.isTemplateName(getCurScope(), SS,
|
|
|
|
TemplateKWLoc.isValid(), Id,
|
|
|
|
ObjectType, EnteringContext, Template,
|
2010-05-22 07:18:07 +08:00
|
|
|
MemberOfUnknownSpecialization);
|
|
|
|
|
|
|
|
if (TNK == TNK_Non_template && MemberOfUnknownSpecialization &&
|
|
|
|
ObjectType && IsTemplateArgumentList()) {
|
|
|
|
// We have something like t->getAs<T>(), where getAs is a
|
|
|
|
// member of an unknown specialization. However, this will only
|
|
|
|
// parse correctly as a template, so suggest the keyword 'template'
|
|
|
|
// before 'getAs' and treat this as a dependent template name.
|
|
|
|
std::string Name;
|
|
|
|
if (Id.getKind() == UnqualifiedId::IK_Identifier)
|
|
|
|
Name = Id.Identifier->getName();
|
|
|
|
else {
|
|
|
|
Name = "operator ";
|
|
|
|
if (Id.getKind() == UnqualifiedId::IK_OperatorFunctionId)
|
|
|
|
Name += getOperatorSpelling(Id.OperatorFunctionId.Operator);
|
|
|
|
else
|
|
|
|
Name += Id.Identifier->getName();
|
|
|
|
}
|
|
|
|
Diag(Id.StartLocation, diag::err_missing_dependent_template_keyword)
|
|
|
|
<< Name
|
|
|
|
<< FixItHint::CreateInsertion(Id.StartLocation, "template ");
|
2012-01-27 17:46:47 +08:00
|
|
|
TNK = Actions.ActOnDependentTemplateName(getCurScope(),
|
|
|
|
SS, TemplateKWLoc, Id,
|
|
|
|
ObjectType, EnteringContext,
|
|
|
|
Template);
|
2010-06-17 07:00:59 +08:00
|
|
|
if (TNK == TNK_Non_template)
|
2010-05-22 07:18:07 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2009-11-03 09:35:08 +08:00
|
|
|
break;
|
|
|
|
|
2009-11-04 07:16:33 +08:00
|
|
|
case UnqualifiedId::IK_ConstructorName: {
|
|
|
|
UnqualifiedId TemplateName;
|
2010-05-22 07:18:07 +08:00
|
|
|
bool MemberOfUnknownSpecialization;
|
2009-11-04 07:16:33 +08:00
|
|
|
TemplateName.setIdentifier(Name, NameLoc);
|
2010-08-06 20:11:11 +08:00
|
|
|
TNK = Actions.isTemplateName(getCurScope(), SS, TemplateKWLoc.isValid(),
|
|
|
|
TemplateName, ObjectType,
|
2010-05-22 07:18:07 +08:00
|
|
|
EnteringContext, Template,
|
|
|
|
MemberOfUnknownSpecialization);
|
2009-11-03 09:35:08 +08:00
|
|
|
break;
|
2009-11-04 07:16:33 +08:00
|
|
|
}
|
2009-11-03 09:35:08 +08:00
|
|
|
|
2009-11-04 07:16:33 +08:00
|
|
|
case UnqualifiedId::IK_DestructorName: {
|
|
|
|
UnqualifiedId TemplateName;
|
2010-05-22 07:18:07 +08:00
|
|
|
bool MemberOfUnknownSpecialization;
|
2009-11-04 07:16:33 +08:00
|
|
|
TemplateName.setIdentifier(Name, NameLoc);
|
2009-11-04 03:44:04 +08:00
|
|
|
if (ObjectType) {
|
2012-01-27 17:46:47 +08:00
|
|
|
TNK = Actions.ActOnDependentTemplateName(getCurScope(),
|
|
|
|
SS, TemplateKWLoc, TemplateName,
|
|
|
|
ObjectType, EnteringContext,
|
|
|
|
Template);
|
2010-06-17 07:00:59 +08:00
|
|
|
if (TNK == TNK_Non_template)
|
2009-11-04 03:44:04 +08:00
|
|
|
return true;
|
|
|
|
} else {
|
2010-08-06 20:11:11 +08:00
|
|
|
TNK = Actions.isTemplateName(getCurScope(), SS, TemplateKWLoc.isValid(),
|
|
|
|
TemplateName, ObjectType,
|
2010-05-22 07:18:07 +08:00
|
|
|
EnteringContext, Template,
|
|
|
|
MemberOfUnknownSpecialization);
|
2009-11-04 03:44:04 +08:00
|
|
|
|
2010-08-24 13:47:05 +08:00
|
|
|
if (TNK == TNK_Non_template && !Id.DestructorName.get()) {
|
2010-02-17 03:09:40 +08:00
|
|
|
Diag(NameLoc, diag::err_destructor_template_id)
|
|
|
|
<< Name << SS.getRange();
|
2009-11-04 03:44:04 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2009-11-03 09:35:08 +08:00
|
|
|
break;
|
2009-11-04 07:16:33 +08:00
|
|
|
}
|
2009-11-03 09:35:08 +08:00
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (TNK == TNK_Non_template)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Parse the enclosed template argument list.
|
|
|
|
SourceLocation LAngleLoc, RAngleLoc;
|
|
|
|
TemplateArgList TemplateArgs;
|
2010-05-05 13:58:24 +08:00
|
|
|
if (Tok.is(tok::less) &&
|
|
|
|
ParseTemplateIdAfterTemplateName(Template, Id.StartLocation,
|
2011-03-02 08:47:37 +08:00
|
|
|
SS, true, LAngleLoc,
|
2009-11-03 09:35:08 +08:00
|
|
|
TemplateArgs,
|
|
|
|
RAngleLoc))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (Id.getKind() == UnqualifiedId::IK_Identifier ||
|
2009-11-28 16:58:14 +08:00
|
|
|
Id.getKind() == UnqualifiedId::IK_OperatorFunctionId ||
|
|
|
|
Id.getKind() == UnqualifiedId::IK_LiteralOperatorId) {
|
2009-11-03 09:35:08 +08:00
|
|
|
// Form a parsed representation of the template-id to be stored in the
|
|
|
|
// UnqualifiedId.
|
|
|
|
TemplateIdAnnotation *TemplateId
|
2012-04-14 20:14:03 +08:00
|
|
|
= TemplateIdAnnotation::Allocate(TemplateArgs.size(), TemplateIds);
|
2009-11-03 09:35:08 +08:00
|
|
|
|
2013-12-04 08:28:23 +08:00
|
|
|
// FIXME: Store name for literal operator too.
|
2009-11-03 09:35:08 +08:00
|
|
|
if (Id.getKind() == UnqualifiedId::IK_Identifier) {
|
|
|
|
TemplateId->Name = Id.Identifier;
|
2009-11-04 07:16:33 +08:00
|
|
|
TemplateId->Operator = OO_None;
|
2009-11-03 09:35:08 +08:00
|
|
|
TemplateId->TemplateNameLoc = Id.StartLocation;
|
|
|
|
} else {
|
2014-05-21 14:02:52 +08:00
|
|
|
TemplateId->Name = nullptr;
|
2009-11-04 07:16:33 +08:00
|
|
|
TemplateId->Operator = Id.OperatorFunctionId.Operator;
|
|
|
|
TemplateId->TemplateNameLoc = Id.StartLocation;
|
2009-11-03 09:35:08 +08:00
|
|
|
}
|
|
|
|
|
2011-03-02 08:47:37 +08:00
|
|
|
TemplateId->SS = SS;
|
2012-02-20 07:37:39 +08:00
|
|
|
TemplateId->TemplateKWLoc = TemplateKWLoc;
|
2010-08-23 15:28:44 +08:00
|
|
|
TemplateId->Template = Template;
|
2009-11-03 09:35:08 +08:00
|
|
|
TemplateId->Kind = TNK;
|
|
|
|
TemplateId->LAngleLoc = LAngleLoc;
|
|
|
|
TemplateId->RAngleLoc = RAngleLoc;
|
2009-11-11 03:49:08 +08:00
|
|
|
ParsedTemplateArgument *Args = TemplateId->getTemplateArgs();
|
2009-11-03 09:35:08 +08:00
|
|
|
for (unsigned Arg = 0, ArgEnd = TemplateArgs.size();
|
2009-11-11 03:49:08 +08:00
|
|
|
Arg != ArgEnd; ++Arg)
|
2009-11-03 09:35:08 +08:00
|
|
|
Args[Arg] = TemplateArgs[Arg];
|
|
|
|
|
|
|
|
Id.setTemplateId(TemplateId);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Bundle the template arguments together.
|
2012-08-24 07:38:35 +08:00
|
|
|
ASTTemplateArgsPtr TemplateArgsPtr(TemplateArgs);
|
2012-01-27 16:46:19 +08:00
|
|
|
|
2009-11-03 09:35:08 +08:00
|
|
|
// Constructor and destructor names.
|
2010-08-27 07:41:50 +08:00
|
|
|
TypeResult Type
|
2012-02-06 22:41:24 +08:00
|
|
|
= Actions.ActOnTemplateIdType(SS, TemplateKWLoc,
|
2017-01-20 05:00:13 +08:00
|
|
|
Template, Name, NameLoc,
|
2012-01-27 16:46:19 +08:00
|
|
|
LAngleLoc, TemplateArgsPtr, RAngleLoc,
|
|
|
|
/*IsCtorOrDtorName=*/true);
|
2009-11-03 09:35:08 +08:00
|
|
|
if (Type.isInvalid())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (Id.getKind() == UnqualifiedId::IK_ConstructorName)
|
|
|
|
Id.setConstructorName(Type.get(), NameLoc, RAngleLoc);
|
|
|
|
else
|
|
|
|
Id.setDestructorName(Id.StartLocation, Type.get(), RAngleLoc);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-11-04 08:56:37 +08:00
|
|
|
/// \brief Parse an operator-function-id or conversion-function-id as part
|
|
|
|
/// of a C++ unqualified-id.
|
2009-11-03 09:35:08 +08:00
|
|
|
///
|
2009-11-04 08:56:37 +08:00
|
|
|
/// This routine is responsible only for parsing the operator-function-id or
|
|
|
|
/// conversion-function-id; it does not handle template arguments in any way.
|
2009-11-03 09:35:08 +08:00
|
|
|
///
|
2009-11-04 08:56:37 +08:00
|
|
|
/// \code
|
2009-11-03 09:35:08 +08:00
|
|
|
/// operator-function-id: [C++ 13.5]
|
|
|
|
/// 'operator' operator
|
|
|
|
///
|
2009-11-04 08:56:37 +08:00
|
|
|
/// operator: one of
|
2009-11-03 09:35:08 +08:00
|
|
|
/// new delete new[] delete[]
|
|
|
|
/// + - * / % ^ & | ~
|
|
|
|
/// ! = < > += -= *= /= %=
|
|
|
|
/// ^= &= |= << >> >>= <<= == !=
|
|
|
|
/// <= >= && || ++ -- , ->* ->
|
|
|
|
/// () []
|
|
|
|
///
|
|
|
|
/// conversion-function-id: [C++ 12.3.2]
|
|
|
|
/// operator conversion-type-id
|
|
|
|
///
|
|
|
|
/// conversion-type-id:
|
|
|
|
/// type-specifier-seq conversion-declarator[opt]
|
|
|
|
///
|
|
|
|
/// conversion-declarator:
|
|
|
|
/// ptr-operator conversion-declarator[opt]
|
|
|
|
/// \endcode
|
|
|
|
///
|
2012-08-24 08:01:24 +08:00
|
|
|
/// \param SS The nested-name-specifier that preceded this unqualified-id. If
|
2009-11-03 09:35:08 +08:00
|
|
|
/// non-empty, then we are parsing the unqualified-id of a qualified-id.
|
|
|
|
///
|
|
|
|
/// \param EnteringContext whether we are entering the scope of the
|
|
|
|
/// nested-name-specifier.
|
|
|
|
///
|
2009-11-04 08:56:37 +08:00
|
|
|
/// \param ObjectType if this unqualified-id occurs within a member access
|
|
|
|
/// expression, the type of the base object whose member is being accessed.
|
|
|
|
///
|
|
|
|
/// \param Result on a successful parse, contains the parsed unqualified-id.
|
|
|
|
///
|
|
|
|
/// \returns true if parsing fails, false otherwise.
|
|
|
|
bool Parser::ParseUnqualifiedIdOperator(CXXScopeSpec &SS, bool EnteringContext,
|
2010-08-24 13:47:05 +08:00
|
|
|
ParsedType ObjectType,
|
2009-11-04 08:56:37 +08:00
|
|
|
UnqualifiedId &Result) {
|
|
|
|
assert(Tok.is(tok::kw_operator) && "Expected 'operator' keyword");
|
|
|
|
|
|
|
|
// Consume the 'operator' keyword.
|
|
|
|
SourceLocation KeywordLoc = ConsumeToken();
|
|
|
|
|
|
|
|
// Determine what kind of operator name we have.
|
|
|
|
unsigned SymbolIdx = 0;
|
|
|
|
SourceLocation SymbolLocations[3];
|
|
|
|
OverloadedOperatorKind Op = OO_None;
|
|
|
|
switch (Tok.getKind()) {
|
|
|
|
case tok::kw_new:
|
|
|
|
case tok::kw_delete: {
|
|
|
|
bool isNew = Tok.getKind() == tok::kw_new;
|
|
|
|
// Consume the 'new' or 'delete'.
|
|
|
|
SymbolLocations[SymbolIdx++] = ConsumeToken();
|
2012-04-10 09:32:12 +08:00
|
|
|
// Check for array new/delete.
|
|
|
|
if (Tok.is(tok::l_square) &&
|
2013-01-02 19:42:31 +08:00
|
|
|
(!getLangOpts().CPlusPlus11 || NextToken().isNot(tok::l_square))) {
|
2011-10-13 00:37:45 +08:00
|
|
|
// Consume the '[' and ']'.
|
|
|
|
BalancedDelimiterTracker T(*this, tok::l_square);
|
|
|
|
T.consumeOpen();
|
|
|
|
T.consumeClose();
|
|
|
|
if (T.getCloseLocation().isInvalid())
|
2009-11-04 08:56:37 +08:00
|
|
|
return true;
|
|
|
|
|
2011-10-13 00:37:45 +08:00
|
|
|
SymbolLocations[SymbolIdx++] = T.getOpenLocation();
|
|
|
|
SymbolLocations[SymbolIdx++] = T.getCloseLocation();
|
2009-11-04 08:56:37 +08:00
|
|
|
Op = isNew? OO_Array_New : OO_Array_Delete;
|
|
|
|
} else {
|
|
|
|
Op = isNew? OO_New : OO_Delete;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
|
|
|
|
case tok::Token: \
|
|
|
|
SymbolLocations[SymbolIdx++] = ConsumeToken(); \
|
|
|
|
Op = OO_##Name; \
|
|
|
|
break;
|
|
|
|
#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
|
|
|
|
#include "clang/Basic/OperatorKinds.def"
|
|
|
|
|
|
|
|
case tok::l_paren: {
|
2011-10-13 00:37:45 +08:00
|
|
|
// Consume the '(' and ')'.
|
|
|
|
BalancedDelimiterTracker T(*this, tok::l_paren);
|
|
|
|
T.consumeOpen();
|
|
|
|
T.consumeClose();
|
|
|
|
if (T.getCloseLocation().isInvalid())
|
2009-11-04 08:56:37 +08:00
|
|
|
return true;
|
|
|
|
|
2011-10-13 00:37:45 +08:00
|
|
|
SymbolLocations[SymbolIdx++] = T.getOpenLocation();
|
|
|
|
SymbolLocations[SymbolIdx++] = T.getCloseLocation();
|
2009-11-04 08:56:37 +08:00
|
|
|
Op = OO_Call;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case tok::l_square: {
|
2011-10-13 00:37:45 +08:00
|
|
|
// Consume the '[' and ']'.
|
|
|
|
BalancedDelimiterTracker T(*this, tok::l_square);
|
|
|
|
T.consumeOpen();
|
|
|
|
T.consumeClose();
|
|
|
|
if (T.getCloseLocation().isInvalid())
|
2009-11-04 08:56:37 +08:00
|
|
|
return true;
|
|
|
|
|
2011-10-13 00:37:45 +08:00
|
|
|
SymbolLocations[SymbolIdx++] = T.getOpenLocation();
|
|
|
|
SymbolLocations[SymbolIdx++] = T.getCloseLocation();
|
2009-11-04 08:56:37 +08:00
|
|
|
Op = OO_Subscript;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case tok::code_completion: {
|
|
|
|
// Code completion for the operator name.
|
2010-07-03 01:43:08 +08:00
|
|
|
Actions.CodeCompleteOperatorName(getCurScope());
|
2011-09-04 11:32:15 +08:00
|
|
|
cutOffParsing();
|
2009-11-04 08:56:37 +08:00
|
|
|
// Don't try to parse any further.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Op != OO_None) {
|
|
|
|
// We have parsed an operator-function-id.
|
|
|
|
Result.setOperatorFunctionId(KeywordLoc, Op, SymbolLocations);
|
|
|
|
return false;
|
|
|
|
}
|
2009-11-28 12:44:28 +08:00
|
|
|
|
|
|
|
// Parse a literal-operator-id.
|
|
|
|
//
|
2012-10-20 16:41:10 +08:00
|
|
|
// literal-operator-id: C++11 [over.literal]
|
|
|
|
// operator string-literal identifier
|
|
|
|
// operator user-defined-string-literal
|
2009-11-28 12:44:28 +08:00
|
|
|
|
2013-01-02 19:42:31 +08:00
|
|
|
if (getLangOpts().CPlusPlus11 && isTokenStringLiteral()) {
|
2011-10-15 13:09:34 +08:00
|
|
|
Diag(Tok.getLocation(), diag::warn_cxx98_compat_literal_operator);
|
2012-03-09 07:06:02 +08:00
|
|
|
|
|
|
|
SourceLocation DiagLoc;
|
|
|
|
unsigned DiagId = 0;
|
|
|
|
|
|
|
|
// We're past translation phase 6, so perform string literal concatenation
|
|
|
|
// before checking for "".
|
2013-01-13 03:30:44 +08:00
|
|
|
SmallVector<Token, 4> Toks;
|
|
|
|
SmallVector<SourceLocation, 4> TokLocs;
|
2012-03-09 07:06:02 +08:00
|
|
|
while (isTokenStringLiteral()) {
|
|
|
|
if (!Tok.is(tok::string_literal) && !DiagId) {
|
2012-10-20 16:41:10 +08:00
|
|
|
// C++11 [over.literal]p1:
|
|
|
|
// The string-literal or user-defined-string-literal in a
|
|
|
|
// literal-operator-id shall have no encoding-prefix [...].
|
2012-03-09 07:06:02 +08:00
|
|
|
DiagLoc = Tok.getLocation();
|
|
|
|
DiagId = diag::err_literal_operator_string_prefix;
|
|
|
|
}
|
|
|
|
Toks.push_back(Tok);
|
|
|
|
TokLocs.push_back(ConsumeStringToken());
|
2012-03-06 11:21:47 +08:00
|
|
|
}
|
2009-11-28 12:44:28 +08:00
|
|
|
|
2014-06-26 12:58:39 +08:00
|
|
|
StringLiteralParser Literal(Toks, PP);
|
2012-03-09 07:06:02 +08:00
|
|
|
if (Literal.hadError)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Grab the literal operator's suffix, which will be either the next token
|
|
|
|
// or a ud-suffix from the string literal.
|
2014-05-21 14:02:52 +08:00
|
|
|
IdentifierInfo *II = nullptr;
|
2012-03-09 07:06:02 +08:00
|
|
|
SourceLocation SuffixLoc;
|
|
|
|
if (!Literal.getUDSuffix().empty()) {
|
|
|
|
II = &PP.getIdentifierTable().get(Literal.getUDSuffix());
|
|
|
|
SuffixLoc =
|
|
|
|
Lexer::AdvanceToTokenCharacter(TokLocs[Literal.getUDSuffixToken()],
|
|
|
|
Literal.getUDSuffixOffset(),
|
2012-03-11 15:00:24 +08:00
|
|
|
PP.getSourceManager(), getLangOpts());
|
2012-03-09 07:06:02 +08:00
|
|
|
} else if (Tok.is(tok::identifier)) {
|
|
|
|
II = Tok.getIdentifierInfo();
|
|
|
|
SuffixLoc = ConsumeToken();
|
|
|
|
TokLocs.push_back(SuffixLoc);
|
|
|
|
} else {
|
2013-12-24 17:48:30 +08:00
|
|
|
Diag(Tok.getLocation(), diag::err_expected) << tok::identifier;
|
2009-11-28 12:44:28 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-03-09 07:06:02 +08:00
|
|
|
// The string literal must be empty.
|
|
|
|
if (!Literal.GetString().empty() || Literal.Pascal) {
|
2012-10-20 16:41:10 +08:00
|
|
|
// C++11 [over.literal]p1:
|
|
|
|
// The string-literal or user-defined-string-literal in a
|
|
|
|
// literal-operator-id shall [...] contain no characters
|
|
|
|
// other than the implicit terminating '\0'.
|
2012-03-09 07:06:02 +08:00
|
|
|
DiagLoc = TokLocs.front();
|
|
|
|
DiagId = diag::err_literal_operator_string_not_empty;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (DiagId) {
|
|
|
|
// This isn't a valid literal-operator-id, but we think we know
|
|
|
|
// what the user meant. Tell them what they should have written.
|
2013-01-13 03:30:44 +08:00
|
|
|
SmallString<32> Str;
|
2015-10-08 08:17:59 +08:00
|
|
|
Str += "\"\"";
|
2012-03-09 07:06:02 +08:00
|
|
|
Str += II->getName();
|
|
|
|
Diag(DiagLoc, DiagId) << FixItHint::CreateReplacement(
|
|
|
|
SourceRange(TokLocs.front(), TokLocs.back()), Str);
|
|
|
|
}
|
|
|
|
|
|
|
|
Result.setLiteralOperatorId(II, KeywordLoc, SuffixLoc);
|
2013-12-05 08:58:33 +08:00
|
|
|
|
|
|
|
return Actions.checkLiteralOperatorId(SS, Result);
|
2009-11-28 12:44:28 +08:00
|
|
|
}
|
2013-12-05 08:58:33 +08:00
|
|
|
|
2009-11-04 08:56:37 +08:00
|
|
|
// Parse a conversion-function-id.
|
|
|
|
//
|
|
|
|
// conversion-function-id: [C++ 12.3.2]
|
|
|
|
// operator conversion-type-id
|
|
|
|
//
|
|
|
|
// conversion-type-id:
|
|
|
|
// type-specifier-seq conversion-declarator[opt]
|
|
|
|
//
|
|
|
|
// conversion-declarator:
|
|
|
|
// ptr-operator conversion-declarator[opt]
|
|
|
|
|
|
|
|
// Parse the type-specifier-seq.
|
2011-03-24 19:26:52 +08:00
|
|
|
DeclSpec DS(AttrFactory);
|
2009-11-21 06:03:38 +08:00
|
|
|
if (ParseCXXTypeSpecifierSeq(DS)) // FIXME: ObjectType?
|
2009-11-04 08:56:37 +08:00
|
|
|
return true;
|
|
|
|
|
|
|
|
// Parse the conversion-declarator, which is merely a sequence of
|
|
|
|
// ptr-operators.
|
2013-05-04 09:26:46 +08:00
|
|
|
Declarator D(DS, Declarator::ConversionIdContext);
|
2014-05-21 14:02:52 +08:00
|
|
|
ParseDeclaratorInternal(D, /*DirectDeclParser=*/nullptr);
|
|
|
|
|
2009-11-04 08:56:37 +08:00
|
|
|
// Finish up the type.
|
2010-08-27 07:41:50 +08:00
|
|
|
TypeResult Ty = Actions.ActOnTypeName(getCurScope(), D);
|
2009-11-04 08:56:37 +08:00
|
|
|
if (Ty.isInvalid())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Note that this is a conversion-function-id.
|
|
|
|
Result.setConversionFunctionId(KeywordLoc, Ty.get(),
|
|
|
|
D.getSourceRange().getEnd());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Parse a C++ unqualified-id (or a C identifier), which describes the
|
|
|
|
/// name of an entity.
|
|
|
|
///
|
|
|
|
/// \code
|
|
|
|
/// unqualified-id: [C++ expr.prim.general]
|
|
|
|
/// identifier
|
|
|
|
/// operator-function-id
|
|
|
|
/// conversion-function-id
|
|
|
|
/// [C++0x] literal-operator-id [TODO]
|
|
|
|
/// ~ class-name
|
|
|
|
/// template-id
|
|
|
|
///
|
|
|
|
/// \endcode
|
|
|
|
///
|
2012-08-24 08:01:24 +08:00
|
|
|
/// \param SS The nested-name-specifier that preceded this unqualified-id. If
|
2009-11-04 08:56:37 +08:00
|
|
|
/// non-empty, then we are parsing the unqualified-id of a qualified-id.
|
|
|
|
///
|
|
|
|
/// \param EnteringContext whether we are entering the scope of the
|
|
|
|
/// nested-name-specifier.
|
|
|
|
///
|
2009-11-03 09:35:08 +08:00
|
|
|
/// \param AllowDestructorName whether we allow parsing of a destructor name.
|
|
|
|
///
|
|
|
|
/// \param AllowConstructorName whether we allow parsing a constructor name.
|
|
|
|
///
|
2009-11-04 05:24:04 +08:00
|
|
|
/// \param ObjectType if this unqualified-id occurs within a member access
|
|
|
|
/// expression, the type of the base object whose member is being accessed.
|
|
|
|
///
|
2009-11-03 09:35:08 +08:00
|
|
|
/// \param Result on a successful parse, contains the parsed unqualified-id.
|
|
|
|
///
|
|
|
|
/// \returns true if parsing fails, false otherwise.
|
|
|
|
bool Parser::ParseUnqualifiedId(CXXScopeSpec &SS, bool EnteringContext,
|
|
|
|
bool AllowDestructorName,
|
|
|
|
bool AllowConstructorName,
|
2010-08-24 13:47:05 +08:00
|
|
|
ParsedType ObjectType,
|
2012-01-27 17:46:47 +08:00
|
|
|
SourceLocation& TemplateKWLoc,
|
2009-11-03 09:35:08 +08:00
|
|
|
UnqualifiedId &Result) {
|
2010-05-05 13:58:24 +08:00
|
|
|
|
|
|
|
// Handle 'A::template B'. This is for template-ids which have not
|
|
|
|
// already been annotated by ParseOptionalCXXScopeSpecifier().
|
|
|
|
bool TemplateSpecified = false;
|
2012-03-11 15:00:24 +08:00
|
|
|
if (getLangOpts().CPlusPlus && Tok.is(tok::kw_template) &&
|
2010-05-05 13:58:24 +08:00
|
|
|
(ObjectType || SS.isSet())) {
|
|
|
|
TemplateSpecified = true;
|
|
|
|
TemplateKWLoc = ConsumeToken();
|
|
|
|
}
|
|
|
|
|
2009-11-03 09:35:08 +08:00
|
|
|
// unqualified-id:
|
|
|
|
// identifier
|
|
|
|
// template-id (when it hasn't already been annotated)
|
|
|
|
if (Tok.is(tok::identifier)) {
|
|
|
|
// Consume the identifier.
|
|
|
|
IdentifierInfo *Id = Tok.getIdentifierInfo();
|
|
|
|
SourceLocation IdLoc = ConsumeToken();
|
|
|
|
|
2012-03-11 15:00:24 +08:00
|
|
|
if (!getLangOpts().CPlusPlus) {
|
2010-01-12 07:29:10 +08:00
|
|
|
// If we're not in C++, only identifiers matter. Record the
|
|
|
|
// identifier and return.
|
|
|
|
Result.setIdentifier(Id, IdLoc);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-11-03 09:35:08 +08:00
|
|
|
if (AllowConstructorName &&
|
2010-07-03 01:43:08 +08:00
|
|
|
Actions.isCurrentClassName(*Id, getCurScope(), &SS)) {
|
2009-11-03 09:35:08 +08:00
|
|
|
// We have parsed a constructor name.
|
2016-01-16 07:43:34 +08:00
|
|
|
ParsedType Ty = Actions.getTypeName(*Id, IdLoc, getCurScope(), &SS, false,
|
|
|
|
false, nullptr,
|
2012-01-27 16:46:19 +08:00
|
|
|
/*IsCtorOrDtorName=*/true,
|
|
|
|
/*NonTrivialTypeSourceInfo=*/true);
|
|
|
|
Result.setConstructorName(Ty, IdLoc, IdLoc);
|
2009-11-03 09:35:08 +08:00
|
|
|
} else {
|
|
|
|
// We have parsed an identifier.
|
|
|
|
Result.setIdentifier(Id, IdLoc);
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the next token is a '<', we may have a template.
|
2010-05-05 13:58:24 +08:00
|
|
|
if (TemplateSpecified || Tok.is(tok::less))
|
2012-01-27 17:46:47 +08:00
|
|
|
return ParseUnqualifiedIdTemplateId(SS, TemplateKWLoc, Id, IdLoc,
|
|
|
|
EnteringContext, ObjectType,
|
|
|
|
Result, TemplateSpecified);
|
2009-11-03 09:35:08 +08:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// unqualified-id:
|
|
|
|
// template-id (already parsed and annotated)
|
|
|
|
if (Tok.is(tok::annot_template_id)) {
|
2011-06-22 14:09:49 +08:00
|
|
|
TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Tok);
|
2010-01-14 01:31:36 +08:00
|
|
|
|
|
|
|
// If the template-name names the current class, then this is a constructor
|
|
|
|
if (AllowConstructorName && TemplateId->Name &&
|
2010-07-03 01:43:08 +08:00
|
|
|
Actions.isCurrentClassName(*TemplateId->Name, getCurScope(), &SS)) {
|
2010-01-14 01:31:36 +08:00
|
|
|
if (SS.isSet()) {
|
|
|
|
// C++ [class.qual]p2 specifies that a qualified template-name
|
|
|
|
// is taken as the constructor name where a constructor can be
|
|
|
|
// declared. Thus, the template arguments are extraneous, so
|
|
|
|
// complain about them and remove them entirely.
|
|
|
|
Diag(TemplateId->TemplateNameLoc,
|
|
|
|
diag::err_out_of_line_constructor_template_id)
|
|
|
|
<< TemplateId->Name
|
2010-04-01 01:46:05 +08:00
|
|
|
<< FixItHint::CreateRemoval(
|
2010-01-14 01:31:36 +08:00
|
|
|
SourceRange(TemplateId->LAngleLoc, TemplateId->RAngleLoc));
|
2016-01-16 07:43:34 +08:00
|
|
|
ParsedType Ty =
|
|
|
|
Actions.getTypeName(*TemplateId->Name, TemplateId->TemplateNameLoc,
|
|
|
|
getCurScope(), &SS, false, false, nullptr,
|
|
|
|
/*IsCtorOrDtorName=*/true,
|
|
|
|
/*NontrivialTypeSourceInfo=*/true);
|
2012-01-27 16:46:19 +08:00
|
|
|
Result.setConstructorName(Ty, TemplateId->TemplateNameLoc,
|
2010-01-14 01:31:36 +08:00
|
|
|
TemplateId->RAngleLoc);
|
|
|
|
ConsumeToken();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Result.setConstructorTemplateId(TemplateId);
|
|
|
|
ConsumeToken();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-11-03 09:35:08 +08:00
|
|
|
// We have already parsed a template-id; consume the annotation token as
|
|
|
|
// our unqualified-id.
|
2010-01-14 01:31:36 +08:00
|
|
|
Result.setTemplateId(TemplateId);
|
2012-01-27 17:46:47 +08:00
|
|
|
TemplateKWLoc = TemplateId->TemplateKWLoc;
|
2009-11-03 09:35:08 +08:00
|
|
|
ConsumeToken();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// unqualified-id:
|
|
|
|
// operator-function-id
|
|
|
|
// conversion-function-id
|
|
|
|
if (Tok.is(tok::kw_operator)) {
|
2009-11-04 08:56:37 +08:00
|
|
|
if (ParseUnqualifiedIdOperator(SS, EnteringContext, ObjectType, Result))
|
2009-11-03 09:35:08 +08:00
|
|
|
return true;
|
|
|
|
|
2009-11-28 16:58:14 +08:00
|
|
|
// If we have an operator-function-id or a literal-operator-id and the next
|
|
|
|
// token is a '<', we may have a
|
2009-11-04 08:56:37 +08:00
|
|
|
//
|
|
|
|
// template-id:
|
|
|
|
// operator-function-id < template-argument-list[opt] >
|
2009-11-28 16:58:14 +08:00
|
|
|
if ((Result.getKind() == UnqualifiedId::IK_OperatorFunctionId ||
|
|
|
|
Result.getKind() == UnqualifiedId::IK_LiteralOperatorId) &&
|
2010-05-05 13:58:24 +08:00
|
|
|
(TemplateSpecified || Tok.is(tok::less)))
|
2012-01-27 17:46:47 +08:00
|
|
|
return ParseUnqualifiedIdTemplateId(SS, TemplateKWLoc,
|
2014-05-21 14:02:52 +08:00
|
|
|
nullptr, SourceLocation(),
|
2012-01-27 17:46:47 +08:00
|
|
|
EnteringContext, ObjectType,
|
|
|
|
Result, TemplateSpecified);
|
2014-05-21 14:02:52 +08:00
|
|
|
|
2009-11-03 09:35:08 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-03-11 15:00:24 +08:00
|
|
|
if (getLangOpts().CPlusPlus &&
|
2010-01-12 07:29:10 +08:00
|
|
|
(AllowDestructorName || SS.isSet()) && Tok.is(tok::tilde)) {
|
2009-11-03 09:35:08 +08:00
|
|
|
// C++ [expr.unary.op]p10:
|
|
|
|
// There is an ambiguity in the unary-expression ~X(), where X is a
|
|
|
|
// class-name. The ambiguity is resolved in favor of treating ~ as a
|
|
|
|
// unary complement rather than treating ~X as referring to a destructor.
|
|
|
|
|
|
|
|
// Parse the '~'.
|
|
|
|
SourceLocation TildeLoc = ConsumeToken();
|
2011-12-09 00:13:53 +08:00
|
|
|
|
|
|
|
if (SS.isEmpty() && Tok.is(tok::kw_decltype)) {
|
|
|
|
DeclSpec DS(AttrFactory);
|
|
|
|
SourceLocation EndLoc = ParseDecltypeSpecifier(DS);
|
|
|
|
if (ParsedType Type = Actions.getDestructorType(DS, ObjectType)) {
|
|
|
|
Result.setDestructorName(TildeLoc, Type, EndLoc);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2009-11-03 09:35:08 +08:00
|
|
|
|
|
|
|
// Parse the class-name.
|
|
|
|
if (Tok.isNot(tok::identifier)) {
|
2010-02-17 03:09:40 +08:00
|
|
|
Diag(Tok, diag::err_destructor_tilde_identifier);
|
2009-11-03 09:35:08 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-09-06 10:06:12 +08:00
|
|
|
// If the user wrote ~T::T, correct it to T::~T.
|
2015-01-15 08:48:52 +08:00
|
|
|
DeclaratorScopeObj DeclScopeObj(*this, SS);
|
2015-02-02 12:18:38 +08:00
|
|
|
if (!TemplateSpecified && NextToken().is(tok::coloncolon)) {
|
2015-01-31 00:53:11 +08:00
|
|
|
// Don't let ParseOptionalCXXScopeSpecifier() "correct"
|
|
|
|
// `int A; struct { ~A::A(); };` to `int A; struct { ~A:A(); };`,
|
|
|
|
// it will confuse this recovery logic.
|
|
|
|
ColonProtectionRAIIObject ColonRAII(*this, false);
|
|
|
|
|
2014-09-06 10:06:12 +08:00
|
|
|
if (SS.isSet()) {
|
|
|
|
AnnotateScopeToken(SS, /*NewAnnotation*/true);
|
|
|
|
SS.clear();
|
|
|
|
}
|
|
|
|
if (ParseOptionalCXXScopeSpecifier(SS, ObjectType, EnteringContext))
|
|
|
|
return true;
|
2015-02-02 13:33:50 +08:00
|
|
|
if (SS.isNotEmpty())
|
2016-01-16 07:43:34 +08:00
|
|
|
ObjectType = nullptr;
|
2015-01-30 12:05:15 +08:00
|
|
|
if (Tok.isNot(tok::identifier) || NextToken().is(tok::coloncolon) ||
|
2015-03-29 22:35:39 +08:00
|
|
|
!SS.isSet()) {
|
2014-09-06 10:06:12 +08:00
|
|
|
Diag(TildeLoc, diag::err_destructor_tilde_scope);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Recover as if the tilde had been written before the identifier.
|
|
|
|
Diag(TildeLoc, diag::err_destructor_tilde_scope)
|
|
|
|
<< FixItHint::CreateRemoval(TildeLoc)
|
|
|
|
<< FixItHint::CreateInsertion(Tok.getLocation(), "~");
|
2015-01-15 08:48:52 +08:00
|
|
|
|
|
|
|
// Temporarily enter the scope for the rest of this function.
|
|
|
|
if (Actions.ShouldEnterDeclaratorScope(getCurScope(), SS))
|
|
|
|
DeclScopeObj.EnterDeclaratorScope();
|
2014-09-06 10:06:12 +08:00
|
|
|
}
|
|
|
|
|
2009-11-03 09:35:08 +08:00
|
|
|
// Parse the class-name (or template-name in a simple-template-id).
|
|
|
|
IdentifierInfo *ClassName = Tok.getIdentifierInfo();
|
|
|
|
SourceLocation ClassNameLoc = ConsumeToken();
|
2014-09-06 10:06:12 +08:00
|
|
|
|
2010-05-05 13:58:24 +08:00
|
|
|
if (TemplateSpecified || Tok.is(tok::less)) {
|
2016-01-16 07:43:34 +08:00
|
|
|
Result.setDestructorName(TildeLoc, nullptr, ClassNameLoc);
|
2012-01-27 17:46:47 +08:00
|
|
|
return ParseUnqualifiedIdTemplateId(SS, TemplateKWLoc,
|
|
|
|
ClassName, ClassNameLoc,
|
|
|
|
EnteringContext, ObjectType,
|
|
|
|
Result, TemplateSpecified);
|
2009-11-04 03:44:04 +08:00
|
|
|
}
|
2014-09-06 10:06:12 +08:00
|
|
|
|
2009-11-03 09:35:08 +08:00
|
|
|
// Note that this is a destructor name.
|
2010-08-24 13:47:05 +08:00
|
|
|
ParsedType Ty = Actions.getDestructorName(TildeLoc, *ClassName,
|
|
|
|
ClassNameLoc, getCurScope(),
|
|
|
|
SS, ObjectType,
|
|
|
|
EnteringContext);
|
2010-02-17 03:09:40 +08:00
|
|
|
if (!Ty)
|
2009-11-03 09:35:08 +08:00
|
|
|
return true;
|
2010-02-17 03:09:40 +08:00
|
|
|
|
2009-11-03 09:35:08 +08:00
|
|
|
Result.setDestructorName(TildeLoc, Ty, ClassNameLoc);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-11-04 03:44:04 +08:00
|
|
|
Diag(Tok, diag::err_expected_unqualified_id)
|
2012-03-11 15:00:24 +08:00
|
|
|
<< getLangOpts().CPlusPlus;
|
2009-11-03 09:35:08 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-11-22 03:14:01 +08:00
|
|
|
/// ParseCXXNewExpression - Parse a C++ new-expression. New is used to allocate
|
|
|
|
/// memory in a typesafe manner and call constructors.
|
2009-09-09 23:08:12 +08:00
|
|
|
///
|
2009-01-05 05:25:24 +08:00
|
|
|
/// This method is called to parse the new expression after the optional :: has
|
|
|
|
/// been already parsed. If the :: was present, "UseGlobal" is true and "Start"
|
|
|
|
/// is its location. Otherwise, "Start" is the location of the 'new' token.
|
2008-11-22 03:14:01 +08:00
|
|
|
///
|
|
|
|
/// new-expression:
|
|
|
|
/// '::'[opt] 'new' new-placement[opt] new-type-id
|
|
|
|
/// new-initializer[opt]
|
|
|
|
/// '::'[opt] 'new' new-placement[opt] '(' type-id ')'
|
|
|
|
/// new-initializer[opt]
|
|
|
|
///
|
|
|
|
/// new-placement:
|
|
|
|
/// '(' expression-list ')'
|
|
|
|
///
|
2008-12-02 22:43:59 +08:00
|
|
|
/// new-type-id:
|
|
|
|
/// type-specifier-seq new-declarator[opt]
|
2011-04-16 03:40:02 +08:00
|
|
|
/// [GNU] attributes type-specifier-seq new-declarator[opt]
|
2008-12-02 22:43:59 +08:00
|
|
|
///
|
|
|
|
/// new-declarator:
|
|
|
|
/// ptr-operator new-declarator[opt]
|
|
|
|
/// direct-new-declarator
|
|
|
|
///
|
2008-11-22 03:14:01 +08:00
|
|
|
/// new-initializer:
|
|
|
|
/// '(' expression-list[opt] ')'
|
2011-06-05 20:23:16 +08:00
|
|
|
/// [C++0x] braced-init-list
|
2008-11-22 03:14:01 +08:00
|
|
|
///
|
2010-08-24 14:29:42 +08:00
|
|
|
ExprResult
|
2009-01-05 05:25:24 +08:00
|
|
|
Parser::ParseCXXNewExpression(bool UseGlobal, SourceLocation Start) {
|
|
|
|
assert(Tok.is(tok::kw_new) && "expected 'new' token");
|
|
|
|
ConsumeToken(); // Consume 'new'
|
2008-11-22 03:14:01 +08:00
|
|
|
|
|
|
|
// A '(' now can be a new-placement or the '(' wrapping the type-id in the
|
|
|
|
// second form of new-expression. It can't be a new-type-id.
|
|
|
|
|
2012-08-24 06:51:59 +08:00
|
|
|
ExprVector PlacementArgs;
|
2008-11-22 03:14:01 +08:00
|
|
|
SourceLocation PlacementLParen, PlacementRParen;
|
|
|
|
|
2010-07-13 23:54:32 +08:00
|
|
|
SourceRange TypeIdParens;
|
2011-03-24 19:26:52 +08:00
|
|
|
DeclSpec DS(AttrFactory);
|
2011-06-28 11:01:23 +08:00
|
|
|
Declarator DeclaratorInfo(DS, Declarator::CXXNewContext);
|
2008-11-22 03:14:01 +08:00
|
|
|
if (Tok.is(tok::l_paren)) {
|
|
|
|
// If it turns out to be a placement, we change the type location.
|
2011-10-13 00:37:45 +08:00
|
|
|
BalancedDelimiterTracker T(*this, tok::l_paren);
|
|
|
|
T.consumeOpen();
|
|
|
|
PlacementLParen = T.getOpenLocation();
|
2008-12-02 22:43:59 +08:00
|
|
|
if (ParseExpressionListOrTypeId(PlacementArgs, DeclaratorInfo)) {
|
2013-11-18 16:17:37 +08:00
|
|
|
SkipUntil(tok::semi, StopAtSemi | StopBeforeMatch);
|
2008-12-12 06:51:44 +08:00
|
|
|
return ExprError();
|
2008-12-02 22:43:59 +08:00
|
|
|
}
|
2008-11-22 03:14:01 +08:00
|
|
|
|
2011-10-13 00:37:45 +08:00
|
|
|
T.consumeClose();
|
|
|
|
PlacementRParen = T.getCloseLocation();
|
2008-12-02 22:43:59 +08:00
|
|
|
if (PlacementRParen.isInvalid()) {
|
2013-11-18 16:17:37 +08:00
|
|
|
SkipUntil(tok::semi, StopAtSemi | StopBeforeMatch);
|
2008-12-12 06:51:44 +08:00
|
|
|
return ExprError();
|
2008-12-02 22:43:59 +08:00
|
|
|
}
|
2008-11-22 03:14:01 +08:00
|
|
|
|
2008-12-02 22:43:59 +08:00
|
|
|
if (PlacementArgs.empty()) {
|
2008-11-22 03:14:01 +08:00
|
|
|
// Reset the placement locations. There was no placement.
|
2011-10-13 00:37:45 +08:00
|
|
|
TypeIdParens = T.getRange();
|
2008-11-22 03:14:01 +08:00
|
|
|
PlacementLParen = PlacementRParen = SourceLocation();
|
|
|
|
} else {
|
|
|
|
// We still need the type.
|
|
|
|
if (Tok.is(tok::l_paren)) {
|
2011-10-13 00:37:45 +08:00
|
|
|
BalancedDelimiterTracker T(*this, tok::l_paren);
|
|
|
|
T.consumeOpen();
|
2011-04-16 03:40:02 +08:00
|
|
|
MaybeParseGNUAttributes(DeclaratorInfo);
|
2008-12-02 22:43:59 +08:00
|
|
|
ParseSpecifierQualifierList(DS);
|
2009-02-10 02:23:29 +08:00
|
|
|
DeclaratorInfo.SetSourceRange(DS.getSourceRange());
|
2008-12-02 22:43:59 +08:00
|
|
|
ParseDeclarator(DeclaratorInfo);
|
2011-10-13 00:37:45 +08:00
|
|
|
T.consumeClose();
|
|
|
|
TypeIdParens = T.getRange();
|
2008-11-22 03:14:01 +08:00
|
|
|
} else {
|
2011-04-16 03:40:02 +08:00
|
|
|
MaybeParseGNUAttributes(DeclaratorInfo);
|
2008-12-02 22:43:59 +08:00
|
|
|
if (ParseCXXTypeSpecifierSeq(DS))
|
|
|
|
DeclaratorInfo.setInvalidType(true);
|
2009-02-10 02:23:29 +08:00
|
|
|
else {
|
|
|
|
DeclaratorInfo.SetSourceRange(DS.getSourceRange());
|
2008-12-02 22:43:59 +08:00
|
|
|
ParseDeclaratorInternal(DeclaratorInfo,
|
|
|
|
&Parser::ParseDirectNewDeclarator);
|
2009-02-10 02:23:29 +08:00
|
|
|
}
|
2008-11-22 03:14:01 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2008-12-02 22:43:59 +08:00
|
|
|
// A new-type-id is a simplified type-id, where essentially the
|
|
|
|
// direct-declarator is replaced by a direct-new-declarator.
|
2011-04-16 03:40:02 +08:00
|
|
|
MaybeParseGNUAttributes(DeclaratorInfo);
|
2008-12-02 22:43:59 +08:00
|
|
|
if (ParseCXXTypeSpecifierSeq(DS))
|
|
|
|
DeclaratorInfo.setInvalidType(true);
|
2009-02-10 02:23:29 +08:00
|
|
|
else {
|
|
|
|
DeclaratorInfo.SetSourceRange(DS.getSourceRange());
|
2008-12-02 22:43:59 +08:00
|
|
|
ParseDeclaratorInternal(DeclaratorInfo,
|
|
|
|
&Parser::ParseDirectNewDeclarator);
|
2009-02-10 02:23:29 +08:00
|
|
|
}
|
2008-11-22 03:14:01 +08:00
|
|
|
}
|
2009-04-25 16:06:05 +08:00
|
|
|
if (DeclaratorInfo.isInvalidType()) {
|
2013-11-18 16:17:37 +08:00
|
|
|
SkipUntil(tok::semi, StopAtSemi | StopBeforeMatch);
|
2008-12-12 06:51:44 +08:00
|
|
|
return ExprError();
|
2008-12-02 22:43:59 +08:00
|
|
|
}
|
2008-11-22 03:14:01 +08:00
|
|
|
|
2012-02-16 20:22:20 +08:00
|
|
|
ExprResult Initializer;
|
2008-11-22 03:14:01 +08:00
|
|
|
|
|
|
|
if (Tok.is(tok::l_paren)) {
|
2012-02-16 20:22:20 +08:00
|
|
|
SourceLocation ConstructorLParen, ConstructorRParen;
|
2012-08-24 06:51:59 +08:00
|
|
|
ExprVector ConstructorArgs;
|
2011-10-13 00:37:45 +08:00
|
|
|
BalancedDelimiterTracker T(*this, tok::l_paren);
|
|
|
|
T.consumeOpen();
|
|
|
|
ConstructorLParen = T.getOpenLocation();
|
2008-11-22 03:14:01 +08:00
|
|
|
if (Tok.isNot(tok::r_paren)) {
|
|
|
|
CommaLocsTy CommaLocs;
|
2015-01-22 00:24:11 +08:00
|
|
|
if (ParseExpressionList(ConstructorArgs, CommaLocs, [&] {
|
|
|
|
ParsedType TypeRep = Actions.ActOnTypeName(getCurScope(),
|
|
|
|
DeclaratorInfo).get();
|
|
|
|
Actions.CodeCompleteConstructor(getCurScope(),
|
|
|
|
TypeRep.get()->getCanonicalTypeInternal(),
|
|
|
|
DeclaratorInfo.getLocEnd(),
|
|
|
|
ConstructorArgs);
|
|
|
|
})) {
|
2013-11-18 16:17:37 +08:00
|
|
|
SkipUntil(tok::semi, StopAtSemi | StopBeforeMatch);
|
2008-12-12 06:51:44 +08:00
|
|
|
return ExprError();
|
2008-12-02 22:43:59 +08:00
|
|
|
}
|
2008-11-22 03:14:01 +08:00
|
|
|
}
|
2011-10-13 00:37:45 +08:00
|
|
|
T.consumeClose();
|
|
|
|
ConstructorRParen = T.getCloseLocation();
|
2008-12-02 22:43:59 +08:00
|
|
|
if (ConstructorRParen.isInvalid()) {
|
2013-11-18 16:17:37 +08:00
|
|
|
SkipUntil(tok::semi, StopAtSemi | StopBeforeMatch);
|
2008-12-12 06:51:44 +08:00
|
|
|
return ExprError();
|
2008-12-02 22:43:59 +08:00
|
|
|
}
|
2012-02-16 20:22:20 +08:00
|
|
|
Initializer = Actions.ActOnParenListExpr(ConstructorLParen,
|
|
|
|
ConstructorRParen,
|
2012-08-24 05:35:17 +08:00
|
|
|
ConstructorArgs);
|
2013-01-02 19:42:31 +08:00
|
|
|
} else if (Tok.is(tok::l_brace) && getLangOpts().CPlusPlus11) {
|
2011-10-15 13:09:34 +08:00
|
|
|
Diag(Tok.getLocation(),
|
|
|
|
diag::warn_cxx98_compat_generalized_initializer_lists);
|
2012-02-16 20:22:20 +08:00
|
|
|
Initializer = ParseBraceInitializer();
|
2008-11-22 03:14:01 +08:00
|
|
|
}
|
2012-02-16 20:22:20 +08:00
|
|
|
if (Initializer.isInvalid())
|
|
|
|
return Initializer;
|
2008-11-22 03:14:01 +08:00
|
|
|
|
2009-03-16 01:47:39 +08:00
|
|
|
return Actions.ActOnCXXNew(Start, UseGlobal, PlacementLParen,
|
2012-08-24 05:35:17 +08:00
|
|
|
PlacementArgs, PlacementRParen,
|
2014-05-29 18:55:11 +08:00
|
|
|
TypeIdParens, DeclaratorInfo, Initializer.get());
|
2008-11-22 03:14:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// ParseDirectNewDeclarator - Parses a direct-new-declarator. Intended to be
|
|
|
|
/// passed to ParseDeclaratorInternal.
|
|
|
|
///
|
|
|
|
/// direct-new-declarator:
|
|
|
|
/// '[' expression ']'
|
|
|
|
/// direct-new-declarator '[' constant-expression ']'
|
|
|
|
///
|
2009-01-05 05:25:24 +08:00
|
|
|
void Parser::ParseDirectNewDeclarator(Declarator &D) {
|
2008-11-22 03:14:01 +08:00
|
|
|
// Parse the array dimensions.
|
|
|
|
bool first = true;
|
|
|
|
while (Tok.is(tok::l_square)) {
|
2012-04-10 09:32:12 +08:00
|
|
|
// An array-size expression can't start with a lambda.
|
|
|
|
if (CheckProhibitedCXX11Attribute())
|
|
|
|
continue;
|
|
|
|
|
2011-10-13 00:37:45 +08:00
|
|
|
BalancedDelimiterTracker T(*this, tok::l_square);
|
|
|
|
T.consumeOpen();
|
|
|
|
|
2010-08-24 14:29:42 +08:00
|
|
|
ExprResult Size(first ? ParseExpression()
|
2008-12-12 05:36:32 +08:00
|
|
|
: ParseConstantExpression());
|
2008-12-09 21:15:23 +08:00
|
|
|
if (Size.isInvalid()) {
|
2008-11-22 03:14:01 +08:00
|
|
|
// Recover
|
2013-11-18 16:17:37 +08:00
|
|
|
SkipUntil(tok::r_square, StopAtSemi);
|
2008-11-22 03:14:01 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
first = false;
|
|
|
|
|
2011-10-13 00:37:45 +08:00
|
|
|
T.consumeClose();
|
2011-03-24 19:26:52 +08:00
|
|
|
|
2012-12-21 03:22:21 +08:00
|
|
|
// Attributes here appertain to the array type. C++11 [expr.new]p5.
|
2012-04-10 09:32:12 +08:00
|
|
|
ParsedAttributes Attrs(AttrFactory);
|
2013-01-02 20:01:23 +08:00
|
|
|
MaybeParseCXX11Attributes(Attrs);
|
2012-04-10 09:32:12 +08:00
|
|
|
|
2011-03-24 19:26:52 +08:00
|
|
|
D.AddTypeInfo(DeclaratorChunk::getArray(0,
|
2010-12-24 10:08:15 +08:00
|
|
|
/*static=*/false, /*star=*/false,
|
2014-05-29 18:55:11 +08:00
|
|
|
Size.get(),
|
2011-10-13 00:37:45 +08:00
|
|
|
T.getOpenLocation(),
|
|
|
|
T.getCloseLocation()),
|
2012-04-10 09:32:12 +08:00
|
|
|
Attrs, T.getCloseLocation());
|
2008-11-22 03:14:01 +08:00
|
|
|
|
2011-10-13 00:37:45 +08:00
|
|
|
if (T.getCloseLocation().isInvalid())
|
2008-11-22 03:14:01 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// ParseExpressionListOrTypeId - Parse either an expression-list or a type-id.
|
|
|
|
/// This ambiguity appears in the syntax of the C++ new operator.
|
|
|
|
///
|
|
|
|
/// new-expression:
|
|
|
|
/// '::'[opt] 'new' new-placement[opt] '(' type-id ')'
|
|
|
|
/// new-initializer[opt]
|
|
|
|
///
|
|
|
|
/// new-placement:
|
|
|
|
/// '(' expression-list ')'
|
|
|
|
///
|
2010-08-23 14:44:23 +08:00
|
|
|
bool Parser::ParseExpressionListOrTypeId(
|
2011-07-23 18:55:15 +08:00
|
|
|
SmallVectorImpl<Expr*> &PlacementArgs,
|
2009-01-05 05:25:24 +08:00
|
|
|
Declarator &D) {
|
2008-11-22 03:14:01 +08:00
|
|
|
// The '(' was already consumed.
|
|
|
|
if (isTypeIdInParens()) {
|
2008-12-02 22:43:59 +08:00
|
|
|
ParseSpecifierQualifierList(D.getMutableDeclSpec());
|
2009-02-10 02:23:29 +08:00
|
|
|
D.SetSourceRange(D.getDeclSpec().getSourceRange());
|
2008-12-02 22:43:59 +08:00
|
|
|
ParseDeclarator(D);
|
2009-04-25 16:06:05 +08:00
|
|
|
return D.isInvalidType();
|
2008-11-22 03:14:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// It's not a type, it has to be an expression list.
|
|
|
|
// Discard the comma locations - ActOnCXXNew has enough parameters.
|
|
|
|
CommaLocsTy CommaLocs;
|
|
|
|
return ParseExpressionList(PlacementArgs, CommaLocs);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// ParseCXXDeleteExpression - Parse a C++ delete-expression. Delete is used
|
|
|
|
/// to free memory allocated by new.
|
|
|
|
///
|
2009-01-05 05:25:24 +08:00
|
|
|
/// This method is called to parse the 'delete' expression after the optional
|
|
|
|
/// '::' has been already parsed. If the '::' was present, "UseGlobal" is true
|
|
|
|
/// and "Start" is its location. Otherwise, "Start" is the location of the
|
|
|
|
/// 'delete' token.
|
|
|
|
///
|
2008-11-22 03:14:01 +08:00
|
|
|
/// delete-expression:
|
|
|
|
/// '::'[opt] 'delete' cast-expression
|
|
|
|
/// '::'[opt] 'delete' '[' ']' cast-expression
|
2010-08-24 14:29:42 +08:00
|
|
|
ExprResult
|
2009-01-05 05:25:24 +08:00
|
|
|
Parser::ParseCXXDeleteExpression(bool UseGlobal, SourceLocation Start) {
|
|
|
|
assert(Tok.is(tok::kw_delete) && "Expected 'delete' keyword");
|
|
|
|
ConsumeToken(); // Consume 'delete'
|
2008-11-22 03:14:01 +08:00
|
|
|
|
|
|
|
// Array delete?
|
|
|
|
bool ArrayDelete = false;
|
2012-04-10 09:32:12 +08:00
|
|
|
if (Tok.is(tok::l_square) && NextToken().is(tok::r_square)) {
|
2012-08-10 03:01:51 +08:00
|
|
|
// C++11 [expr.delete]p1:
|
|
|
|
// Whenever the delete keyword is followed by empty square brackets, it
|
|
|
|
// shall be interpreted as [array delete].
|
|
|
|
// [Footnote: A lambda expression with a lambda-introducer that consists
|
|
|
|
// of empty square brackets can follow the delete keyword if
|
|
|
|
// the lambda expression is enclosed in parentheses.]
|
|
|
|
// FIXME: Produce a better diagnostic if the '[]' is unambiguously a
|
|
|
|
// lambda-introducer.
|
2008-11-22 03:14:01 +08:00
|
|
|
ArrayDelete = true;
|
2011-10-13 00:37:45 +08:00
|
|
|
BalancedDelimiterTracker T(*this, tok::l_square);
|
|
|
|
|
|
|
|
T.consumeOpen();
|
|
|
|
T.consumeClose();
|
|
|
|
if (T.getCloseLocation().isInvalid())
|
2008-12-12 06:51:44 +08:00
|
|
|
return ExprError();
|
2008-11-22 03:14:01 +08:00
|
|
|
}
|
|
|
|
|
2010-08-24 14:29:42 +08:00
|
|
|
ExprResult Operand(ParseCastExpression(false));
|
2008-12-09 21:15:23 +08:00
|
|
|
if (Operand.isInvalid())
|
2012-08-24 05:35:17 +08:00
|
|
|
return Operand;
|
2008-11-22 03:14:01 +08:00
|
|
|
|
2014-05-29 18:55:11 +08:00
|
|
|
return Actions.ActOnCXXDelete(Start, UseGlobal, ArrayDelete, Operand.get());
|
2008-11-22 03:14:01 +08:00
|
|
|
}
|
2009-01-06 04:52:13 +08:00
|
|
|
|
2012-02-24 15:38:34 +08:00
|
|
|
static TypeTrait TypeTraitFromTokKind(tok::TokenKind kind) {
|
|
|
|
switch (kind) {
|
|
|
|
default: llvm_unreachable("Not a known type trait");
|
2014-01-01 13:57:51 +08:00
|
|
|
#define TYPE_TRAIT_1(Spelling, Name, Key) \
|
|
|
|
case tok::kw_ ## Spelling: return UTT_ ## Name;
|
2013-12-14 04:49:58 +08:00
|
|
|
#define TYPE_TRAIT_2(Spelling, Name, Key) \
|
|
|
|
case tok::kw_ ## Spelling: return BTT_ ## Name;
|
|
|
|
#include "clang/Basic/TokenKinds.def"
|
2013-12-13 05:23:03 +08:00
|
|
|
#define TYPE_TRAIT_N(Spelling, Name, Key) \
|
|
|
|
case tok::kw_ ## Spelling: return TT_ ## Name;
|
|
|
|
#include "clang/Basic/TokenKinds.def"
|
2012-02-24 15:38:34 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-28 08:16:57 +08:00
|
|
|
static ArrayTypeTrait ArrayTypeTraitFromTokKind(tok::TokenKind kind) {
|
|
|
|
switch(kind) {
|
|
|
|
default: llvm_unreachable("Not a known binary type trait");
|
|
|
|
case tok::kw___array_rank: return ATT_ArrayRank;
|
|
|
|
case tok::kw___array_extent: return ATT_ArrayExtent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-25 14:54:41 +08:00
|
|
|
static ExpressionTrait ExpressionTraitFromTokKind(tok::TokenKind kind) {
|
|
|
|
switch(kind) {
|
2011-09-23 13:06:16 +08:00
|
|
|
default: llvm_unreachable("Not a known unary expression trait.");
|
2011-04-25 14:54:41 +08:00
|
|
|
case tok::kw___is_lvalue_expr: return ET_IsLValueExpr;
|
|
|
|
case tok::kw___is_rvalue_expr: return ET_IsRValueExpr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-13 05:23:03 +08:00
|
|
|
static unsigned TypeTraitArity(tok::TokenKind kind) {
|
|
|
|
switch (kind) {
|
|
|
|
default: llvm_unreachable("Not a known type trait");
|
|
|
|
#define TYPE_TRAIT(N,Spelling,K) case tok::kw_##Spelling: return N;
|
|
|
|
#include "clang/Basic/TokenKinds.def"
|
2010-12-07 08:08:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-24 15:38:34 +08:00
|
|
|
/// \brief Parse the built-in type-trait pseudo-functions that allow
|
|
|
|
/// implementation of the TR1/C++11 type traits templates.
|
|
|
|
///
|
|
|
|
/// primary-expression:
|
2013-12-13 05:23:03 +08:00
|
|
|
/// unary-type-trait '(' type-id ')'
|
|
|
|
/// binary-type-trait '(' type-id ',' type-id ')'
|
2012-02-24 15:38:34 +08:00
|
|
|
/// type-trait '(' type-id-seq ')'
|
|
|
|
///
|
|
|
|
/// type-id-seq:
|
|
|
|
/// type-id ...[opt] type-id-seq[opt]
|
|
|
|
///
|
|
|
|
ExprResult Parser::ParseTypeTrait() {
|
2013-12-13 05:23:03 +08:00
|
|
|
tok::TokenKind Kind = Tok.getKind();
|
|
|
|
unsigned Arity = TypeTraitArity(Kind);
|
|
|
|
|
2012-02-24 15:38:34 +08:00
|
|
|
SourceLocation Loc = ConsumeToken();
|
|
|
|
|
|
|
|
BalancedDelimiterTracker Parens(*this, tok::l_paren);
|
2014-01-01 11:08:43 +08:00
|
|
|
if (Parens.expectAndConsume())
|
2012-02-24 15:38:34 +08:00
|
|
|
return ExprError();
|
|
|
|
|
2013-01-13 03:30:44 +08:00
|
|
|
SmallVector<ParsedType, 2> Args;
|
2012-02-24 15:38:34 +08:00
|
|
|
do {
|
|
|
|
// Parse the next type.
|
|
|
|
TypeResult Ty = ParseTypeName();
|
|
|
|
if (Ty.isInvalid()) {
|
|
|
|
Parens.skipToEnd();
|
|
|
|
return ExprError();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Parse the ellipsis, if present.
|
|
|
|
if (Tok.is(tok::ellipsis)) {
|
|
|
|
Ty = Actions.ActOnPackExpansion(Ty.get(), ConsumeToken());
|
|
|
|
if (Ty.isInvalid()) {
|
|
|
|
Parens.skipToEnd();
|
|
|
|
return ExprError();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add this type to the list of arguments.
|
|
|
|
Args.push_back(Ty.get());
|
2013-12-17 22:12:37 +08:00
|
|
|
} while (TryConsumeToken(tok::comma));
|
|
|
|
|
2012-02-24 15:38:34 +08:00
|
|
|
if (Parens.consumeClose())
|
|
|
|
return ExprError();
|
2013-12-13 05:23:03 +08:00
|
|
|
|
|
|
|
SourceLocation EndLoc = Parens.getCloseLocation();
|
|
|
|
|
|
|
|
if (Arity && Args.size() != Arity) {
|
|
|
|
Diag(EndLoc, diag::err_type_trait_arity)
|
|
|
|
<< Arity << 0 << (Arity > 1) << (int)Args.size() << SourceRange(Loc);
|
|
|
|
return ExprError();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Arity && Args.empty()) {
|
|
|
|
Diag(EndLoc, diag::err_type_trait_arity)
|
|
|
|
<< 1 << 1 << 1 << (int)Args.size() << SourceRange(Loc);
|
|
|
|
return ExprError();
|
|
|
|
}
|
|
|
|
|
2013-12-14 05:19:30 +08:00
|
|
|
return Actions.ActOnTypeTrait(TypeTraitFromTokKind(Kind), Loc, Args, EndLoc);
|
2012-02-24 15:38:34 +08:00
|
|
|
}
|
|
|
|
|
2011-04-28 08:16:57 +08:00
|
|
|
/// ParseArrayTypeTrait - Parse the built-in array type-trait
|
|
|
|
/// pseudo-functions.
|
|
|
|
///
|
|
|
|
/// primary-expression:
|
|
|
|
/// [Embarcadero] '__array_rank' '(' type-id ')'
|
|
|
|
/// [Embarcadero] '__array_extent' '(' type-id ',' expression ')'
|
|
|
|
///
|
|
|
|
ExprResult Parser::ParseArrayTypeTrait() {
|
|
|
|
ArrayTypeTrait ATT = ArrayTypeTraitFromTokKind(Tok.getKind());
|
|
|
|
SourceLocation Loc = ConsumeToken();
|
|
|
|
|
2011-10-13 00:37:45 +08:00
|
|
|
BalancedDelimiterTracker T(*this, tok::l_paren);
|
2014-01-01 11:08:43 +08:00
|
|
|
if (T.expectAndConsume())
|
2011-04-28 08:16:57 +08:00
|
|
|
return ExprError();
|
|
|
|
|
|
|
|
TypeResult Ty = ParseTypeName();
|
|
|
|
if (Ty.isInvalid()) {
|
2013-11-18 16:17:37 +08:00
|
|
|
SkipUntil(tok::comma, StopAtSemi);
|
|
|
|
SkipUntil(tok::r_paren, StopAtSemi);
|
2011-04-28 08:16:57 +08:00
|
|
|
return ExprError();
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (ATT) {
|
|
|
|
case ATT_ArrayRank: {
|
2011-10-13 00:37:45 +08:00
|
|
|
T.consumeClose();
|
2014-05-21 14:02:52 +08:00
|
|
|
return Actions.ActOnArrayTypeTrait(ATT, Loc, Ty.get(), nullptr,
|
2011-10-13 00:37:45 +08:00
|
|
|
T.getCloseLocation());
|
2011-04-28 08:16:57 +08:00
|
|
|
}
|
|
|
|
case ATT_ArrayExtent: {
|
2014-01-01 11:08:43 +08:00
|
|
|
if (ExpectAndConsume(tok::comma)) {
|
2013-11-18 16:17:37 +08:00
|
|
|
SkipUntil(tok::r_paren, StopAtSemi);
|
2011-04-28 08:16:57 +08:00
|
|
|
return ExprError();
|
|
|
|
}
|
|
|
|
|
|
|
|
ExprResult DimExpr = ParseExpression();
|
2011-10-13 00:37:45 +08:00
|
|
|
T.consumeClose();
|
2011-04-28 08:16:57 +08:00
|
|
|
|
2011-10-13 00:37:45 +08:00
|
|
|
return Actions.ActOnArrayTypeTrait(ATT, Loc, Ty.get(), DimExpr.get(),
|
|
|
|
T.getCloseLocation());
|
2011-04-28 08:16:57 +08:00
|
|
|
}
|
|
|
|
}
|
2012-01-21 05:50:17 +08:00
|
|
|
llvm_unreachable("Invalid ArrayTypeTrait!");
|
2011-04-28 08:16:57 +08:00
|
|
|
}
|
|
|
|
|
2011-04-25 14:54:41 +08:00
|
|
|
/// ParseExpressionTrait - Parse built-in expression-trait
|
|
|
|
/// pseudo-functions like __is_lvalue_expr( xxx ).
|
|
|
|
///
|
|
|
|
/// primary-expression:
|
|
|
|
/// [Embarcadero] expression-trait '(' expression ')'
|
|
|
|
///
|
|
|
|
ExprResult Parser::ParseExpressionTrait() {
|
|
|
|
ExpressionTrait ET = ExpressionTraitFromTokKind(Tok.getKind());
|
|
|
|
SourceLocation Loc = ConsumeToken();
|
|
|
|
|
2011-10-13 00:37:45 +08:00
|
|
|
BalancedDelimiterTracker T(*this, tok::l_paren);
|
2014-01-01 11:08:43 +08:00
|
|
|
if (T.expectAndConsume())
|
2011-04-25 14:54:41 +08:00
|
|
|
return ExprError();
|
|
|
|
|
|
|
|
ExprResult Expr = ParseExpression();
|
|
|
|
|
2011-10-13 00:37:45 +08:00
|
|
|
T.consumeClose();
|
2011-04-25 14:54:41 +08:00
|
|
|
|
2011-10-13 00:37:45 +08:00
|
|
|
return Actions.ActOnExpressionTrait(ET, Loc, Expr.get(),
|
|
|
|
T.getCloseLocation());
|
2011-04-25 14:54:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-22 18:24:42 +08:00
|
|
|
/// ParseCXXAmbiguousParenExpression - We have parsed the left paren of a
|
|
|
|
/// parenthesized ambiguous type-id. This uses tentative parsing to disambiguate
|
|
|
|
/// based on the context past the parens.
|
2010-08-24 14:29:42 +08:00
|
|
|
ExprResult
|
2009-05-22 18:24:42 +08:00
|
|
|
Parser::ParseCXXAmbiguousParenExpression(ParenParseOption &ExprType,
|
2010-08-24 13:47:05 +08:00
|
|
|
ParsedType &CastTy,
|
2014-05-15 10:43:47 +08:00
|
|
|
BalancedDelimiterTracker &Tracker,
|
|
|
|
ColonProtectionRAIIObject &ColonProt) {
|
2012-03-11 15:00:24 +08:00
|
|
|
assert(getLangOpts().CPlusPlus && "Should only be called for C++!");
|
2009-05-22 18:24:42 +08:00
|
|
|
assert(ExprType == CastExpr && "Compound literals are not ambiguous!");
|
|
|
|
assert(isTypeIdInParens() && "Not a type-id!");
|
|
|
|
|
2010-08-24 14:29:42 +08:00
|
|
|
ExprResult Result(true);
|
2016-01-16 07:43:34 +08:00
|
|
|
CastTy = nullptr;
|
2009-05-22 18:24:42 +08:00
|
|
|
|
|
|
|
// We need to disambiguate a very ugly part of the C++ syntax:
|
|
|
|
//
|
|
|
|
// (T())x; - type-id
|
|
|
|
// (T())*x; - type-id
|
|
|
|
// (T())/x; - expression
|
|
|
|
// (T()); - expression
|
|
|
|
//
|
|
|
|
// The bad news is that we cannot use the specialized tentative parser, since
|
|
|
|
// it can only verify that the thing inside the parens can be parsed as
|
|
|
|
// type-id, it is not useful for determining the context past the parens.
|
|
|
|
//
|
|
|
|
// The good news is that the parser can disambiguate this part without
|
2009-05-22 23:12:46 +08:00
|
|
|
// making any unnecessary Action calls.
|
2009-05-23 05:09:47 +08:00
|
|
|
//
|
|
|
|
// It uses a scheme similar to parsing inline methods. The parenthesized
|
|
|
|
// tokens are cached, the context that follows is determined (possibly by
|
|
|
|
// parsing a cast-expression), and then we re-introduce the cached tokens
|
|
|
|
// into the token stream and parse them appropriately.
|
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
ParenParseOption ParseAs;
|
2009-05-23 05:09:47 +08:00
|
|
|
CachedTokens Toks;
|
|
|
|
|
|
|
|
// Store the tokens of the parentheses. We will parse them after we determine
|
|
|
|
// the context that follows them.
|
2010-04-24 05:20:12 +08:00
|
|
|
if (!ConsumeAndStoreUntil(tok::r_paren, Toks)) {
|
2009-05-23 05:09:47 +08:00
|
|
|
// We didn't find the ')' we expected.
|
2011-10-13 00:37:45 +08:00
|
|
|
Tracker.consumeClose();
|
2009-05-22 18:24:42 +08:00
|
|
|
return ExprError();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Tok.is(tok::l_brace)) {
|
2009-05-23 05:09:47 +08:00
|
|
|
ParseAs = CompoundLiteral;
|
|
|
|
} else {
|
|
|
|
bool NotCastExpr;
|
2009-05-26 03:41:42 +08:00
|
|
|
if (Tok.is(tok::l_paren) && NextToken().is(tok::r_paren)) {
|
|
|
|
NotCastExpr = true;
|
|
|
|
} else {
|
|
|
|
// Try parsing the cast-expression that may follow.
|
|
|
|
// If it is not a cast-expression, NotCastExpr will be true and no token
|
|
|
|
// will be consumed.
|
2014-05-15 10:43:47 +08:00
|
|
|
ColonProt.restore();
|
2009-05-26 03:41:42 +08:00
|
|
|
Result = ParseCastExpression(false/*isUnaryExpression*/,
|
|
|
|
false/*isAddressofOperand*/,
|
2010-08-24 13:47:05 +08:00
|
|
|
NotCastExpr,
|
2011-07-02 06:22:59 +08:00
|
|
|
// type-id has priority.
|
2012-01-26 04:49:08 +08:00
|
|
|
IsTypeCast);
|
2009-05-26 03:41:42 +08:00
|
|
|
}
|
2009-05-23 05:09:47 +08:00
|
|
|
|
|
|
|
// If we parsed a cast-expression, it's really a type-id, otherwise it's
|
|
|
|
// an expression.
|
|
|
|
ParseAs = NotCastExpr ? SimpleExpr : CastExpr;
|
2009-05-22 18:24:42 +08:00
|
|
|
}
|
|
|
|
|
2016-02-04 12:22:09 +08:00
|
|
|
// Create a fake EOF to mark end of Toks buffer.
|
|
|
|
Token AttrEnd;
|
|
|
|
AttrEnd.startToken();
|
|
|
|
AttrEnd.setKind(tok::eof);
|
|
|
|
AttrEnd.setLocation(Tok.getLocation());
|
|
|
|
AttrEnd.setEofData(Toks.data());
|
|
|
|
Toks.push_back(AttrEnd);
|
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
// The current token should go after the cached tokens.
|
2009-05-23 05:09:47 +08:00
|
|
|
Toks.push_back(Tok);
|
|
|
|
// Re-enter the stored parenthesized tokens into the token stream, so we may
|
|
|
|
// parse them now.
|
2016-02-10 02:52:09 +08:00
|
|
|
PP.EnterTokenStream(Toks, true /*DisableMacroExpansion*/);
|
2009-05-23 05:09:47 +08:00
|
|
|
// Drop the current token and bring the first cached one. It's the same token
|
|
|
|
// as when we entered this function.
|
|
|
|
ConsumeAnyToken();
|
|
|
|
|
|
|
|
if (ParseAs >= CompoundLiteral) {
|
2011-07-02 06:22:59 +08:00
|
|
|
// Parse the type declarator.
|
|
|
|
DeclSpec DS(AttrFactory);
|
|
|
|
Declarator DeclaratorInfo(DS, Declarator::TypeNameContext);
|
2014-05-15 10:43:47 +08:00
|
|
|
{
|
|
|
|
ColonProtectionRAIIObject InnerColonProtection(*this);
|
|
|
|
ParseSpecifierQualifierList(DS);
|
|
|
|
ParseDeclarator(DeclaratorInfo);
|
|
|
|
}
|
2009-05-22 18:24:42 +08:00
|
|
|
|
2009-05-23 05:09:47 +08:00
|
|
|
// Match the ')'.
|
2011-10-13 00:37:45 +08:00
|
|
|
Tracker.consumeClose();
|
2014-05-15 10:43:47 +08:00
|
|
|
ColonProt.restore();
|
2009-05-23 05:09:47 +08:00
|
|
|
|
2016-02-04 12:22:09 +08:00
|
|
|
// Consume EOF marker for Toks buffer.
|
|
|
|
assert(Tok.is(tok::eof) && Tok.getEofData() == AttrEnd.getEofData());
|
|
|
|
ConsumeAnyToken();
|
|
|
|
|
2009-05-23 05:09:47 +08:00
|
|
|
if (ParseAs == CompoundLiteral) {
|
|
|
|
ExprType = CompoundLiteral;
|
2014-05-15 10:51:15 +08:00
|
|
|
if (DeclaratorInfo.isInvalidType())
|
|
|
|
return ExprError();
|
|
|
|
|
|
|
|
TypeResult Ty = Actions.ActOnTypeName(getCurScope(), DeclaratorInfo);
|
2014-05-15 10:43:47 +08:00
|
|
|
return ParseCompoundLiteralExpression(Ty.get(),
|
2011-10-13 00:37:45 +08:00
|
|
|
Tracker.getOpenLocation(),
|
|
|
|
Tracker.getCloseLocation());
|
2009-05-23 05:09:47 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-05-23 05:09:47 +08:00
|
|
|
// We parsed '(' type-id ')' and the thing after it wasn't a '{'.
|
|
|
|
assert(ParseAs == CastExpr);
|
|
|
|
|
2011-07-02 06:22:59 +08:00
|
|
|
if (DeclaratorInfo.isInvalidType())
|
2009-05-23 05:09:47 +08:00
|
|
|
return ExprError();
|
2009-05-22 18:24:42 +08:00
|
|
|
|
2009-05-23 05:09:47 +08:00
|
|
|
// Result is what ParseCastExpression returned earlier.
|
2009-05-22 18:24:42 +08:00
|
|
|
if (!Result.isInvalid())
|
2011-10-13 00:37:45 +08:00
|
|
|
Result = Actions.ActOnCastExpr(getCurScope(), Tracker.getOpenLocation(),
|
|
|
|
DeclaratorInfo, CastTy,
|
2014-05-29 18:55:11 +08:00
|
|
|
Tracker.getCloseLocation(), Result.get());
|
2012-08-24 05:35:17 +08:00
|
|
|
return Result;
|
2009-05-22 18:24:42 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-05-23 05:09:47 +08:00
|
|
|
// Not a compound literal, and not followed by a cast-expression.
|
|
|
|
assert(ParseAs == SimpleExpr);
|
2009-05-22 18:24:42 +08:00
|
|
|
|
|
|
|
ExprType = SimpleExpr;
|
2009-05-23 05:09:47 +08:00
|
|
|
Result = ParseExpression();
|
2009-05-22 18:24:42 +08:00
|
|
|
if (!Result.isInvalid() && Tok.is(tok::r_paren))
|
2011-10-13 00:37:45 +08:00
|
|
|
Result = Actions.ActOnParenExpr(Tracker.getOpenLocation(),
|
2014-05-29 18:55:11 +08:00
|
|
|
Tok.getLocation(), Result.get());
|
2009-05-22 18:24:42 +08:00
|
|
|
|
|
|
|
// Match the ')'.
|
|
|
|
if (Result.isInvalid()) {
|
2016-02-04 12:22:09 +08:00
|
|
|
while (Tok.isNot(tok::eof))
|
|
|
|
ConsumeAnyToken();
|
|
|
|
assert(Tok.getEofData() == AttrEnd.getEofData());
|
|
|
|
ConsumeAnyToken();
|
2009-05-22 18:24:42 +08:00
|
|
|
return ExprError();
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-10-13 00:37:45 +08:00
|
|
|
Tracker.consumeClose();
|
2016-02-04 12:22:09 +08:00
|
|
|
// Consume EOF marker for Toks buffer.
|
|
|
|
assert(Tok.is(tok::eof) && Tok.getEofData() == AttrEnd.getEofData());
|
|
|
|
ConsumeAnyToken();
|
2012-08-24 05:35:17 +08:00
|
|
|
return Result;
|
2009-05-22 18:24:42 +08:00
|
|
|
}
|