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++.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2009-01-29 13:15:15 +08:00
|
|
|
#include "clang/Parse/ParseDiagnostic.h"
|
2006-12-05 02:06:35 +08:00
|
|
|
#include "clang/Parse/Parser.h"
|
2011-01-11 08:33:19 +08:00
|
|
|
#include "RAIIObjectsForParser.h"
|
2010-08-21 02:27:03 +08:00
|
|
|
#include "clang/Sema/DeclSpec.h"
|
|
|
|
#include "clang/Sema/ParsedTemplate.h"
|
2009-11-03 09:35:08 +08:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
|
|
|
|
2006-12-05 02:06:35 +08:00
|
|
|
using namespace clang;
|
|
|
|
|
2011-04-15 05:45:45 +08:00
|
|
|
static int SelectDigraphErrorMessage(tok::TokenKind Kind) {
|
|
|
|
switch (Kind) {
|
|
|
|
case tok::kw_template: return 0;
|
|
|
|
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:
|
|
|
|
assert(0 && "Unknown type for digraph error message.");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Are the two tokens adjacent in the same source file?
|
|
|
|
static bool AreTokensAdjacent(Preprocessor &PP, Token &First, Token &Second) {
|
|
|
|
SourceManager &SM = PP.getSourceManager();
|
|
|
|
SourceLocation FirstLoc = SM.getSpellingLoc(First.getLocation());
|
|
|
|
SourceLocation FirstEnd = FirstLoc.getFileLocWithOffset(First.getLength());
|
|
|
|
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)
|
|
|
|
<< SelectDigraphErrorMessage(Kind)
|
|
|
|
<< FixItHint::CreateReplacement(Range, "< ::");
|
|
|
|
|
|
|
|
// Update token information to reflect their change in token type.
|
|
|
|
ColonToken.setKind(tok::coloncolon);
|
|
|
|
ColonToken.setLocation(ColonToken.getLocation().getFileLocWithOffset(-1));
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
|
2010-02-22 02:36:56 +08:00
|
|
|
/// member access expression, e.g., the \p T:: in \p p->T::m.
|
|
|
|
///
|
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,
|
|
|
|
bool IsTypename) {
|
2008-11-27 05:41:52 +08:00
|
|
|
assert(getLang().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)) {
|
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
|
|
|
|
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
|
|
|
|
2009-01-05 08:13:00 +08:00
|
|
|
// '::' - Global scope qualifier.
|
2011-02-24 08:17:56 +08:00
|
|
|
if (Actions.ActOnCXXGlobalScopeSpecifier(getCurScope(), ConsumeToken(), SS))
|
|
|
|
return 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
|
|
|
HasScopeSpecifier = true;
|
2008-11-09 00:45:02 +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
|
|
|
bool CheckForDestructor = false;
|
|
|
|
if (MayBePseudoDestructor && *MayBePseudoDestructor) {
|
|
|
|
CheckForDestructor = true;
|
|
|
|
*MayBePseudoDestructor = false;
|
|
|
|
}
|
|
|
|
|
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.
|
2010-08-24 13:47:05 +08:00
|
|
|
ObjectType = ParsedType();
|
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
|
|
|
SourceLocation ccLoc = ConsumeCodeCompletionToken();
|
|
|
|
// 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.
|
|
|
|
SS.setEndLoc(ccLoc);
|
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();
|
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)) {
|
|
|
|
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
|
|
|
}
|
2009-11-04 08:56:37 +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;
|
2010-07-03 01:43:08 +08:00
|
|
|
if (TemplateNameKind TNK = Actions.ActOnDependentTemplateName(getCurScope(),
|
2010-06-17 07:00:59 +08:00
|
|
|
TemplateKWLoc,
|
|
|
|
SS,
|
|
|
|
TemplateName,
|
|
|
|
ObjectType,
|
|
|
|
EnteringContext,
|
|
|
|
Template)) {
|
2011-03-02 08:47:37 +08:00
|
|
|
if (AnnotateTemplateIdToken(Template, TNK, SS, TemplateName,
|
2010-06-17 07:00:59 +08:00
|
|
|
TemplateKWLoc, false))
|
|
|
|
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
|
|
|
//
|
|
|
|
// simple-template-id '::'
|
|
|
|
//
|
|
|
|
// So we need to check whether the simple-template-id is of the
|
2009-03-31 08:43:58 +08:00
|
|
|
// right kind (it should name a type or be dependent), and then
|
|
|
|
// convert it into a type within the nested-name-specifier.
|
2009-09-09 23:08:12 +08:00
|
|
|
TemplateIdAnnotation *TemplateId
|
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
|
|
|
= static_cast<TemplateIdAnnotation *>(Tok.getAnnotationValue());
|
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
|
|
|
}
|
|
|
|
|
2011-03-05 05:37:14 +08:00
|
|
|
// Consume the template-id token.
|
|
|
|
ConsumeToken();
|
|
|
|
|
|
|
|
assert(Tok.is(tok::coloncolon) && "NextToken() not working properly!");
|
|
|
|
SourceLocation CCLoc = ConsumeToken();
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-03-05 05:37:14 +08:00
|
|
|
if (!HasScopeSpecifier)
|
|
|
|
HasScopeSpecifier = true;
|
|
|
|
|
|
|
|
ASTTemplateArgsPtr TemplateArgsPtr(Actions,
|
|
|
|
TemplateId->getTemplateArgs(),
|
|
|
|
TemplateId->NumArgs);
|
|
|
|
|
|
|
|
if (Actions.ActOnCXXNestedNameSpecifier(getCurScope(),
|
|
|
|
/*FIXME:*/SourceLocation(),
|
|
|
|
SS,
|
|
|
|
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-03-05 05:37:14 +08:00
|
|
|
|
|
|
|
TemplateId->Destroy();
|
|
|
|
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();
|
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) {
|
2011-02-24 08:17:56 +08:00
|
|
|
if (Actions.IsInvalidUnlessNestedName(getCurScope(), SS, II,
|
|
|
|
Tok.getLocation(),
|
|
|
|
Next.getLocation(), ObjectType,
|
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)) {
|
|
|
|
Diag(Next, diag::err_unexected_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
|
|
|
}
|
|
|
|
|
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) &&
|
2010-07-03 01:43:08 +08:00
|
|
|
!Actions.isNonTypeNestedNameSpecifier(getCurScope(), SS, Tok.getLocation(),
|
2010-02-25 05:29:12 +08:00
|
|
|
II, 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
|
|
|
*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
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
SourceLocation IdLoc = ConsumeToken();
|
2009-12-07 09:36:53 +08:00
|
|
|
assert((Tok.is(tok::coloncolon) || Tok.is(tok::colon)) &&
|
|
|
|
"NextToken() not working properly!");
|
2009-06-26 11:52:38 +08:00
|
|
|
SourceLocation CCLoc = ConsumeToken();
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-02-24 08:17:56 +08:00
|
|
|
HasScopeSpecifier = true;
|
|
|
|
if (Actions.ActOnCXXNestedNameSpecifier(getCurScope(), II, IdLoc, CCLoc,
|
|
|
|
ObjectType, EnteringContext, SS))
|
|
|
|
SS.SetInvalid(SourceRange(IdLoc, CCLoc));
|
|
|
|
|
2009-06-26 11:52:38 +08:00
|
|
|
continue;
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-04-15 05:45:45 +08:00
|
|
|
// Check for '<::' which should be '< ::' instead of '[:' when following
|
|
|
|
// a template name.
|
|
|
|
if (Next.is(tok::l_square) && Next.getLength() == 2) {
|
|
|
|
Token SecondToken = GetLookAheadToken(2);
|
|
|
|
if (SecondToken.is(tok::colon) &&
|
|
|
|
AreTokensAdjacent(PP, Next, SecondToken)) {
|
|
|
|
TemplateTy Template;
|
|
|
|
UnqualifiedId TemplateName;
|
|
|
|
TemplateName.setIdentifier(&II, Tok.getLocation());
|
|
|
|
bool MemberOfUnknownSpecialization;
|
|
|
|
if (Actions.isTemplateName(getCurScope(), SS,
|
|
|
|
/*hasTemplateKeyword=*/false,
|
|
|
|
TemplateName,
|
|
|
|
ObjectType,
|
|
|
|
EnteringContext,
|
|
|
|
Template,
|
|
|
|
MemberOfUnknownSpecialization)) {
|
|
|
|
FixDigraph(*this, PP, Next, SecondToken, tok::kw_template,
|
|
|
|
/*AtDigraph*/false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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)) {
|
2009-06-26 11:52:38 +08:00
|
|
|
// We have found a template name, so annotate this this token
|
|
|
|
// 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();
|
2011-03-02 08:47:37 +08:00
|
|
|
if (AnnotateTemplateIdToken(Template, TNK, SS, TemplateName,
|
2009-11-04 08:56:37 +08:00
|
|
|
SourceLocation(), false))
|
2010-02-26 16:45:28 +08:00
|
|
|
return true;
|
2009-06-26 11:52:38 +08:00
|
|
|
continue;
|
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;
|
|
|
|
if (getLang().Microsoft)
|
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(),
|
2010-06-17 07:00:59 +08:00
|
|
|
Tok.getLocation(), SS,
|
|
|
|
TemplateName, ObjectType,
|
|
|
|
EnteringContext, Template)) {
|
|
|
|
// Consume the identifier.
|
|
|
|
ConsumeToken();
|
2011-03-02 08:47:37 +08:00
|
|
|
if (AnnotateTemplateIdToken(Template, TNK, SS, TemplateName,
|
2010-06-17 07:00:59 +08:00
|
|
|
SourceLocation(), false))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/// 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;
|
2010-08-24 13:47:05 +08:00
|
|
|
ParseOptionalCXXScopeSpecifier(SS, ParsedType(), false);
|
2009-11-04 00:56:39 +08:00
|
|
|
|
|
|
|
UnqualifiedId Name;
|
|
|
|
if (ParseUnqualifiedId(SS,
|
|
|
|
/*EnteringContext=*/false,
|
|
|
|
/*AllowDestructorName=*/false,
|
|
|
|
/*AllowConstructorName=*/false,
|
2010-08-24 13:47:05 +08:00
|
|
|
/*ObjectType=*/ ParsedType(),
|
2009-11-04 00:56:39 +08:00
|
|
|
Name))
|
|
|
|
return ExprError();
|
2009-11-22 10:49:43 +08:00
|
|
|
|
|
|
|
// This is only the direct operand of an & operator if it is not
|
|
|
|
// followed by a postfix-expression suffix.
|
2010-08-27 17:08:28 +08:00
|
|
|
if (isAddressOfOperand && isPostfixExpressionSuffixStart())
|
|
|
|
isAddressOfOperand = false;
|
2009-11-04 00:56:39 +08:00
|
|
|
|
2010-07-03 01:43:08 +08:00
|
|
|
return Actions.ActOnIdExpression(getCurScope(), SS, Name, Tok.is(tok::l_paren),
|
2009-11-04 00:56:39 +08:00
|
|
|
isAddressOfOperand);
|
|
|
|
|
2008-11-09 00:45:02 +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();
|
|
|
|
const char *CastName = 0; // For error messages
|
|
|
|
|
|
|
|
switch (Kind) {
|
|
|
|
default: assert(0 && "Unknown C++ cast!"); abort();
|
|
|
|
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.
|
|
|
|
Token Next = NextToken();
|
|
|
|
if (Tok.is(tok::l_square) && Tok.getLength() == 2 && Next.is(tok::colon) &&
|
|
|
|
AreTokensAdjacent(PP, Tok, Next))
|
|
|
|
FixDigraph(*this, PP, Tok, Next, Kind, /*AtDigraph*/true);
|
|
|
|
|
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
|
|
|
|
2009-02-19 01:45:20 +08:00
|
|
|
TypeResult CastTy = ParseTypeName();
|
2006-12-05 02:06:35 +08:00
|
|
|
SourceLocation RAngleBracketLoc = Tok.getLocation();
|
|
|
|
|
2008-11-18 15:48:38 +08:00
|
|
|
if (ExpectAndConsume(tok::greater, diag::err_expected_greater))
|
2008-12-12 06:51:44 +08:00
|
|
|
return ExprError(Diag(LAngleBracketLoc, diag::note_matching) << "<");
|
2006-12-05 02:06:35 +08:00
|
|
|
|
|
|
|
SourceLocation LParenLoc = Tok.getLocation(), RParenLoc;
|
|
|
|
|
2009-05-22 18:23:16 +08:00
|
|
|
if (ExpectAndConsume(tok::l_paren, diag::err_expected_lparen_after, CastName))
|
|
|
|
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 ')'.
|
2009-11-06 13:48:00 +08:00
|
|
|
RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc);
|
2006-12-05 02:06:35 +08:00
|
|
|
|
2009-02-19 01:45:20 +08:00
|
|
|
if (!Result.isInvalid() && !CastTy.isInvalid())
|
2008-10-28 03:41:14 +08:00
|
|
|
Result = Actions.ActOnCXXNamedCast(OpLoc, Kind,
|
2009-03-16 01:47:39 +08:00
|
|
|
LAngleBracketLoc, CastTy.get(),
|
2009-02-19 01:45:20 +08:00
|
|
|
RAngleBracketLoc,
|
2010-08-24 07:25:46 +08:00
|
|
|
LParenLoc, Result.take(), RParenLoc);
|
2006-12-05 02:06:35 +08:00
|
|
|
|
2008-12-12 06:51:44 +08:00
|
|
|
return move(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();
|
|
|
|
SourceLocation LParenLoc = Tok.getLocation();
|
|
|
|
SourceLocation RParenLoc;
|
|
|
|
|
|
|
|
// typeid expressions are always parenthesized.
|
|
|
|
if (ExpectAndConsume(tok::l_paren, diag::err_expected_lparen_after,
|
|
|
|
"typeid"))
|
2008-12-12 06:51:44 +08:00
|
|
|
return ExprError();
|
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
|
|
|
|
|
|
|
if (isTypeIdInParens()) {
|
2009-02-19 01:45:20 +08:00
|
|
|
TypeResult Ty = ParseTypeName();
|
2008-11-11 19:37:55 +08:00
|
|
|
|
|
|
|
// Match the ')'.
|
2010-09-09 07:14:30 +08:00
|
|
|
RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc);
|
2008-11-11 19:37:55 +08:00
|
|
|
|
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 {
|
2009-06-20 07:52:42 +08:00
|
|
|
// C++0x [expr.typeid]p3:
|
2009-09-09 23:08:12 +08:00
|
|
|
// When typeid is applied to an expression other than an lvalue of a
|
|
|
|
// polymorphic class type [...] The expression is an unevaluated
|
2009-06-20 07:52:42 +08:00
|
|
|
// operand (Clause 5).
|
|
|
|
//
|
2009-09-09 23:08:12 +08:00
|
|
|
// Note that we can't tell whether the expression is an lvalue of a
|
2009-06-20 07:52:42 +08:00
|
|
|
// polymorphic class type until after we've parsed the expression, so
|
2009-06-23 04:57:11 +08:00
|
|
|
// we the expression is potentially potentially evaluated.
|
|
|
|
EnterExpressionEvaluationContext Unevaluated(Actions,
|
2010-08-27 07:41:50 +08:00
|
|
|
Sema::PotentiallyPotentiallyEvaluated);
|
2008-11-11 19:37:55 +08:00
|
|
|
Result = ParseExpression();
|
|
|
|
|
|
|
|
// Match the ')'.
|
2008-12-09 21:15:23 +08:00
|
|
|
if (Result.isInvalid())
|
2008-11-11 19:37:55 +08:00
|
|
|
SkipUntil(tok::r_paren);
|
|
|
|
else {
|
2010-09-09 07:14:30 +08:00
|
|
|
RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc);
|
|
|
|
if (RParenLoc.isInvalid())
|
|
|
|
return ExprError();
|
2011-03-12 09:48:56 +08:00
|
|
|
|
|
|
|
// If we are a foo<int> that identifies a single function, resolve it now...
|
|
|
|
Expr* e = Result.get();
|
|
|
|
if (e->getType() == Actions.Context.OverloadTy) {
|
|
|
|
ExprResult er =
|
|
|
|
Actions.ResolveAndFixSingleFunctionTemplateSpecialization(e);
|
|
|
|
if (er.isUsable())
|
|
|
|
Result = er.release();
|
|
|
|
}
|
2008-11-11 19:37:55 +08:00
|
|
|
Result = Actions.ActOnCXXTypeid(OpLoc, LParenLoc, /*isType=*/false,
|
2008-12-10 08:02:53 +08:00
|
|
|
Result.release(), RParenLoc);
|
2008-11-11 19:37:55 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-12 06:51:44 +08:00
|
|
|
return move(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();
|
|
|
|
SourceLocation LParenLoc = Tok.getLocation();
|
|
|
|
SourceLocation RParenLoc;
|
|
|
|
|
|
|
|
// __uuidof expressions are always parenthesized.
|
|
|
|
if (ExpectAndConsume(tok::l_paren, diag::err_expected_lparen_after,
|
|
|
|
"__uuidof"))
|
|
|
|
return ExprError();
|
|
|
|
|
|
|
|
ExprResult Result;
|
|
|
|
|
|
|
|
if (isTypeIdInParens()) {
|
|
|
|
TypeResult Ty = ParseTypeName();
|
|
|
|
|
|
|
|
// Match the ')'.
|
|
|
|
RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc);
|
|
|
|
|
|
|
|
if (Ty.isInvalid())
|
|
|
|
return ExprError();
|
|
|
|
|
|
|
|
Result = Actions.ActOnCXXUuidof(OpLoc, LParenLoc, /*isType=*/true,
|
|
|
|
Ty.get().getAsOpaquePtr(), RParenLoc);
|
|
|
|
} else {
|
|
|
|
EnterExpressionEvaluationContext Unevaluated(Actions, Sema::Unevaluated);
|
|
|
|
Result = ParseExpression();
|
|
|
|
|
|
|
|
// Match the ')'.
|
|
|
|
if (Result.isInvalid())
|
|
|
|
SkipUntil(tok::r_paren);
|
|
|
|
else {
|
|
|
|
RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc);
|
|
|
|
|
|
|
|
Result = Actions.ActOnCXXUuidof(OpLoc, LParenLoc, /*isType=*/false,
|
|
|
|
Result.release(), RParenLoc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return move(Result);
|
|
|
|
}
|
|
|
|
|
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
|
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
|
|
|
Parser::ParseCXXPseudoDestructor(ExprArg Base, SourceLocation OpLoc,
|
|
|
|
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)) {
|
|
|
|
FirstTypeName.setTemplateId(
|
|
|
|
(TemplateIdAnnotation *)Tok.getAnnotationValue());
|
|
|
|
ConsumeToken();
|
|
|
|
assert(Tok.is(tok::coloncolon) &&"ParseOptionalCXXScopeSpecifier fail");
|
|
|
|
CCLoc = ConsumeToken();
|
|
|
|
} else {
|
|
|
|
FirstTypeName.setIdentifier(0, SourceLocation());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Parse the tilde.
|
|
|
|
assert(Tok.is(tok::tilde) && "ParseOptionalCXXScopeSpecifier fail");
|
|
|
|
SourceLocation TildeLoc = ConsumeToken();
|
|
|
|
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) &&
|
|
|
|
ParseUnqualifiedIdTemplateId(SS, Name, NameLoc, false, ObjectType,
|
2010-05-05 13:58:24 +08:00
|
|
|
SecondTypeName, /*AssumeTemplateName=*/true,
|
|
|
|
/*TemplateKWLoc*/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
|
|
|
return ExprError();
|
|
|
|
|
2010-08-24 07:25:46 +08:00
|
|
|
return Actions.ActOnPseudoDestructorExpr(getCurScope(), Base,
|
|
|
|
OpLoc, OpKind,
|
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
|
|
|
SS, FirstTypeName, CCLoc,
|
|
|
|
TildeLoc, SecondTypeName,
|
|
|
|
Tok.is(tok::l_paren));
|
|
|
|
}
|
|
|
|
|
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:
|
2010-08-24 07:25:46 +08:00
|
|
|
return Actions.ActOnCXXThrow(ThrowLoc, 0);
|
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());
|
2008-12-12 06:51:44 +08:00
|
|
|
if (Expr.isInvalid()) return move(Expr);
|
2010-08-24 07:25:46 +08:00
|
|
|
return Actions.ActOnCXXThrow(ThrowLoc, Expr.take());
|
2008-04-06 14:02:23 +08:00
|
|
|
}
|
2008-02-26 08:51:44 +08:00
|
|
|
}
|
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()").
|
|
|
|
///
|
|
|
|
/// postfix-expression: [C++ 5.2p1]
|
|
|
|
/// simple-type-specifier '(' expression-list[opt] ')' [C++ 5.2.3]
|
|
|
|
/// typename-specifier '(' expression-list[opt] ')' [TODO]
|
|
|
|
///
|
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
|
|
|
|
|
|
|
assert(Tok.is(tok::l_paren) && "Expected '('!");
|
2011-01-11 08:33:19 +08:00
|
|
|
GreaterThanIsOperatorScope G(GreaterThanIsOperator, true);
|
|
|
|
|
2008-08-22 23:38:55 +08:00
|
|
|
SourceLocation LParenLoc = ConsumeParen();
|
|
|
|
|
2008-11-26 06:21:31 +08:00
|
|
|
ExprVector Exprs(Actions);
|
2008-08-22 23:38:55 +08:00
|
|
|
CommaLocsTy CommaLocs;
|
|
|
|
|
|
|
|
if (Tok.isNot(tok::r_paren)) {
|
|
|
|
if (ParseExpressionList(Exprs, CommaLocs)) {
|
|
|
|
SkipUntil(tok::r_paren);
|
2008-12-12 06:51:44 +08:00
|
|
|
return ExprError();
|
2008-08-22 23:38:55 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Match the ')'.
|
|
|
|
SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc);
|
|
|
|
|
2009-07-29 21:50:23 +08:00
|
|
|
// TypeRep could be null, if it references an invalid typedef.
|
|
|
|
if (!TypeRep)
|
|
|
|
return ExprError();
|
|
|
|
|
2008-08-22 23:38:55 +08:00
|
|
|
assert((Exprs.size() == 0 || Exprs.size()-1 == CommaLocs.size())&&
|
|
|
|
"Unexpected number of commas!");
|
2010-09-08 08:15:04 +08:00
|
|
|
return Actions.ActOnCXXTypeConstructExpr(TypeRep, LParenLoc, move_arg(Exprs),
|
2010-09-10 00:33:13 +08:00
|
|
|
RParenLoc);
|
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
|
|
|
|
/// [GNU] type-specifier-seq declarator simple-asm-expr[opt] attributes[opt]
|
|
|
|
/// '=' assignment-expression
|
|
|
|
///
|
2009-11-25 08:27:52 +08:00
|
|
|
/// \param ExprResult if the condition was parsed as an expression, the
|
|
|
|
/// parsed expression.
|
|
|
|
///
|
|
|
|
/// \param DeclResult if the condition was parsed as a declaration, the
|
|
|
|
/// parsed declaration.
|
|
|
|
///
|
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.
|
|
|
|
///
|
|
|
|
/// \param ConvertToBoolean Whether the condition expression should be
|
|
|
|
/// converted to a boolean value.
|
|
|
|
///
|
2009-11-25 08:27:52 +08:00
|
|
|
/// \returns true if there was a parsing, false otherwise.
|
2010-08-24 14:29:42 +08:00
|
|
|
bool Parser::ParseCXXCondition(ExprResult &ExprOut,
|
|
|
|
Decl *&DeclOut,
|
2010-05-07 01:25:47 +08:00
|
|
|
SourceLocation Loc,
|
|
|
|
bool ConvertToBoolean) {
|
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);
|
2010-05-25 13:58:43 +08:00
|
|
|
ConsumeCodeCompletionToken();
|
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
|
|
|
}
|
|
|
|
|
2009-11-25 08:27:52 +08:00
|
|
|
if (!isCXXConditionDeclaration()) {
|
2010-05-07 01:25:47 +08:00
|
|
|
// Parse the expression.
|
2010-08-24 14:29:42 +08:00
|
|
|
ExprOut = ParseExpression(); // expression
|
|
|
|
DeclOut = 0;
|
|
|
|
if (ExprOut.isInvalid())
|
2010-05-07 01:25:47 +08:00
|
|
|
return true;
|
|
|
|
|
|
|
|
// If required, convert to a boolean value.
|
|
|
|
if (ConvertToBoolean)
|
2010-08-24 14:29:42 +08:00
|
|
|
ExprOut
|
|
|
|
= Actions.ActOnBooleanCondition(getCurScope(), Loc, ExprOut.get());
|
|
|
|
return ExprOut.isInvalid();
|
2009-11-25 08:27:52 +08:00
|
|
|
}
|
2008-09-10 04:38:47 +08:00
|
|
|
|
|
|
|
// type-specifier-seq
|
2011-03-24 19:26:52 +08:00
|
|
|
DeclSpec DS(AttrFactory);
|
2008-09-10 04:38:47 +08:00
|
|
|
ParseSpecifierQualifierList(DS);
|
|
|
|
|
|
|
|
// 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()) {
|
2008-09-10 04:38:47 +08:00
|
|
|
SkipUntil(tok::semi);
|
2009-11-25 08:27:52 +08:00
|
|
|
return true;
|
2008-09-10 04:38:47 +08:00
|
|
|
}
|
2008-12-10 08:02:53 +08:00
|
|
|
DeclaratorInfo.setAsmLabel(AsmLabel.release());
|
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);
|
2010-08-24 14:29:42 +08:00
|
|
|
DeclOut = Dcl.get();
|
|
|
|
ExprOut = ExprError();
|
2010-10-08 10:39:23 +08:00
|
|
|
|
2008-09-10 04:38:47 +08:00
|
|
|
// '=' assignment-expression
|
2010-10-08 10:39:23 +08:00
|
|
|
if (isTokenEqualOrMistypedEqualEqual(
|
|
|
|
diag::err_invalid_equalequal_after_declarator)) {
|
2011-01-18 10:00:16 +08:00
|
|
|
ConsumeToken();
|
2010-08-24 14:29:42 +08:00
|
|
|
ExprResult AssignExpr(ParseAssignmentExpression());
|
2009-11-25 08:27:52 +08:00
|
|
|
if (!AssignExpr.isInvalid())
|
2011-02-20 11:19:35 +08:00
|
|
|
Actions.AddInitializerToDecl(DeclOut, AssignExpr.take(), false,
|
|
|
|
DS.getTypeSpecType() == DeclSpec::TST_auto);
|
2009-11-25 08:27:52 +08:00
|
|
|
} else {
|
|
|
|
// FIXME: C++0x allows a braced-init-list
|
|
|
|
Diag(Tok, diag::err_expected_equal_after_declarator);
|
|
|
|
}
|
|
|
|
|
2010-05-07 01:25:47 +08:00
|
|
|
// FIXME: Build a reference to this declaration? Convert it to bool?
|
|
|
|
// (This is currently handled by Sema).
|
2011-02-22 04:05:19 +08:00
|
|
|
|
|
|
|
Actions.FinalizeDeclaration(DeclOut);
|
2010-05-07 01:25:47 +08:00
|
|
|
|
2009-11-25 08:27:52 +08:00
|
|
|
return false;
|
2008-09-10 04:38:47 +08:00
|
|
|
}
|
|
|
|
|
2010-04-22 06:36:40 +08:00
|
|
|
/// \brief Determine whether the current token starts a C++
|
|
|
|
/// simple-type-specifier.
|
|
|
|
bool Parser::isCXXSimpleTypeSpecifier() const {
|
|
|
|
switch (Tok.getKind()) {
|
|
|
|
case tok::annot_typename:
|
|
|
|
case tok::kw_short:
|
|
|
|
case tok::kw_long:
|
|
|
|
case tok::kw_signed:
|
|
|
|
case tok::kw_unsigned:
|
|
|
|
case tok::kw_void:
|
|
|
|
case tok::kw_char:
|
|
|
|
case tok::kw_int:
|
|
|
|
case tok::kw_float:
|
|
|
|
case tok::kw_double:
|
|
|
|
case tok::kw_wchar_t:
|
|
|
|
case tok::kw_char16_t:
|
|
|
|
case tok::kw_char32_t:
|
|
|
|
case tok::kw_bool:
|
|
|
|
// FIXME: C++0x decltype support.
|
|
|
|
// GNU typeof support.
|
|
|
|
case tok::kw_typeof:
|
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
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();
|
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
|
|
|
|
assert(0 && "Annotation token should already be formed!");
|
2009-09-09 23:08:12 +08:00
|
|
|
default:
|
2008-08-22 23:38:55 +08:00
|
|
|
assert(0 && "Not a simple-type-specifier token!");
|
|
|
|
abort();
|
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,
|
|
|
|
getTypeAnnotation(Tok));
|
|
|
|
else
|
|
|
|
DS.SetTypeSpecError();
|
2010-10-22 07:17:00 +08:00
|
|
|
|
|
|
|
DS.SetRangeEnd(Tok.getAnnotationEndLoc());
|
|
|
|
ConsumeToken();
|
|
|
|
|
|
|
|
// Objective-C supports syntax of the form 'id<proto1,proto2>' where 'id'
|
|
|
|
// is a specific typedef and 'itf<proto1,proto2>' where 'itf' is an
|
|
|
|
// Objective-C interface. If we don't have Objective-C or a '<', this is
|
|
|
|
// just a normal reference to a typedef name.
|
|
|
|
if (Tok.is(tok::less) && getLang().ObjC1)
|
|
|
|
ParseObjCProtocolQualifiers(DS);
|
|
|
|
|
|
|
|
DS.Finish(Diags, PP);
|
|
|
|
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:
|
2009-08-04 04:12:06 +08:00
|
|
|
DS.SetTypeSpecWidth(DeclSpec::TSW_short, Loc, PrevSpec, DiagID);
|
2008-08-22 23:38:55 +08:00
|
|
|
break;
|
|
|
|
case tok::kw_long:
|
2009-08-04 04:12:06 +08:00
|
|
|
DS.SetTypeSpecWidth(DeclSpec::TSW_long, Loc, PrevSpec, DiagID);
|
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:
|
2009-08-04 04:12:06 +08:00
|
|
|
DS.SetTypeSpecType(DeclSpec::TST_void, Loc, PrevSpec, DiagID);
|
2008-08-22 23:38:55 +08:00
|
|
|
break;
|
|
|
|
case tok::kw_char:
|
2009-08-04 04:12:06 +08:00
|
|
|
DS.SetTypeSpecType(DeclSpec::TST_char, Loc, PrevSpec, DiagID);
|
2008-08-22 23:38:55 +08:00
|
|
|
break;
|
|
|
|
case tok::kw_int:
|
2009-08-04 04:12:06 +08:00
|
|
|
DS.SetTypeSpecType(DeclSpec::TST_int, Loc, PrevSpec, DiagID);
|
2008-08-22 23:38:55 +08:00
|
|
|
break;
|
|
|
|
case tok::kw_float:
|
2009-08-04 04:12:06 +08:00
|
|
|
DS.SetTypeSpecType(DeclSpec::TST_float, Loc, PrevSpec, DiagID);
|
2008-08-22 23:38:55 +08:00
|
|
|
break;
|
|
|
|
case tok::kw_double:
|
2009-08-04 04:12:06 +08:00
|
|
|
DS.SetTypeSpecType(DeclSpec::TST_double, Loc, PrevSpec, DiagID);
|
2008-08-22 23:38:55 +08:00
|
|
|
break;
|
|
|
|
case tok::kw_wchar_t:
|
2009-08-04 04:12:06 +08:00
|
|
|
DS.SetTypeSpecType(DeclSpec::TST_wchar, Loc, PrevSpec, DiagID);
|
2008-08-22 23:38:55 +08:00
|
|
|
break;
|
2009-07-14 14:30:34 +08:00
|
|
|
case tok::kw_char16_t:
|
2009-08-04 04:12:06 +08:00
|
|
|
DS.SetTypeSpecType(DeclSpec::TST_char16, Loc, PrevSpec, DiagID);
|
2009-07-14 14:30:34 +08:00
|
|
|
break;
|
|
|
|
case tok::kw_char32_t:
|
2009-08-04 04:12:06 +08:00
|
|
|
DS.SetTypeSpecType(DeclSpec::TST_char32, Loc, PrevSpec, DiagID);
|
2009-07-14 14:30:34 +08:00
|
|
|
break;
|
2008-08-22 23:38:55 +08:00
|
|
|
case tok::kw_bool:
|
2009-08-04 04:12:06 +08:00
|
|
|
DS.SetTypeSpecType(DeclSpec::TST_bool, Loc, PrevSpec, DiagID);
|
2008-08-22 23:38:55 +08:00
|
|
|
break;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2010-04-22 06:36:40 +08:00
|
|
|
// FIXME: C++0x decltype support.
|
2008-08-22 23:38:55 +08:00
|
|
|
// GNU typeof support.
|
|
|
|
case tok::kw_typeof:
|
|
|
|
ParseTypeofSpecifier(DS);
|
2009-04-02 06:41:11 +08:00
|
|
|
DS.Finish(Diags, PP);
|
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();
|
2009-04-02 06:41:11 +08:00
|
|
|
DS.Finish(Diags, PP);
|
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) {
|
|
|
|
DS.SetRangeStart(Tok.getLocation());
|
|
|
|
const char *PrevSpec = 0;
|
2009-08-04 04:12:06 +08:00
|
|
|
unsigned DiagID;
|
|
|
|
bool isInvalid = 0;
|
2008-11-08 04:08:42 +08:00
|
|
|
|
|
|
|
// Parse one or more of the type specifiers.
|
2010-02-04 05:21:43 +08:00
|
|
|
if (!ParseOptionalTypeSpecifier(DS, isInvalid, PrevSpec, DiagID,
|
|
|
|
ParsedTemplateInfo(), /*SuppressDeclarations*/true)) {
|
2010-11-04 01:52:57 +08:00
|
|
|
Diag(Tok, diag::err_expected_type);
|
2008-11-08 04:08:42 +08:00
|
|
|
return true;
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2010-02-04 05:21:43 +08:00
|
|
|
while (ParseOptionalTypeSpecifier(DS, isInvalid, PrevSpec, DiagID,
|
|
|
|
ParsedTemplateInfo(), /*SuppressDeclarations*/true))
|
|
|
|
{}
|
2008-11-08 04:08:42 +08:00
|
|
|
|
2010-02-25 07:13:13 +08:00
|
|
|
DS.Finish(Diags, PP);
|
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,
|
|
|
|
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,
|
2010-05-05 13:58:24 +08:00
|
|
|
bool AssumeTemplateId,
|
|
|
|
SourceLocation TemplateKWLoc) {
|
|
|
|
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) {
|
2010-07-03 01:43:08 +08:00
|
|
|
TNK = Actions.ActOnDependentTemplateName(getCurScope(), TemplateKWLoc, SS,
|
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 ");
|
2010-07-03 01:43:08 +08:00
|
|
|
TNK = Actions.ActOnDependentTemplateName(getCurScope(), TemplateKWLoc,
|
2010-06-17 07:00:59 +08:00
|
|
|
SS, Id, ObjectType,
|
|
|
|
EnteringContext, Template);
|
|
|
|
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) {
|
2010-07-03 01:43:08 +08:00
|
|
|
TNK = Actions.ActOnDependentTemplateName(getCurScope(), TemplateKWLoc, SS,
|
2010-06-17 07:00:59 +08:00
|
|
|
TemplateName, ObjectType,
|
|
|
|
EnteringContext, Template);
|
|
|
|
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
|
|
|
|
= TemplateIdAnnotation::Allocate(TemplateArgs.size());
|
|
|
|
|
|
|
|
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 {
|
2009-11-04 07:16:33 +08:00
|
|
|
TemplateId->Name = 0;
|
|
|
|
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;
|
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.
|
|
|
|
ASTTemplateArgsPtr TemplateArgsPtr(Actions, TemplateArgs.data(),
|
|
|
|
TemplateArgs.size());
|
|
|
|
|
|
|
|
// Constructor and destructor names.
|
2010-08-27 07:41:50 +08:00
|
|
|
TypeResult Type
|
2011-03-02 08:47:37 +08:00
|
|
|
= Actions.ActOnTemplateIdType(SS, Template, NameLoc,
|
2009-11-03 09:35:08 +08:00
|
|
|
LAngleLoc, TemplateArgsPtr,
|
|
|
|
RAngleLoc);
|
|
|
|
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
|
|
|
|
///
|
|
|
|
/// \param The nested-name-specifier that preceded this unqualified-id. If
|
|
|
|
/// 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();
|
|
|
|
if (Tok.is(tok::l_square)) {
|
|
|
|
// Consume the '['.
|
|
|
|
SourceLocation LBracketLoc = ConsumeBracket();
|
|
|
|
// Consume the ']'.
|
|
|
|
SourceLocation RBracketLoc = MatchRHSPunctuation(tok::r_square,
|
|
|
|
LBracketLoc);
|
|
|
|
if (RBracketLoc.isInvalid())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
SymbolLocations[SymbolIdx++] = LBracketLoc;
|
|
|
|
SymbolLocations[SymbolIdx++] = RBracketLoc;
|
|
|
|
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: {
|
|
|
|
// Consume the '('.
|
|
|
|
SourceLocation LParenLoc = ConsumeParen();
|
|
|
|
// Consume the ')'.
|
|
|
|
SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren,
|
|
|
|
LParenLoc);
|
|
|
|
if (RParenLoc.isInvalid())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
SymbolLocations[SymbolIdx++] = LParenLoc;
|
|
|
|
SymbolLocations[SymbolIdx++] = RParenLoc;
|
|
|
|
Op = OO_Call;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case tok::l_square: {
|
|
|
|
// Consume the '['.
|
|
|
|
SourceLocation LBracketLoc = ConsumeBracket();
|
|
|
|
// Consume the ']'.
|
|
|
|
SourceLocation RBracketLoc = MatchRHSPunctuation(tok::r_square,
|
|
|
|
LBracketLoc);
|
|
|
|
if (RBracketLoc.isInvalid())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
SymbolLocations[SymbolIdx++] = LBracketLoc;
|
|
|
|
SymbolLocations[SymbolIdx++] = RBracketLoc;
|
|
|
|
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());
|
2009-11-04 08:56:37 +08:00
|
|
|
|
|
|
|
// Consume the operator token.
|
2010-05-25 13:58:43 +08:00
|
|
|
ConsumeCodeCompletionToken();
|
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.
|
|
|
|
//
|
|
|
|
// literal-operator-id: [C++0x 13.5.8]
|
|
|
|
// operator "" identifier
|
|
|
|
|
|
|
|
if (getLang().CPlusPlus0x && Tok.is(tok::string_literal)) {
|
|
|
|
if (Tok.getLength() != 2)
|
|
|
|
Diag(Tok.getLocation(), diag::err_operator_string_not_empty);
|
|
|
|
ConsumeStringToken();
|
|
|
|
|
|
|
|
if (Tok.isNot(tok::identifier)) {
|
|
|
|
Diag(Tok.getLocation(), diag::err_expected_ident);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
IdentifierInfo *II = Tok.getIdentifierInfo();
|
|
|
|
Result.setLiteralOperatorId(II, KeywordLoc, ConsumeToken());
|
2009-11-29 15:34:05 +08:00
|
|
|
return false;
|
2009-11-28 12:44:28 +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.
|
|
|
|
Declarator D(DS, Declarator::TypeNameContext);
|
|
|
|
ParseDeclaratorInternal(D, /*DirectDeclParser=*/0);
|
|
|
|
|
|
|
|
// 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
|
|
|
|
///
|
|
|
|
/// \param The nested-name-specifier that preceded this unqualified-id. If
|
|
|
|
/// 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,
|
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;
|
|
|
|
SourceLocation TemplateKWLoc;
|
|
|
|
if (getLang().CPlusPlus && Tok.is(tok::kw_template) &&
|
|
|
|
(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();
|
|
|
|
|
2010-01-12 07:29:10 +08:00
|
|
|
if (!getLang().CPlusPlus) {
|
|
|
|
// 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.
|
2010-07-03 01:43:08 +08:00
|
|
|
Result.setConstructorName(Actions.getTypeName(*Id, IdLoc, getCurScope(),
|
2011-03-02 02:12:44 +08:00
|
|
|
&SS, false, false,
|
|
|
|
ParsedType(),
|
|
|
|
/*NonTrivialTypeSourceInfo=*/true),
|
2009-11-03 09:35:08 +08:00
|
|
|
IdLoc, IdLoc);
|
|
|
|
} 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))
|
2009-11-03 09:35:08 +08:00
|
|
|
return ParseUnqualifiedIdTemplateId(SS, Id, IdLoc, EnteringContext,
|
2010-05-05 13:58:24 +08:00
|
|
|
ObjectType, Result,
|
|
|
|
TemplateSpecified, TemplateKWLoc);
|
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)) {
|
2010-01-14 01:31:36 +08:00
|
|
|
TemplateIdAnnotation *TemplateId
|
|
|
|
= static_cast<TemplateIdAnnotation*>(Tok.getAnnotationValue());
|
|
|
|
|
|
|
|
// 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));
|
|
|
|
Result.setConstructorName(Actions.getTypeName(*TemplateId->Name,
|
|
|
|
TemplateId->TemplateNameLoc,
|
2010-07-03 01:43:08 +08:00
|
|
|
getCurScope(),
|
2011-03-02 02:12:44 +08:00
|
|
|
&SS, false, false,
|
|
|
|
ParsedType(),
|
|
|
|
/*NontrivialTypeSourceInfo=*/true),
|
2010-01-14 01:31:36 +08:00
|
|
|
TemplateId->TemplateNameLoc,
|
|
|
|
TemplateId->RAngleLoc);
|
|
|
|
TemplateId->Destroy();
|
|
|
|
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);
|
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)))
|
2009-11-04 08:56:37 +08:00
|
|
|
return ParseUnqualifiedIdTemplateId(SS, 0, SourceLocation(),
|
|
|
|
EnteringContext, ObjectType,
|
2010-05-05 13:58:24 +08:00
|
|
|
Result,
|
|
|
|
TemplateSpecified, TemplateKWLoc);
|
2009-11-03 09:35:08 +08:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-01-12 07:29:10 +08:00
|
|
|
if (getLang().CPlusPlus &&
|
|
|
|
(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();
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Parse the class-name (or template-name in a simple-template-id).
|
|
|
|
IdentifierInfo *ClassName = Tok.getIdentifierInfo();
|
|
|
|
SourceLocation ClassNameLoc = ConsumeToken();
|
|
|
|
|
2010-05-05 13:58:24 +08:00
|
|
|
if (TemplateSpecified || Tok.is(tok::less)) {
|
2010-08-24 13:47:05 +08:00
|
|
|
Result.setDestructorName(TildeLoc, ParsedType(), ClassNameLoc);
|
2009-11-04 03:44:04 +08:00
|
|
|
return ParseUnqualifiedIdTemplateId(SS, ClassName, ClassNameLoc,
|
2010-05-05 13:58:24 +08:00
|
|
|
EnteringContext, ObjectType, Result,
|
|
|
|
TemplateSpecified, TemplateKWLoc);
|
2009-11-04 03:44:04 +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)
|
|
|
|
<< getLang().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] ')'
|
|
|
|
/// [C++0x] braced-init-list [TODO]
|
|
|
|
///
|
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.
|
|
|
|
|
2008-11-26 06:21:31 +08:00
|
|
|
ExprVector PlacementArgs(Actions);
|
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);
|
2008-12-02 22:43:59 +08:00
|
|
|
Declarator DeclaratorInfo(DS, Declarator::TypeNameContext);
|
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.
|
|
|
|
PlacementLParen = ConsumeParen();
|
2008-12-02 22:43:59 +08:00
|
|
|
if (ParseExpressionListOrTypeId(PlacementArgs, DeclaratorInfo)) {
|
|
|
|
SkipUntil(tok::semi, /*StopAtSemi=*/true, /*DontConsume=*/true);
|
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
|
|
|
|
|
|
|
PlacementRParen = MatchRHSPunctuation(tok::r_paren, PlacementLParen);
|
2008-12-02 22:43:59 +08:00
|
|
|
if (PlacementRParen.isInvalid()) {
|
|
|
|
SkipUntil(tok::semi, /*StopAtSemi=*/true, /*DontConsume=*/true);
|
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.
|
2010-07-13 23:54:32 +08:00
|
|
|
TypeIdParens = SourceRange(PlacementLParen, PlacementRParen);
|
2008-11-22 03:14:01 +08:00
|
|
|
PlacementLParen = PlacementRParen = SourceLocation();
|
|
|
|
} else {
|
|
|
|
// We still need the type.
|
|
|
|
if (Tok.is(tok::l_paren)) {
|
2010-07-13 23:54:32 +08:00
|
|
|
TypeIdParens.setBegin(ConsumeParen());
|
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);
|
2010-07-13 23:54:32 +08:00
|
|
|
TypeIdParens.setEnd(MatchRHSPunctuation(tok::r_paren,
|
|
|
|
TypeIdParens.getBegin()));
|
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()) {
|
2008-12-02 22:43:59 +08:00
|
|
|
SkipUntil(tok::semi, /*StopAtSemi=*/true, /*DontConsume=*/true);
|
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-11-26 06:21:31 +08:00
|
|
|
ExprVector ConstructorArgs(Actions);
|
2008-11-22 03:14:01 +08:00
|
|
|
SourceLocation ConstructorLParen, ConstructorRParen;
|
|
|
|
|
|
|
|
if (Tok.is(tok::l_paren)) {
|
|
|
|
ConstructorLParen = ConsumeParen();
|
|
|
|
if (Tok.isNot(tok::r_paren)) {
|
|
|
|
CommaLocsTy CommaLocs;
|
2008-12-02 22:43:59 +08:00
|
|
|
if (ParseExpressionList(ConstructorArgs, CommaLocs)) {
|
|
|
|
SkipUntil(tok::semi, /*StopAtSemi=*/true, /*DontConsume=*/true);
|
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
|
|
|
}
|
|
|
|
ConstructorRParen = MatchRHSPunctuation(tok::r_paren, ConstructorLParen);
|
2008-12-02 22:43:59 +08:00
|
|
|
if (ConstructorRParen.isInvalid()) {
|
|
|
|
SkipUntil(tok::semi, /*StopAtSemi=*/true, /*DontConsume=*/true);
|
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
|
|
|
}
|
|
|
|
|
2009-03-16 01:47:39 +08:00
|
|
|
return Actions.ActOnCXXNew(Start, UseGlobal, PlacementLParen,
|
|
|
|
move_arg(PlacementArgs), PlacementRParen,
|
2010-07-13 23:54:32 +08:00
|
|
|
TypeIdParens, DeclaratorInfo, ConstructorLParen,
|
2009-03-16 01:47:39 +08:00
|
|
|
move_arg(ConstructorArgs), ConstructorRParen);
|
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)) {
|
|
|
|
SourceLocation LLoc = ConsumeBracket();
|
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
|
|
|
|
SkipUntil(tok::r_square);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
first = false;
|
|
|
|
|
2009-02-10 02:23:29 +08:00
|
|
|
SourceLocation RLoc = MatchRHSPunctuation(tok::r_square, LLoc);
|
2011-03-24 19:26:52 +08:00
|
|
|
|
|
|
|
ParsedAttributes attrs(AttrFactory);
|
|
|
|
D.AddTypeInfo(DeclaratorChunk::getArray(0,
|
2010-12-24 10:08:15 +08:00
|
|
|
/*static=*/false, /*star=*/false,
|
2009-07-06 23:59:29 +08:00
|
|
|
Size.release(), LLoc, RLoc),
|
2011-03-24 19:26:52 +08:00
|
|
|
attrs, RLoc);
|
2008-11-22 03:14:01 +08:00
|
|
|
|
2009-02-10 02:23:29 +08:00
|
|
|
if (RLoc.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(
|
|
|
|
llvm::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;
|
|
|
|
if (Tok.is(tok::l_square)) {
|
|
|
|
ArrayDelete = true;
|
|
|
|
SourceLocation LHS = ConsumeBracket();
|
|
|
|
SourceLocation RHS = MatchRHSPunctuation(tok::r_square, LHS);
|
|
|
|
if (RHS.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())
|
2008-12-12 06:51:44 +08:00
|
|
|
return move(Operand);
|
2008-11-22 03:14:01 +08:00
|
|
|
|
2010-08-24 07:25:46 +08:00
|
|
|
return Actions.ActOnCXXDelete(Start, UseGlobal, ArrayDelete, Operand.take());
|
2008-11-22 03:14:01 +08:00
|
|
|
}
|
2009-01-06 04:52:13 +08:00
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
static UnaryTypeTrait UnaryTypeTraitFromTokKind(tok::TokenKind kind) {
|
2009-01-06 04:52:13 +08:00
|
|
|
switch(kind) {
|
2010-12-07 08:55:57 +08:00
|
|
|
default: llvm_unreachable("Not a known unary type trait");
|
2009-01-06 04:52:13 +08:00
|
|
|
case tok::kw___has_nothrow_assign: return UTT_HasNothrowAssign;
|
|
|
|
case tok::kw___has_nothrow_copy: return UTT_HasNothrowCopy;
|
|
|
|
case tok::kw___has_nothrow_constructor: return UTT_HasNothrowConstructor;
|
|
|
|
case tok::kw___has_trivial_assign: return UTT_HasTrivialAssign;
|
|
|
|
case tok::kw___has_trivial_copy: return UTT_HasTrivialCopy;
|
|
|
|
case tok::kw___has_trivial_constructor: return UTT_HasTrivialConstructor;
|
|
|
|
case tok::kw___has_trivial_destructor: return UTT_HasTrivialDestructor;
|
|
|
|
case tok::kw___has_virtual_destructor: return UTT_HasVirtualDestructor;
|
|
|
|
case tok::kw___is_abstract: return UTT_IsAbstract;
|
|
|
|
case tok::kw___is_class: return UTT_IsClass;
|
|
|
|
case tok::kw___is_empty: return UTT_IsEmpty;
|
|
|
|
case tok::kw___is_enum: return UTT_IsEnum;
|
|
|
|
case tok::kw___is_pod: return UTT_IsPOD;
|
|
|
|
case tok::kw___is_polymorphic: return UTT_IsPolymorphic;
|
|
|
|
case tok::kw___is_union: return UTT_IsUnion;
|
2009-12-03 08:13:20 +08:00
|
|
|
case tok::kw___is_literal: return UTT_IsLiteral;
|
2009-01-06 04:52:13 +08:00
|
|
|
}
|
2010-12-07 08:08:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static BinaryTypeTrait BinaryTypeTraitFromTokKind(tok::TokenKind kind) {
|
|
|
|
switch(kind) {
|
2010-12-07 08:55:57 +08:00
|
|
|
default: llvm_unreachable("Not a known binary type trait");
|
2010-12-09 06:35:30 +08:00
|
|
|
case tok::kw___is_base_of: return BTT_IsBaseOf;
|
|
|
|
case tok::kw___builtin_types_compatible_p: return BTT_TypeCompatible;
|
2011-01-28 04:28:01 +08:00
|
|
|
case tok::kw___is_convertible_to: return BTT_IsConvertibleTo;
|
2010-12-07 08:08:36 +08:00
|
|
|
}
|
2009-01-06 04:52:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// ParseUnaryTypeTrait - Parse the built-in unary type-trait
|
|
|
|
/// pseudo-functions that allow implementation of the TR1/C++0x type traits
|
|
|
|
/// templates.
|
|
|
|
///
|
|
|
|
/// primary-expression:
|
|
|
|
/// [GNU] unary-type-trait '(' type-id ')'
|
|
|
|
///
|
2010-08-24 14:29:42 +08:00
|
|
|
ExprResult Parser::ParseUnaryTypeTrait() {
|
2009-01-06 04:52:13 +08:00
|
|
|
UnaryTypeTrait UTT = UnaryTypeTraitFromTokKind(Tok.getKind());
|
|
|
|
SourceLocation Loc = ConsumeToken();
|
|
|
|
|
|
|
|
SourceLocation LParen = Tok.getLocation();
|
|
|
|
if (ExpectAndConsume(tok::l_paren, diag::err_expected_lparen))
|
|
|
|
return ExprError();
|
|
|
|
|
|
|
|
// FIXME: Error reporting absolutely sucks! If the this fails to parse a type
|
|
|
|
// there will be cryptic errors about mismatched parentheses and missing
|
|
|
|
// specifiers.
|
2009-02-19 01:45:20 +08:00
|
|
|
TypeResult Ty = ParseTypeName();
|
2009-01-06 04:52:13 +08:00
|
|
|
|
|
|
|
SourceLocation RParen = MatchRHSPunctuation(tok::r_paren, LParen);
|
|
|
|
|
2009-02-19 01:45:20 +08:00
|
|
|
if (Ty.isInvalid())
|
|
|
|
return ExprError();
|
|
|
|
|
2010-09-10 00:14:44 +08:00
|
|
|
return Actions.ActOnUnaryTypeTrait(UTT, Loc, Ty.get(), RParen);
|
2009-01-06 04:52:13 +08:00
|
|
|
}
|
2009-05-22 18:24:42 +08:00
|
|
|
|
2010-12-07 08:08:36 +08:00
|
|
|
/// ParseBinaryTypeTrait - Parse the built-in binary type-trait
|
|
|
|
/// pseudo-functions that allow implementation of the TR1/C++0x type traits
|
|
|
|
/// templates.
|
|
|
|
///
|
|
|
|
/// primary-expression:
|
|
|
|
/// [GNU] binary-type-trait '(' type-id ',' type-id ')'
|
|
|
|
///
|
|
|
|
ExprResult Parser::ParseBinaryTypeTrait() {
|
|
|
|
BinaryTypeTrait BTT = BinaryTypeTraitFromTokKind(Tok.getKind());
|
|
|
|
SourceLocation Loc = ConsumeToken();
|
|
|
|
|
|
|
|
SourceLocation LParen = Tok.getLocation();
|
|
|
|
if (ExpectAndConsume(tok::l_paren, diag::err_expected_lparen))
|
|
|
|
return ExprError();
|
|
|
|
|
|
|
|
TypeResult LhsTy = ParseTypeName();
|
|
|
|
if (LhsTy.isInvalid()) {
|
|
|
|
SkipUntil(tok::r_paren);
|
|
|
|
return ExprError();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ExpectAndConsume(tok::comma, diag::err_expected_comma)) {
|
|
|
|
SkipUntil(tok::r_paren);
|
|
|
|
return ExprError();
|
|
|
|
}
|
|
|
|
|
|
|
|
TypeResult RhsTy = ParseTypeName();
|
|
|
|
if (RhsTy.isInvalid()) {
|
|
|
|
SkipUntil(tok::r_paren);
|
|
|
|
return ExprError();
|
|
|
|
}
|
|
|
|
|
|
|
|
SourceLocation RParen = MatchRHSPunctuation(tok::r_paren, LParen);
|
|
|
|
|
|
|
|
return Actions.ActOnBinaryTypeTrait(BTT, Loc, LhsTy.get(), RhsTy.get(), RParen);
|
|
|
|
}
|
|
|
|
|
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,
|
2009-05-22 18:24:42 +08:00
|
|
|
SourceLocation LParenLoc,
|
|
|
|
SourceLocation &RParenLoc) {
|
|
|
|
assert(getLang().CPlusPlus && "Should only be called for C++!");
|
|
|
|
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);
|
2010-08-24 13:47:05 +08:00
|
|
|
CastTy = ParsedType();
|
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.
|
2009-05-22 18:24:42 +08:00
|
|
|
MatchRHSPunctuation(tok::r_paren, LParenLoc);
|
|
|
|
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
|
|
|
// FIXME: Special-case ++ and --: "(S())++;" is not a cast-expression
|
|
|
|
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.
|
|
|
|
Result = ParseCastExpression(false/*isUnaryExpression*/,
|
|
|
|
false/*isAddressofOperand*/,
|
2010-08-24 13:47:05 +08:00
|
|
|
NotCastExpr,
|
|
|
|
ParsedType()/*TypeOfCast*/);
|
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
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
PP.EnterTokenStream(Toks.data(), Toks.size(),
|
|
|
|
true/*DisableMacroExpansion*/, false/*OwnsTokens*/);
|
|
|
|
// 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) {
|
|
|
|
TypeResult Ty = ParseTypeName();
|
2009-05-22 18:24:42 +08:00
|
|
|
|
2009-05-23 05:09:47 +08:00
|
|
|
// Match the ')'.
|
|
|
|
if (Tok.is(tok::r_paren))
|
|
|
|
RParenLoc = ConsumeParen();
|
|
|
|
else
|
|
|
|
MatchRHSPunctuation(tok::r_paren, LParenLoc);
|
|
|
|
|
|
|
|
if (ParseAs == CompoundLiteral) {
|
|
|
|
ExprType = CompoundLiteral;
|
|
|
|
return ParseCompoundLiteralExpression(Ty.get(), LParenLoc, RParenLoc);
|
|
|
|
}
|
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);
|
|
|
|
|
|
|
|
if (Ty.isInvalid())
|
|
|
|
return ExprError();
|
2009-05-22 18:24:42 +08:00
|
|
|
|
|
|
|
CastTy = Ty.get();
|
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())
|
2010-07-03 01:43:08 +08:00
|
|
|
Result = Actions.ActOnCastExpr(getCurScope(), LParenLoc, CastTy, RParenLoc,
|
2010-08-24 07:25:46 +08:00
|
|
|
Result.take());
|
2009-05-22 18:24:42 +08:00
|
|
|
return move(Result);
|
|
|
|
}
|
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))
|
2010-08-24 07:25:46 +08:00
|
|
|
Result = Actions.ActOnParenExpr(LParenLoc, Tok.getLocation(), Result.take());
|
2009-05-22 18:24:42 +08:00
|
|
|
|
|
|
|
// Match the ')'.
|
|
|
|
if (Result.isInvalid()) {
|
|
|
|
SkipUntil(tok::r_paren);
|
|
|
|
return ExprError();
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-05-22 18:24:42 +08:00
|
|
|
if (Tok.is(tok::r_paren))
|
|
|
|
RParenLoc = ConsumeParen();
|
|
|
|
else
|
|
|
|
MatchRHSPunctuation(tok::r_paren, LParenLoc);
|
|
|
|
|
|
|
|
return move(Result);
|
|
|
|
}
|