2006-11-05 15:46:30 +08:00
|
|
|
//===--- ParseExpr.cpp - Expression Parsing -------------------------------===//
|
2006-08-10 12:23:57 +08:00
|
|
|
//
|
|
|
|
// 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-08-10 12:23:57 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2012-06-20 05:02:26 +08:00
|
|
|
///
|
2012-06-17 12:36:28 +08:00
|
|
|
/// \file
|
|
|
|
/// \brief Provides the Expression parsing implementation.
|
|
|
|
///
|
|
|
|
/// Expressions in C99 basically consist of a bunch of binary operators with
|
|
|
|
/// unary operators and other random stuff at the leaves.
|
|
|
|
///
|
|
|
|
/// In the C99 grammar, these unary operators bind tightest and are represented
|
|
|
|
/// as the 'cast-expression' production. Everything else is either a binary
|
|
|
|
/// operator (e.g. '/') or a ternary operator ("?:"). The unary leaves are
|
|
|
|
/// handled by ParseCastExpression, the higher level pieces are handled by
|
|
|
|
/// ParseBinaryExpression.
|
2012-06-20 05:02:26 +08:00
|
|
|
///
|
|
|
|
//===----------------------------------------------------------------------===//
|
2006-08-10 12:23:57 +08:00
|
|
|
|
|
|
|
#include "clang/Parse/Parser.h"
|
2012-12-04 17:13:33 +08:00
|
|
|
#include "RAIIObjectsForParser.h"
|
|
|
|
#include "clang/Basic/PrettyStackTrace.h"
|
2010-08-21 02:27:03 +08:00
|
|
|
#include "clang/Sema/DeclSpec.h"
|
|
|
|
#include "clang/Sema/ParsedTemplate.h"
|
2012-12-04 17:13:33 +08:00
|
|
|
#include "clang/Sema/Scope.h"
|
2012-01-26 04:49:08 +08:00
|
|
|
#include "clang/Sema/TypoCorrection.h"
|
2006-11-03 15:48:41 +08:00
|
|
|
#include "llvm/ADT/SmallString.h"
|
2012-12-04 17:13:33 +08:00
|
|
|
#include "llvm/ADT/SmallVector.h"
|
2006-08-10 12:23:57 +08:00
|
|
|
using namespace clang;
|
|
|
|
|
2012-06-17 12:36:28 +08:00
|
|
|
/// \brief Simple precedence-based parser for binary/ternary operators.
|
2006-08-12 16:13:25 +08:00
|
|
|
///
|
2006-08-13 00:45:01 +08:00
|
|
|
/// Note: we diverge from the C99 grammar when parsing the assignment-expression
|
|
|
|
/// production. C99 specifies that the LHS of an assignment operator should be
|
|
|
|
/// parsed as a unary-expression, but consistency dictates that it be a
|
|
|
|
/// conditional-expession. In practice, the important thing here is that the
|
|
|
|
/// LHS of an assignment has to be an l-value, which productions between
|
|
|
|
/// unary-expression and conditional-expression don't produce. Because we want
|
|
|
|
/// consistency, we parse the LHS as a conditional-expression, then check for
|
|
|
|
/// l-value-ness in semantic analysis stages.
|
|
|
|
///
|
2012-06-17 12:36:28 +08:00
|
|
|
/// \verbatim
|
2009-02-07 08:15:38 +08:00
|
|
|
/// pm-expression: [C++ 5.5]
|
|
|
|
/// cast-expression
|
|
|
|
/// pm-expression '.*' cast-expression
|
|
|
|
/// pm-expression '->*' cast-expression
|
|
|
|
///
|
2006-08-12 16:13:25 +08:00
|
|
|
/// multiplicative-expression: [C99 6.5.5]
|
2009-02-07 08:15:38 +08:00
|
|
|
/// Note: in C++, apply pm-expression instead of cast-expression
|
2006-08-12 16:13:25 +08:00
|
|
|
/// cast-expression
|
|
|
|
/// multiplicative-expression '*' cast-expression
|
|
|
|
/// multiplicative-expression '/' cast-expression
|
|
|
|
/// multiplicative-expression '%' cast-expression
|
|
|
|
///
|
|
|
|
/// additive-expression: [C99 6.5.6]
|
|
|
|
/// multiplicative-expression
|
|
|
|
/// additive-expression '+' multiplicative-expression
|
|
|
|
/// additive-expression '-' multiplicative-expression
|
|
|
|
///
|
|
|
|
/// shift-expression: [C99 6.5.7]
|
|
|
|
/// additive-expression
|
|
|
|
/// shift-expression '<<' additive-expression
|
|
|
|
/// shift-expression '>>' additive-expression
|
|
|
|
///
|
|
|
|
/// relational-expression: [C99 6.5.8]
|
|
|
|
/// shift-expression
|
|
|
|
/// relational-expression '<' shift-expression
|
|
|
|
/// relational-expression '>' shift-expression
|
|
|
|
/// relational-expression '<=' shift-expression
|
|
|
|
/// relational-expression '>=' shift-expression
|
|
|
|
///
|
|
|
|
/// equality-expression: [C99 6.5.9]
|
|
|
|
/// relational-expression
|
|
|
|
/// equality-expression '==' relational-expression
|
|
|
|
/// equality-expression '!=' relational-expression
|
|
|
|
///
|
|
|
|
/// AND-expression: [C99 6.5.10]
|
|
|
|
/// equality-expression
|
|
|
|
/// AND-expression '&' equality-expression
|
|
|
|
///
|
|
|
|
/// exclusive-OR-expression: [C99 6.5.11]
|
|
|
|
/// AND-expression
|
|
|
|
/// exclusive-OR-expression '^' AND-expression
|
|
|
|
///
|
|
|
|
/// inclusive-OR-expression: [C99 6.5.12]
|
|
|
|
/// exclusive-OR-expression
|
|
|
|
/// inclusive-OR-expression '|' exclusive-OR-expression
|
|
|
|
///
|
|
|
|
/// logical-AND-expression: [C99 6.5.13]
|
|
|
|
/// inclusive-OR-expression
|
|
|
|
/// logical-AND-expression '&&' inclusive-OR-expression
|
|
|
|
///
|
|
|
|
/// logical-OR-expression: [C99 6.5.14]
|
|
|
|
/// logical-AND-expression
|
|
|
|
/// logical-OR-expression '||' logical-AND-expression
|
|
|
|
///
|
|
|
|
/// conditional-expression: [C99 6.5.15]
|
|
|
|
/// logical-OR-expression
|
|
|
|
/// logical-OR-expression '?' expression ':' conditional-expression
|
|
|
|
/// [GNU] logical-OR-expression '?' ':' conditional-expression
|
2009-04-17 01:51:27 +08:00
|
|
|
/// [C++] the third operand is an assignment-expression
|
2006-08-12 16:13:25 +08:00
|
|
|
///
|
|
|
|
/// assignment-expression: [C99 6.5.16]
|
|
|
|
/// conditional-expression
|
|
|
|
/// unary-expression assignment-operator assignment-expression
|
2008-02-26 08:51:44 +08:00
|
|
|
/// [C++] throw-expression [C++ 15]
|
2006-08-12 16:13:25 +08:00
|
|
|
///
|
|
|
|
/// assignment-operator: one of
|
|
|
|
/// = *= /= %= += -= <<= >>= &= ^= |=
|
|
|
|
///
|
|
|
|
/// expression: [C99 6.5.17]
|
2011-01-04 03:31:53 +08:00
|
|
|
/// assignment-expression ...[opt]
|
|
|
|
/// expression ',' assignment-expression ...[opt]
|
2012-06-17 12:36:28 +08:00
|
|
|
/// \endverbatim
|
2012-01-26 04:49:08 +08:00
|
|
|
ExprResult Parser::ParseExpression(TypeCastState isTypeCast) {
|
|
|
|
ExprResult LHS(ParseAssignmentExpression(isTypeCast));
|
2012-08-24 05:35:17 +08:00
|
|
|
return ParseRHSOfBinaryExpression(LHS, prec::Comma);
|
2006-08-12 16:13:25 +08:00
|
|
|
}
|
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
/// This routine is called when the '@' is seen and consumed.
|
2007-09-20 03:14:32 +08:00
|
|
|
/// Current token is an Identifier and is not a 'try'. This
|
2012-06-15 14:52:33 +08:00
|
|
|
/// routine is necessary to disambiguate \@try-statement from,
|
|
|
|
/// for example, \@encode-expression.
|
2007-09-20 03:14:32 +08:00
|
|
|
///
|
2010-08-24 14:29:42 +08:00
|
|
|
ExprResult
|
2008-12-12 06:33:27 +08:00
|
|
|
Parser::ParseExpressionWithLeadingAt(SourceLocation AtLoc) {
|
2010-08-24 14:29:42 +08:00
|
|
|
ExprResult LHS(ParseObjCAtExpression(AtLoc));
|
2012-08-24 05:35:17 +08:00
|
|
|
return ParseRHSOfBinaryExpression(LHS, prec::Comma);
|
2007-09-20 03:14:32 +08:00
|
|
|
}
|
|
|
|
|
2009-01-27 16:43:38 +08:00
|
|
|
/// This routine is called when a leading '__extension__' is seen and
|
|
|
|
/// consumed. This is necessary because the token gets consumed in the
|
|
|
|
/// process of disambiguating between an expression and a declaration.
|
2010-08-24 14:29:42 +08:00
|
|
|
ExprResult
|
2009-01-27 16:43:38 +08:00
|
|
|
Parser::ParseExpressionWithLeadingExtension(SourceLocation ExtLoc) {
|
2010-08-24 14:29:42 +08:00
|
|
|
ExprResult LHS(true);
|
2009-05-17 07:40:44 +08:00
|
|
|
{
|
|
|
|
// Silence extension warnings in the sub-expression
|
|
|
|
ExtensionRAIIObject O(Diags);
|
|
|
|
|
|
|
|
LHS = ParseCastExpression(false);
|
|
|
|
}
|
2009-01-27 16:43:38 +08:00
|
|
|
|
When we run into an error parsing or type-checking the left-hand side
of a binary expression, continue on and parse the right-hand side of
the binary expression anyway, but don't call the semantic actions to
type-check. Previously, we would see the error and then, effectively,
skip tokens until the end of the statement.
The result should be more useful recovery, both in the normal case
(we'll actually see errors beyond the first one in a statement), but
it also helps code completion do a much better job, because we do
"real" code completion on the right-hand side of an invalid binary
expression rather than completing with the recovery completion. For
example, given
x = p->y
if there is no variable named "x", we can still complete after the p->
as a member expression. Along the recovery path, we would have
completed after the "->" as if we were in an expression context, which
is mostly useless.
llvm-svn: 114225
2010-09-18 06:25:06 +08:00
|
|
|
if (!LHS.isInvalid())
|
|
|
|
LHS = Actions.ActOnUnaryOp(getCurScope(), ExtLoc, tok::kw___extension__,
|
|
|
|
LHS.take());
|
2009-01-27 16:43:38 +08:00
|
|
|
|
2012-08-24 05:35:17 +08:00
|
|
|
return ParseRHSOfBinaryExpression(LHS, prec::Comma);
|
2009-01-27 16:43:38 +08:00
|
|
|
}
|
|
|
|
|
2012-06-17 12:36:28 +08:00
|
|
|
/// \brief Parse an expr that doesn't include (top-level) commas.
|
2012-01-26 04:49:08 +08:00
|
|
|
ExprResult Parser::ParseAssignmentExpression(TypeCastState isTypeCast) {
|
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)) {
|
2011-04-27 14:18:01 +08:00
|
|
|
Actions.CodeCompleteOrdinaryName(getCurScope(), Sema::PCC_Expression);
|
2011-09-04 11:32:15 +08:00
|
|
|
cutOffParsing();
|
|
|
|
return ExprError();
|
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
|
|
|
}
|
|
|
|
|
2011-04-27 14:18:01 +08:00
|
|
|
if (Tok.is(tok::kw_throw))
|
2008-12-12 06:51:44 +08:00
|
|
|
return ParseThrowExpression();
|
2008-02-26 08:51:44 +08:00
|
|
|
|
2012-01-26 04:49:08 +08:00
|
|
|
ExprResult LHS = ParseCastExpression(/*isUnaryExpression=*/false,
|
|
|
|
/*isAddressOfOperand=*/false,
|
|
|
|
isTypeCast);
|
2012-08-24 05:35:17 +08:00
|
|
|
return ParseRHSOfBinaryExpression(LHS, prec::Assignment);
|
2006-08-13 01:22:40 +08:00
|
|
|
}
|
|
|
|
|
2012-06-17 12:36:28 +08:00
|
|
|
/// \brief Parse an assignment expression where part of an Objective-C message
|
|
|
|
/// send has already been parsed.
|
|
|
|
///
|
|
|
|
/// In this case \p LBracLoc indicates the location of the '[' of the message
|
|
|
|
/// send, and either \p ReceiverName or \p ReceiverExpr is non-null indicating
|
|
|
|
/// the receiver of the message.
|
2008-06-03 05:31:07 +08:00
|
|
|
///
|
|
|
|
/// Since this handles full assignment-expression's, it handles postfix
|
|
|
|
/// expressions and other binary operators for these expressions as well.
|
2010-08-24 14:29:42 +08:00
|
|
|
ExprResult
|
2008-06-03 05:31:07 +08:00
|
|
|
Parser::ParseAssignmentExprWithObjCMessageExprStart(SourceLocation LBracLoc,
|
Rework the Parser-Sema interaction for Objective-C message
sends. Major changes include:
- Expanded the interface from two actions (ActOnInstanceMessage,
ActOnClassMessage), where ActOnClassMessage also handled sends to
"super" by checking whether the identifier was "super", to three
actions (ActOnInstanceMessage, ActOnClassMessage,
ActOnSuperMessage). Code completion has the same changes.
- The parser now resolves the type to which we are sending a class
message, so ActOnClassMessage now accepts a TypeTy* (rather than
an IdentifierInfo *). This opens the door to more interesting
types (for Objective-C++ support).
- Split ActOnInstanceMessage and ActOnClassMessage into parser
action functions (with their original names) and semantic
functions (BuildInstanceMessage and BuildClassMessage,
respectively). At present, this split is onyl used by
ActOnSuperMessage, which decides which kind of super message it
has and forwards to the appropriate Build*Message. In the future,
Build*Message will be used by template instantiation.
- Use getObjCMessageKind() within the disambiguation of Objective-C
message sends vs. array designators.
Two notes about substandard bits in this patch:
- There is some redundancy in the code in ParseObjCMessageExpr and
ParseInitializerWithPotentialDesignator; this will be addressed
shortly by centralizing the mapping from identifiers to type names
for the message receiver.
- There is some #if 0'd code that won't likely ever be used---it
handles the use of 'super' in methods whose class does not have a
superclass---but could be used to model GCC's behavior more
closely. This code will die in my next check-in, but I want it in
Subversion.
llvm-svn: 102021
2010-04-22 03:57:20 +08:00
|
|
|
SourceLocation SuperLoc,
|
2010-08-24 13:47:05 +08:00
|
|
|
ParsedType ReceiverType,
|
2010-08-24 07:25:46 +08:00
|
|
|
Expr *ReceiverExpr) {
|
2010-08-24 14:29:42 +08:00
|
|
|
ExprResult R
|
2010-08-24 07:25:46 +08:00
|
|
|
= ParseObjCMessageExpressionBody(LBracLoc, SuperLoc,
|
|
|
|
ReceiverType, ReceiverExpr);
|
2010-09-18 09:28:11 +08:00
|
|
|
R = ParsePostfixExpressionSuffix(R);
|
When we run into an error parsing or type-checking the left-hand side
of a binary expression, continue on and parse the right-hand side of
the binary expression anyway, but don't call the semantic actions to
type-check. Previously, we would see the error and then, effectively,
skip tokens until the end of the statement.
The result should be more useful recovery, both in the normal case
(we'll actually see errors beyond the first one in a statement), but
it also helps code completion do a much better job, because we do
"real" code completion on the right-hand side of an invalid binary
expression rather than completing with the recovery completion. For
example, given
x = p->y
if there is no variable named "x", we can still complete after the p->
as a member expression. Along the recovery path, we would have
completed after the "->" as if we were in an expression context, which
is mostly useless.
llvm-svn: 114225
2010-09-18 06:25:06 +08:00
|
|
|
return ParseRHSOfBinaryExpression(R, prec::Assignment);
|
2008-06-03 05:31:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-22 09:03:07 +08:00
|
|
|
ExprResult Parser::ParseConstantExpression(TypeCastState isTypeCast) {
|
2011-12-20 10:08:33 +08:00
|
|
|
// C++03 [basic.def.odr]p2:
|
2009-09-09 23:08:12 +08:00
|
|
|
// An expression is potentially evaluated unless it appears where an
|
2009-06-20 07:52:42 +08:00
|
|
|
// integral constant expression is required (see 5.19) [...].
|
2011-12-20 10:08:33 +08:00
|
|
|
// C++98 and C++11 have no such rule, but this is only a defect in C++98.
|
2009-06-23 04:57:11 +08:00
|
|
|
EnterExpressionEvaluationContext Unevaluated(Actions,
|
2011-12-20 10:08:33 +08:00
|
|
|
Sema::ConstantEvaluated);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2012-02-22 09:03:07 +08:00
|
|
|
ExprResult LHS(ParseCastExpression(false, false, isTypeCast));
|
2012-02-29 11:16:56 +08:00
|
|
|
ExprResult Res(ParseRHSOfBinaryExpression(LHS, prec::Conditional));
|
|
|
|
return Actions.ActOnConstantExpression(Res);
|
2006-08-13 08:12:11 +08:00
|
|
|
}
|
|
|
|
|
2012-09-18 08:52:05 +08:00
|
|
|
bool Parser::isNotExpressionStart() {
|
|
|
|
tok::TokenKind K = Tok.getKind();
|
|
|
|
if (K == tok::l_brace || K == tok::r_brace ||
|
|
|
|
K == tok::kw_for || K == tok::kw_while ||
|
|
|
|
K == tok::kw_if || K == tok::kw_else ||
|
|
|
|
K == tok::kw_goto || K == tok::kw_try)
|
|
|
|
return true;
|
|
|
|
// If this is a decl-specifier, we can't be at the start of an expression.
|
|
|
|
return isKnownToBeDeclarationSpecifier();
|
|
|
|
}
|
|
|
|
|
2012-06-17 12:36:28 +08:00
|
|
|
/// \brief Parse a binary expression that starts with \p LHS and has a
|
|
|
|
/// precedence of at least \p MinPrec.
|
2010-08-24 14:29:42 +08:00
|
|
|
ExprResult
|
|
|
|
Parser::ParseRHSOfBinaryExpression(ExprResult LHS, prec::Level MinPrec) {
|
2010-04-22 06:36:40 +08:00
|
|
|
prec::Level NextTokPrec = getBinOpPrecedence(Tok.getKind(),
|
|
|
|
GreaterThanIsOperator,
|
2013-01-02 19:42:31 +08:00
|
|
|
getLangOpts().CPlusPlus11);
|
2006-08-23 13:17:46 +08:00
|
|
|
SourceLocation ColonLoc;
|
|
|
|
|
2006-08-12 16:13:25 +08:00
|
|
|
while (1) {
|
|
|
|
// If this token has a lower precedence than we are allowed to parse (e.g.
|
|
|
|
// because we are called recursively, or because the token is not a binop),
|
|
|
|
// then we are done!
|
2008-12-09 21:15:23 +08:00
|
|
|
if (NextTokPrec < MinPrec)
|
2012-08-24 05:35:17 +08:00
|
|
|
return LHS;
|
2006-08-12 16:13:25 +08:00
|
|
|
|
|
|
|
// Consume the operator, saving the operator token for error reporting.
|
2007-07-21 00:59:19 +08:00
|
|
|
Token OpToken = Tok;
|
2006-08-12 16:13:25 +08:00
|
|
|
ConsumeToken();
|
2009-02-07 08:15:38 +08:00
|
|
|
|
2012-09-18 08:52:05 +08:00
|
|
|
// Bail out when encountering a comma followed by a token which can't
|
|
|
|
// possibly be the start of an expression. For instance:
|
|
|
|
// int f() { return 1, }
|
|
|
|
// We can't do this before consuming the comma, because
|
|
|
|
// isNotExpressionStart() looks at the token stream.
|
|
|
|
if (OpToken.is(tok::comma) && isNotExpressionStart()) {
|
|
|
|
PP.EnterToken(Tok);
|
|
|
|
Tok = OpToken;
|
|
|
|
return LHS;
|
|
|
|
}
|
|
|
|
|
2006-08-13 01:13:08 +08:00
|
|
|
// Special case handling for the ternary operator.
|
2010-08-24 14:29:42 +08:00
|
|
|
ExprResult TernaryMiddle(true);
|
2006-08-13 01:13:08 +08:00
|
|
|
if (NextTokPrec == prec::Conditional) {
|
2007-10-10 01:41:39 +08:00
|
|
|
if (Tok.isNot(tok::colon)) {
|
2009-12-10 10:02:58 +08:00
|
|
|
// Don't parse FOO:BAR as if it were a typo for FOO::BAR.
|
|
|
|
ColonProtectionRAIIObject X(*this);
|
|
|
|
|
2006-08-13 01:13:08 +08:00
|
|
|
// Handle this production specially:
|
|
|
|
// logical-OR-expression '?' expression ':' conditional-expression
|
|
|
|
// In particular, the RHS of the '?' is 'expression', not
|
|
|
|
// 'logical-OR-expression' as we might expect.
|
|
|
|
TernaryMiddle = ParseExpression();
|
2010-09-18 06:41:34 +08:00
|
|
|
if (TernaryMiddle.isInvalid()) {
|
|
|
|
LHS = ExprError();
|
|
|
|
TernaryMiddle = 0;
|
|
|
|
}
|
2006-08-13 01:13:08 +08:00
|
|
|
} else {
|
|
|
|
// Special case handling of "X ? Y : Z" where Y is empty:
|
|
|
|
// logical-OR-expression '?' ':' conditional-expression [GNU]
|
2008-12-10 04:22:58 +08:00
|
|
|
TernaryMiddle = 0;
|
2006-08-13 01:13:08 +08:00
|
|
|
Diag(Tok, diag::ext_gnu_conditional_expr);
|
|
|
|
}
|
2008-12-09 21:15:23 +08:00
|
|
|
|
2010-04-21 05:33:39 +08:00
|
|
|
if (Tok.is(tok::colon)) {
|
|
|
|
// Eat the colon.
|
|
|
|
ColonLoc = ConsumeToken();
|
|
|
|
} else {
|
2011-07-26 13:19:46 +08:00
|
|
|
// Otherwise, we're missing a ':'. Assume that this was a typo that
|
|
|
|
// the user forgot. If we're not in a macro expansion, we can suggest
|
|
|
|
// a fixit hint. If there were two spaces before the current token,
|
2010-05-25 06:31:37 +08:00
|
|
|
// suggest inserting the colon in between them, otherwise insert ": ".
|
|
|
|
SourceLocation FILoc = Tok.getLocation();
|
|
|
|
const char *FIText = ": ";
|
2011-06-25 01:28:29 +08:00
|
|
|
const SourceManager &SM = PP.getSourceManager();
|
2012-01-19 23:59:08 +08:00
|
|
|
if (FILoc.isFileID() || PP.isAtStartOfMacroExpansion(FILoc, &FILoc)) {
|
|
|
|
assert(FILoc.isFileID());
|
2010-05-25 06:31:37 +08:00
|
|
|
bool IsInvalid = false;
|
|
|
|
const char *SourcePtr =
|
2011-09-20 04:40:19 +08:00
|
|
|
SM.getCharacterData(FILoc.getLocWithOffset(-1), &IsInvalid);
|
2010-05-25 06:31:37 +08:00
|
|
|
if (!IsInvalid && *SourcePtr == ' ') {
|
|
|
|
SourcePtr =
|
2011-09-20 04:40:19 +08:00
|
|
|
SM.getCharacterData(FILoc.getLocWithOffset(-2), &IsInvalid);
|
2010-05-25 06:31:37 +08:00
|
|
|
if (!IsInvalid && *SourcePtr == ' ') {
|
2011-09-20 04:40:19 +08:00
|
|
|
FILoc = FILoc.getLocWithOffset(-1);
|
2010-05-25 06:31:37 +08:00
|
|
|
FIText = ":";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-13 06:10:35 +08:00
|
|
|
Diag(Tok, diag::err_expected_colon)
|
2010-05-25 06:31:37 +08:00
|
|
|
<< FixItHint::CreateInsertion(FILoc, FIText);
|
2008-11-24 07:17:07 +08:00
|
|
|
Diag(OpToken, diag::note_matching) << "?";
|
2010-04-21 05:33:39 +08:00
|
|
|
ColonLoc = Tok.getLocation();
|
2006-08-13 01:13:08 +08:00
|
|
|
}
|
2006-08-12 16:13:25 +08:00
|
|
|
}
|
2009-10-24 05:01:39 +08:00
|
|
|
|
2010-05-30 09:49:25 +08:00
|
|
|
// Code completion for the right-hand side of an assignment expression
|
|
|
|
// goes through a special hook that takes the left-hand side into account.
|
|
|
|
if (Tok.is(tok::code_completion) && NextTokPrec == prec::Assignment) {
|
2010-07-03 01:43:08 +08:00
|
|
|
Actions.CodeCompleteAssignmentRHS(getCurScope(), LHS.get());
|
2011-09-04 11:32:15 +08:00
|
|
|
cutOffParsing();
|
2010-05-30 09:49:25 +08:00
|
|
|
return ExprError();
|
|
|
|
}
|
|
|
|
|
2006-08-13 01:13:08 +08:00
|
|
|
// Parse another leaf here for the RHS of the operator.
|
2009-04-17 01:51:27 +08:00
|
|
|
// ParseCastExpression works here because all RHS expressions in C have it
|
|
|
|
// as a prefix, at least. However, in C++, an assignment-expression could
|
|
|
|
// be a throw-expression, which is not a valid cast-expression.
|
|
|
|
// Therefore we need some special-casing here.
|
|
|
|
// Also note that the third operand of the conditional operator is
|
2012-02-27 07:40:27 +08:00
|
|
|
// an assignment-expression in C++, and in C++11, we can have a
|
2012-03-01 10:59:17 +08:00
|
|
|
// braced-init-list on the RHS of an assignment. For better diagnostics,
|
|
|
|
// parse as if we were allowed braced-init-lists everywhere, and check that
|
|
|
|
// they only appear on the RHS of assignments later.
|
2010-08-24 14:29:42 +08:00
|
|
|
ExprResult RHS;
|
2012-03-01 15:10:06 +08:00
|
|
|
bool RHSIsInitList = false;
|
2013-01-02 19:42:31 +08:00
|
|
|
if (getLangOpts().CPlusPlus11 && Tok.is(tok::l_brace)) {
|
2012-02-27 07:40:27 +08:00
|
|
|
RHS = ParseBraceInitializer();
|
2012-03-01 15:10:06 +08:00
|
|
|
RHSIsInitList = true;
|
2012-03-11 15:00:24 +08:00
|
|
|
} else if (getLangOpts().CPlusPlus && NextTokPrec <= prec::Conditional)
|
2009-04-17 01:51:27 +08:00
|
|
|
RHS = ParseAssignmentExpression();
|
2012-03-01 10:59:17 +08:00
|
|
|
else
|
2009-04-17 01:51:27 +08:00
|
|
|
RHS = ParseCastExpression(false);
|
2006-08-12 16:13:25 +08:00
|
|
|
|
When we run into an error parsing or type-checking the left-hand side
of a binary expression, continue on and parse the right-hand side of
the binary expression anyway, but don't call the semantic actions to
type-check. Previously, we would see the error and then, effectively,
skip tokens until the end of the statement.
The result should be more useful recovery, both in the normal case
(we'll actually see errors beyond the first one in a statement), but
it also helps code completion do a much better job, because we do
"real" code completion on the right-hand side of an invalid binary
expression rather than completing with the recovery completion. For
example, given
x = p->y
if there is no variable named "x", we can still complete after the p->
as a member expression. Along the recovery path, we would have
completed after the "->" as if we were in an expression context, which
is mostly useless.
llvm-svn: 114225
2010-09-18 06:25:06 +08:00
|
|
|
if (RHS.isInvalid())
|
|
|
|
LHS = ExprError();
|
|
|
|
|
2006-08-12 16:13:25 +08:00
|
|
|
// Remember the precedence of this operator and get the precedence of the
|
|
|
|
// operator immediately to the right of the RHS.
|
2010-04-22 06:36:40 +08:00
|
|
|
prec::Level ThisPrec = NextTokPrec;
|
2009-02-26 07:02:36 +08:00
|
|
|
NextTokPrec = getBinOpPrecedence(Tok.getKind(), GreaterThanIsOperator,
|
2013-01-02 19:42:31 +08:00
|
|
|
getLangOpts().CPlusPlus11);
|
2006-08-13 01:18:19 +08:00
|
|
|
|
|
|
|
// Assignment and conditional expressions are right-associative.
|
2007-12-18 14:06:23 +08:00
|
|
|
bool isRightAssoc = ThisPrec == prec::Conditional ||
|
|
|
|
ThisPrec == prec::Assignment;
|
2006-08-12 16:13:25 +08:00
|
|
|
|
|
|
|
// Get the precedence of the operator to the right of the RHS. If it binds
|
|
|
|
// more tightly with RHS than we do, evaluate it completely first.
|
|
|
|
if (ThisPrec < NextTokPrec ||
|
|
|
|
(ThisPrec == NextTokPrec && isRightAssoc)) {
|
2012-03-01 15:10:06 +08:00
|
|
|
if (!RHS.isInvalid() && RHSIsInitList) {
|
|
|
|
Diag(Tok, diag::err_init_list_bin_op)
|
|
|
|
<< /*LHS*/0 << PP.getSpelling(Tok) << Actions.getExprRange(RHS.get());
|
|
|
|
RHS = ExprError();
|
2012-03-01 10:59:17 +08:00
|
|
|
}
|
2006-08-13 01:18:19 +08:00
|
|
|
// If this is left-associative, only parse things on the RHS that bind
|
|
|
|
// more tightly than the current operator. If it is left-associative, it
|
|
|
|
// is okay, to bind exactly as tightly. For example, compile A=B=C=D as
|
|
|
|
// A=(B=(C=D)), where each paren is a level of recursion here.
|
2008-11-26 06:21:31 +08:00
|
|
|
// The function takes ownership of the RHS.
|
When we run into an error parsing or type-checking the left-hand side
of a binary expression, continue on and parse the right-hand side of
the binary expression anyway, but don't call the semantic actions to
type-check. Previously, we would see the error and then, effectively,
skip tokens until the end of the statement.
The result should be more useful recovery, both in the normal case
(we'll actually see errors beyond the first one in a statement), but
it also helps code completion do a much better job, because we do
"real" code completion on the right-hand side of an invalid binary
expression rather than completing with the recovery completion. For
example, given
x = p->y
if there is no variable named "x", we can still complete after the p->
as a member expression. Along the recovery path, we would have
completed after the "->" as if we were in an expression context, which
is mostly useless.
llvm-svn: 114225
2010-09-18 06:25:06 +08:00
|
|
|
RHS = ParseRHSOfBinaryExpression(RHS,
|
2010-04-22 06:36:40 +08:00
|
|
|
static_cast<prec::Level>(ThisPrec + !isRightAssoc));
|
2012-03-01 15:10:06 +08:00
|
|
|
RHSIsInitList = false;
|
When we run into an error parsing or type-checking the left-hand side
of a binary expression, continue on and parse the right-hand side of
the binary expression anyway, but don't call the semantic actions to
type-check. Previously, we would see the error and then, effectively,
skip tokens until the end of the statement.
The result should be more useful recovery, both in the normal case
(we'll actually see errors beyond the first one in a statement), but
it also helps code completion do a much better job, because we do
"real" code completion on the right-hand side of an invalid binary
expression rather than completing with the recovery completion. For
example, given
x = p->y
if there is no variable named "x", we can still complete after the p->
as a member expression. Along the recovery path, we would have
completed after the "->" as if we were in an expression context, which
is mostly useless.
llvm-svn: 114225
2010-09-18 06:25:06 +08:00
|
|
|
|
2008-12-09 21:15:23 +08:00
|
|
|
if (RHS.isInvalid())
|
When we run into an error parsing or type-checking the left-hand side
of a binary expression, continue on and parse the right-hand side of
the binary expression anyway, but don't call the semantic actions to
type-check. Previously, we would see the error and then, effectively,
skip tokens until the end of the statement.
The result should be more useful recovery, both in the normal case
(we'll actually see errors beyond the first one in a statement), but
it also helps code completion do a much better job, because we do
"real" code completion on the right-hand side of an invalid binary
expression rather than completing with the recovery completion. For
example, given
x = p->y
if there is no variable named "x", we can still complete after the p->
as a member expression. Along the recovery path, we would have
completed after the "->" as if we were in an expression context, which
is mostly useless.
llvm-svn: 114225
2010-09-18 06:25:06 +08:00
|
|
|
LHS = ExprError();
|
2006-08-12 16:13:25 +08:00
|
|
|
|
2009-02-26 07:02:36 +08:00
|
|
|
NextTokPrec = getBinOpPrecedence(Tok.getKind(), GreaterThanIsOperator,
|
2013-01-02 19:42:31 +08:00
|
|
|
getLangOpts().CPlusPlus11);
|
2006-08-12 16:13:25 +08:00
|
|
|
}
|
|
|
|
assert(NextTokPrec <= ThisPrec && "Recursion didn't work!");
|
2008-11-26 06:21:31 +08:00
|
|
|
|
2012-03-01 15:10:06 +08:00
|
|
|
if (!RHS.isInvalid() && RHSIsInitList) {
|
2012-03-01 10:59:17 +08:00
|
|
|
if (ThisPrec == prec::Assignment) {
|
|
|
|
Diag(OpToken, diag::warn_cxx98_compat_generalized_initializer_lists)
|
2012-03-01 15:10:06 +08:00
|
|
|
<< Actions.getExprRange(RHS.get());
|
2012-03-01 10:59:17 +08:00
|
|
|
} else {
|
|
|
|
Diag(OpToken, diag::err_init_list_bin_op)
|
2012-03-01 15:10:06 +08:00
|
|
|
<< /*RHS*/1 << PP.getSpelling(OpToken)
|
|
|
|
<< Actions.getExprRange(RHS.get());
|
2012-03-01 10:59:17 +08:00
|
|
|
LHS = ExprError();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-09 21:15:23 +08:00
|
|
|
if (!LHS.isInvalid()) {
|
2007-08-31 13:01:50 +08:00
|
|
|
// Combine the LHS and RHS into the LHS (e.g. build AST).
|
Introduce code modification hints into the diagnostics system. When we
know how to recover from an error, we can attach a hint to the
diagnostic that states how to modify the code, which can be one of:
- Insert some new code (a text string) at a particular source
location
- Remove the code within a given range
- Replace the code within a given range with some new code (a text
string)
Right now, we use these hints to annotate diagnostic information. For
example, if one uses the '>>' in a template argument in C++98, as in
this code:
template<int I> class B { };
B<1000 >> 2> *b1;
we'll warn that the behavior will change in C++0x. The fix is to
insert parenthese, so we use code insertion annotations to illustrate
where the parentheses go:
test.cpp:10:10: warning: use of right-shift operator ('>>') in template
argument will require parentheses in C++0x
B<1000 >> 2> *b1;
^
( )
Use of these annotations is partially implemented for HTML
diagnostics, but it's not (yet) producing valid HTML, which may be
related to PR2386, so it has been #if 0'd out.
In this future, we could consider hooking this mechanism up to the
rewriter to actually try to fix these problems during compilation (or,
after a compilation whose only errors have fixes). For now, however, I
suggest that we use these code modification hints whenever we can, so
that we get better diagnostics now and will have better coverage when
we find better ways to use this information.
This also fixes PR3410 by placing the complaint about missing tokens
just after the previous token (rather than at the location of the next
token).
llvm-svn: 65570
2009-02-27 05:00:50 +08:00
|
|
|
if (TernaryMiddle.isInvalid()) {
|
|
|
|
// If we're using '>>' as an operator within a template
|
|
|
|
// argument list (in C++98), suggest the addition of
|
|
|
|
// parentheses so that the code remains well-formed in C++0x.
|
|
|
|
if (!GreaterThanIsOperator && OpToken.is(tok::greatergreater))
|
|
|
|
SuggestParentheses(OpToken.getLocation(),
|
2013-07-15 01:02:30 +08:00
|
|
|
diag::warn_cxx11_right_shift_in_template_arg,
|
Introduce code modification hints into the diagnostics system. When we
know how to recover from an error, we can attach a hint to the
diagnostic that states how to modify the code, which can be one of:
- Insert some new code (a text string) at a particular source
location
- Remove the code within a given range
- Replace the code within a given range with some new code (a text
string)
Right now, we use these hints to annotate diagnostic information. For
example, if one uses the '>>' in a template argument in C++98, as in
this code:
template<int I> class B { };
B<1000 >> 2> *b1;
we'll warn that the behavior will change in C++0x. The fix is to
insert parenthese, so we use code insertion annotations to illustrate
where the parentheses go:
test.cpp:10:10: warning: use of right-shift operator ('>>') in template
argument will require parentheses in C++0x
B<1000 >> 2> *b1;
^
( )
Use of these annotations is partially implemented for HTML
diagnostics, but it's not (yet) producing valid HTML, which may be
related to PR2386, so it has been #if 0'd out.
In this future, we could consider hooking this mechanism up to the
rewriter to actually try to fix these problems during compilation (or,
after a compilation whose only errors have fixes). For now, however, I
suggest that we use these code modification hints whenever we can, so
that we get better diagnostics now and will have better coverage when
we find better ways to use this information.
This also fixes PR3410 by placing the complaint about missing tokens
just after the previous token (rather than at the location of the next
token).
llvm-svn: 65570
2009-02-27 05:00:50 +08:00
|
|
|
SourceRange(Actions.getExprRange(LHS.get()).getBegin(),
|
|
|
|
Actions.getExprRange(RHS.get()).getEnd()));
|
|
|
|
|
2010-07-03 01:43:08 +08:00
|
|
|
LHS = Actions.ActOnBinOp(getCurScope(), OpToken.getLocation(),
|
2010-08-24 07:25:46 +08:00
|
|
|
OpToken.getKind(), LHS.take(), RHS.take());
|
Introduce code modification hints into the diagnostics system. When we
know how to recover from an error, we can attach a hint to the
diagnostic that states how to modify the code, which can be one of:
- Insert some new code (a text string) at a particular source
location
- Remove the code within a given range
- Replace the code within a given range with some new code (a text
string)
Right now, we use these hints to annotate diagnostic information. For
example, if one uses the '>>' in a template argument in C++98, as in
this code:
template<int I> class B { };
B<1000 >> 2> *b1;
we'll warn that the behavior will change in C++0x. The fix is to
insert parenthese, so we use code insertion annotations to illustrate
where the parentheses go:
test.cpp:10:10: warning: use of right-shift operator ('>>') in template
argument will require parentheses in C++0x
B<1000 >> 2> *b1;
^
( )
Use of these annotations is partially implemented for HTML
diagnostics, but it's not (yet) producing valid HTML, which may be
related to PR2386, so it has been #if 0'd out.
In this future, we could consider hooking this mechanism up to the
rewriter to actually try to fix these problems during compilation (or,
after a compilation whose only errors have fixes). For now, however, I
suggest that we use these code modification hints whenever we can, so
that we get better diagnostics now and will have better coverage when
we find better ways to use this information.
This also fixes PR3410 by placing the complaint about missing tokens
just after the previous token (rather than at the location of the next
token).
llvm-svn: 65570
2009-02-27 05:00:50 +08:00
|
|
|
} else
|
2007-09-16 11:34:24 +08:00
|
|
|
LHS = Actions.ActOnConditionalOp(OpToken.getLocation(), ColonLoc,
|
2010-08-24 07:25:46 +08:00
|
|
|
LHS.take(), TernaryMiddle.take(),
|
|
|
|
RHS.take());
|
2007-08-31 13:01:50 +08:00
|
|
|
}
|
2006-08-12 16:13:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-17 12:36:28 +08:00
|
|
|
/// \brief Parse a cast-expression, or, if \p isUnaryExpression is true,
|
|
|
|
/// parse a unary-expression.
|
|
|
|
///
|
|
|
|
/// \p isAddressOfOperand exists because an id-expression that is the
|
|
|
|
/// operand of address-of gets special treatment due to member pointers.
|
2006-08-11 10:02:23 +08:00
|
|
|
///
|
2010-08-24 14:29:42 +08:00
|
|
|
ExprResult Parser::ParseCastExpression(bool isUnaryExpression,
|
2011-04-24 13:37:28 +08:00
|
|
|
bool isAddressOfOperand,
|
2012-01-26 04:49:08 +08:00
|
|
|
TypeCastState isTypeCast) {
|
2009-05-22 18:24:42 +08:00
|
|
|
bool NotCastExpr;
|
2010-08-24 14:29:42 +08:00
|
|
|
ExprResult Res = ParseCastExpression(isUnaryExpression,
|
When we run into an error parsing or type-checking the left-hand side
of a binary expression, continue on and parse the right-hand side of
the binary expression anyway, but don't call the semantic actions to
type-check. Previously, we would see the error and then, effectively,
skip tokens until the end of the statement.
The result should be more useful recovery, both in the normal case
(we'll actually see errors beyond the first one in a statement), but
it also helps code completion do a much better job, because we do
"real" code completion on the right-hand side of an invalid binary
expression rather than completing with the recovery completion. For
example, given
x = p->y
if there is no variable named "x", we can still complete after the p->
as a member expression. Along the recovery path, we would have
completed after the "->" as if we were in an expression context, which
is mostly useless.
llvm-svn: 114225
2010-09-18 06:25:06 +08:00
|
|
|
isAddressOfOperand,
|
|
|
|
NotCastExpr,
|
2011-07-02 06:22:59 +08:00
|
|
|
isTypeCast);
|
2009-05-22 18:24:42 +08:00
|
|
|
if (NotCastExpr)
|
|
|
|
Diag(Tok, diag::err_expected_expression);
|
2012-08-24 05:35:17 +08:00
|
|
|
return Res;
|
2009-05-22 18:24:42 +08:00
|
|
|
}
|
|
|
|
|
2012-01-26 04:49:08 +08:00
|
|
|
namespace {
|
|
|
|
class CastExpressionIdValidator : public CorrectionCandidateCallback {
|
|
|
|
public:
|
|
|
|
CastExpressionIdValidator(bool AllowTypes, bool AllowNonTypes)
|
|
|
|
: AllowNonTypes(AllowNonTypes) {
|
|
|
|
WantTypeSpecifiers = AllowTypes;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool ValidateCandidate(const TypoCorrection &candidate) {
|
|
|
|
NamedDecl *ND = candidate.getCorrectionDecl();
|
|
|
|
if (!ND)
|
|
|
|
return candidate.isKeyword();
|
|
|
|
|
|
|
|
if (isa<TypeDecl>(ND))
|
|
|
|
return WantTypeSpecifiers;
|
|
|
|
return AllowNonTypes;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool AllowNonTypes;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2012-06-17 12:36:28 +08:00
|
|
|
/// \brief Parse a cast-expression, or, if \pisUnaryExpression is true, parse
|
|
|
|
/// a unary-expression.
|
2009-05-22 18:24:42 +08:00
|
|
|
///
|
2012-06-17 12:36:28 +08:00
|
|
|
/// \p isAddressOfOperand exists because an id-expression that is the operand
|
|
|
|
/// of address-of gets special treatment due to member pointers. NotCastExpr
|
|
|
|
/// is set to true if the token is not the start of a cast-expression, and no
|
|
|
|
/// diagnostic is emitted in this case.
|
|
|
|
///
|
|
|
|
/// \verbatim
|
2006-08-11 07:14:52 +08:00
|
|
|
/// cast-expression: [C99 6.5.4]
|
|
|
|
/// unary-expression
|
|
|
|
/// '(' type-name ')' cast-expression
|
2006-08-11 10:13:20 +08:00
|
|
|
///
|
2006-08-11 06:57:16 +08:00
|
|
|
/// unary-expression: [C99 6.5.3]
|
|
|
|
/// postfix-expression
|
|
|
|
/// '++' unary-expression
|
|
|
|
/// '--' unary-expression
|
|
|
|
/// unary-operator cast-expression
|
|
|
|
/// 'sizeof' unary-expression
|
|
|
|
/// 'sizeof' '(' type-name ')'
|
2012-03-06 11:21:47 +08:00
|
|
|
/// [C++11] 'sizeof' '...' '(' identifier ')'
|
2006-08-11 06:57:16 +08:00
|
|
|
/// [GNU] '__alignof' unary-expression
|
|
|
|
/// [GNU] '__alignof' '(' type-name ')'
|
2012-07-01 05:33:57 +08:00
|
|
|
/// [C11] '_Alignof' '(' type-name ')'
|
2012-03-06 11:21:47 +08:00
|
|
|
/// [C++11] 'alignof' '(' type-id ')'
|
2006-08-11 06:57:16 +08:00
|
|
|
/// [GNU] '&&' identifier
|
2012-03-06 11:21:47 +08:00
|
|
|
/// [C++11] 'noexcept' '(' expression ')' [C++11 5.3.7]
|
2008-11-22 03:14:01 +08:00
|
|
|
/// [C++] new-expression
|
|
|
|
/// [C++] delete-expression
|
2006-08-11 10:13:20 +08:00
|
|
|
///
|
2006-08-11 06:57:16 +08:00
|
|
|
/// unary-operator: one of
|
|
|
|
/// '&' '*' '+' '-' '~' '!'
|
|
|
|
/// [GNU] '__extension__' '__real' '__imag'
|
|
|
|
///
|
2006-08-11 04:56:00 +08:00
|
|
|
/// primary-expression: [C99 6.5.1]
|
2008-11-07 06:13:31 +08:00
|
|
|
/// [C99] identifier
|
2008-11-11 19:37:55 +08:00
|
|
|
/// [C++] id-expression
|
2006-08-11 03:06:03 +08:00
|
|
|
/// constant
|
|
|
|
/// string-literal
|
2007-02-13 09:51:42 +08:00
|
|
|
/// [C++] boolean-literal [C++ 2.13.5]
|
2012-03-06 11:21:47 +08:00
|
|
|
/// [C++11] 'nullptr' [C++11 2.14.7]
|
|
|
|
/// [C++11] user-defined-literal
|
2006-08-11 03:06:03 +08:00
|
|
|
/// '(' expression ')'
|
2011-12-24 01:00:35 +08:00
|
|
|
/// [C11] generic-selection
|
2006-08-11 04:56:00 +08:00
|
|
|
/// '__func__' [C99 6.4.2.2]
|
|
|
|
/// [GNU] '__FUNCTION__'
|
|
|
|
/// [GNU] '__PRETTY_FUNCTION__'
|
|
|
|
/// [GNU] '(' compound-statement ')'
|
|
|
|
/// [GNU] '__builtin_va_arg' '(' assignment-expression ',' type-name ')'
|
|
|
|
/// [GNU] '__builtin_offsetof' '(' type-name ',' offsetof-member-designator')'
|
|
|
|
/// [GNU] '__builtin_choose_expr' '(' assign-expr ',' assign-expr ','
|
|
|
|
/// assign-expr ')'
|
|
|
|
/// [GNU] '__builtin_types_compatible_p' '(' type-name ',' type-name ')'
|
2008-11-29 12:51:27 +08:00
|
|
|
/// [GNU] '__null'
|
2009-09-09 23:08:12 +08:00
|
|
|
/// [OBJC] '[' objc-message-expr ']'
|
2012-06-15 14:52:33 +08:00
|
|
|
/// [OBJC] '\@selector' '(' objc-selector-arg ')'
|
|
|
|
/// [OBJC] '\@protocol' '(' identifier ')'
|
|
|
|
/// [OBJC] '\@encode' '(' type-name ')'
|
2007-09-06 03:52:07 +08:00
|
|
|
/// [OBJC] objc-string-literal
|
2008-08-22 23:38:55 +08:00
|
|
|
/// [C++] simple-type-specifier '(' expression-list[opt] ')' [C++ 5.2.3]
|
2012-03-06 11:21:47 +08:00
|
|
|
/// [C++11] simple-type-specifier braced-init-list [C++11 5.2.3]
|
Rework the Parser-Sema interaction for Objective-C message
sends. Major changes include:
- Expanded the interface from two actions (ActOnInstanceMessage,
ActOnClassMessage), where ActOnClassMessage also handled sends to
"super" by checking whether the identifier was "super", to three
actions (ActOnInstanceMessage, ActOnClassMessage,
ActOnSuperMessage). Code completion has the same changes.
- The parser now resolves the type to which we are sending a class
message, so ActOnClassMessage now accepts a TypeTy* (rather than
an IdentifierInfo *). This opens the door to more interesting
types (for Objective-C++ support).
- Split ActOnInstanceMessage and ActOnClassMessage into parser
action functions (with their original names) and semantic
functions (BuildInstanceMessage and BuildClassMessage,
respectively). At present, this split is onyl used by
ActOnSuperMessage, which decides which kind of super message it
has and forwards to the appropriate Build*Message. In the future,
Build*Message will be used by template instantiation.
- Use getObjCMessageKind() within the disambiguation of Objective-C
message sends vs. array designators.
Two notes about substandard bits in this patch:
- There is some redundancy in the code in ParseObjCMessageExpr and
ParseInitializerWithPotentialDesignator; this will be addressed
shortly by centralizing the mapping from identifiers to type names
for the message receiver.
- There is some #if 0'd code that won't likely ever be used---it
handles the use of 'super' in methods whose class does not have a
superclass---but could be used to model GCC's behavior more
closely. This code will die in my next check-in, but I want it in
Subversion.
llvm-svn: 102021
2010-04-22 03:57:20 +08:00
|
|
|
/// [C++] typename-specifier '(' expression-list[opt] ')' [C++ 5.2.3]
|
2012-03-06 11:21:47 +08:00
|
|
|
/// [C++11] typename-specifier braced-init-list [C++11 5.2.3]
|
2007-06-30 02:21:34 +08:00
|
|
|
/// [C++] 'const_cast' '<' type-name '>' '(' expression ')' [C++ 5.2p1]
|
|
|
|
/// [C++] 'dynamic_cast' '<' type-name '>' '(' expression ')' [C++ 5.2p1]
|
|
|
|
/// [C++] 'reinterpret_cast' '<' type-name '>' '(' expression ')' [C++ 5.2p1]
|
|
|
|
/// [C++] 'static_cast' '<' type-name '>' '(' expression ')' [C++ 5.2p1]
|
2008-11-11 19:37:55 +08:00
|
|
|
/// [C++] 'typeid' '(' expression ')' [C++ 5.2p1]
|
|
|
|
/// [C++] 'typeid' '(' type-id ')' [C++ 5.2p1]
|
2008-07-16 15:23:27 +08:00
|
|
|
/// [C++] 'this' [C++ 9.3.2]
|
2009-01-06 04:52:13 +08:00
|
|
|
/// [G++] unary-type-trait '(' type-id ')'
|
|
|
|
/// [G++] binary-type-trait '(' type-id ',' type-id ')' [TODO]
|
2011-04-28 08:16:57 +08:00
|
|
|
/// [EMBT] array-type-trait '(' type-id ',' integer ')'
|
2008-08-29 03:20:44 +08:00
|
|
|
/// [clang] '^' block-literal
|
2006-08-11 04:56:00 +08:00
|
|
|
///
|
|
|
|
/// constant: [C99 6.4.4]
|
|
|
|
/// integer-constant
|
|
|
|
/// floating-constant
|
|
|
|
/// enumeration-constant -> identifier
|
|
|
|
/// character-constant
|
|
|
|
///
|
2008-11-07 06:13:31 +08:00
|
|
|
/// id-expression: [C++ 5.1]
|
|
|
|
/// unqualified-id
|
Rework the Parser-Sema interaction for Objective-C message
sends. Major changes include:
- Expanded the interface from two actions (ActOnInstanceMessage,
ActOnClassMessage), where ActOnClassMessage also handled sends to
"super" by checking whether the identifier was "super", to three
actions (ActOnInstanceMessage, ActOnClassMessage,
ActOnSuperMessage). Code completion has the same changes.
- The parser now resolves the type to which we are sending a class
message, so ActOnClassMessage now accepts a TypeTy* (rather than
an IdentifierInfo *). This opens the door to more interesting
types (for Objective-C++ support).
- Split ActOnInstanceMessage and ActOnClassMessage into parser
action functions (with their original names) and semantic
functions (BuildInstanceMessage and BuildClassMessage,
respectively). At present, this split is onyl used by
ActOnSuperMessage, which decides which kind of super message it
has and forwards to the appropriate Build*Message. In the future,
Build*Message will be used by template instantiation.
- Use getObjCMessageKind() within the disambiguation of Objective-C
message sends vs. array designators.
Two notes about substandard bits in this patch:
- There is some redundancy in the code in ParseObjCMessageExpr and
ParseInitializerWithPotentialDesignator; this will be addressed
shortly by centralizing the mapping from identifiers to type names
for the message receiver.
- There is some #if 0'd code that won't likely ever be used---it
handles the use of 'super' in methods whose class does not have a
superclass---but could be used to model GCC's behavior more
closely. This code will die in my next check-in, but I want it in
Subversion.
llvm-svn: 102021
2010-04-22 03:57:20 +08:00
|
|
|
/// qualified-id
|
2008-11-07 06:13:31 +08:00
|
|
|
///
|
|
|
|
/// unqualified-id: [C++ 5.1]
|
|
|
|
/// identifier
|
|
|
|
/// operator-function-id
|
Rework the Parser-Sema interaction for Objective-C message
sends. Major changes include:
- Expanded the interface from two actions (ActOnInstanceMessage,
ActOnClassMessage), where ActOnClassMessage also handled sends to
"super" by checking whether the identifier was "super", to three
actions (ActOnInstanceMessage, ActOnClassMessage,
ActOnSuperMessage). Code completion has the same changes.
- The parser now resolves the type to which we are sending a class
message, so ActOnClassMessage now accepts a TypeTy* (rather than
an IdentifierInfo *). This opens the door to more interesting
types (for Objective-C++ support).
- Split ActOnInstanceMessage and ActOnClassMessage into parser
action functions (with their original names) and semantic
functions (BuildInstanceMessage and BuildClassMessage,
respectively). At present, this split is onyl used by
ActOnSuperMessage, which decides which kind of super message it
has and forwards to the appropriate Build*Message. In the future,
Build*Message will be used by template instantiation.
- Use getObjCMessageKind() within the disambiguation of Objective-C
message sends vs. array designators.
Two notes about substandard bits in this patch:
- There is some redundancy in the code in ParseObjCMessageExpr and
ParseInitializerWithPotentialDesignator; this will be addressed
shortly by centralizing the mapping from identifiers to type names
for the message receiver.
- There is some #if 0'd code that won't likely ever be used---it
handles the use of 'super' in methods whose class does not have a
superclass---but could be used to model GCC's behavior more
closely. This code will die in my next check-in, but I want it in
Subversion.
llvm-svn: 102021
2010-04-22 03:57:20 +08:00
|
|
|
/// conversion-function-id
|
|
|
|
/// '~' class-name
|
|
|
|
/// template-id
|
2008-11-09 00:45:02 +08:00
|
|
|
///
|
2008-11-22 03:14:01 +08:00
|
|
|
/// new-expression: [C++ 5.3.4]
|
|
|
|
/// '::'[opt] 'new' new-placement[opt] new-type-id
|
|
|
|
/// new-initializer[opt]
|
|
|
|
/// '::'[opt] 'new' new-placement[opt] '(' type-id ')'
|
|
|
|
/// new-initializer[opt]
|
|
|
|
///
|
|
|
|
/// delete-expression: [C++ 5.3.5]
|
|
|
|
/// '::'[opt] 'delete' cast-expression
|
|
|
|
/// '::'[opt] 'delete' '[' ']' cast-expression
|
|
|
|
///
|
2011-04-28 07:09:49 +08:00
|
|
|
/// [GNU/Embarcadero] unary-type-trait:
|
|
|
|
/// '__is_arithmetic'
|
|
|
|
/// '__is_floating_point'
|
|
|
|
/// '__is_integral'
|
|
|
|
/// '__is_lvalue_expr'
|
|
|
|
/// '__is_rvalue_expr'
|
|
|
|
/// '__is_complete_type'
|
|
|
|
/// '__is_void'
|
|
|
|
/// '__is_array'
|
|
|
|
/// '__is_function'
|
|
|
|
/// '__is_reference'
|
|
|
|
/// '__is_lvalue_reference'
|
|
|
|
/// '__is_rvalue_reference'
|
|
|
|
/// '__is_fundamental'
|
|
|
|
/// '__is_object'
|
|
|
|
/// '__is_scalar'
|
|
|
|
/// '__is_compound'
|
|
|
|
/// '__is_pointer'
|
|
|
|
/// '__is_member_object_pointer'
|
|
|
|
/// '__is_member_function_pointer'
|
|
|
|
/// '__is_member_pointer'
|
|
|
|
/// '__is_const'
|
|
|
|
/// '__is_volatile'
|
|
|
|
/// '__is_trivial'
|
|
|
|
/// '__is_standard_layout'
|
|
|
|
/// '__is_signed'
|
|
|
|
/// '__is_unsigned'
|
|
|
|
///
|
2009-01-06 04:52:13 +08:00
|
|
|
/// [GNU] unary-type-trait:
|
2010-08-31 12:59:00 +08:00
|
|
|
/// '__has_nothrow_assign'
|
|
|
|
/// '__has_nothrow_copy'
|
|
|
|
/// '__has_nothrow_constructor'
|
2009-01-06 04:52:13 +08:00
|
|
|
/// '__has_trivial_assign' [TODO]
|
|
|
|
/// '__has_trivial_copy' [TODO]
|
2009-04-16 08:08:20 +08:00
|
|
|
/// '__has_trivial_constructor'
|
2009-04-17 10:34:54 +08:00
|
|
|
/// '__has_trivial_destructor'
|
2010-09-03 07:19:42 +08:00
|
|
|
/// '__has_virtual_destructor'
|
2009-01-06 04:52:13 +08:00
|
|
|
/// '__is_abstract' [TODO]
|
|
|
|
/// '__is_class'
|
|
|
|
/// '__is_empty' [TODO]
|
|
|
|
/// '__is_enum'
|
2011-12-04 02:14:24 +08:00
|
|
|
/// '__is_final'
|
2009-01-06 04:52:13 +08:00
|
|
|
/// '__is_pod'
|
|
|
|
/// '__is_polymorphic'
|
2011-04-23 18:47:28 +08:00
|
|
|
/// '__is_trivial'
|
2009-01-06 04:52:13 +08:00
|
|
|
/// '__is_union'
|
|
|
|
///
|
2011-05-13 08:31:07 +08:00
|
|
|
/// [Clang] unary-type-trait:
|
|
|
|
/// '__trivially_copyable'
|
|
|
|
///
|
2011-01-28 04:28:01 +08:00
|
|
|
/// binary-type-trait:
|
|
|
|
/// [GNU] '__is_base_of'
|
|
|
|
/// [MS] '__is_convertible_to'
|
2011-04-28 07:09:49 +08:00
|
|
|
/// '__is_convertible'
|
|
|
|
/// '__is_same'
|
2009-01-06 04:52:13 +08:00
|
|
|
///
|
2011-04-28 08:16:57 +08:00
|
|
|
/// [Embarcadero] array-type-trait:
|
|
|
|
/// '__array_rank'
|
|
|
|
/// '__array_extent'
|
|
|
|
///
|
2011-04-25 14:54:41 +08:00
|
|
|
/// [Embarcadero] expression-trait:
|
|
|
|
/// '__is_lvalue_expr'
|
|
|
|
/// '__is_rvalue_expr'
|
2012-06-17 12:36:28 +08:00
|
|
|
/// \endverbatim
|
2011-04-25 14:54:41 +08:00
|
|
|
///
|
2010-08-24 14:29:42 +08:00
|
|
|
ExprResult Parser::ParseCastExpression(bool isUnaryExpression,
|
2010-09-11 04:55:37 +08:00
|
|
|
bool isAddressOfOperand,
|
|
|
|
bool &NotCastExpr,
|
2012-01-26 04:49:08 +08:00
|
|
|
TypeCastState isTypeCast) {
|
2010-08-24 14:29:42 +08:00
|
|
|
ExprResult Res;
|
2006-10-25 11:38:23 +08:00
|
|
|
tok::TokenKind SavedKind = Tok.getKind();
|
2009-05-22 18:24:42 +08:00
|
|
|
NotCastExpr = false;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2006-08-11 10:13:20 +08:00
|
|
|
// This handles all of cast-expression, unary-expression, postfix-expression,
|
|
|
|
// and primary-expression. We handle them together like this for efficiency
|
|
|
|
// and to simplify handling of an expression starting with a '(' token: which
|
|
|
|
// may be one of a parenthesized expression, cast-expression, compound literal
|
|
|
|
// expression, or statement expression.
|
|
|
|
//
|
|
|
|
// If the parsed tokens consist of a primary-expression, the cases below
|
2010-08-24 07:25:46 +08:00
|
|
|
// break out of the switch; at the end we call ParsePostfixExpressionSuffix
|
|
|
|
// to handle the postfix expression suffixes. Cases that cannot be followed
|
|
|
|
// by postfix exprs should return without invoking
|
|
|
|
// ParsePostfixExpressionSuffix.
|
2006-10-25 11:49:28 +08:00
|
|
|
switch (SavedKind) {
|
2006-08-24 14:37:51 +08:00
|
|
|
case tok::l_paren: {
|
2006-08-11 10:13:20 +08:00
|
|
|
// If this expression is limited to being a unary-expression, the parent can
|
|
|
|
// not start a cast expression.
|
|
|
|
ParenParseOption ParenExprType =
|
2012-03-11 15:00:24 +08:00
|
|
|
(isUnaryExpression && !getLangOpts().CPlusPlus)? CompoundLiteral : CastExpr;
|
2010-08-24 13:47:05 +08:00
|
|
|
ParsedType CastTy;
|
2006-08-24 14:37:51 +08:00
|
|
|
SourceLocation RParenLoc;
|
2009-12-10 10:08:07 +08:00
|
|
|
|
|
|
|
{
|
2010-09-15 22:51:05 +08:00
|
|
|
// The inside of the parens don't need to be a colon protected scope, and
|
|
|
|
// isn't immediately a message send.
|
2009-12-10 10:08:07 +08:00
|
|
|
ColonProtectionRAIIObject X(*this, false);
|
2010-09-15 22:51:05 +08:00
|
|
|
|
2009-12-10 10:08:07 +08:00
|
|
|
Res = ParseParenExpression(ParenExprType, false/*stopIfCastExr*/,
|
2012-01-26 04:49:08 +08:00
|
|
|
isTypeCast == IsTypeCast, CastTy, RParenLoc);
|
2009-12-10 10:08:07 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2006-08-11 10:13:20 +08:00
|
|
|
switch (ParenExprType) {
|
|
|
|
case SimpleExpr: break; // Nothing else to do.
|
|
|
|
case CompoundStmt: break; // Nothing else to do.
|
|
|
|
case CompoundLiteral:
|
|
|
|
// We parsed '(' type-name ')' '{' ... '}'. If any suffixes of
|
|
|
|
// postfix-expression exist, parse them now.
|
|
|
|
break;
|
|
|
|
case CastExpr:
|
2009-05-22 18:23:40 +08:00
|
|
|
// We have parsed the cast-expression and no postfix-expr pieces are
|
|
|
|
// following.
|
2012-08-24 05:35:17 +08:00
|
|
|
return Res;
|
2006-08-11 10:13:20 +08:00
|
|
|
}
|
2008-12-09 21:15:23 +08:00
|
|
|
|
2010-08-24 07:25:46 +08:00
|
|
|
break;
|
2006-08-24 14:37:51 +08:00
|
|
|
}
|
2008-12-09 21:15:23 +08:00
|
|
|
|
2006-08-11 04:56:00 +08:00
|
|
|
// primary-expression
|
2006-08-23 13:17:46 +08:00
|
|
|
case tok::numeric_constant:
|
|
|
|
// constant: integer-constant
|
|
|
|
// constant: floating-constant
|
2008-12-12 05:36:32 +08:00
|
|
|
|
2012-03-09 16:00:36 +08:00
|
|
|
Res = Actions.ActOnNumericConstant(Tok, /*UDLScope*/getCurScope());
|
2006-08-23 13:17:46 +08:00
|
|
|
ConsumeToken();
|
2010-08-24 07:25:46 +08:00
|
|
|
break;
|
2006-08-23 13:17:46 +08:00
|
|
|
|
2007-02-13 09:51:42 +08:00
|
|
|
case tok::kw_true:
|
|
|
|
case tok::kw_false:
|
2008-12-12 06:51:44 +08:00
|
|
|
return ParseCXXBoolLiteral();
|
2012-03-07 04:05:56 +08:00
|
|
|
|
|
|
|
case tok::kw___objc_yes:
|
|
|
|
case tok::kw___objc_no:
|
|
|
|
return ParseObjCBoolLiteral();
|
2007-02-13 09:51:42 +08:00
|
|
|
|
2009-05-11 02:38:11 +08:00
|
|
|
case tok::kw_nullptr:
|
2011-10-18 07:06:20 +08:00
|
|
|
Diag(Tok, diag::warn_cxx98_compat_nullptr);
|
2009-05-11 02:38:11 +08:00
|
|
|
return Actions.ActOnCXXNullPtrLiteral(ConsumeToken());
|
|
|
|
|
2011-04-27 14:18:01 +08:00
|
|
|
case tok::annot_primary_expr:
|
|
|
|
assert(Res.get() == 0 && "Stray primary-expression annotation?");
|
|
|
|
Res = getExprAnnotation(Tok);
|
|
|
|
ConsumeToken();
|
|
|
|
break;
|
2013-04-27 00:15:35 +08:00
|
|
|
|
2011-12-04 13:04:18 +08:00
|
|
|
case tok::kw_decltype:
|
2013-04-27 00:15:35 +08:00
|
|
|
// Annotate the token and tail recurse.
|
|
|
|
if (TryAnnotateTypeOrScopeToken())
|
|
|
|
return ExprError();
|
|
|
|
assert(Tok.isNot(tok::kw_decltype));
|
|
|
|
return ParseCastExpression(isUnaryExpression, isAddressOfOperand);
|
|
|
|
|
2008-11-09 00:45:02 +08:00
|
|
|
case tok::identifier: { // primary-expression: identifier
|
|
|
|
// unqualified-id: identifier
|
|
|
|
// constant: enumeration-constant
|
2009-01-06 13:06:21 +08:00
|
|
|
// Turn a potentially qualified name into a annot_typename or
|
2009-01-05 06:52:14 +08:00
|
|
|
// annot_cxxscope if it would be valid. This handles things like x::y, etc.
|
2012-03-11 15:00:24 +08:00
|
|
|
if (getLangOpts().CPlusPlus) {
|
2010-01-08 03:29:58 +08:00
|
|
|
// Avoid the unnecessary parse-time lookup in the common case
|
|
|
|
// where the syntax forbids a type.
|
|
|
|
const Token &Next = NextToken();
|
2012-08-31 04:04:43 +08:00
|
|
|
|
|
|
|
// If this identifier was reverted from a token ID, and the next token
|
|
|
|
// is a parenthesis, this is likely to be a use of a type trait. Check
|
|
|
|
// those tokens.
|
|
|
|
if (Next.is(tok::l_paren) &&
|
|
|
|
Tok.is(tok::identifier) &&
|
|
|
|
Tok.getIdentifierInfo()->hasRevertedTokenIDToIdentifier()) {
|
|
|
|
IdentifierInfo *II = Tok.getIdentifierInfo();
|
|
|
|
// Build up the mapping of revertable type traits, for future use.
|
|
|
|
if (RevertableTypeTraits.empty()) {
|
|
|
|
#define RTT_JOIN(X,Y) X##Y
|
|
|
|
#define REVERTABLE_TYPE_TRAIT(Name) \
|
|
|
|
RevertableTypeTraits[PP.getIdentifierInfo(#Name)] \
|
|
|
|
= RTT_JOIN(tok::kw_,Name)
|
|
|
|
|
|
|
|
REVERTABLE_TYPE_TRAIT(__is_arithmetic);
|
|
|
|
REVERTABLE_TYPE_TRAIT(__is_convertible);
|
|
|
|
REVERTABLE_TYPE_TRAIT(__is_empty);
|
|
|
|
REVERTABLE_TYPE_TRAIT(__is_floating_point);
|
|
|
|
REVERTABLE_TYPE_TRAIT(__is_function);
|
|
|
|
REVERTABLE_TYPE_TRAIT(__is_fundamental);
|
|
|
|
REVERTABLE_TYPE_TRAIT(__is_integral);
|
|
|
|
REVERTABLE_TYPE_TRAIT(__is_member_function_pointer);
|
|
|
|
REVERTABLE_TYPE_TRAIT(__is_member_pointer);
|
|
|
|
REVERTABLE_TYPE_TRAIT(__is_pod);
|
|
|
|
REVERTABLE_TYPE_TRAIT(__is_pointer);
|
|
|
|
REVERTABLE_TYPE_TRAIT(__is_same);
|
|
|
|
REVERTABLE_TYPE_TRAIT(__is_scalar);
|
|
|
|
REVERTABLE_TYPE_TRAIT(__is_signed);
|
|
|
|
REVERTABLE_TYPE_TRAIT(__is_unsigned);
|
|
|
|
REVERTABLE_TYPE_TRAIT(__is_void);
|
|
|
|
#undef REVERTABLE_TYPE_TRAIT
|
|
|
|
#undef RTT_JOIN
|
2013-08-12 10:53:18 +08:00
|
|
|
}
|
2012-08-31 04:04:43 +08:00
|
|
|
|
2013-08-12 10:53:18 +08:00
|
|
|
// If we find that this is in fact the name of a type trait,
|
|
|
|
// update the token kind in place and parse again to treat it as
|
|
|
|
// the appropriate kind of type trait.
|
|
|
|
llvm::SmallDenseMap<IdentifierInfo *, tok::TokenKind>::iterator Known
|
|
|
|
= RevertableTypeTraits.find(II);
|
|
|
|
if (Known != RevertableTypeTraits.end()) {
|
|
|
|
Tok.setKind(Known->second);
|
|
|
|
return ParseCastExpression(isUnaryExpression, isAddressOfOperand,
|
|
|
|
NotCastExpr, isTypeCast);
|
2012-08-31 04:04:43 +08:00
|
|
|
}
|
2013-08-12 10:53:18 +08:00
|
|
|
}
|
2012-08-31 04:04:43 +08:00
|
|
|
|
2010-01-08 03:29:58 +08:00
|
|
|
if (Next.is(tok::coloncolon) ||
|
|
|
|
(!ColonIsSacred && Next.is(tok::colon)) ||
|
|
|
|
Next.is(tok::less) ||
|
2011-12-23 02:58:29 +08:00
|
|
|
Next.is(tok::l_paren) ||
|
|
|
|
Next.is(tok::l_brace)) {
|
2010-01-08 03:29:58 +08:00
|
|
|
// If TryAnnotateTypeOrScopeToken annotates the token, tail recurse.
|
|
|
|
if (TryAnnotateTypeOrScopeToken())
|
2010-02-26 16:45:28 +08:00
|
|
|
return ExprError();
|
|
|
|
if (!Tok.is(tok::identifier))
|
2010-01-08 03:29:58 +08:00
|
|
|
return ParseCastExpression(isUnaryExpression, isAddressOfOperand);
|
|
|
|
}
|
2009-01-05 07:23:14 +08:00
|
|
|
}
|
2008-08-22 23:38:55 +08:00
|
|
|
|
2009-10-26 01:04:48 +08:00
|
|
|
// Consume the identifier so that we can see if it is followed by a '(' or
|
|
|
|
// '.'.
|
|
|
|
IdentifierInfo &II = *Tok.getIdentifierInfo();
|
|
|
|
SourceLocation ILoc = ConsumeToken();
|
2012-08-31 04:04:43 +08:00
|
|
|
|
2010-04-11 16:28:14 +08:00
|
|
|
// Support 'Class.property' and 'super.property' notation.
|
2012-03-11 15:00:24 +08:00
|
|
|
if (getLangOpts().ObjC1 && Tok.is(tok::period) &&
|
2010-07-03 01:43:08 +08:00
|
|
|
(Actions.getTypeName(II, ILoc, getCurScope()) ||
|
2010-04-12 14:20:33 +08:00
|
|
|
// Allow the base to be 'super' if in an objc-method.
|
2010-07-03 01:43:08 +08:00
|
|
|
(&II == Ident_super && getCurScope()->isInObjcMethodScope()))) {
|
2011-01-18 10:00:16 +08:00
|
|
|
ConsumeToken();
|
2009-10-26 01:04:48 +08:00
|
|
|
|
2012-02-17 02:19:22 +08:00
|
|
|
// Allow either an identifier or the keyword 'class' (in C++).
|
|
|
|
if (Tok.isNot(tok::identifier) &&
|
2012-03-11 15:00:24 +08:00
|
|
|
!(getLangOpts().CPlusPlus && Tok.is(tok::kw_class))) {
|
2009-10-26 01:04:48 +08:00
|
|
|
Diag(Tok, diag::err_expected_property_name);
|
2009-03-10 05:12:44 +08:00
|
|
|
return ExprError();
|
|
|
|
}
|
|
|
|
IdentifierInfo &PropertyName = *Tok.getIdentifierInfo();
|
|
|
|
SourceLocation PropertyLoc = ConsumeToken();
|
2009-10-26 01:04:48 +08:00
|
|
|
|
|
|
|
Res = Actions.ActOnClassPropertyRefExpr(II, PropertyName,
|
|
|
|
ILoc, PropertyLoc);
|
2010-08-24 07:25:46 +08:00
|
|
|
break;
|
2009-03-10 05:12:44 +08:00
|
|
|
}
|
2010-08-27 17:08:28 +08:00
|
|
|
|
2010-09-15 23:09:43 +08:00
|
|
|
// In an Objective-C method, if we have "super" followed by an identifier,
|
2010-09-16 00:23:04 +08:00
|
|
|
// the token sequence is ill-formed. However, if there's a ':' or ']' after
|
2010-09-15 23:09:43 +08:00
|
|
|
// that identifier, this is probably a message send with a missing open
|
2010-09-16 00:23:04 +08:00
|
|
|
// bracket. Treat it as such.
|
2012-03-11 15:00:24 +08:00
|
|
|
if (getLangOpts().ObjC1 && &II == Ident_super && !InMessageExpression &&
|
2010-09-15 23:09:43 +08:00
|
|
|
getCurScope()->isInObjcMethodScope() &&
|
2010-09-16 00:23:04 +08:00
|
|
|
((Tok.is(tok::identifier) &&
|
|
|
|
(NextToken().is(tok::colon) || NextToken().is(tok::r_square))) ||
|
|
|
|
Tok.is(tok::code_completion))) {
|
2010-09-15 23:09:43 +08:00
|
|
|
Res = ParseObjCMessageExpressionBody(SourceLocation(), ILoc, ParsedType(),
|
|
|
|
0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-02-16 03:17:31 +08:00
|
|
|
// If we have an Objective-C class name followed by an identifier
|
|
|
|
// and either ':' or ']', this is an Objective-C class message
|
|
|
|
// send that's missing the opening '['. Recovery
|
|
|
|
// appropriately. Also take this path if we're performing code
|
|
|
|
// completion after an Objective-C class name.
|
2012-03-11 15:00:24 +08:00
|
|
|
if (getLangOpts().ObjC1 &&
|
2011-02-16 03:17:31 +08:00
|
|
|
((Tok.is(tok::identifier) && !InMessageExpression) ||
|
|
|
|
Tok.is(tok::code_completion))) {
|
2010-09-16 09:51:54 +08:00
|
|
|
const Token& Next = NextToken();
|
2011-02-16 03:17:31 +08:00
|
|
|
if (Tok.is(tok::code_completion) ||
|
|
|
|
Next.is(tok::colon) || Next.is(tok::r_square))
|
2010-09-17 18:21:45 +08:00
|
|
|
if (ParsedType Typ = Actions.getTypeName(II, ILoc, getCurScope()))
|
|
|
|
if (Typ.get()->isObjCObjectOrInterfaceType()) {
|
2010-09-16 09:51:54 +08:00
|
|
|
// Fake up a Declarator to use with ActOnTypeName.
|
2011-03-24 19:26:52 +08:00
|
|
|
DeclSpec DS(AttrFactory);
|
2010-09-16 09:51:54 +08:00
|
|
|
DS.SetRangeStart(ILoc);
|
|
|
|
DS.SetRangeEnd(ILoc);
|
|
|
|
const char *PrevSpec = 0;
|
|
|
|
unsigned DiagID;
|
2010-09-17 18:21:45 +08:00
|
|
|
DS.SetTypeSpecType(TST_typename, ILoc, PrevSpec, DiagID, Typ);
|
2010-09-16 09:51:54 +08:00
|
|
|
|
|
|
|
Declarator DeclaratorInfo(DS, Declarator::TypeNameContext);
|
|
|
|
TypeResult Ty = Actions.ActOnTypeName(getCurScope(),
|
|
|
|
DeclaratorInfo);
|
|
|
|
if (Ty.isInvalid())
|
|
|
|
break;
|
|
|
|
|
|
|
|
Res = ParseObjCMessageExpressionBody(SourceLocation(),
|
|
|
|
SourceLocation(),
|
|
|
|
Ty.get(), 0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-27 17:08:28 +08:00
|
|
|
// Make sure to pass down the right value for isAddressOfOperand.
|
|
|
|
if (isAddressOfOperand && isPostfixExpressionSuffixStart())
|
|
|
|
isAddressOfOperand = false;
|
2009-10-26 01:04:48 +08:00
|
|
|
|
2006-11-20 14:49:47 +08:00
|
|
|
// Function designators are allowed to be undeclared (C99 6.5.1p2), so we
|
|
|
|
// need to know whether or not this identifier is a function designator or
|
|
|
|
// not.
|
2009-11-04 00:56:39 +08:00
|
|
|
UnqualifiedId Name;
|
|
|
|
CXXScopeSpec ScopeSpec;
|
2012-01-27 17:46:47 +08:00
|
|
|
SourceLocation TemplateKWLoc;
|
2012-01-26 04:49:08 +08:00
|
|
|
CastExpressionIdValidator Validator(isTypeCast != NotTypeCast,
|
|
|
|
isTypeCast != IsTypeCast);
|
2009-11-04 00:56:39 +08:00
|
|
|
Name.setIdentifier(&II, ILoc);
|
2012-01-27 17:46:47 +08:00
|
|
|
Res = Actions.ActOnIdExpression(getCurScope(), ScopeSpec, TemplateKWLoc,
|
|
|
|
Name, Tok.is(tok::l_paren),
|
|
|
|
isAddressOfOperand, &Validator);
|
2010-08-24 07:25:46 +08:00
|
|
|
break;
|
2006-11-20 14:49:47 +08:00
|
|
|
}
|
2006-08-11 04:56:00 +08:00
|
|
|
case tok::char_constant: // constant: character-constant
|
2011-07-27 13:40:30 +08:00
|
|
|
case tok::wide_char_constant:
|
|
|
|
case tok::utf16_char_constant:
|
|
|
|
case tok::utf32_char_constant:
|
2012-03-09 16:00:36 +08:00
|
|
|
Res = Actions.ActOnCharacterConstant(Tok, /*UDLScope*/getCurScope());
|
2007-04-27 04:39:23 +08:00
|
|
|
ConsumeToken();
|
2010-08-24 07:25:46 +08:00
|
|
|
break;
|
2006-08-11 04:56:00 +08:00
|
|
|
case tok::kw___func__: // primary-expression: __func__ [C99 6.4.2.2]
|
|
|
|
case tok::kw___FUNCTION__: // primary-expression: __FUNCTION__ [GNU]
|
2012-06-23 10:07:59 +08:00
|
|
|
case tok::kw_L__FUNCTION__: // primary-expression: L__FUNCTION__ [MS]
|
2006-08-11 04:56:00 +08:00
|
|
|
case tok::kw___PRETTY_FUNCTION__: // primary-expression: __P..Y_F..N__ [GNU]
|
2008-08-10 09:53:14 +08:00
|
|
|
Res = Actions.ActOnPredefinedExpr(Tok.getLocation(), SavedKind);
|
2006-08-11 04:56:00 +08:00
|
|
|
ConsumeToken();
|
2010-08-24 07:25:46 +08:00
|
|
|
break;
|
2006-08-11 04:56:00 +08:00
|
|
|
case tok::string_literal: // primary-expression: string-literal
|
2006-10-06 13:22:26 +08:00
|
|
|
case tok::wide_string_literal:
|
2011-07-27 13:40:30 +08:00
|
|
|
case tok::utf8_string_literal:
|
|
|
|
case tok::utf16_string_literal:
|
|
|
|
case tok::utf32_string_literal:
|
2012-03-06 11:21:47 +08:00
|
|
|
Res = ParseStringLiteralExpression(true);
|
2010-08-24 07:25:46 +08:00
|
|
|
break;
|
2011-12-24 01:00:35 +08:00
|
|
|
case tok::kw__Generic: // primary-expression: generic-selection [C11 6.5.1]
|
2011-04-15 08:35:48 +08:00
|
|
|
Res = ParseGenericSelectionExpression();
|
|
|
|
break;
|
2006-08-11 06:01:51 +08:00
|
|
|
case tok::kw___builtin_va_arg:
|
|
|
|
case tok::kw___builtin_offsetof:
|
|
|
|
case tok::kw___builtin_choose_expr:
|
2011-06-04 08:47:47 +08:00
|
|
|
case tok::kw___builtin_astype: // primary-expression: [OCL] as_type()
|
2013-09-18 11:29:45 +08:00
|
|
|
case tok::kw___builtin_convertvector:
|
2008-12-12 06:33:27 +08:00
|
|
|
return ParseBuiltinPrimaryExpression();
|
2008-11-29 12:51:27 +08:00
|
|
|
case tok::kw___null:
|
2009-03-16 01:47:39 +08:00
|
|
|
return Actions.ActOnGNUNullExpr(ConsumeToken());
|
2011-07-08 12:59:44 +08:00
|
|
|
|
2010-08-06 22:50:36 +08:00
|
|
|
case tok::plusplus: // unary-expression: '++' unary-expression [C99]
|
|
|
|
case tok::minusminus: { // unary-expression: '--' unary-expression [C99]
|
|
|
|
// C++ [expr.unary] has:
|
|
|
|
// unary-expression:
|
|
|
|
// ++ cast-expression
|
|
|
|
// -- cast-expression
|
2006-10-25 11:38:23 +08:00
|
|
|
SourceLocation SavedLoc = ConsumeToken();
|
2012-03-11 15:00:24 +08:00
|
|
|
Res = ParseCastExpression(!getLangOpts().CPlusPlus);
|
2008-12-09 21:15:23 +08:00
|
|
|
if (!Res.isInvalid())
|
2010-08-24 07:25:46 +08:00
|
|
|
Res = Actions.ActOnUnaryOp(getCurScope(), SavedLoc, SavedKind, Res.get());
|
2012-08-24 05:35:17 +08:00
|
|
|
return Res;
|
2006-10-25 11:38:23 +08:00
|
|
|
}
|
2009-02-04 04:19:35 +08:00
|
|
|
case tok::amp: { // unary-expression: '&' cast-expression
|
|
|
|
// Special treatment because of member pointers
|
|
|
|
SourceLocation SavedLoc = ConsumeToken();
|
|
|
|
Res = ParseCastExpression(false, true);
|
|
|
|
if (!Res.isInvalid())
|
2010-08-24 07:25:46 +08:00
|
|
|
Res = Actions.ActOnUnaryOp(getCurScope(), SavedLoc, SavedKind, Res.get());
|
2012-08-24 05:35:17 +08:00
|
|
|
return Res;
|
2009-02-04 04:19:35 +08:00
|
|
|
}
|
|
|
|
|
2006-08-11 10:13:20 +08:00
|
|
|
case tok::star: // unary-expression: '*' cast-expression
|
|
|
|
case tok::plus: // unary-expression: '+' cast-expression
|
|
|
|
case tok::minus: // unary-expression: '-' cast-expression
|
|
|
|
case tok::tilde: // unary-expression: '~' cast-expression
|
|
|
|
case tok::exclaim: // unary-expression: '!' cast-expression
|
|
|
|
case tok::kw___real: // unary-expression: '__real' cast-expression [GNU]
|
2008-02-03 04:20:10 +08:00
|
|
|
case tok::kw___imag: { // unary-expression: '__imag' cast-expression [GNU]
|
|
|
|
SourceLocation SavedLoc = ConsumeToken();
|
|
|
|
Res = ParseCastExpression(false);
|
2008-12-09 21:15:23 +08:00
|
|
|
if (!Res.isInvalid())
|
2010-08-24 07:25:46 +08:00
|
|
|
Res = Actions.ActOnUnaryOp(getCurScope(), SavedLoc, SavedKind, Res.get());
|
2012-08-24 05:35:17 +08:00
|
|
|
return Res;
|
2008-12-09 21:15:23 +08:00
|
|
|
}
|
|
|
|
|
2006-10-25 11:38:23 +08:00
|
|
|
case tok::kw___extension__:{//unary-expression:'__extension__' cast-expr [GNU]
|
2008-02-03 04:20:10 +08:00
|
|
|
// __extension__ silences extension warnings in the subexpression.
|
2008-10-20 14:45:43 +08:00
|
|
|
ExtensionRAIIObject O(Diags); // Use RAII to do this.
|
2006-10-25 11:38:23 +08:00
|
|
|
SourceLocation SavedLoc = ConsumeToken();
|
2006-08-23 14:42:10 +08:00
|
|
|
Res = ParseCastExpression(false);
|
2008-12-09 21:15:23 +08:00
|
|
|
if (!Res.isInvalid())
|
2010-08-24 07:25:46 +08:00
|
|
|
Res = Actions.ActOnUnaryOp(getCurScope(), SavedLoc, SavedKind, Res.get());
|
2012-08-24 05:35:17 +08:00
|
|
|
return Res;
|
2006-10-25 11:38:23 +08:00
|
|
|
}
|
2012-07-01 05:33:57 +08:00
|
|
|
case tok::kw__Alignof: // unary-expression: '_Alignof' '(' type-name ')'
|
|
|
|
if (!getLangOpts().C11)
|
|
|
|
Diag(Tok, diag::ext_c11_alignment) << Tok.getName();
|
|
|
|
// fallthrough
|
|
|
|
case tok::kw_alignof: // unary-expression: 'alignof' '(' type-id ')'
|
2006-08-11 10:13:20 +08:00
|
|
|
case tok::kw___alignof: // unary-expression: '__alignof' unary-expression
|
|
|
|
// unary-expression: '__alignof' '(' type-name ')'
|
2012-07-01 05:33:57 +08:00
|
|
|
case tok::kw_sizeof: // unary-expression: 'sizeof' unary-expression
|
|
|
|
// unary-expression: 'sizeof' '(' type-name ')'
|
2011-03-12 03:24:49 +08:00
|
|
|
case tok::kw_vec_step: // unary-expression: OpenCL 'vec_step' expression
|
|
|
|
return ParseUnaryExprOrTypeTraitExpression();
|
2006-10-25 11:38:23 +08:00
|
|
|
case tok::ampamp: { // unary-expression: '&&' identifier
|
2007-05-28 14:56:27 +08:00
|
|
|
SourceLocation AmpAmpLoc = ConsumeToken();
|
2008-12-12 05:36:32 +08:00
|
|
|
if (Tok.isNot(tok::identifier))
|
|
|
|
return ExprError(Diag(Tok, diag::err_expected_ident));
|
2008-12-10 08:02:53 +08:00
|
|
|
|
2011-02-19 05:16:39 +08:00
|
|
|
if (getCurScope()->getFnParent() == 0)
|
|
|
|
return ExprError(Diag(Tok, diag::err_address_of_label_outside_fn));
|
|
|
|
|
2007-05-28 14:56:27 +08:00
|
|
|
Diag(AmpAmpLoc, diag::ext_gnu_address_of_label);
|
2011-02-18 09:27:55 +08:00
|
|
|
LabelDecl *LD = Actions.LookupOrCreateLabel(Tok.getIdentifierInfo(),
|
|
|
|
Tok.getLocation());
|
|
|
|
Res = Actions.ActOnAddrLabel(AmpAmpLoc, Tok.getLocation(), LD);
|
2006-10-16 06:33:58 +08:00
|
|
|
ConsumeToken();
|
2012-08-24 05:35:17 +08:00
|
|
|
return Res;
|
2006-10-25 11:38:23 +08:00
|
|
|
}
|
2006-12-05 02:06:35 +08:00
|
|
|
case tok::kw_const_cast:
|
|
|
|
case tok::kw_dynamic_cast:
|
|
|
|
case tok::kw_reinterpret_cast:
|
|
|
|
case tok::kw_static_cast:
|
2008-08-17 03:45:32 +08:00
|
|
|
Res = ParseCXXCasts();
|
2010-08-24 07:25:46 +08:00
|
|
|
break;
|
2008-11-11 19:37:55 +08:00
|
|
|
case tok::kw_typeid:
|
|
|
|
Res = ParseCXXTypeid();
|
2010-08-24 07:25:46 +08:00
|
|
|
break;
|
2010-09-08 20:20:18 +08:00
|
|
|
case tok::kw___uuidof:
|
|
|
|
Res = ParseCXXUuidof();
|
|
|
|
break;
|
2008-06-25 06:12:16 +08:00
|
|
|
case tok::kw_this:
|
2008-08-17 03:34:46 +08:00
|
|
|
Res = ParseCXXThis();
|
2010-08-24 07:25:46 +08:00
|
|
|
break;
|
2008-08-22 23:38:55 +08:00
|
|
|
|
2010-09-16 09:51:54 +08:00
|
|
|
case tok::annot_typename:
|
|
|
|
if (isStartOfObjCClassMessageMissingOpenBracket()) {
|
|
|
|
ParsedType Type = getTypeAnnotation(Tok);
|
2013-02-02 02:28:04 +08:00
|
|
|
|
2010-09-16 09:51:54 +08:00
|
|
|
// Fake up a Declarator to use with ActOnTypeName.
|
2011-03-24 19:26:52 +08:00
|
|
|
DeclSpec DS(AttrFactory);
|
2010-09-16 09:51:54 +08:00
|
|
|
DS.SetRangeStart(Tok.getLocation());
|
|
|
|
DS.SetRangeEnd(Tok.getLastLoc());
|
|
|
|
|
|
|
|
const char *PrevSpec = 0;
|
|
|
|
unsigned DiagID;
|
2010-11-22 18:30:56 +08:00
|
|
|
DS.SetTypeSpecType(TST_typename, Tok.getAnnotationEndLoc(),
|
|
|
|
PrevSpec, DiagID, Type);
|
2013-02-02 02:28:04 +08:00
|
|
|
|
2010-09-16 09:51:54 +08:00
|
|
|
Declarator DeclaratorInfo(DS, Declarator::TypeNameContext);
|
|
|
|
TypeResult Ty = Actions.ActOnTypeName(getCurScope(), DeclaratorInfo);
|
|
|
|
if (Ty.isInvalid())
|
|
|
|
break;
|
|
|
|
|
|
|
|
ConsumeToken();
|
|
|
|
Res = ParseObjCMessageExpressionBody(SourceLocation(), SourceLocation(),
|
|
|
|
Ty.get(), 0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// Fall through
|
2013-02-02 02:28:04 +08:00
|
|
|
|
2012-01-24 13:47:35 +08:00
|
|
|
case tok::annot_decltype:
|
2008-08-22 23:38:55 +08:00
|
|
|
case tok::kw_char:
|
|
|
|
case tok::kw_wchar_t:
|
2009-07-14 14:30:34 +08:00
|
|
|
case tok::kw_char16_t:
|
|
|
|
case tok::kw_char32_t:
|
2008-08-22 23:38:55 +08:00
|
|
|
case tok::kw_bool:
|
|
|
|
case tok::kw_short:
|
|
|
|
case tok::kw_int:
|
|
|
|
case tok::kw_long:
|
2011-04-28 09:59:37 +08:00
|
|
|
case tok::kw___int64:
|
2012-04-04 14:24:32 +08:00
|
|
|
case tok::kw___int128:
|
2008-08-22 23:38:55 +08:00
|
|
|
case tok::kw_signed:
|
|
|
|
case tok::kw_unsigned:
|
2011-10-15 07:23:15 +08:00
|
|
|
case tok::kw_half:
|
2008-08-22 23:38:55 +08:00
|
|
|
case tok::kw_float:
|
|
|
|
case tok::kw_double:
|
|
|
|
case tok::kw_void:
|
2009-03-28 07:10:48 +08:00
|
|
|
case tok::kw_typename:
|
2009-01-05 06:28:21 +08:00
|
|
|
case tok::kw_typeof:
|
2012-12-18 22:38:23 +08:00
|
|
|
case tok::kw___vector:
|
|
|
|
case tok::kw_image1d_t:
|
|
|
|
case tok::kw_image1d_array_t:
|
|
|
|
case tok::kw_image1d_buffer_t:
|
|
|
|
case tok::kw_image2d_t:
|
|
|
|
case tok::kw_image2d_array_t:
|
2013-02-02 02:28:04 +08:00
|
|
|
case tok::kw_image3d_t:
|
2013-02-07 18:55:47 +08:00
|
|
|
case tok::kw_sampler_t:
|
2013-02-02 02:28:04 +08:00
|
|
|
case tok::kw_event_t: {
|
2012-03-11 15:00:24 +08:00
|
|
|
if (!getLangOpts().CPlusPlus) {
|
2009-01-05 06:28:21 +08:00
|
|
|
Diag(Tok, diag::err_expected_expression);
|
|
|
|
return ExprError();
|
|
|
|
}
|
2009-06-11 08:33:41 +08:00
|
|
|
|
|
|
|
if (SavedKind == tok::kw_typename) {
|
|
|
|
// postfix-expression: typename-specifier '(' expression-list[opt] ')'
|
2011-06-05 20:23:16 +08:00
|
|
|
// typename-specifier braced-init-list
|
2010-02-26 16:45:28 +08:00
|
|
|
if (TryAnnotateTypeOrScopeToken())
|
2009-06-11 08:33:41 +08:00
|
|
|
return ExprError();
|
2013-09-22 11:30:01 +08:00
|
|
|
|
|
|
|
if (!Actions.isSimpleTypeSpecifier(Tok.getKind()))
|
|
|
|
// We are trying to parse a simple-type-specifier but might not get such
|
|
|
|
// a token after error recovery.
|
|
|
|
return ExprError();
|
2009-06-11 08:33:41 +08:00
|
|
|
}
|
|
|
|
|
2008-08-22 23:38:55 +08:00
|
|
|
// postfix-expression: simple-type-specifier '(' expression-list[opt] ')'
|
2011-06-05 20:23:16 +08:00
|
|
|
// simple-type-specifier braced-init-list
|
2008-08-22 23:38:55 +08:00
|
|
|
//
|
2011-03-24 19:26:52 +08:00
|
|
|
DeclSpec DS(AttrFactory);
|
2013-09-22 09:24:26 +08:00
|
|
|
|
2008-08-22 23:38:55 +08:00
|
|
|
ParseCXXSimpleTypeSpecifier(DS);
|
2011-06-05 20:23:16 +08:00
|
|
|
if (Tok.isNot(tok::l_paren) &&
|
2013-01-02 19:42:31 +08:00
|
|
|
(!getLangOpts().CPlusPlus11 || Tok.isNot(tok::l_brace)))
|
2008-12-12 05:36:32 +08:00
|
|
|
return ExprError(Diag(Tok, diag::err_expected_lparen_after_type)
|
|
|
|
<< DS.getSourceRange());
|
2008-08-22 23:38:55 +08:00
|
|
|
|
2011-10-15 13:09:34 +08:00
|
|
|
if (Tok.is(tok::l_brace))
|
|
|
|
Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists);
|
|
|
|
|
2008-08-22 23:38:55 +08:00
|
|
|
Res = ParseCXXTypeConstructExpression(DS);
|
2010-08-24 07:25:46 +08:00
|
|
|
break;
|
2008-08-22 23:38:55 +08:00
|
|
|
}
|
|
|
|
|
2010-02-06 03:11:37 +08:00
|
|
|
case tok::annot_cxxscope: { // [C++] id-expression: qualified-id
|
2010-04-23 10:08:13 +08:00
|
|
|
// If TryAnnotateTypeOrScopeToken annotates the token, tail recurse.
|
|
|
|
// (We can end up in this situation after tentative parsing.)
|
|
|
|
if (TryAnnotateTypeOrScopeToken())
|
|
|
|
return ExprError();
|
|
|
|
if (!Tok.is(tok::annot_cxxscope))
|
|
|
|
return ParseCastExpression(isUnaryExpression, isAddressOfOperand,
|
2011-07-02 06:22:59 +08:00
|
|
|
NotCastExpr, isTypeCast);
|
2010-04-23 10:08:13 +08:00
|
|
|
|
2010-02-06 03:11:37 +08:00
|
|
|
Token Next = NextToken();
|
|
|
|
if (Next.is(tok::annot_template_id)) {
|
2011-06-22 14:09:49 +08:00
|
|
|
TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Next);
|
2010-02-06 03:11:37 +08:00
|
|
|
if (TemplateId->Kind == TNK_Type_template) {
|
|
|
|
// We have a qualified template-id that we know refers to a
|
|
|
|
// type, translate it into a type and continue parsing as a
|
|
|
|
// cast expression.
|
|
|
|
CXXScopeSpec SS;
|
2011-11-08 01:33:42 +08:00
|
|
|
ParseOptionalCXXScopeSpecifier(SS, ParsedType(),
|
|
|
|
/*EnteringContext=*/false);
|
2011-03-02 08:47:37 +08:00
|
|
|
AnnotateTemplateIdTokenAsType();
|
2010-02-06 03:11:37 +08:00
|
|
|
return ParseCastExpression(isUnaryExpression, isAddressOfOperand,
|
2011-07-02 06:22:59 +08:00
|
|
|
NotCastExpr, isTypeCast);
|
2010-02-06 03:11:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Parse as an id-expression.
|
|
|
|
Res = ParseCXXIdExpression(isAddressOfOperand);
|
2010-08-24 07:25:46 +08:00
|
|
|
break;
|
2010-02-06 03:11:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
case tok::annot_template_id: { // [C++] template-id
|
2011-06-22 14:09:49 +08:00
|
|
|
TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Tok);
|
2010-02-06 03:11:37 +08:00
|
|
|
if (TemplateId->Kind == TNK_Type_template) {
|
|
|
|
// We have a template-id that we know refers to a type,
|
|
|
|
// translate it into a type and continue parsing as a cast
|
|
|
|
// expression.
|
|
|
|
AnnotateTemplateIdTokenAsType();
|
|
|
|
return ParseCastExpression(isUnaryExpression, isAddressOfOperand,
|
2011-07-02 06:22:59 +08:00
|
|
|
NotCastExpr, isTypeCast);
|
2010-02-06 03:11:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Fall through to treat the template-id as an id-expression.
|
|
|
|
}
|
|
|
|
|
2008-11-09 00:45:02 +08:00
|
|
|
case tok::kw_operator: // [C++] id-expression: operator/conversion-function-id
|
2009-02-04 04:19:35 +08:00
|
|
|
Res = ParseCXXIdExpression(isAddressOfOperand);
|
2010-08-24 07:25:46 +08:00
|
|
|
break;
|
2008-11-07 06:13:31 +08:00
|
|
|
|
2009-01-05 06:52:14 +08:00
|
|
|
case tok::coloncolon: {
|
2009-01-05 11:55:46 +08:00
|
|
|
// ::foo::bar -> global qualified name etc. If TryAnnotateTypeOrScopeToken
|
|
|
|
// annotates the token, tail recurse.
|
|
|
|
if (TryAnnotateTypeOrScopeToken())
|
2010-02-26 16:45:28 +08:00
|
|
|
return ExprError();
|
|
|
|
if (!Tok.is(tok::coloncolon))
|
2009-02-04 04:19:35 +08:00
|
|
|
return ParseCastExpression(isUnaryExpression, isAddressOfOperand);
|
|
|
|
|
2009-01-05 06:52:14 +08:00
|
|
|
// ::new -> [C++] new-expression
|
|
|
|
// ::delete -> [C++] delete-expression
|
2009-01-05 11:55:46 +08:00
|
|
|
SourceLocation CCLoc = ConsumeToken();
|
2009-01-05 05:25:24 +08:00
|
|
|
if (Tok.is(tok::kw_new))
|
2009-01-05 11:55:46 +08:00
|
|
|
return ParseCXXNewExpression(true, CCLoc);
|
2009-01-05 06:52:14 +08:00
|
|
|
if (Tok.is(tok::kw_delete))
|
2009-01-05 11:55:46 +08:00
|
|
|
return ParseCXXDeleteExpression(true, CCLoc);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-01-05 07:23:14 +08:00
|
|
|
// This is not a type name or scope specifier, it is an invalid expression.
|
2009-01-05 11:55:46 +08:00
|
|
|
Diag(CCLoc, diag::err_expected_expression);
|
2009-01-05 07:23:14 +08:00
|
|
|
return ExprError();
|
2009-01-05 05:25:24 +08:00
|
|
|
}
|
2008-12-03 00:35:44 +08:00
|
|
|
|
2008-11-22 03:14:01 +08:00
|
|
|
case tok::kw_new: // [C++] new-expression
|
2009-01-05 05:25:24 +08:00
|
|
|
return ParseCXXNewExpression(false, Tok.getLocation());
|
2008-11-22 03:14:01 +08:00
|
|
|
|
|
|
|
case tok::kw_delete: // [C++] delete-expression
|
2009-01-05 05:25:24 +08:00
|
|
|
return ParseCXXDeleteExpression(false, Tok.getLocation());
|
2008-11-22 03:14:01 +08:00
|
|
|
|
2010-09-11 04:55:37 +08:00
|
|
|
case tok::kw_noexcept: { // [C++0x] 'noexcept' '(' expression ')'
|
2011-10-18 07:06:20 +08:00
|
|
|
Diag(Tok, diag::warn_cxx98_compat_noexcept_expr);
|
2010-09-11 04:55:37 +08:00
|
|
|
SourceLocation KeyLoc = ConsumeToken();
|
2011-10-13 00:37:45 +08:00
|
|
|
BalancedDelimiterTracker T(*this, tok::l_paren);
|
|
|
|
|
|
|
|
if (T.expectAndConsume(diag::err_expected_lparen_after, "noexcept"))
|
2010-09-11 04:55:37 +08:00
|
|
|
return ExprError();
|
2011-12-20 10:08:33 +08:00
|
|
|
// C++11 [expr.unary.noexcept]p1:
|
2010-09-11 05:57:27 +08:00
|
|
|
// The noexcept operator determines whether the evaluation of its operand,
|
|
|
|
// which is an unevaluated operand, can throw an exception.
|
|
|
|
EnterExpressionEvaluationContext Unevaluated(Actions, Sema::Unevaluated);
|
2010-09-11 04:55:37 +08:00
|
|
|
ExprResult Result = ParseExpression();
|
2011-10-13 00:37:45 +08:00
|
|
|
|
|
|
|
T.consumeClose();
|
|
|
|
|
2010-09-11 04:55:37 +08:00
|
|
|
if (!Result.isInvalid())
|
2011-10-13 00:37:45 +08:00
|
|
|
Result = Actions.ActOnNoexceptExpr(KeyLoc, T.getOpenLocation(),
|
|
|
|
Result.take(), T.getCloseLocation());
|
2012-08-24 05:35:17 +08:00
|
|
|
return Result;
|
2010-09-11 04:55:37 +08:00
|
|
|
}
|
|
|
|
|
2011-04-23 18:47:20 +08:00
|
|
|
case tok::kw___is_abstract: // [GNU] unary-type-trait
|
2009-01-06 04:52:13 +08:00
|
|
|
case tok::kw___is_class:
|
2009-08-16 05:55:26 +08:00
|
|
|
case tok::kw___is_empty:
|
2011-04-23 18:47:20 +08:00
|
|
|
case tok::kw___is_enum:
|
2012-09-25 15:32:49 +08:00
|
|
|
case tok::kw___is_interface_class:
|
2009-12-03 08:13:20 +08:00
|
|
|
case tok::kw___is_literal:
|
2011-04-28 07:09:49 +08:00
|
|
|
case tok::kw___is_arithmetic:
|
|
|
|
case tok::kw___is_integral:
|
|
|
|
case tok::kw___is_floating_point:
|
|
|
|
case tok::kw___is_complete_type:
|
|
|
|
case tok::kw___is_void:
|
|
|
|
case tok::kw___is_array:
|
|
|
|
case tok::kw___is_function:
|
|
|
|
case tok::kw___is_reference:
|
|
|
|
case tok::kw___is_lvalue_reference:
|
|
|
|
case tok::kw___is_rvalue_reference:
|
|
|
|
case tok::kw___is_fundamental:
|
|
|
|
case tok::kw___is_object:
|
|
|
|
case tok::kw___is_scalar:
|
|
|
|
case tok::kw___is_compound:
|
|
|
|
case tok::kw___is_pointer:
|
|
|
|
case tok::kw___is_member_object_pointer:
|
|
|
|
case tok::kw___is_member_function_pointer:
|
|
|
|
case tok::kw___is_member_pointer:
|
|
|
|
case tok::kw___is_const:
|
|
|
|
case tok::kw___is_volatile:
|
|
|
|
case tok::kw___is_standard_layout:
|
|
|
|
case tok::kw___is_signed:
|
|
|
|
case tok::kw___is_unsigned:
|
2011-04-24 10:49:28 +08:00
|
|
|
case tok::kw___is_literal_type:
|
2011-04-23 18:47:20 +08:00
|
|
|
case tok::kw___is_pod:
|
|
|
|
case tok::kw___is_polymorphic:
|
2011-04-23 18:47:28 +08:00
|
|
|
case tok::kw___is_trivial:
|
2011-05-13 08:31:07 +08:00
|
|
|
case tok::kw___is_trivially_copyable:
|
2011-04-23 18:47:20 +08:00
|
|
|
case tok::kw___is_union:
|
2011-12-04 02:14:24 +08:00
|
|
|
case tok::kw___is_final:
|
2009-04-16 08:08:20 +08:00
|
|
|
case tok::kw___has_trivial_constructor:
|
2013-03-27 09:34:16 +08:00
|
|
|
case tok::kw___has_trivial_move_constructor:
|
2009-07-24 07:49:00 +08:00
|
|
|
case tok::kw___has_trivial_copy:
|
|
|
|
case tok::kw___has_trivial_assign:
|
2013-03-27 09:34:16 +08:00
|
|
|
case tok::kw___has_trivial_move_assign:
|
2009-04-17 10:34:54 +08:00
|
|
|
case tok::kw___has_trivial_destructor:
|
2010-08-31 12:59:00 +08:00
|
|
|
case tok::kw___has_nothrow_assign:
|
2013-03-27 09:34:16 +08:00
|
|
|
case tok::kw___has_nothrow_move_assign:
|
2010-08-31 12:59:00 +08:00
|
|
|
case tok::kw___has_nothrow_copy:
|
|
|
|
case tok::kw___has_nothrow_constructor:
|
2010-09-03 07:19:42 +08:00
|
|
|
case tok::kw___has_virtual_destructor:
|
2009-01-06 04:52:13 +08:00
|
|
|
return ParseUnaryTypeTrait();
|
|
|
|
|
2010-12-09 06:35:30 +08:00
|
|
|
case tok::kw___builtin_types_compatible_p:
|
2010-12-07 08:08:36 +08:00
|
|
|
case tok::kw___is_base_of:
|
2011-04-28 07:09:49 +08:00
|
|
|
case tok::kw___is_same:
|
|
|
|
case tok::kw___is_convertible:
|
2011-01-28 04:28:01 +08:00
|
|
|
case tok::kw___is_convertible_to:
|
2012-02-23 15:33:15 +08:00
|
|
|
case tok::kw___is_trivially_assignable:
|
2010-12-07 08:08:36 +08:00
|
|
|
return ParseBinaryTypeTrait();
|
|
|
|
|
2012-02-24 15:38:34 +08:00
|
|
|
case tok::kw___is_trivially_constructible:
|
|
|
|
return ParseTypeTrait();
|
|
|
|
|
2011-04-28 08:16:57 +08:00
|
|
|
case tok::kw___array_rank:
|
|
|
|
case tok::kw___array_extent:
|
|
|
|
return ParseArrayTypeTrait();
|
|
|
|
|
2011-04-25 14:54:41 +08:00
|
|
|
case tok::kw___is_lvalue_expr:
|
|
|
|
case tok::kw___is_rvalue_expr:
|
|
|
|
return ParseExpressionTrait();
|
|
|
|
|
2007-10-04 06:03:06 +08:00
|
|
|
case tok::at: {
|
|
|
|
SourceLocation AtLoc = ConsumeToken();
|
2008-12-13 23:32:12 +08:00
|
|
|
return ParseObjCAtExpression(AtLoc);
|
2007-10-04 06:03:06 +08:00
|
|
|
}
|
2008-08-29 03:20:44 +08:00
|
|
|
case tok::caret:
|
2011-07-08 12:28:55 +08:00
|
|
|
Res = ParseBlockLiteralExpression();
|
|
|
|
break;
|
|
|
|
case tok::code_completion: {
|
2010-08-27 07:41:50 +08:00
|
|
|
Actions.CodeCompleteOrdinaryName(getCurScope(), Sema::PCC_Expression);
|
2011-09-04 11:32:15 +08:00
|
|
|
cutOffParsing();
|
|
|
|
return ExprError();
|
2011-07-08 12:28:55 +08:00
|
|
|
}
|
2008-12-13 03:20:14 +08:00
|
|
|
case tok::l_square:
|
2013-01-02 19:42:31 +08:00
|
|
|
if (getLangOpts().CPlusPlus11) {
|
2012-03-11 15:00:24 +08:00
|
|
|
if (getLangOpts().ObjC1) {
|
2012-01-04 10:40:39 +08:00
|
|
|
// C++11 lambda expressions and Objective-C message sends both start with a
|
|
|
|
// square bracket. There are three possibilities here:
|
|
|
|
// we have a valid lambda expression, we have an invalid lambda
|
|
|
|
// expression, or we have something that doesn't appear to be a lambda.
|
|
|
|
// If we're in the last case, we fall back to ParseObjCMessageExpression.
|
2011-08-04 23:30:47 +08:00
|
|
|
Res = TryParseLambdaExpression();
|
2012-01-04 10:40:39 +08:00
|
|
|
if (!Res.isInvalid() && !Res.get())
|
2011-08-04 23:30:47 +08:00
|
|
|
Res = ParseObjCMessageExpression();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
Res = ParseLambdaExpression();
|
|
|
|
break;
|
|
|
|
}
|
2012-03-11 15:00:24 +08:00
|
|
|
if (getLangOpts().ObjC1) {
|
2011-07-08 12:28:55 +08:00
|
|
|
Res = ParseObjCMessageExpression();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// FALL THROUGH.
|
2006-08-11 04:56:00 +08:00
|
|
|
default:
|
2009-05-22 18:24:42 +08:00
|
|
|
NotCastExpr = true;
|
2008-12-12 05:36:32 +08:00
|
|
|
return ExprError();
|
2006-08-11 06:01:51 +08:00
|
|
|
}
|
2008-12-12 05:36:32 +08:00
|
|
|
|
2010-08-24 07:25:46 +08:00
|
|
|
// These can be followed by postfix-expr pieces.
|
2010-09-18 09:28:11 +08:00
|
|
|
return ParsePostfixExpressionSuffix(Res);
|
2006-08-13 01:40:43 +08:00
|
|
|
}
|
|
|
|
|
2012-06-17 12:36:28 +08:00
|
|
|
/// \brief Once the leading part of a postfix-expression is parsed, this
|
|
|
|
/// method parses any suffixes that apply.
|
2006-08-13 01:40:43 +08:00
|
|
|
///
|
2012-06-17 12:36:28 +08:00
|
|
|
/// \verbatim
|
2006-08-13 01:40:43 +08:00
|
|
|
/// postfix-expression: [C99 6.5.2]
|
|
|
|
/// primary-expression
|
|
|
|
/// postfix-expression '[' expression ']'
|
2011-06-05 20:23:16 +08:00
|
|
|
/// postfix-expression '[' braced-init-list ']'
|
2006-08-13 01:40:43 +08:00
|
|
|
/// postfix-expression '(' argument-expression-list[opt] ')'
|
|
|
|
/// postfix-expression '.' identifier
|
|
|
|
/// postfix-expression '->' identifier
|
|
|
|
/// postfix-expression '++'
|
|
|
|
/// postfix-expression '--'
|
|
|
|
/// '(' type-name ')' '{' initializer-list '}'
|
|
|
|
/// '(' type-name ')' '{' initializer-list ',' '}'
|
|
|
|
///
|
|
|
|
/// argument-expression-list: [C99 6.5.2]
|
2011-01-04 03:31:53 +08:00
|
|
|
/// argument-expression ...[opt]
|
|
|
|
/// argument-expression-list ',' assignment-expression ...[opt]
|
2012-06-17 12:36:28 +08:00
|
|
|
/// \endverbatim
|
2010-08-24 14:29:42 +08:00
|
|
|
ExprResult
|
|
|
|
Parser::ParsePostfixExpressionSuffix(ExprResult LHS) {
|
2006-08-11 06:01:51 +08:00
|
|
|
// Now that the primary-expression piece of the postfix-expression has been
|
|
|
|
// parsed, see if there are any postfix-expression pieces here.
|
|
|
|
SourceLocation Loc;
|
|
|
|
while (1) {
|
|
|
|
switch (Tok.getKind()) {
|
2010-09-16 00:23:04 +08:00
|
|
|
case tok::code_completion:
|
|
|
|
if (InMessageExpression)
|
2012-08-24 05:35:17 +08:00
|
|
|
return LHS;
|
2010-09-16 00:23:04 +08:00
|
|
|
|
2010-09-18 09:28:11 +08:00
|
|
|
Actions.CodeCompletePostfixExpression(getCurScope(), LHS);
|
2011-09-04 11:32:15 +08:00
|
|
|
cutOffParsing();
|
|
|
|
return ExprError();
|
2010-09-16 00:23:04 +08:00
|
|
|
|
2010-09-15 22:51:05 +08:00
|
|
|
case tok::identifier:
|
|
|
|
// If we see identifier: after an expression, and we're not already in a
|
|
|
|
// message send, then this is probably a message send with a missing
|
|
|
|
// opening bracket '['.
|
2012-03-11 15:00:24 +08:00
|
|
|
if (getLangOpts().ObjC1 && !InMessageExpression &&
|
2010-09-15 22:54:45 +08:00
|
|
|
(NextToken().is(tok::colon) || NextToken().is(tok::r_square))) {
|
2010-09-15 22:51:05 +08:00
|
|
|
LHS = ParseObjCMessageExpressionBody(SourceLocation(), SourceLocation(),
|
|
|
|
ParsedType(), LHS.get());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fall through; this isn't a message send.
|
|
|
|
|
2006-08-13 01:40:43 +08:00
|
|
|
default: // Not a postfix-expression suffix.
|
2012-08-24 05:35:17 +08:00
|
|
|
return LHS;
|
2006-08-24 11:51:22 +08:00
|
|
|
case tok::l_square: { // postfix-expression: p-e '[' expression ']'
|
2010-06-01 02:18:22 +08:00
|
|
|
// If we have a array postfix expression that starts on a new line and
|
|
|
|
// Objective-C is enabled, it is highly likely that the user forgot a
|
|
|
|
// semicolon after the base expression and that the array postfix-expr is
|
|
|
|
// actually another message send. In this case, do some look-ahead to see
|
|
|
|
// if the contents of the square brackets are obviously not a valid
|
|
|
|
// expression and recover by pretending there is no suffix.
|
2012-03-11 15:00:24 +08:00
|
|
|
if (getLangOpts().ObjC1 && Tok.isAtStartOfLine() &&
|
2010-06-01 02:18:22 +08:00
|
|
|
isSimpleObjCMessageExpression())
|
2012-08-24 05:35:17 +08:00
|
|
|
return LHS;
|
2012-04-10 09:32:12 +08:00
|
|
|
|
|
|
|
// Reject array indices starting with a lambda-expression. '[[' is
|
|
|
|
// reserved for attributes.
|
|
|
|
if (CheckProhibitedCXX11Attribute())
|
|
|
|
return ExprError();
|
|
|
|
|
2011-10-13 00:37:45 +08:00
|
|
|
BalancedDelimiterTracker T(*this, tok::l_square);
|
|
|
|
T.consumeOpen();
|
|
|
|
Loc = T.getOpenLocation();
|
2011-06-05 20:23:16 +08:00
|
|
|
ExprResult Idx;
|
2013-01-02 19:42:31 +08:00
|
|
|
if (getLangOpts().CPlusPlus11 && Tok.is(tok::l_brace)) {
|
2011-10-15 13:09:34 +08:00
|
|
|
Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists);
|
2011-06-05 20:23:16 +08:00
|
|
|
Idx = ParseBraceInitializer();
|
2011-10-15 13:09:34 +08:00
|
|
|
} else
|
2011-06-05 20:23:16 +08:00
|
|
|
Idx = ParseExpression();
|
2008-11-26 06:21:31 +08:00
|
|
|
|
2006-08-24 11:51:22 +08:00
|
|
|
SourceLocation RLoc = Tok.getLocation();
|
2008-12-09 21:15:23 +08:00
|
|
|
|
|
|
|
if (!LHS.isInvalid() && !Idx.isInvalid() && Tok.is(tok::r_square)) {
|
2010-08-24 07:25:46 +08:00
|
|
|
LHS = Actions.ActOnArraySubscriptExpr(getCurScope(), LHS.take(), Loc,
|
|
|
|
Idx.take(), RLoc);
|
2008-12-09 21:15:23 +08:00
|
|
|
} else
|
2008-12-12 05:36:32 +08:00
|
|
|
LHS = ExprError();
|
2006-08-24 11:51:22 +08:00
|
|
|
|
2006-08-11 14:41:18 +08:00
|
|
|
// Match the ']'.
|
2011-10-13 00:37:45 +08:00
|
|
|
T.consumeClose();
|
2006-08-11 14:41:18 +08:00
|
|
|
break;
|
2006-08-24 11:51:22 +08:00
|
|
|
}
|
2008-12-09 21:15:23 +08:00
|
|
|
|
2011-02-10 05:12:02 +08:00
|
|
|
case tok::l_paren: // p-e: p-e '(' argument-expression-list[opt] ')'
|
|
|
|
case tok::lesslessless: { // p-e: p-e '<<<' argument-expression-list '>>>'
|
|
|
|
// '(' argument-expression-list[opt] ')'
|
|
|
|
tok::TokenKind OpKind = Tok.getKind();
|
2010-09-15 22:51:05 +08:00
|
|
|
InMessageExpressionRAIIObject InMessage(*this, false);
|
|
|
|
|
2011-02-10 05:12:02 +08:00
|
|
|
Expr *ExecConfig = 0;
|
|
|
|
|
2011-10-13 00:37:45 +08:00
|
|
|
BalancedDelimiterTracker PT(*this, tok::l_paren);
|
|
|
|
|
2011-02-10 05:12:02 +08:00
|
|
|
if (OpKind == tok::lesslessless) {
|
2012-08-24 06:51:59 +08:00
|
|
|
ExprVector ExecConfigExprs;
|
2011-02-10 05:12:02 +08:00
|
|
|
CommaLocsTy ExecConfigCommaLocs;
|
2012-03-08 09:00:17 +08:00
|
|
|
SourceLocation OpenLoc = ConsumeToken();
|
2011-02-10 05:12:02 +08:00
|
|
|
|
2013-08-14 07:38:34 +08:00
|
|
|
if (ParseSimpleExpressionList(ExecConfigExprs, ExecConfigCommaLocs)) {
|
2011-02-10 05:12:02 +08:00
|
|
|
LHS = ExprError();
|
|
|
|
}
|
|
|
|
|
2012-03-08 09:00:17 +08:00
|
|
|
SourceLocation CloseLoc = Tok.getLocation();
|
|
|
|
if (Tok.is(tok::greatergreatergreater)) {
|
|
|
|
ConsumeToken();
|
|
|
|
} else if (LHS.isInvalid()) {
|
2011-02-10 05:12:02 +08:00
|
|
|
SkipUntil(tok::greatergreatergreater);
|
2012-03-08 09:00:17 +08:00
|
|
|
} else {
|
2011-10-13 00:37:45 +08:00
|
|
|
// There was an error closing the brackets
|
2012-03-08 09:00:17 +08:00
|
|
|
Diag(Tok, diag::err_expected_ggg);
|
|
|
|
Diag(OpenLoc, diag::note_matching) << "<<<";
|
|
|
|
SkipUntil(tok::greatergreatergreater);
|
2011-02-10 05:12:02 +08:00
|
|
|
LHS = ExprError();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!LHS.isInvalid()) {
|
|
|
|
if (ExpectAndConsume(tok::l_paren, diag::err_expected_lparen, ""))
|
|
|
|
LHS = ExprError();
|
|
|
|
else
|
|
|
|
Loc = PrevTokLocation;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!LHS.isInvalid()) {
|
|
|
|
ExprResult ECResult = Actions.ActOnCUDAExecConfigExpr(getCurScope(),
|
2012-03-08 09:00:17 +08:00
|
|
|
OpenLoc,
|
2012-08-24 05:35:17 +08:00
|
|
|
ExecConfigExprs,
|
2012-03-08 09:00:17 +08:00
|
|
|
CloseLoc);
|
2011-02-10 05:12:02 +08:00
|
|
|
if (ECResult.isInvalid())
|
|
|
|
LHS = ExprError();
|
|
|
|
else
|
|
|
|
ExecConfig = ECResult.get();
|
|
|
|
}
|
|
|
|
} else {
|
2011-10-13 00:37:45 +08:00
|
|
|
PT.consumeOpen();
|
|
|
|
Loc = PT.getOpenLocation();
|
2011-02-10 05:12:02 +08:00
|
|
|
}
|
|
|
|
|
2012-08-24 06:51:59 +08:00
|
|
|
ExprVector ArgExprs;
|
2008-08-17 04:03:01 +08:00
|
|
|
CommaLocsTy CommaLocs;
|
2010-09-18 09:28:11 +08:00
|
|
|
|
2009-09-22 23:41:20 +08:00
|
|
|
if (Tok.is(tok::code_completion)) {
|
2013-05-05 08:41:58 +08:00
|
|
|
Actions.CodeCompleteCall(getCurScope(), LHS.get(), None);
|
2011-09-04 11:32:15 +08:00
|
|
|
cutOffParsing();
|
|
|
|
return ExprError();
|
2009-09-22 23:41:20 +08:00
|
|
|
}
|
2011-02-10 05:12:02 +08:00
|
|
|
|
|
|
|
if (OpKind == tok::l_paren || !LHS.isInvalid()) {
|
|
|
|
if (Tok.isNot(tok::r_paren)) {
|
|
|
|
if (ParseExpressionList(ArgExprs, CommaLocs, &Sema::CodeCompleteCall,
|
|
|
|
LHS.get())) {
|
|
|
|
LHS = ExprError();
|
|
|
|
}
|
2006-08-13 02:12:45 +08:00
|
|
|
}
|
2006-08-11 14:41:18 +08:00
|
|
|
}
|
2008-12-12 05:36:32 +08:00
|
|
|
|
2006-08-11 14:41:18 +08:00
|
|
|
// Match the ')'.
|
2010-09-18 09:28:11 +08:00
|
|
|
if (LHS.isInvalid()) {
|
|
|
|
SkipUntil(tok::r_paren);
|
|
|
|
} else if (Tok.isNot(tok::r_paren)) {
|
2011-10-13 00:37:45 +08:00
|
|
|
PT.consumeClose();
|
2010-09-18 09:28:11 +08:00
|
|
|
LHS = ExprError();
|
|
|
|
} else {
|
|
|
|
assert((ArgExprs.size() == 0 ||
|
|
|
|
ArgExprs.size()-1 == CommaLocs.size())&&
|
2006-08-24 12:40:38 +08:00
|
|
|
"Unexpected number of commas!");
|
2010-08-24 07:25:46 +08:00
|
|
|
LHS = Actions.ActOnCallExpr(getCurScope(), LHS.take(), Loc,
|
2012-08-24 05:35:17 +08:00
|
|
|
ArgExprs, Tok.getLocation(),
|
2011-02-10 05:12:02 +08:00
|
|
|
ExecConfig);
|
2011-10-13 00:37:45 +08:00
|
|
|
PT.consumeClose();
|
2006-08-24 12:40:38 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2006-08-11 14:41:18 +08:00
|
|
|
break;
|
2006-08-24 11:51:22 +08:00
|
|
|
}
|
2009-09-09 08:23:06 +08:00
|
|
|
case tok::arrow:
|
|
|
|
case tok::period: {
|
|
|
|
// postfix-expression: p-e '->' template[opt] id-expression
|
|
|
|
// postfix-expression: p-e '.' template[opt] id-expression
|
2006-08-24 11:51:22 +08:00
|
|
|
tok::TokenKind OpKind = Tok.getKind();
|
2006-10-16 14:06:51 +08:00
|
|
|
SourceLocation OpLoc = ConsumeToken(); // Eat the "." or "->" token.
|
2008-12-12 05:36:32 +08:00
|
|
|
|
2009-08-06 11:17:00 +08:00
|
|
|
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
|
|
|
bool MayBePseudoDestructor = false;
|
2012-03-11 15:00:24 +08:00
|
|
|
if (getLangOpts().CPlusPlus && !LHS.isInvalid()) {
|
2013-07-13 05:43:02 +08:00
|
|
|
Expr *Base = LHS.take();
|
|
|
|
const Type* BaseType = Base->getType().getTypePtrOrNull();
|
|
|
|
if (BaseType && Tok.is(tok::l_paren) &&
|
|
|
|
(BaseType->isFunctionType() ||
|
|
|
|
BaseType->getAsPlaceholderType()->getKind() ==
|
|
|
|
BuiltinType::BoundMember)) {
|
|
|
|
Diag(OpLoc, diag::err_function_is_not_record)
|
|
|
|
<< (OpKind == tok::arrow) << Base->getSourceRange()
|
|
|
|
<< FixItHint::CreateRemoval(OpLoc);
|
|
|
|
return ParsePostfixExpressionSuffix(Base);
|
|
|
|
}
|
|
|
|
|
|
|
|
LHS = Actions.ActOnStartCXXMemberReference(getCurScope(), Base,
|
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
|
|
|
OpLoc, OpKind, ObjectType,
|
|
|
|
MayBePseudoDestructor);
|
2009-08-06 11:17:00 +08:00
|
|
|
if (LHS.isInvalid())
|
|
|
|
break;
|
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-11-08 01:33:42 +08:00
|
|
|
ParseOptionalCXXScopeSpecifier(SS, ObjectType,
|
|
|
|
/*EnteringContext=*/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
|
|
|
&MayBePseudoDestructor);
|
2010-05-27 23:25:59 +08:00
|
|
|
if (SS.isNotEmpty())
|
2010-08-24 13:47:05 +08:00
|
|
|
ObjectType = ParsedType();
|
2009-08-06 11:17:00 +08:00
|
|
|
}
|
|
|
|
|
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 member access expression.
|
2010-07-03 01:43:08 +08:00
|
|
|
Actions.CodeCompleteMemberReferenceExpr(getCurScope(), LHS.get(),
|
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
|
|
|
OpLoc, OpKind == tok::arrow);
|
|
|
|
|
2011-09-04 11:32:15 +08:00
|
|
|
cutOffParsing();
|
|
|
|
return ExprError();
|
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
|
|
|
}
|
|
|
|
|
2010-08-24 07:25:46 +08:00
|
|
|
if (MayBePseudoDestructor && !LHS.isInvalid()) {
|
|
|
|
LHS = ParseCXXPseudoDestructor(LHS.take(), OpLoc, OpKind, SS,
|
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
|
|
|
ObjectType);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Either the action has told is that this cannot be a
|
|
|
|
// pseudo-destructor expression (based on the type of base
|
|
|
|
// expression), or we didn't see a '~' in the right place. We
|
|
|
|
// can still parse a destructor name here, but in that case it
|
|
|
|
// names a real destructor.
|
2011-01-18 13:04:39 +08:00
|
|
|
// Allow explicit constructor calls in Microsoft mode.
|
|
|
|
// FIXME: Add support for explicit call of template constructor.
|
2012-01-27 17:46:47 +08:00
|
|
|
SourceLocation TemplateKWLoc;
|
2009-11-04 03:44:04 +08:00
|
|
|
UnqualifiedId Name;
|
2012-03-11 15:00:24 +08:00
|
|
|
if (getLangOpts().ObjC2 && OpKind == tok::period && Tok.is(tok::kw_class)) {
|
2012-02-17 02:19:22 +08:00
|
|
|
// Objective-C++:
|
|
|
|
// After a '.' in a member access expression, treat the keyword
|
|
|
|
// 'class' as if it were an identifier.
|
|
|
|
//
|
|
|
|
// This hack allows property access to the 'class' method because it is
|
|
|
|
// such a common method name. For other C++ keywords that are
|
|
|
|
// Objective-C method names, one must use the message send syntax.
|
|
|
|
IdentifierInfo *Id = Tok.getIdentifierInfo();
|
|
|
|
SourceLocation Loc = ConsumeToken();
|
|
|
|
Name.setIdentifier(Id, Loc);
|
|
|
|
} else if (ParseUnqualifiedId(SS,
|
|
|
|
/*EnteringContext=*/false,
|
|
|
|
/*AllowDestructorName=*/true,
|
|
|
|
/*AllowConstructorName=*/
|
2012-03-11 15:00:24 +08:00
|
|
|
getLangOpts().MicrosoftExt,
|
2012-02-17 02:19:22 +08:00
|
|
|
ObjectType, TemplateKWLoc, Name))
|
2010-09-18 09:28:11 +08:00
|
|
|
LHS = ExprError();
|
2009-11-04 03:44:04 +08:00
|
|
|
|
|
|
|
if (!LHS.isInvalid())
|
2010-08-24 07:25:46 +08:00
|
|
|
LHS = Actions.ActOnMemberAccessExpr(getCurScope(), LHS.take(), OpLoc,
|
2012-01-27 17:46:47 +08:00
|
|
|
OpKind, SS, TemplateKWLoc, Name,
|
2012-02-08 00:50:53 +08:00
|
|
|
CurParsedObjCImpl ? CurParsedObjCImpl->Dcl : 0,
|
|
|
|
Tok.is(tok::l_paren));
|
2006-08-11 14:41:18 +08:00
|
|
|
break;
|
2006-08-24 11:51:22 +08:00
|
|
|
}
|
2006-08-11 14:41:18 +08:00
|
|
|
case tok::plusplus: // postfix-expression: postfix-expression '++'
|
|
|
|
case tok::minusminus: // postfix-expression: postfix-expression '--'
|
2008-12-09 21:15:23 +08:00
|
|
|
if (!LHS.isInvalid()) {
|
2010-07-03 01:43:08 +08:00
|
|
|
LHS = Actions.ActOnPostfixUnaryOp(getCurScope(), Tok.getLocation(),
|
2010-08-24 07:25:46 +08:00
|
|
|
Tok.getKind(), LHS.take());
|
2008-11-26 06:21:31 +08:00
|
|
|
}
|
2006-08-11 14:41:18 +08:00
|
|
|
ConsumeToken();
|
|
|
|
break;
|
2006-08-11 06:01:51 +08:00
|
|
|
}
|
|
|
|
}
|
2006-08-11 04:56:00 +08:00
|
|
|
}
|
|
|
|
|
2011-03-12 03:24:49 +08:00
|
|
|
/// ParseExprAfterUnaryExprOrTypeTrait - We parsed a typeof/sizeof/alignof/
|
|
|
|
/// vec_step and we are at the start of an expression or a parenthesized
|
|
|
|
/// type-id. OpTok is the operand token (typeof/sizeof/alignof). Returns the
|
|
|
|
/// expression (isCastExpr == false) or the type (isCastExpr == true).
|
2009-05-22 18:22:50 +08:00
|
|
|
///
|
2012-06-17 12:36:28 +08:00
|
|
|
/// \verbatim
|
2006-08-11 10:13:20 +08:00
|
|
|
/// unary-expression: [C99 6.5.3]
|
|
|
|
/// 'sizeof' unary-expression
|
|
|
|
/// 'sizeof' '(' type-name ')'
|
|
|
|
/// [GNU] '__alignof' unary-expression
|
|
|
|
/// [GNU] '__alignof' '(' type-name ')'
|
2012-07-01 05:33:57 +08:00
|
|
|
/// [C11] '_Alignof' '(' type-name ')'
|
2008-11-06 23:17:27 +08:00
|
|
|
/// [C++0x] 'alignof' '(' type-id ')'
|
2009-05-22 18:22:50 +08:00
|
|
|
///
|
|
|
|
/// [GNU] typeof-specifier:
|
|
|
|
/// typeof ( expressions )
|
|
|
|
/// typeof ( type-name )
|
|
|
|
/// [GNU/C++] typeof unary-expression
|
|
|
|
///
|
2011-03-12 03:24:49 +08:00
|
|
|
/// [OpenCL 1.1 6.11.12] vec_step built-in function:
|
|
|
|
/// vec_step ( expressions )
|
|
|
|
/// vec_step ( type-name )
|
2012-06-17 12:36:28 +08:00
|
|
|
/// \endverbatim
|
2010-08-24 14:29:42 +08:00
|
|
|
ExprResult
|
2011-03-12 03:24:49 +08:00
|
|
|
Parser::ParseExprAfterUnaryExprOrTypeTrait(const Token &OpTok,
|
|
|
|
bool &isCastExpr,
|
|
|
|
ParsedType &CastTy,
|
|
|
|
SourceRange &CastRange) {
|
2009-09-09 23:08:12 +08:00
|
|
|
|
|
|
|
assert((OpTok.is(tok::kw_typeof) || OpTok.is(tok::kw_sizeof) ||
|
2011-03-12 03:24:49 +08:00
|
|
|
OpTok.is(tok::kw___alignof) || OpTok.is(tok::kw_alignof) ||
|
2012-07-01 05:33:57 +08:00
|
|
|
OpTok.is(tok::kw__Alignof) || OpTok.is(tok::kw_vec_step)) &&
|
2011-03-12 03:24:49 +08:00
|
|
|
"Not a typeof/sizeof/alignof/vec_step expression!");
|
2009-05-22 18:22:50 +08:00
|
|
|
|
2010-08-24 14:29:42 +08:00
|
|
|
ExprResult Operand;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-05-22 18:22:50 +08:00
|
|
|
// If the operand doesn't start with an '(', it must be an expression.
|
2007-10-10 01:41:39 +08:00
|
|
|
if (Tok.isNot(tok::l_paren)) {
|
2009-05-22 18:22:50 +08:00
|
|
|
isCastExpr = false;
|
2012-03-11 15:00:24 +08:00
|
|
|
if (OpTok.is(tok::kw_typeof) && !getLangOpts().CPlusPlus) {
|
2009-05-22 18:22:50 +08:00
|
|
|
Diag(Tok,diag::err_expected_lparen_after_id) << OpTok.getIdentifierInfo();
|
|
|
|
return ExprError();
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-05-22 18:22:50 +08:00
|
|
|
Operand = ParseCastExpression(true/*isUnaryExpression*/);
|
2006-08-24 14:10:04 +08:00
|
|
|
} else {
|
|
|
|
// If it starts with a '(', we know that it is either a parenthesized
|
|
|
|
// type-name, or it is a unary-expression that starts with a compound
|
|
|
|
// literal, or starts with a primary-expression that is a parenthesized
|
|
|
|
// expression.
|
|
|
|
ParenParseOption ExprType = CastExpr;
|
2006-08-24 14:49:19 +08:00
|
|
|
SourceLocation LParenLoc = Tok.getLocation(), RParenLoc;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-11-25 09:26:41 +08:00
|
|
|
Operand = ParseParenExpression(ExprType, true/*stopIfCastExpr*/,
|
2011-07-02 06:22:59 +08:00
|
|
|
false, CastTy, RParenLoc);
|
2009-05-22 18:22:50 +08:00
|
|
|
CastRange = SourceRange(LParenLoc, RParenLoc);
|
2008-12-12 06:33:27 +08:00
|
|
|
|
2009-05-22 18:22:50 +08:00
|
|
|
// If ParseParenExpression parsed a '(typename)' sequence only, then this is
|
|
|
|
// a type.
|
|
|
|
if (ExprType == CastExpr) {
|
|
|
|
isCastExpr = true;
|
|
|
|
return ExprEmpty();
|
|
|
|
}
|
2008-12-12 06:33:27 +08:00
|
|
|
|
2012-03-11 15:00:24 +08:00
|
|
|
if (getLangOpts().CPlusPlus || OpTok.isNot(tok::kw_typeof)) {
|
2010-07-29 02:22:12 +08:00
|
|
|
// GNU typeof in C requires the expression to be parenthesized. Not so for
|
|
|
|
// sizeof/alignof or in C++. Therefore, the parenthesized expression is
|
|
|
|
// the start of a unary-expression, but doesn't include any postfix
|
|
|
|
// pieces. Parse these now if present.
|
2010-08-25 07:41:43 +08:00
|
|
|
if (!Operand.isInvalid())
|
|
|
|
Operand = ParsePostfixExpressionSuffix(Operand.get());
|
2010-07-29 02:22:12 +08:00
|
|
|
}
|
2006-08-24 14:10:04 +08:00
|
|
|
}
|
2008-12-12 06:33:27 +08:00
|
|
|
|
2009-05-22 18:22:50 +08:00
|
|
|
// If we get here, the operand to the typeof/sizeof/alignof was an expresion.
|
|
|
|
isCastExpr = false;
|
2012-08-24 05:35:17 +08:00
|
|
|
return Operand;
|
2009-05-22 18:22:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-17 12:36:28 +08:00
|
|
|
/// \brief Parse a sizeof or alignof expression.
|
|
|
|
///
|
|
|
|
/// \verbatim
|
2009-05-22 18:22:50 +08:00
|
|
|
/// unary-expression: [C99 6.5.3]
|
|
|
|
/// 'sizeof' unary-expression
|
|
|
|
/// 'sizeof' '(' type-name ')'
|
2013-01-29 18:18:18 +08:00
|
|
|
/// [C++11] 'sizeof' '...' '(' identifier ')'
|
2009-05-22 18:22:50 +08:00
|
|
|
/// [GNU] '__alignof' unary-expression
|
|
|
|
/// [GNU] '__alignof' '(' type-name ')'
|
2012-07-01 05:33:57 +08:00
|
|
|
/// [C11] '_Alignof' '(' type-name ')'
|
2013-01-29 18:18:18 +08:00
|
|
|
/// [C++11] 'alignof' '(' type-id ')'
|
2012-06-17 12:36:28 +08:00
|
|
|
/// \endverbatim
|
2011-03-12 03:24:49 +08:00
|
|
|
ExprResult Parser::ParseUnaryExprOrTypeTraitExpression() {
|
2012-07-01 05:33:57 +08:00
|
|
|
assert((Tok.is(tok::kw_sizeof) || Tok.is(tok::kw___alignof) ||
|
|
|
|
Tok.is(tok::kw_alignof) || Tok.is(tok::kw__Alignof) ||
|
|
|
|
Tok.is(tok::kw_vec_step)) &&
|
2011-03-12 03:24:49 +08:00
|
|
|
"Not a sizeof/alignof/vec_step expression!");
|
2009-05-22 18:22:50 +08:00
|
|
|
Token OpTok = Tok;
|
|
|
|
ConsumeToken();
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2013-01-29 18:18:18 +08:00
|
|
|
// [C++11] 'sizeof' '...' '(' identifier ')'
|
2011-01-05 01:33:58 +08:00
|
|
|
if (Tok.is(tok::ellipsis) && OpTok.is(tok::kw_sizeof)) {
|
|
|
|
SourceLocation EllipsisLoc = ConsumeToken();
|
|
|
|
SourceLocation LParenLoc, RParenLoc;
|
|
|
|
IdentifierInfo *Name = 0;
|
|
|
|
SourceLocation NameLoc;
|
|
|
|
if (Tok.is(tok::l_paren)) {
|
2011-10-13 00:37:45 +08:00
|
|
|
BalancedDelimiterTracker T(*this, tok::l_paren);
|
|
|
|
T.consumeOpen();
|
|
|
|
LParenLoc = T.getOpenLocation();
|
2011-01-05 01:33:58 +08:00
|
|
|
if (Tok.is(tok::identifier)) {
|
|
|
|
Name = Tok.getIdentifierInfo();
|
|
|
|
NameLoc = ConsumeToken();
|
2011-10-13 00:37:45 +08:00
|
|
|
T.consumeClose();
|
|
|
|
RParenLoc = T.getCloseLocation();
|
2011-01-05 01:33:58 +08:00
|
|
|
if (RParenLoc.isInvalid())
|
|
|
|
RParenLoc = PP.getLocForEndOfToken(NameLoc);
|
|
|
|
} else {
|
|
|
|
Diag(Tok, diag::err_expected_parameter_pack);
|
|
|
|
SkipUntil(tok::r_paren);
|
|
|
|
}
|
|
|
|
} else if (Tok.is(tok::identifier)) {
|
|
|
|
Name = Tok.getIdentifierInfo();
|
|
|
|
NameLoc = ConsumeToken();
|
|
|
|
LParenLoc = PP.getLocForEndOfToken(EllipsisLoc);
|
|
|
|
RParenLoc = PP.getLocForEndOfToken(NameLoc);
|
|
|
|
Diag(LParenLoc, diag::err_paren_sizeof_parameter_pack)
|
|
|
|
<< Name
|
|
|
|
<< FixItHint::CreateInsertion(LParenLoc, "(")
|
|
|
|
<< FixItHint::CreateInsertion(RParenLoc, ")");
|
|
|
|
} else {
|
|
|
|
Diag(Tok, diag::err_sizeof_parameter_pack);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Name)
|
|
|
|
return ExprError();
|
|
|
|
|
|
|
|
return Actions.ActOnSizeofParameterPackExpr(getCurScope(),
|
|
|
|
OpTok.getLocation(),
|
|
|
|
*Name, NameLoc,
|
|
|
|
RParenLoc);
|
|
|
|
}
|
2011-10-18 07:06:20 +08:00
|
|
|
|
2012-07-01 05:33:57 +08:00
|
|
|
if (OpTok.is(tok::kw_alignof) || OpTok.is(tok::kw__Alignof))
|
2011-10-18 07:06:20 +08:00
|
|
|
Diag(OpTok, diag::warn_cxx98_compat_alignof);
|
|
|
|
|
2012-09-26 12:34:21 +08:00
|
|
|
EnterExpressionEvaluationContext Unevaluated(Actions, Sema::Unevaluated,
|
|
|
|
Sema::ReuseLambdaContextDecl);
|
2012-01-21 09:01:51 +08:00
|
|
|
|
2009-05-22 18:22:50 +08:00
|
|
|
bool isCastExpr;
|
2010-08-24 13:47:05 +08:00
|
|
|
ParsedType CastTy;
|
2009-05-22 18:22:50 +08:00
|
|
|
SourceRange CastRange;
|
2011-03-12 03:24:49 +08:00
|
|
|
ExprResult Operand = ParseExprAfterUnaryExprOrTypeTrait(OpTok,
|
|
|
|
isCastExpr,
|
|
|
|
CastTy,
|
|
|
|
CastRange);
|
|
|
|
|
|
|
|
UnaryExprOrTypeTrait ExprKind = UETT_SizeOf;
|
2012-07-01 05:33:57 +08:00
|
|
|
if (OpTok.is(tok::kw_alignof) || OpTok.is(tok::kw___alignof) ||
|
|
|
|
OpTok.is(tok::kw__Alignof))
|
2011-03-12 03:24:49 +08:00
|
|
|
ExprKind = UETT_AlignOf;
|
|
|
|
else if (OpTok.is(tok::kw_vec_step))
|
|
|
|
ExprKind = UETT_VecStep;
|
2009-05-22 18:22:50 +08:00
|
|
|
|
|
|
|
if (isCastExpr)
|
2011-03-12 03:24:49 +08:00
|
|
|
return Actions.ActOnUnaryExprOrTypeTraitExpr(OpTok.getLocation(),
|
|
|
|
ExprKind,
|
|
|
|
/*isType=*/true,
|
|
|
|
CastTy.getAsOpaquePtr(),
|
|
|
|
CastRange);
|
2009-05-22 18:22:50 +08:00
|
|
|
|
2013-01-29 18:18:18 +08:00
|
|
|
if (OpTok.is(tok::kw_alignof) || OpTok.is(tok::kw__Alignof))
|
|
|
|
Diag(OpTok, diag::ext_alignof_expr) << OpTok.getIdentifierInfo();
|
|
|
|
|
2006-08-24 14:10:04 +08:00
|
|
|
// If we get here, the operand to the sizeof/alignof was an expresion.
|
2008-12-09 21:15:23 +08:00
|
|
|
if (!Operand.isInvalid())
|
2011-03-12 03:24:49 +08:00
|
|
|
Operand = Actions.ActOnUnaryExprOrTypeTraitExpr(OpTok.getLocation(),
|
|
|
|
ExprKind,
|
|
|
|
/*isType=*/false,
|
|
|
|
Operand.release(),
|
|
|
|
CastRange);
|
2012-08-24 05:35:17 +08:00
|
|
|
return Operand;
|
2006-08-11 10:13:20 +08:00
|
|
|
}
|
|
|
|
|
2006-08-13 03:16:08 +08:00
|
|
|
/// ParseBuiltinPrimaryExpression
|
|
|
|
///
|
2012-06-17 12:36:28 +08:00
|
|
|
/// \verbatim
|
2006-08-13 03:16:08 +08:00
|
|
|
/// primary-expression: [C99 6.5.1]
|
|
|
|
/// [GNU] '__builtin_va_arg' '(' assignment-expression ',' type-name ')'
|
|
|
|
/// [GNU] '__builtin_offsetof' '(' type-name ',' offsetof-member-designator')'
|
|
|
|
/// [GNU] '__builtin_choose_expr' '(' assign-expr ',' assign-expr ','
|
|
|
|
/// assign-expr ')'
|
|
|
|
/// [GNU] '__builtin_types_compatible_p' '(' type-name ',' type-name ')'
|
2011-11-05 11:47:48 +08:00
|
|
|
/// [OCL] '__builtin_astype' '(' assignment-expression ',' type-name ')'
|
2009-09-09 23:08:12 +08:00
|
|
|
///
|
2006-08-13 03:16:08 +08:00
|
|
|
/// [GNU] offsetof-member-designator:
|
|
|
|
/// [GNU] identifier
|
|
|
|
/// [GNU] offsetof-member-designator '.' identifier
|
|
|
|
/// [GNU] offsetof-member-designator '[' expression ']'
|
2012-06-17 12:36:28 +08:00
|
|
|
/// \endverbatim
|
2010-08-24 14:29:42 +08:00
|
|
|
ExprResult Parser::ParseBuiltinPrimaryExpression() {
|
|
|
|
ExprResult Res;
|
2006-08-13 03:16:08 +08:00
|
|
|
const IdentifierInfo *BuiltinII = Tok.getIdentifierInfo();
|
|
|
|
|
|
|
|
tok::TokenKind T = Tok.getKind();
|
2006-10-16 14:06:51 +08:00
|
|
|
SourceLocation StartLoc = ConsumeToken(); // Eat the builtin identifier.
|
2006-08-13 03:16:08 +08:00
|
|
|
|
|
|
|
// All of these start with an open paren.
|
2008-12-12 06:33:27 +08:00
|
|
|
if (Tok.isNot(tok::l_paren))
|
|
|
|
return ExprError(Diag(Tok, diag::err_expected_lparen_after_id)
|
|
|
|
<< BuiltinII);
|
|
|
|
|
2011-10-13 00:37:45 +08:00
|
|
|
BalancedDelimiterTracker PT(*this, tok::l_paren);
|
|
|
|
PT.consumeOpen();
|
|
|
|
|
2006-08-24 11:51:22 +08:00
|
|
|
// TODO: Build AST.
|
|
|
|
|
2006-08-13 03:16:08 +08:00
|
|
|
switch (T) {
|
2011-09-23 13:06:16 +08:00
|
|
|
default: llvm_unreachable("Not a builtin primary expression!");
|
2007-10-16 04:28:48 +08:00
|
|
|
case tok::kw___builtin_va_arg: {
|
2010-08-24 14:29:42 +08:00
|
|
|
ExprResult Expr(ParseAssignmentExpression());
|
2006-08-13 03:30:51 +08:00
|
|
|
|
2006-08-15 11:41:14 +08:00
|
|
|
if (ExpectAndConsume(tok::comma, diag::err_expected_comma, "",tok::r_paren))
|
2010-09-18 09:28:11 +08:00
|
|
|
Expr = ExprError();
|
2006-08-13 03:30:51 +08:00
|
|
|
|
2009-02-19 01:45:20 +08:00
|
|
|
TypeResult Ty = ParseTypeName();
|
2008-12-09 21:15:23 +08:00
|
|
|
|
2007-10-16 04:28:48 +08:00
|
|
|
if (Tok.isNot(tok::r_paren)) {
|
|
|
|
Diag(Tok, diag::err_expected_rparen);
|
2010-09-18 09:28:11 +08:00
|
|
|
Expr = ExprError();
|
2007-10-16 04:28:48 +08:00
|
|
|
}
|
2010-09-18 09:28:11 +08:00
|
|
|
|
|
|
|
if (Expr.isInvalid() || Ty.isInvalid())
|
2009-02-19 01:45:20 +08:00
|
|
|
Res = ExprError();
|
|
|
|
else
|
2010-08-24 07:25:46 +08:00
|
|
|
Res = Actions.ActOnVAArg(StartLoc, Expr.take(), Ty.get(), ConsumeParen());
|
2006-08-13 03:16:08 +08:00
|
|
|
break;
|
2007-10-16 04:28:48 +08:00
|
|
|
}
|
2007-08-30 23:51:11 +08:00
|
|
|
case tok::kw___builtin_offsetof: {
|
2007-08-31 01:08:45 +08:00
|
|
|
SourceLocation TypeLoc = Tok.getLocation();
|
2009-02-19 01:45:20 +08:00
|
|
|
TypeResult Ty = ParseTypeName();
|
2009-03-25 01:21:43 +08:00
|
|
|
if (Ty.isInvalid()) {
|
|
|
|
SkipUntil(tok::r_paren);
|
|
|
|
return ExprError();
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2006-08-15 11:41:14 +08:00
|
|
|
if (ExpectAndConsume(tok::comma, diag::err_expected_comma, "",tok::r_paren))
|
2008-12-12 06:33:27 +08:00
|
|
|
return ExprError();
|
|
|
|
|
2006-08-13 03:16:08 +08:00
|
|
|
// We must have at least one identifier here.
|
2007-10-10 01:41:39 +08:00
|
|
|
if (Tok.isNot(tok::identifier)) {
|
2007-08-30 23:51:11 +08:00
|
|
|
Diag(Tok, diag::err_expected_ident);
|
|
|
|
SkipUntil(tok::r_paren);
|
2008-12-12 06:33:27 +08:00
|
|
|
return ExprError();
|
2007-08-30 23:51:11 +08:00
|
|
|
}
|
2008-12-12 06:33:27 +08:00
|
|
|
|
2007-08-30 23:51:11 +08:00
|
|
|
// Keep track of the various subcomponents we see.
|
2011-07-23 18:55:15 +08:00
|
|
|
SmallVector<Sema::OffsetOfComponent, 4> Comps;
|
2008-12-12 06:33:27 +08:00
|
|
|
|
2010-08-27 07:41:50 +08:00
|
|
|
Comps.push_back(Sema::OffsetOfComponent());
|
2007-08-30 23:51:11 +08:00
|
|
|
Comps.back().isBrackets = false;
|
|
|
|
Comps.back().U.IdentInfo = Tok.getIdentifierInfo();
|
|
|
|
Comps.back().LocStart = Comps.back().LocEnd = ConsumeToken();
|
2006-08-13 03:26:13 +08:00
|
|
|
|
2008-11-26 06:21:31 +08:00
|
|
|
// FIXME: This loop leaks the index expressions on error.
|
2006-08-13 03:16:08 +08:00
|
|
|
while (1) {
|
2007-10-10 01:41:39 +08:00
|
|
|
if (Tok.is(tok::period)) {
|
2006-08-13 03:16:08 +08:00
|
|
|
// offsetof-member-designator: offsetof-member-designator '.' identifier
|
2010-08-27 07:41:50 +08:00
|
|
|
Comps.push_back(Sema::OffsetOfComponent());
|
2007-08-30 23:51:11 +08:00
|
|
|
Comps.back().isBrackets = false;
|
|
|
|
Comps.back().LocStart = ConsumeToken();
|
2008-12-12 06:33:27 +08:00
|
|
|
|
2007-10-10 01:41:39 +08:00
|
|
|
if (Tok.isNot(tok::identifier)) {
|
2007-08-30 23:51:11 +08:00
|
|
|
Diag(Tok, diag::err_expected_ident);
|
|
|
|
SkipUntil(tok::r_paren);
|
2008-12-12 06:33:27 +08:00
|
|
|
return ExprError();
|
2007-08-30 23:51:11 +08:00
|
|
|
}
|
|
|
|
Comps.back().U.IdentInfo = Tok.getIdentifierInfo();
|
|
|
|
Comps.back().LocEnd = ConsumeToken();
|
2008-12-12 06:33:27 +08:00
|
|
|
|
2007-10-10 01:41:39 +08:00
|
|
|
} else if (Tok.is(tok::l_square)) {
|
2012-04-10 09:32:12 +08:00
|
|
|
if (CheckProhibitedCXX11Attribute())
|
|
|
|
return ExprError();
|
|
|
|
|
2006-08-13 03:16:08 +08:00
|
|
|
// offsetof-member-designator: offsetof-member-design '[' expression ']'
|
2010-08-27 07:41:50 +08:00
|
|
|
Comps.push_back(Sema::OffsetOfComponent());
|
2007-08-30 23:51:11 +08:00
|
|
|
Comps.back().isBrackets = true;
|
2011-10-13 00:37:45 +08:00
|
|
|
BalancedDelimiterTracker ST(*this, tok::l_square);
|
|
|
|
ST.consumeOpen();
|
|
|
|
Comps.back().LocStart = ST.getOpenLocation();
|
2006-08-13 03:16:08 +08:00
|
|
|
Res = ParseExpression();
|
2008-12-09 21:15:23 +08:00
|
|
|
if (Res.isInvalid()) {
|
2006-08-13 03:16:08 +08:00
|
|
|
SkipUntil(tok::r_paren);
|
2012-08-24 05:35:17 +08:00
|
|
|
return Res;
|
2006-08-13 03:16:08 +08:00
|
|
|
}
|
2008-12-10 08:02:53 +08:00
|
|
|
Comps.back().U.E = Res.release();
|
2006-08-13 03:16:08 +08:00
|
|
|
|
2011-10-13 00:37:45 +08:00
|
|
|
ST.consumeClose();
|
|
|
|
Comps.back().LocEnd = ST.getCloseLocation();
|
2009-06-28 04:38:33 +08:00
|
|
|
} else {
|
|
|
|
if (Tok.isNot(tok::r_paren)) {
|
2011-10-13 00:37:45 +08:00
|
|
|
PT.consumeClose();
|
2009-06-28 04:38:33 +08:00
|
|
|
Res = ExprError();
|
|
|
|
} else if (Ty.isInvalid()) {
|
2009-02-19 01:45:20 +08:00
|
|
|
Res = ExprError();
|
2009-06-28 04:38:33 +08:00
|
|
|
} else {
|
2011-10-13 00:37:45 +08:00
|
|
|
PT.consumeClose();
|
2010-07-03 01:43:08 +08:00
|
|
|
Res = Actions.ActOnBuiltinOffsetOf(getCurScope(), StartLoc, TypeLoc,
|
2011-10-13 00:37:45 +08:00
|
|
|
Ty.get(), &Comps[0], Comps.size(),
|
|
|
|
PT.getCloseLocation());
|
2009-06-28 04:38:33 +08:00
|
|
|
}
|
2007-08-30 23:52:49 +08:00
|
|
|
break;
|
2006-08-13 03:16:08 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2007-08-30 23:51:11 +08:00
|
|
|
}
|
2007-08-04 05:21:27 +08:00
|
|
|
case tok::kw___builtin_choose_expr: {
|
2010-08-24 14:29:42 +08:00
|
|
|
ExprResult Cond(ParseAssignmentExpression());
|
2008-12-09 21:15:23 +08:00
|
|
|
if (Cond.isInvalid()) {
|
2007-08-04 05:21:27 +08:00
|
|
|
SkipUntil(tok::r_paren);
|
2012-08-24 05:35:17 +08:00
|
|
|
return Cond;
|
2007-08-04 05:21:27 +08:00
|
|
|
}
|
2006-08-15 11:41:14 +08:00
|
|
|
if (ExpectAndConsume(tok::comma, diag::err_expected_comma, "",tok::r_paren))
|
2008-12-12 06:33:27 +08:00
|
|
|
return ExprError();
|
|
|
|
|
2010-08-24 14:29:42 +08:00
|
|
|
ExprResult Expr1(ParseAssignmentExpression());
|
2008-12-09 21:15:23 +08:00
|
|
|
if (Expr1.isInvalid()) {
|
2007-08-04 05:21:27 +08:00
|
|
|
SkipUntil(tok::r_paren);
|
2012-08-24 05:35:17 +08:00
|
|
|
return Expr1;
|
2008-12-09 21:15:23 +08:00
|
|
|
}
|
2006-08-15 11:41:14 +08:00
|
|
|
if (ExpectAndConsume(tok::comma, diag::err_expected_comma, "",tok::r_paren))
|
2008-12-12 06:33:27 +08:00
|
|
|
return ExprError();
|
|
|
|
|
2010-08-24 14:29:42 +08:00
|
|
|
ExprResult Expr2(ParseAssignmentExpression());
|
2008-12-09 21:15:23 +08:00
|
|
|
if (Expr2.isInvalid()) {
|
2007-08-04 05:21:27 +08:00
|
|
|
SkipUntil(tok::r_paren);
|
2012-08-24 05:35:17 +08:00
|
|
|
return Expr2;
|
2008-12-09 21:15:23 +08:00
|
|
|
}
|
2007-10-10 01:41:39 +08:00
|
|
|
if (Tok.isNot(tok::r_paren)) {
|
2007-08-04 05:21:27 +08:00
|
|
|
Diag(Tok, diag::err_expected_rparen);
|
2008-12-12 06:33:27 +08:00
|
|
|
return ExprError();
|
2007-08-04 05:21:27 +08:00
|
|
|
}
|
2010-08-24 07:25:46 +08:00
|
|
|
Res = Actions.ActOnChooseExpr(StartLoc, Cond.take(), Expr1.take(),
|
|
|
|
Expr2.take(), ConsumeParen());
|
2007-08-30 23:52:49 +08:00
|
|
|
break;
|
2007-08-04 05:21:27 +08:00
|
|
|
}
|
2011-06-04 08:47:47 +08:00
|
|
|
case tok::kw___builtin_astype: {
|
|
|
|
// The first argument is an expression to be converted, followed by a comma.
|
|
|
|
ExprResult Expr(ParseAssignmentExpression());
|
|
|
|
if (Expr.isInvalid()) {
|
|
|
|
SkipUntil(tok::r_paren);
|
|
|
|
return ExprError();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ExpectAndConsume(tok::comma, diag::err_expected_comma, "",
|
|
|
|
tok::r_paren))
|
|
|
|
return ExprError();
|
|
|
|
|
|
|
|
// Second argument is the type to bitcast to.
|
|
|
|
TypeResult DestTy = ParseTypeName();
|
|
|
|
if (DestTy.isInvalid())
|
|
|
|
return ExprError();
|
|
|
|
|
|
|
|
// Attempt to consume the r-paren.
|
|
|
|
if (Tok.isNot(tok::r_paren)) {
|
|
|
|
Diag(Tok, diag::err_expected_rparen);
|
|
|
|
SkipUntil(tok::r_paren);
|
|
|
|
return ExprError();
|
|
|
|
}
|
|
|
|
|
|
|
|
Res = Actions.ActOnAsTypeExpr(Expr.take(), DestTy.get(), StartLoc,
|
|
|
|
ConsumeParen());
|
|
|
|
break;
|
2008-12-12 05:36:32 +08:00
|
|
|
}
|
2013-09-18 11:29:45 +08:00
|
|
|
case tok::kw___builtin_convertvector: {
|
|
|
|
// The first argument is an expression to be converted, followed by a comma.
|
|
|
|
ExprResult Expr(ParseAssignmentExpression());
|
|
|
|
if (Expr.isInvalid()) {
|
|
|
|
SkipUntil(tok::r_paren);
|
|
|
|
return ExprError();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ExpectAndConsume(tok::comma, diag::err_expected_comma, "",
|
|
|
|
tok::r_paren))
|
|
|
|
return ExprError();
|
|
|
|
|
|
|
|
// Second argument is the type to bitcast to.
|
|
|
|
TypeResult DestTy = ParseTypeName();
|
|
|
|
if (DestTy.isInvalid())
|
|
|
|
return ExprError();
|
|
|
|
|
|
|
|
// Attempt to consume the r-paren.
|
|
|
|
if (Tok.isNot(tok::r_paren)) {
|
|
|
|
Diag(Tok, diag::err_expected_rparen);
|
|
|
|
SkipUntil(tok::r_paren);
|
|
|
|
return ExprError();
|
|
|
|
}
|
|
|
|
|
|
|
|
Res = Actions.ActOnConvertVectorExpr(Expr.take(), DestTy.get(), StartLoc,
|
|
|
|
ConsumeParen());
|
|
|
|
break;
|
|
|
|
}
|
2011-07-08 12:59:44 +08:00
|
|
|
}
|
2008-12-12 05:36:32 +08:00
|
|
|
|
2010-08-24 07:25:46 +08:00
|
|
|
if (Res.isInvalid())
|
|
|
|
return ExprError();
|
|
|
|
|
2006-08-13 03:16:08 +08:00
|
|
|
// These can be followed by postfix-expr pieces because they are
|
|
|
|
// primary-expressions.
|
2010-08-24 07:25:46 +08:00
|
|
|
return ParsePostfixExpressionSuffix(Res.take());
|
2006-08-13 03:16:08 +08:00
|
|
|
}
|
|
|
|
|
2006-08-11 09:33:00 +08:00
|
|
|
/// ParseParenExpression - This parses the unit that starts with a '(' token,
|
|
|
|
/// based on what is allowed by ExprType. The actual thing parsed is returned
|
2009-05-22 18:23:40 +08:00
|
|
|
/// in ExprType. If stopIfCastExpr is true, it will only return the parsed type,
|
|
|
|
/// not the parsed cast-expression.
|
2006-08-11 09:33:00 +08:00
|
|
|
///
|
2012-06-17 12:36:28 +08:00
|
|
|
/// \verbatim
|
2006-08-11 09:33:00 +08:00
|
|
|
/// primary-expression: [C99 6.5.1]
|
2006-08-10 12:23:57 +08:00
|
|
|
/// '(' expression ')'
|
2006-08-11 06:01:51 +08:00
|
|
|
/// [GNU] '(' compound-statement ')' (if !ParenExprOnly)
|
|
|
|
/// postfix-expression: [C99 6.5.2]
|
|
|
|
/// '(' type-name ')' '{' initializer-list '}'
|
|
|
|
/// '(' type-name ')' '{' initializer-list ',' '}'
|
2006-08-11 09:33:00 +08:00
|
|
|
/// cast-expression: [C99 6.5.4]
|
|
|
|
/// '(' type-name ')' cast-expression
|
2011-06-16 07:02:42 +08:00
|
|
|
/// [ARC] bridged-cast-expression
|
|
|
|
///
|
|
|
|
/// [ARC] bridged-cast-expression:
|
|
|
|
/// (__bridge type-name) cast-expression
|
|
|
|
/// (__bridge_transfer type-name) cast-expression
|
|
|
|
/// (__bridge_retained type-name) cast-expression
|
2012-06-17 12:36:28 +08:00
|
|
|
/// \endverbatim
|
2010-08-24 14:29:42 +08:00
|
|
|
ExprResult
|
2009-05-22 18:23:40 +08:00
|
|
|
Parser::ParseParenExpression(ParenParseOption &ExprType, bool stopIfCastExpr,
|
2011-07-02 06:22:59 +08:00
|
|
|
bool isTypeCast, ParsedType &CastTy,
|
2009-08-11 07:49:36 +08:00
|
|
|
SourceLocation &RParenLoc) {
|
2007-10-10 01:41:39 +08:00
|
|
|
assert(Tok.is(tok::l_paren) && "Not a paren expr!");
|
2011-10-13 00:37:45 +08:00
|
|
|
BalancedDelimiterTracker T(*this, tok::l_paren);
|
|
|
|
if (T.consumeOpen())
|
|
|
|
return ExprError();
|
|
|
|
SourceLocation OpenLoc = T.getOpenLocation();
|
|
|
|
|
2010-08-24 14:29:42 +08:00
|
|
|
ExprResult Result(true);
|
2009-05-22 18:24:42 +08:00
|
|
|
bool isAmbiguousTypeId;
|
2010-08-24 13:47:05 +08:00
|
|
|
CastTy = ParsedType();
|
2008-12-12 06:33:27 +08:00
|
|
|
|
2010-09-15 07:59:36 +08:00
|
|
|
if (Tok.is(tok::code_completion)) {
|
|
|
|
Actions.CodeCompleteOrdinaryName(getCurScope(),
|
|
|
|
ExprType >= CompoundLiteral? Sema::PCC_ParenthesizedExpression
|
|
|
|
: Sema::PCC_Expression);
|
2011-09-04 11:32:15 +08:00
|
|
|
cutOffParsing();
|
2010-09-15 07:59:36 +08:00
|
|
|
return ExprError();
|
|
|
|
}
|
2011-04-06 10:35:25 +08:00
|
|
|
|
2011-12-20 05:06:15 +08:00
|
|
|
// Diagnose use of bridge casts in non-arc mode.
|
2012-03-11 15:00:24 +08:00
|
|
|
bool BridgeCast = (getLangOpts().ObjC2 &&
|
2011-12-20 05:06:15 +08:00
|
|
|
(Tok.is(tok::kw___bridge) ||
|
|
|
|
Tok.is(tok::kw___bridge_transfer) ||
|
|
|
|
Tok.is(tok::kw___bridge_retained) ||
|
|
|
|
Tok.is(tok::kw___bridge_retain)));
|
2012-03-11 15:00:24 +08:00
|
|
|
if (BridgeCast && !getLangOpts().ObjCAutoRefCount) {
|
2013-04-03 07:48:59 +08:00
|
|
|
if (Tok.isNot(tok::kw___bridge)) {
|
|
|
|
StringRef BridgeCastName = Tok.getName();
|
|
|
|
SourceLocation BridgeKeywordLoc = ConsumeToken();
|
|
|
|
if (!PP.getSourceManager().isInSystemHeader(BridgeKeywordLoc))
|
|
|
|
Diag(BridgeKeywordLoc, diag::warn_arc_bridge_cast_nonarc)
|
|
|
|
<< BridgeCastName
|
|
|
|
<< FixItHint::CreateReplacement(BridgeKeywordLoc, "");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ConsumeToken(); // consume __bridge
|
2011-12-20 05:06:15 +08:00
|
|
|
BridgeCast = false;
|
|
|
|
}
|
|
|
|
|
2011-04-06 10:35:25 +08:00
|
|
|
// None of these cases should fall through with an invalid Result
|
|
|
|
// unless they've already reported an error.
|
2007-10-10 01:41:39 +08:00
|
|
|
if (ExprType >= CompoundStmt && Tok.is(tok::l_brace)) {
|
2006-08-11 06:01:51 +08:00
|
|
|
Diag(Tok, diag::ext_gnu_statement_expr);
|
2012-04-04 09:27:53 +08:00
|
|
|
Actions.ActOnStartStmtExpr();
|
|
|
|
|
2012-04-14 08:33:13 +08:00
|
|
|
StmtResult Stmt(ParseCompoundStatement(true));
|
2006-08-11 09:33:00 +08:00
|
|
|
ExprType = CompoundStmt;
|
2008-12-09 21:15:23 +08:00
|
|
|
|
2007-07-25 00:58:17 +08:00
|
|
|
// If the substmt parsed correctly, build the AST node.
|
2012-04-04 09:27:53 +08:00
|
|
|
if (!Stmt.isInvalid()) {
|
2010-08-24 07:25:46 +08:00
|
|
|
Result = Actions.ActOnStmtExpr(OpenLoc, Stmt.take(), Tok.getLocation());
|
2012-04-04 09:27:53 +08:00
|
|
|
} else {
|
|
|
|
Actions.ActOnStmtExprError();
|
|
|
|
}
|
2011-12-20 05:06:15 +08:00
|
|
|
} else if (ExprType >= CompoundLiteral && BridgeCast) {
|
2011-06-18 05:56:12 +08:00
|
|
|
tok::TokenKind tokenKind = Tok.getKind();
|
|
|
|
SourceLocation BridgeKeywordLoc = ConsumeToken();
|
|
|
|
|
2011-06-16 07:02:42 +08:00
|
|
|
// Parse an Objective-C ARC ownership cast expression.
|
|
|
|
ObjCBridgeCastKind Kind;
|
2011-06-18 05:56:12 +08:00
|
|
|
if (tokenKind == tok::kw___bridge)
|
2011-06-16 07:02:42 +08:00
|
|
|
Kind = OBC_Bridge;
|
2011-06-18 05:56:12 +08:00
|
|
|
else if (tokenKind == tok::kw___bridge_transfer)
|
2011-06-16 07:02:42 +08:00
|
|
|
Kind = OBC_BridgeTransfer;
|
2011-06-18 05:56:12 +08:00
|
|
|
else if (tokenKind == tok::kw___bridge_retained)
|
|
|
|
Kind = OBC_BridgeRetained;
|
|
|
|
else {
|
|
|
|
// As a hopefully temporary workaround, allow __bridge_retain as
|
|
|
|
// a synonym for __bridge_retained, but only in system headers.
|
|
|
|
assert(tokenKind == tok::kw___bridge_retain);
|
2011-06-16 07:02:42 +08:00
|
|
|
Kind = OBC_BridgeRetained;
|
2011-06-18 05:56:12 +08:00
|
|
|
if (!PP.getSourceManager().isInSystemHeader(BridgeKeywordLoc))
|
|
|
|
Diag(BridgeKeywordLoc, diag::err_arc_bridge_retain)
|
|
|
|
<< FixItHint::CreateReplacement(BridgeKeywordLoc,
|
|
|
|
"__bridge_retained");
|
|
|
|
}
|
2011-06-16 07:02:42 +08:00
|
|
|
|
|
|
|
TypeResult Ty = ParseTypeName();
|
2011-10-13 00:37:45 +08:00
|
|
|
T.consumeClose();
|
|
|
|
RParenLoc = T.getCloseLocation();
|
2011-07-02 06:22:59 +08:00
|
|
|
ExprResult SubExpr = ParseCastExpression(/*isUnaryExpression=*/false);
|
2011-06-16 07:02:42 +08:00
|
|
|
|
|
|
|
if (Ty.isInvalid() || SubExpr.isInvalid())
|
|
|
|
return ExprError();
|
|
|
|
|
|
|
|
return Actions.ActOnObjCBridgedCast(getCurScope(), OpenLoc, Kind,
|
|
|
|
BridgeKeywordLoc, Ty.get(),
|
|
|
|
RParenLoc, SubExpr.get());
|
2009-05-22 18:24:42 +08:00
|
|
|
} else if (ExprType >= CompoundLiteral &&
|
|
|
|
isTypeIdInParens(isAmbiguousTypeId)) {
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2006-08-13 00:54:25 +08:00
|
|
|
// Otherwise, this is a compound literal expression or cast expression.
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-05-22 18:24:42 +08:00
|
|
|
// In C++, if the type-id is ambiguous we disambiguate based on context.
|
|
|
|
// If stopIfCastExpr is true the context is a typeof/sizeof/alignof
|
|
|
|
// in which case we should treat it as type-id.
|
|
|
|
// if stopIfCastExpr is false, we need to determine the context past the
|
|
|
|
// parens, so we defer to ParseCXXAmbiguousParenExpression for that.
|
2011-10-13 00:37:45 +08:00
|
|
|
if (isAmbiguousTypeId && !stopIfCastExpr) {
|
|
|
|
ExprResult res = ParseCXXAmbiguousParenExpression(ExprType, CastTy, T);
|
|
|
|
RParenLoc = T.getCloseLocation();
|
|
|
|
return res;
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-07-02 06:22:59 +08:00
|
|
|
// Parse the type declarator.
|
|
|
|
DeclSpec DS(AttrFactory);
|
|
|
|
ParseSpecifierQualifierList(DS);
|
|
|
|
Declarator DeclaratorInfo(DS, Declarator::TypeNameContext);
|
|
|
|
ParseDeclarator(DeclaratorInfo);
|
2010-09-15 22:51:05 +08:00
|
|
|
|
2010-09-16 07:19:31 +08:00
|
|
|
// If our type is followed by an identifier and either ':' or ']', then
|
|
|
|
// this is probably an Objective-C message send where the leading '[' is
|
|
|
|
// missing. Recover as if that were the case.
|
2011-07-02 06:22:59 +08:00
|
|
|
if (!DeclaratorInfo.isInvalidType() && Tok.is(tok::identifier) &&
|
2012-03-11 15:00:24 +08:00
|
|
|
!InMessageExpression && getLangOpts().ObjC1 &&
|
2011-07-02 06:22:59 +08:00
|
|
|
(NextToken().is(tok::colon) || NextToken().is(tok::r_square))) {
|
|
|
|
TypeResult Ty;
|
|
|
|
{
|
|
|
|
InMessageExpressionRAIIObject InMessage(*this, false);
|
|
|
|
Ty = Actions.ActOnTypeName(getCurScope(), DeclaratorInfo);
|
|
|
|
}
|
2010-09-16 07:19:31 +08:00
|
|
|
Result = ParseObjCMessageExpressionBody(SourceLocation(),
|
|
|
|
SourceLocation(),
|
|
|
|
Ty.get(), 0);
|
|
|
|
} else {
|
|
|
|
// Match the ')'.
|
2011-10-13 00:37:45 +08:00
|
|
|
T.consumeClose();
|
|
|
|
RParenLoc = T.getCloseLocation();
|
2010-09-16 07:19:31 +08:00
|
|
|
if (Tok.is(tok::l_brace)) {
|
|
|
|
ExprType = CompoundLiteral;
|
2011-07-02 06:22:59 +08:00
|
|
|
TypeResult Ty;
|
|
|
|
{
|
|
|
|
InMessageExpressionRAIIObject InMessage(*this, false);
|
|
|
|
Ty = Actions.ActOnTypeName(getCurScope(), DeclaratorInfo);
|
|
|
|
}
|
2010-09-16 07:19:31 +08:00
|
|
|
return ParseCompoundLiteralExpression(Ty.get(), OpenLoc, RParenLoc);
|
|
|
|
}
|
2008-12-12 06:33:27 +08:00
|
|
|
|
2010-09-16 07:19:31 +08:00
|
|
|
if (ExprType == CastExpr) {
|
|
|
|
// We parsed '(' type-name ')' and the thing after it wasn't a '{'.
|
2009-01-20 06:31:54 +08:00
|
|
|
|
2011-07-02 06:22:59 +08:00
|
|
|
if (DeclaratorInfo.isInvalidType())
|
2010-09-16 07:19:31 +08:00
|
|
|
return ExprError();
|
2009-02-19 01:45:20 +08:00
|
|
|
|
2010-09-16 07:19:31 +08:00
|
|
|
// Note that this doesn't parse the subsequent cast-expression, it just
|
|
|
|
// returns the parsed type to the callee.
|
2011-07-02 06:22:59 +08:00
|
|
|
if (stopIfCastExpr) {
|
|
|
|
TypeResult Ty;
|
|
|
|
{
|
|
|
|
InMessageExpressionRAIIObject InMessage(*this, false);
|
|
|
|
Ty = Actions.ActOnTypeName(getCurScope(), DeclaratorInfo);
|
|
|
|
}
|
|
|
|
CastTy = Ty.get();
|
2010-09-16 07:19:31 +08:00
|
|
|
return ExprResult();
|
2011-07-02 06:22:59 +08:00
|
|
|
}
|
2010-09-16 07:19:31 +08:00
|
|
|
|
|
|
|
// Reject the cast of super idiom in ObjC.
|
2012-03-11 15:00:24 +08:00
|
|
|
if (Tok.is(tok::identifier) && getLangOpts().ObjC1 &&
|
2010-09-16 07:19:31 +08:00
|
|
|
Tok.getIdentifierInfo() == Ident_super &&
|
|
|
|
getCurScope()->isInObjcMethodScope() &&
|
|
|
|
GetLookAheadToken(1).isNot(tok::period)) {
|
|
|
|
Diag(Tok.getLocation(), diag::err_illegal_super_cast)
|
|
|
|
<< SourceRange(OpenLoc, RParenLoc);
|
|
|
|
return ExprError();
|
|
|
|
}
|
2009-05-22 18:23:40 +08:00
|
|
|
|
2010-09-16 07:19:31 +08:00
|
|
|
// Parse the cast-expression that follows it next.
|
|
|
|
// TODO: For cast expression with CastTy.
|
2011-07-02 06:22:59 +08:00
|
|
|
Result = ParseCastExpression(/*isUnaryExpression=*/false,
|
|
|
|
/*isAddressOfOperand=*/false,
|
2012-01-26 04:49:08 +08:00
|
|
|
/*isTypeCast=*/IsTypeCast);
|
2011-07-02 06:22:59 +08:00
|
|
|
if (!Result.isInvalid()) {
|
|
|
|
Result = Actions.ActOnCastExpr(getCurScope(), OpenLoc,
|
|
|
|
DeclaratorInfo, CastTy,
|
2010-09-16 07:19:31 +08:00
|
|
|
RParenLoc, Result.take());
|
2011-07-02 06:22:59 +08:00
|
|
|
}
|
2012-08-24 05:35:17 +08:00
|
|
|
return Result;
|
2010-04-11 16:28:14 +08:00
|
|
|
}
|
2009-05-22 18:23:40 +08:00
|
|
|
|
2010-09-16 07:19:31 +08:00
|
|
|
Diag(Tok, diag::err_expected_lbrace_in_compound_literal);
|
|
|
|
return ExprError();
|
2006-08-11 07:56:11 +08:00
|
|
|
}
|
2011-07-02 06:22:59 +08:00
|
|
|
} else if (isTypeCast) {
|
2009-08-11 07:49:36 +08:00
|
|
|
// Parse the expression-list.
|
2010-09-15 22:51:05 +08:00
|
|
|
InMessageExpressionRAIIObject InMessage(*this, false);
|
|
|
|
|
2012-08-24 06:51:59 +08:00
|
|
|
ExprVector ArgExprs;
|
2009-08-11 07:49:36 +08:00
|
|
|
CommaLocsTy CommaLocs;
|
|
|
|
|
2013-08-14 07:38:34 +08:00
|
|
|
if (!ParseSimpleExpressionList(ArgExprs, CommaLocs)) {
|
2009-08-11 07:49:36 +08:00
|
|
|
ExprType = SimpleExpr;
|
Represent C++ direct initializers as ParenListExprs before semantic analysis
instead of having a special-purpose function.
- ActOnCXXDirectInitializer, which was mostly duplication of
AddInitializerToDecl (leading e.g. to PR10620, which Eli fixed a few days
ago), is dropped completely.
- MultiInitializer, which was an ugly hack I added, is dropped again.
- We now have the infrastructure in place to distinguish between
int x = {1};
int x({1});
int x{1};
-- VarDecl now has getInitStyle(), which indicates which of the above was used.
-- CXXConstructExpr now has a flag to indicate that it represents list-
initialization, although this is not yet used.
- InstantiateInitializer was renamed to SubstInitializer and simplified.
- ActOnParenOrParenListExpr has been replaced by ActOnParenListExpr, which
always produces a ParenListExpr. Placed that so far failed to convert that
back to a ParenExpr containing comma operators have been fixed. I'm pretty
sure I could have made a crashing test case before this.
The end result is a (I hope) considerably cleaner design of initializers.
More importantly, the fact that I can now distinguish between the various
initialization kinds means that I can get the tricky generalized initializer
test cases Johannes Schaub supplied to work. (This is not yet done.)
This commit passed self-host, with the resulting compiler passing the tests. I
hope it doesn't break more complicated code. It's a pretty big change, but one
that I feel is necessary.
llvm-svn: 150318
2012-02-12 07:51:47 +08:00
|
|
|
Result = Actions.ActOnParenListExpr(OpenLoc, Tok.getLocation(),
|
2012-08-24 05:35:17 +08:00
|
|
|
ArgExprs);
|
2009-08-11 07:49:36 +08:00
|
|
|
}
|
2006-08-11 09:33:00 +08:00
|
|
|
} else {
|
2010-09-15 22:51:05 +08:00
|
|
|
InMessageExpressionRAIIObject InMessage(*this, false);
|
|
|
|
|
2012-01-26 04:49:08 +08:00
|
|
|
Result = ParseExpression(MaybeTypeCast);
|
2006-08-11 09:33:00 +08:00
|
|
|
ExprType = SimpleExpr;
|
2011-04-06 10:35:25 +08:00
|
|
|
|
|
|
|
// Don't build a paren expression unless we actually match a ')'.
|
2008-12-09 21:15:23 +08:00
|
|
|
if (!Result.isInvalid() && Tok.is(tok::r_paren))
|
2010-08-24 07:25:46 +08:00
|
|
|
Result = Actions.ActOnParenExpr(OpenLoc, Tok.getLocation(), Result.take());
|
2006-08-11 06:01:51 +08:00
|
|
|
}
|
2008-12-12 06:33:27 +08:00
|
|
|
|
2006-08-11 07:14:52 +08:00
|
|
|
// Match the ')'.
|
2008-12-12 14:00:12 +08:00
|
|
|
if (Result.isInvalid()) {
|
2006-08-11 14:41:18 +08:00
|
|
|
SkipUntil(tok::r_paren);
|
2008-12-12 14:00:12 +08:00
|
|
|
return ExprError();
|
2006-08-24 14:37:51 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-10-13 00:37:45 +08:00
|
|
|
T.consumeClose();
|
|
|
|
RParenLoc = T.getCloseLocation();
|
2012-08-24 05:35:17 +08:00
|
|
|
return Result;
|
2006-08-10 12:23:57 +08:00
|
|
|
}
|
2006-10-06 13:22:26 +08:00
|
|
|
|
2009-05-22 18:24:05 +08:00
|
|
|
/// ParseCompoundLiteralExpression - We have parsed the parenthesized type-name
|
|
|
|
/// and we are at the left brace.
|
|
|
|
///
|
2012-06-17 12:36:28 +08:00
|
|
|
/// \verbatim
|
2009-05-22 18:24:05 +08:00
|
|
|
/// postfix-expression: [C99 6.5.2]
|
|
|
|
/// '(' type-name ')' '{' initializer-list '}'
|
|
|
|
/// '(' type-name ')' '{' initializer-list ',' '}'
|
2012-06-17 12:36:28 +08:00
|
|
|
/// \endverbatim
|
2010-08-24 14:29:42 +08:00
|
|
|
ExprResult
|
2010-08-24 13:47:05 +08:00
|
|
|
Parser::ParseCompoundLiteralExpression(ParsedType Ty,
|
2009-05-22 18:24:05 +08:00
|
|
|
SourceLocation LParenLoc,
|
|
|
|
SourceLocation RParenLoc) {
|
|
|
|
assert(Tok.is(tok::l_brace) && "Not a compound literal!");
|
2012-03-11 15:00:24 +08:00
|
|
|
if (!getLangOpts().C99) // Compound literals don't exist in C90.
|
2009-05-22 18:24:05 +08:00
|
|
|
Diag(LParenLoc, diag::ext_c99_compound_literal);
|
2010-08-24 14:29:42 +08:00
|
|
|
ExprResult Result = ParseInitializer();
|
2009-05-22 18:24:05 +08:00
|
|
|
if (!Result.isInvalid() && Ty)
|
2010-08-24 07:25:46 +08:00
|
|
|
return Actions.ActOnCompoundLiteral(LParenLoc, Ty, RParenLoc, Result.take());
|
2012-08-24 05:35:17 +08:00
|
|
|
return Result;
|
2009-05-22 18:24:05 +08:00
|
|
|
}
|
|
|
|
|
2006-10-06 13:22:26 +08:00
|
|
|
/// ParseStringLiteralExpression - This handles the various token types that
|
|
|
|
/// form string literals, and also handles string concatenation [C99 5.1.1.2,
|
|
|
|
/// translation phase #6].
|
|
|
|
///
|
2012-06-17 12:36:28 +08:00
|
|
|
/// \verbatim
|
2006-10-06 13:22:26 +08:00
|
|
|
/// primary-expression: [C99 6.5.1]
|
|
|
|
/// string-literal
|
2012-06-17 12:36:28 +08:00
|
|
|
/// \verbatim
|
2012-03-06 11:21:47 +08:00
|
|
|
ExprResult Parser::ParseStringLiteralExpression(bool AllowUserDefinedLiteral) {
|
2006-10-06 13:22:26 +08:00
|
|
|
assert(isTokenStringLiteral() && "Not a string literal!");
|
2008-12-12 06:51:44 +08:00
|
|
|
|
2006-10-06 13:22:26 +08:00
|
|
|
// String concat. Note that keywords like __func__ and __FUNCTION__ are not
|
|
|
|
// considered to be strings for concatenation purposes.
|
2011-07-23 18:55:15 +08:00
|
|
|
SmallVector<Token, 4> StringToks;
|
2008-12-12 06:51:44 +08:00
|
|
|
|
2006-10-06 13:22:26 +08:00
|
|
|
do {
|
|
|
|
StringToks.push_back(Tok);
|
|
|
|
ConsumeStringToken();
|
|
|
|
} while (isTokenStringLiteral());
|
2006-11-09 14:34:47 +08:00
|
|
|
|
|
|
|
// Pass the set of string tokens, ready for concatenation, to the actions.
|
2012-03-09 16:00:36 +08:00
|
|
|
return Actions.ActOnStringLiteral(&StringToks[0], StringToks.size(),
|
|
|
|
AllowUserDefinedLiteral ? getCurScope() : 0);
|
2006-10-06 13:22:26 +08:00
|
|
|
}
|
2008-08-17 04:03:01 +08:00
|
|
|
|
2011-12-24 01:00:35 +08:00
|
|
|
/// ParseGenericSelectionExpression - Parse a C11 generic-selection
|
|
|
|
/// [C11 6.5.1.1].
|
2011-04-15 08:35:48 +08:00
|
|
|
///
|
2012-06-17 12:36:28 +08:00
|
|
|
/// \verbatim
|
2011-04-15 08:35:48 +08:00
|
|
|
/// generic-selection:
|
|
|
|
/// _Generic ( assignment-expression , generic-assoc-list )
|
|
|
|
/// generic-assoc-list:
|
|
|
|
/// generic-association
|
|
|
|
/// generic-assoc-list , generic-association
|
|
|
|
/// generic-association:
|
|
|
|
/// type-name : assignment-expression
|
|
|
|
/// default : assignment-expression
|
2012-06-17 12:36:28 +08:00
|
|
|
/// \endverbatim
|
2011-04-15 08:35:48 +08:00
|
|
|
ExprResult Parser::ParseGenericSelectionExpression() {
|
|
|
|
assert(Tok.is(tok::kw__Generic) && "_Generic keyword expected");
|
|
|
|
SourceLocation KeyLoc = ConsumeToken();
|
|
|
|
|
2012-03-11 15:00:24 +08:00
|
|
|
if (!getLangOpts().C11)
|
2011-12-24 01:00:35 +08:00
|
|
|
Diag(KeyLoc, diag::ext_c11_generic_selection);
|
2011-04-15 08:35:48 +08:00
|
|
|
|
2011-10-13 00:37:45 +08:00
|
|
|
BalancedDelimiterTracker T(*this, tok::l_paren);
|
|
|
|
if (T.expectAndConsume(diag::err_expected_lparen))
|
2011-04-15 08:35:48 +08:00
|
|
|
return ExprError();
|
|
|
|
|
|
|
|
ExprResult ControllingExpr;
|
|
|
|
{
|
2011-12-24 01:00:35 +08:00
|
|
|
// C11 6.5.1.1p3 "The controlling expression of a generic selection is
|
2011-04-15 08:35:48 +08:00
|
|
|
// not evaluated."
|
|
|
|
EnterExpressionEvaluationContext Unevaluated(Actions, Sema::Unevaluated);
|
|
|
|
ControllingExpr = ParseAssignmentExpression();
|
|
|
|
if (ControllingExpr.isInvalid()) {
|
|
|
|
SkipUntil(tok::r_paren);
|
|
|
|
return ExprError();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ExpectAndConsume(tok::comma, diag::err_expected_comma, "")) {
|
|
|
|
SkipUntil(tok::r_paren);
|
|
|
|
return ExprError();
|
|
|
|
}
|
|
|
|
|
|
|
|
SourceLocation DefaultLoc;
|
2012-08-24 06:51:59 +08:00
|
|
|
TypeVector Types;
|
|
|
|
ExprVector Exprs;
|
2011-04-15 08:35:48 +08:00
|
|
|
while (1) {
|
|
|
|
ParsedType Ty;
|
|
|
|
if (Tok.is(tok::kw_default)) {
|
2011-12-24 01:00:35 +08:00
|
|
|
// C11 6.5.1.1p2 "A generic selection shall have no more than one default
|
2011-04-15 08:35:48 +08:00
|
|
|
// generic association."
|
|
|
|
if (!DefaultLoc.isInvalid()) {
|
|
|
|
Diag(Tok, diag::err_duplicate_default_assoc);
|
|
|
|
Diag(DefaultLoc, diag::note_previous_default_assoc);
|
|
|
|
SkipUntil(tok::r_paren);
|
|
|
|
return ExprError();
|
|
|
|
}
|
|
|
|
DefaultLoc = ConsumeToken();
|
|
|
|
Ty = ParsedType();
|
|
|
|
} else {
|
|
|
|
ColonProtectionRAIIObject X(*this);
|
|
|
|
TypeResult TR = ParseTypeName();
|
|
|
|
if (TR.isInvalid()) {
|
|
|
|
SkipUntil(tok::r_paren);
|
|
|
|
return ExprError();
|
|
|
|
}
|
|
|
|
Ty = TR.release();
|
|
|
|
}
|
|
|
|
Types.push_back(Ty);
|
|
|
|
|
|
|
|
if (ExpectAndConsume(tok::colon, diag::err_expected_colon, "")) {
|
|
|
|
SkipUntil(tok::r_paren);
|
|
|
|
return ExprError();
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: These expressions should be parsed in a potentially potentially
|
|
|
|
// evaluated context.
|
|
|
|
ExprResult ER(ParseAssignmentExpression());
|
|
|
|
if (ER.isInvalid()) {
|
|
|
|
SkipUntil(tok::r_paren);
|
|
|
|
return ExprError();
|
|
|
|
}
|
|
|
|
Exprs.push_back(ER.release());
|
|
|
|
|
|
|
|
if (Tok.isNot(tok::comma))
|
|
|
|
break;
|
|
|
|
ConsumeToken();
|
|
|
|
}
|
|
|
|
|
2011-10-13 00:37:45 +08:00
|
|
|
T.consumeClose();
|
|
|
|
if (T.getCloseLocation().isInvalid())
|
2011-04-15 08:35:48 +08:00
|
|
|
return ExprError();
|
|
|
|
|
2011-10-13 00:37:45 +08:00
|
|
|
return Actions.ActOnGenericSelectionExpr(KeyLoc, DefaultLoc,
|
|
|
|
T.getCloseLocation(),
|
2011-04-15 08:35:48 +08:00
|
|
|
ControllingExpr.release(),
|
2012-08-24 05:35:17 +08:00
|
|
|
Types, Exprs);
|
2011-04-15 08:35:48 +08:00
|
|
|
}
|
|
|
|
|
2008-08-17 04:03:01 +08:00
|
|
|
/// ParseExpressionList - Used for C/C++ (argument-)expression-list.
|
|
|
|
///
|
2012-06-17 12:36:28 +08:00
|
|
|
/// \verbatim
|
2008-08-17 04:03:01 +08:00
|
|
|
/// argument-expression-list:
|
|
|
|
/// assignment-expression
|
|
|
|
/// argument-expression-list , assignment-expression
|
|
|
|
///
|
|
|
|
/// [C++] expression-list:
|
2011-06-05 20:23:16 +08:00
|
|
|
/// [C++] assignment-expression
|
|
|
|
/// [C++] expression-list , assignment-expression
|
|
|
|
///
|
|
|
|
/// [C++0x] expression-list:
|
|
|
|
/// [C++0x] initializer-list
|
|
|
|
///
|
|
|
|
/// [C++0x] initializer-list
|
|
|
|
/// [C++0x] initializer-clause ...[opt]
|
|
|
|
/// [C++0x] initializer-list , initializer-clause ...[opt]
|
|
|
|
///
|
|
|
|
/// [C++0x] initializer-clause:
|
|
|
|
/// [C++0x] assignment-expression
|
|
|
|
/// [C++0x] braced-init-list
|
2012-06-17 12:36:28 +08:00
|
|
|
/// \endverbatim
|
2011-07-23 18:55:15 +08:00
|
|
|
bool Parser::ParseExpressionList(SmallVectorImpl<Expr*> &Exprs,
|
2013-01-13 03:30:44 +08:00
|
|
|
SmallVectorImpl<SourceLocation> &CommaLocs,
|
|
|
|
void (Sema::*Completer)(Scope *S,
|
|
|
|
Expr *Data,
|
|
|
|
ArrayRef<Expr *> Args),
|
2010-08-23 14:44:23 +08:00
|
|
|
Expr *Data) {
|
2008-08-17 04:03:01 +08:00
|
|
|
while (1) {
|
2009-09-22 23:41:20 +08:00
|
|
|
if (Tok.is(tok::code_completion)) {
|
|
|
|
if (Completer)
|
2012-02-25 19:00:22 +08:00
|
|
|
(Actions.*Completer)(getCurScope(), Data, Exprs);
|
2011-02-17 11:09:23 +08:00
|
|
|
else
|
|
|
|
Actions.CodeCompleteOrdinaryName(getCurScope(), Sema::PCC_Expression);
|
2011-09-04 11:32:15 +08:00
|
|
|
cutOffParsing();
|
|
|
|
return true;
|
2009-09-22 23:41:20 +08:00
|
|
|
}
|
2011-06-05 20:23:16 +08:00
|
|
|
|
|
|
|
ExprResult Expr;
|
2013-01-02 19:42:31 +08:00
|
|
|
if (getLangOpts().CPlusPlus11 && Tok.is(tok::l_brace)) {
|
2011-10-15 13:09:34 +08:00
|
|
|
Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists);
|
2011-06-05 20:23:16 +08:00
|
|
|
Expr = ParseBraceInitializer();
|
2011-10-15 13:09:34 +08:00
|
|
|
} else
|
2011-06-05 20:23:16 +08:00
|
|
|
Expr = ParseAssignmentExpression();
|
|
|
|
|
2011-01-04 03:31:53 +08:00
|
|
|
if (Tok.is(tok::ellipsis))
|
|
|
|
Expr = Actions.ActOnPackExpansion(Expr.get(), ConsumeToken());
|
2008-12-09 21:15:23 +08:00
|
|
|
if (Expr.isInvalid())
|
2008-08-17 04:03:01 +08:00
|
|
|
return true;
|
2008-08-19 06:49:40 +08:00
|
|
|
|
2008-12-10 08:02:53 +08:00
|
|
|
Exprs.push_back(Expr.release());
|
2008-08-17 04:03:01 +08:00
|
|
|
|
|
|
|
if (Tok.isNot(tok::comma))
|
|
|
|
return false;
|
|
|
|
// Move to the next argument, remember where the comma was.
|
|
|
|
CommaLocs.push_back(ConsumeToken());
|
|
|
|
}
|
|
|
|
}
|
2008-08-29 03:20:44 +08:00
|
|
|
|
2013-08-14 07:38:34 +08:00
|
|
|
/// ParseSimpleExpressionList - A simple comma-separated list of expressions,
|
|
|
|
/// used for misc language extensions.
|
|
|
|
///
|
|
|
|
/// \verbatim
|
|
|
|
/// simple-expression-list:
|
|
|
|
/// assignment-expression
|
|
|
|
/// simple-expression-list , assignment-expression
|
|
|
|
/// \endverbatim
|
|
|
|
bool
|
|
|
|
Parser::ParseSimpleExpressionList(SmallVectorImpl<Expr*> &Exprs,
|
|
|
|
SmallVectorImpl<SourceLocation> &CommaLocs) {
|
|
|
|
while (1) {
|
|
|
|
ExprResult Expr = ParseAssignmentExpression();
|
|
|
|
if (Expr.isInvalid())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
Exprs.push_back(Expr.release());
|
|
|
|
|
|
|
|
if (Tok.isNot(tok::comma))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Move to the next argument, remember where the comma was.
|
|
|
|
CommaLocs.push_back(ConsumeToken());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-05 06:31:32 +08:00
|
|
|
/// ParseBlockId - Parse a block-id, which roughly looks like int (int x).
|
|
|
|
///
|
2012-06-17 12:36:28 +08:00
|
|
|
/// \verbatim
|
2009-02-05 06:31:32 +08:00
|
|
|
/// [clang] block-id:
|
|
|
|
/// [clang] specifier-qualifier-list block-declarator
|
2012-06-17 12:36:28 +08:00
|
|
|
/// \endverbatim
|
2012-06-16 00:59:29 +08:00
|
|
|
void Parser::ParseBlockId(SourceLocation CaretLoc) {
|
2010-10-19 05:34:55 +08:00
|
|
|
if (Tok.is(tok::code_completion)) {
|
|
|
|
Actions.CodeCompleteOrdinaryName(getCurScope(), Sema::PCC_Type);
|
2011-09-04 11:32:15 +08:00
|
|
|
return cutOffParsing();
|
2010-10-19 05:34:55 +08:00
|
|
|
}
|
|
|
|
|
2009-02-05 06:31:32 +08:00
|
|
|
// Parse the specifier-qualifier-list piece.
|
2011-03-24 19:26:52 +08:00
|
|
|
DeclSpec DS(AttrFactory);
|
2009-02-05 06:31:32 +08:00
|
|
|
ParseSpecifierQualifierList(DS);
|
|
|
|
|
|
|
|
// Parse the block-declarator.
|
|
|
|
Declarator DeclaratorInfo(DS, Declarator::BlockLiteralContext);
|
|
|
|
ParseDeclarator(DeclaratorInfo);
|
2009-04-30 03:03:13 +08:00
|
|
|
|
2009-04-30 05:40:37 +08:00
|
|
|
// We do this for: ^ __attribute__((noreturn)) {, as DS has the attributes.
|
2011-03-24 19:26:52 +08:00
|
|
|
DeclaratorInfo.takeAttributes(DS.getAttributes(), SourceLocation());
|
2009-04-30 05:40:37 +08:00
|
|
|
|
2010-12-24 10:08:15 +08:00
|
|
|
MaybeParseGNUAttributes(DeclaratorInfo);
|
2009-04-30 03:03:13 +08:00
|
|
|
|
2009-02-05 06:31:32 +08:00
|
|
|
// Inform sema that we are starting a block.
|
2012-06-16 00:59:29 +08:00
|
|
|
Actions.ActOnBlockArguments(CaretLoc, DeclaratorInfo, getCurScope());
|
2009-02-05 06:31:32 +08:00
|
|
|
}
|
|
|
|
|
2008-08-29 03:20:44 +08:00
|
|
|
/// ParseBlockLiteralExpression - Parse a block literal, which roughly looks
|
2008-09-17 07:11:46 +08:00
|
|
|
/// like ^(int x){ return x+1; }
|
2008-08-29 03:20:44 +08:00
|
|
|
///
|
2012-06-17 12:36:28 +08:00
|
|
|
/// \verbatim
|
2008-08-29 03:20:44 +08:00
|
|
|
/// block-literal:
|
|
|
|
/// [clang] '^' block-args[opt] compound-statement
|
2009-02-05 06:31:32 +08:00
|
|
|
/// [clang] '^' block-id compound-statement
|
2008-08-29 03:20:44 +08:00
|
|
|
/// [clang] block-args:
|
|
|
|
/// [clang] '(' parameter-list ')'
|
2012-06-17 12:36:28 +08:00
|
|
|
/// \endverbatim
|
2010-08-24 14:29:42 +08:00
|
|
|
ExprResult Parser::ParseBlockLiteralExpression() {
|
2008-08-29 03:20:44 +08:00
|
|
|
assert(Tok.is(tok::caret) && "block literal starts with ^");
|
|
|
|
SourceLocation CaretLoc = ConsumeToken();
|
2008-12-13 23:32:12 +08:00
|
|
|
|
2009-03-05 15:32:12 +08:00
|
|
|
PrettyStackTraceLoc CrashInfo(PP.getSourceManager(), CaretLoc,
|
|
|
|
"block literal parsing");
|
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
// Enter a scope to hold everything within the block. This includes the
|
2008-08-29 03:20:44 +08:00
|
|
|
// argument decls, decls within the compound expression, etc. This also
|
|
|
|
// allows determining whether a variable reference inside the block is
|
|
|
|
// within or outside of the block.
|
2009-02-10 02:23:29 +08:00
|
|
|
ParseScope BlockScope(this, Scope::BlockScope | Scope::FnScope |
|
|
|
|
Scope::DeclScope);
|
2008-10-10 09:28:17 +08:00
|
|
|
|
|
|
|
// Inform sema that we are starting a block.
|
2010-07-03 01:43:08 +08:00
|
|
|
Actions.ActOnBlockStart(CaretLoc, getCurScope());
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-08-29 03:20:44 +08:00
|
|
|
// Parse the return type if present.
|
2011-03-24 19:26:52 +08:00
|
|
|
DeclSpec DS(AttrFactory);
|
2009-02-05 06:31:32 +08:00
|
|
|
Declarator ParamInfo(DS, Declarator::BlockLiteralContext);
|
2009-02-10 02:23:29 +08:00
|
|
|
// FIXME: Since the return type isn't actually parsed, it can't be used to
|
|
|
|
// fill ParamInfo with an initial valid range, so do it manually.
|
|
|
|
ParamInfo.SetSourceRange(SourceRange(Tok.getLocation(), Tok.getLocation()));
|
2008-12-13 23:32:12 +08:00
|
|
|
|
2008-08-29 03:20:44 +08:00
|
|
|
// If this block has arguments, parse them. There is no ambiguity here with
|
|
|
|
// the expression case, because the expression case requires a parameter list.
|
|
|
|
if (Tok.is(tok::l_paren)) {
|
|
|
|
ParseParenDeclarator(ParamInfo);
|
|
|
|
// Parse the pieces after the identifier as if we had "int(...)".
|
2009-02-10 02:23:29 +08:00
|
|
|
// SetIdentifier sets the source range end, but in this case we're past
|
|
|
|
// that location.
|
|
|
|
SourceLocation Tmp = ParamInfo.getSourceRange().getEnd();
|
2008-08-29 03:20:44 +08:00
|
|
|
ParamInfo.SetIdentifier(0, CaretLoc);
|
2009-02-10 02:23:29 +08:00
|
|
|
ParamInfo.SetRangeEnd(Tmp);
|
2009-04-25 16:06:05 +08:00
|
|
|
if (ParamInfo.isInvalidType()) {
|
2009-02-05 06:31:32 +08:00
|
|
|
// If there was an error parsing the arguments, they may have
|
|
|
|
// tried to use ^(x+y) which requires an argument list. Just
|
|
|
|
// skip the whole block literal.
|
2010-07-03 01:43:08 +08:00
|
|
|
Actions.ActOnBlockError(CaretLoc, getCurScope());
|
2008-12-13 23:32:12 +08:00
|
|
|
return ExprError();
|
2008-08-29 03:20:44 +08:00
|
|
|
}
|
2009-04-30 03:03:13 +08:00
|
|
|
|
2010-12-24 10:08:15 +08:00
|
|
|
MaybeParseGNUAttributes(ParamInfo);
|
2009-04-30 03:03:13 +08:00
|
|
|
|
2009-02-05 06:31:32 +08:00
|
|
|
// Inform sema that we are starting a block.
|
2012-06-16 00:59:29 +08:00
|
|
|
Actions.ActOnBlockArguments(CaretLoc, ParamInfo, getCurScope());
|
2009-04-15 02:24:37 +08:00
|
|
|
} else if (!Tok.is(tok::l_brace)) {
|
2012-06-16 00:59:29 +08:00
|
|
|
ParseBlockId(CaretLoc);
|
2008-08-29 03:20:44 +08:00
|
|
|
} else {
|
|
|
|
// Otherwise, pretend we saw (void).
|
2011-03-24 19:26:52 +08:00
|
|
|
ParsedAttributes attrs(AttrFactory);
|
2012-10-05 05:42:10 +08:00
|
|
|
SourceLocation NoLoc;
|
|
|
|
ParamInfo.AddTypeInfo(DeclaratorChunk::getFunction(/*HasProto=*/true,
|
|
|
|
/*IsAmbiguous=*/false,
|
|
|
|
/*RParenLoc=*/NoLoc,
|
|
|
|
/*ArgInfo=*/0,
|
|
|
|
/*NumArgs=*/0,
|
|
|
|
/*EllipsisLoc=*/NoLoc,
|
|
|
|
/*RParenLoc=*/NoLoc,
|
|
|
|
/*TypeQuals=*/0,
|
|
|
|
/*RefQualifierIsLvalueRef=*/true,
|
|
|
|
/*RefQualifierLoc=*/NoLoc,
|
|
|
|
/*ConstQualifierLoc=*/NoLoc,
|
|
|
|
/*VolatileQualifierLoc=*/NoLoc,
|
|
|
|
/*MutableLoc=*/NoLoc,
|
|
|
|
EST_None,
|
|
|
|
/*ESpecLoc=*/NoLoc,
|
|
|
|
/*Exceptions=*/0,
|
|
|
|
/*ExceptionRanges=*/0,
|
|
|
|
/*NumExceptions=*/0,
|
|
|
|
/*NoexceptExpr=*/0,
|
|
|
|
CaretLoc, CaretLoc,
|
|
|
|
ParamInfo),
|
2011-03-24 19:26:52 +08:00
|
|
|
attrs, CaretLoc);
|
2009-04-30 03:03:13 +08:00
|
|
|
|
2010-12-24 10:08:15 +08:00
|
|
|
MaybeParseGNUAttributes(ParamInfo);
|
2009-04-30 03:03:13 +08:00
|
|
|
|
2009-02-05 06:31:32 +08:00
|
|
|
// Inform sema that we are starting a block.
|
2012-06-16 00:59:29 +08:00
|
|
|
Actions.ActOnBlockArguments(CaretLoc, ParamInfo, getCurScope());
|
2008-08-29 03:20:44 +08:00
|
|
|
}
|
|
|
|
|
2008-12-13 23:32:12 +08:00
|
|
|
|
2010-08-24 14:29:42 +08:00
|
|
|
ExprResult Result(true);
|
2009-03-27 12:18:06 +08:00
|
|
|
if (!Tok.is(tok::l_brace)) {
|
2009-01-15 03:39:53 +08:00
|
|
|
// Saw something like: ^expr
|
|
|
|
Diag(Tok, diag::err_expected_expression);
|
2010-07-03 01:43:08 +08:00
|
|
|
Actions.ActOnBlockError(CaretLoc, getCurScope());
|
2009-01-15 03:39:53 +08:00
|
|
|
return ExprError();
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2010-08-24 14:29:42 +08:00
|
|
|
StmtResult Stmt(ParseCompoundStatementBody());
|
2011-03-17 01:05:57 +08:00
|
|
|
BlockScope.Exit();
|
2009-03-27 12:18:06 +08:00
|
|
|
if (!Stmt.isInvalid())
|
2010-08-24 07:25:46 +08:00
|
|
|
Result = Actions.ActOnBlockStmtExpr(CaretLoc, Stmt.take(), getCurScope());
|
2009-03-27 12:18:06 +08:00
|
|
|
else
|
2010-07-03 01:43:08 +08:00
|
|
|
Actions.ActOnBlockError(CaretLoc, getCurScope());
|
2012-08-24 05:35:17 +08:00
|
|
|
return Result;
|
2008-08-29 03:20:44 +08:00
|
|
|
}
|
2012-03-07 04:05:56 +08:00
|
|
|
|
|
|
|
/// ParseObjCBoolLiteral - This handles the objective-c Boolean literals.
|
|
|
|
///
|
|
|
|
/// '__objc_yes'
|
|
|
|
/// '__objc_no'
|
|
|
|
ExprResult Parser::ParseObjCBoolLiteral() {
|
|
|
|
tok::TokenKind Kind = Tok.getKind();
|
|
|
|
return Actions.ActOnObjCBoolLiteral(ConsumeToken(), Kind);
|
|
|
|
}
|