#include "clang/Parse/Parser.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/ExprCXX.h"
#include "clang/Basic/PrettyStackTrace.h"
#include "clang/Parse/RAIIObjectsForParser.h"
#include "clang/Sema/DeclSpec.h"
#include "clang/Sema/ParsedTemplate.h"
#include "clang/Sema/Scope.h"
#include "clang/Sema/TypoCorrection.h"
#include "llvm/ADT/SmallVector.h"
using namespace clang;
ExprResult Parser::ParseExpression(TypeCastState isTypeCast) {
ExprResult LHS(ParseAssignmentExpression(isTypeCast));
return ParseRHSOfBinaryExpression(LHS, prec::Comma);
}
ExprResult
Parser::ParseExpressionWithLeadingAt(SourceLocation AtLoc) {
ExprResult LHS(ParseObjCAtExpression(AtLoc));
return ParseRHSOfBinaryExpression(LHS, prec::Comma);
}
ExprResult
Parser::ParseExpressionWithLeadingExtension(SourceLocation ExtLoc) {
ExprResult LHS(true);
{
ExtensionRAIIObject O(Diags);
LHS = ParseCastExpression(AnyCastExpr);
}
if (!LHS.isInvalid())
LHS = Actions.ActOnUnaryOp(getCurScope(), ExtLoc, tok::kw___extension__,
LHS.get());
return ParseRHSOfBinaryExpression(LHS, prec::Comma);
}
ExprResult Parser::ParseAssignmentExpression(TypeCastState isTypeCast) {
if (Tok.is(tok::code_completion)) {
cutOffParsing();
Actions.CodeCompleteExpression(getCurScope(),
PreferredType.get(Tok.getLocation()));
return ExprError();
}
if (Tok.is(tok::kw_throw))
return ParseThrowExpression();
if (Tok.is(tok::kw_co_yield))
return ParseCoyieldExpression();
ExprResult LHS = ParseCastExpression(AnyCastExpr,
false,
isTypeCast);
return ParseRHSOfBinaryExpression(LHS, prec::Assignment);
}
ExprResult
Parser::ParseAssignmentExprWithObjCMessageExprStart(SourceLocation LBracLoc,
SourceLocation SuperLoc,
ParsedType ReceiverType,
Expr *ReceiverExpr) {
ExprResult R
= ParseObjCMessageExpressionBody(LBracLoc, SuperLoc,
ReceiverType, ReceiverExpr);
R = ParsePostfixExpressionSuffix(R);
return ParseRHSOfBinaryExpression(R, prec::Assignment);
}
ExprResult
Parser::ParseConstantExpressionInExprEvalContext(TypeCastState isTypeCast) {
assert(Actions.ExprEvalContexts.back().Context ==
Sema::ExpressionEvaluationContext::ConstantEvaluated &&
"Call this function only if your ExpressionEvaluationContext is "
"already ConstantEvaluated");
ExprResult LHS(ParseCastExpression(AnyCastExpr, false, isTypeCast));
ExprResult Res(ParseRHSOfBinaryExpression(LHS, prec::Conditional));
return Actions.ActOnConstantExpression(Res);
}
ExprResult Parser::ParseConstantExpression(TypeCastState isTypeCast) {
EnterExpressionEvaluationContext ConstantEvaluated(
Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated);
return ParseConstantExpressionInExprEvalContext(isTypeCast);
}
ExprResult Parser::ParseCaseExpression(SourceLocation CaseLoc) {
EnterExpressionEvaluationContext ConstantEvaluated(
Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated);
ExprResult LHS(ParseCastExpression(AnyCastExpr, false, NotTypeCast));
ExprResult Res(ParseRHSOfBinaryExpression(LHS, prec::Conditional));
return Actions.ActOnCaseExpr(CaseLoc, Res);
}
ExprResult Parser::ParseConstraintExpression() {
EnterExpressionEvaluationContext ConstantEvaluated(
Actions, Sema::ExpressionEvaluationContext::Unevaluated);
ExprResult LHS(ParseCastExpression(AnyCastExpr));
ExprResult Res(ParseRHSOfBinaryExpression(LHS, prec::LogicalOr));
if (Res.isUsable() && !Actions.CheckConstraintExpression(Res.get())) {
Actions.CorrectDelayedTyposInExpr(Res);
return ExprError();
}
return Res;
}
ExprResult
Parser::ParseConstraintLogicalAndExpression(bool IsTrailingRequiresClause) {
EnterExpressionEvaluationContext ConstantEvaluated(
Actions, Sema::ExpressionEvaluationContext::Unevaluated);
bool NotPrimaryExpression = false;
auto ParsePrimary = [&] () {
ExprResult E = ParseCastExpression(PrimaryExprOnly,
false,
NotTypeCast,
false,
&NotPrimaryExpression);
if (E.isInvalid())
return ExprError();
auto RecoverFromNonPrimary = [&] (ExprResult E, bool Note) {
E = ParsePostfixExpressionSuffix(E);
E = ParseRHSOfBinaryExpression(E, prec::InclusiveOr);
if (!E.isInvalid())
Diag(E.get()->getExprLoc(),
Note
? diag::note_unparenthesized_non_primary_expr_in_requires_clause
: diag::err_unparenthesized_non_primary_expr_in_requires_clause)
<< FixItHint::CreateInsertion(E.get()->getBeginLoc(), "(")
<< FixItHint::CreateInsertion(
PP.getLocForEndOfToken(E.get()->getEndLoc()), ")")
<< E.get()->getSourceRange();
return E;
};
if (NotPrimaryExpression ||
getBinOpPrecedence(Tok.getKind(), GreaterThanIsOperator,
true) > prec::LogicalAnd ||
Tok.isOneOf(tok::period, tok::plusplus, tok::minusminus) ||
(Tok.is(tok::l_square) && !NextToken().is(tok::l_square))) {
E = RecoverFromNonPrimary(E, false);
if (E.isInvalid())
return ExprError();
NotPrimaryExpression = false;
}
bool PossibleNonPrimary;
bool IsConstraintExpr =
Actions.CheckConstraintExpression(E.get(), Tok, &PossibleNonPrimary,
IsTrailingRequiresClause);
if (!IsConstraintExpr || PossibleNonPrimary) {
if (PossibleNonPrimary)
E = RecoverFromNonPrimary(E, !IsConstraintExpr);
Actions.CorrectDelayedTyposInExpr(E);
return ExprError();
}
return E;
};
ExprResult LHS = ParsePrimary();
if (LHS.isInvalid())
return ExprError();
while (Tok.is(tok::ampamp)) {
SourceLocation LogicalAndLoc = ConsumeToken();
ExprResult RHS = ParsePrimary();
if (RHS.isInvalid()) {
Actions.CorrectDelayedTyposInExpr(LHS);
return ExprError();
}
ExprResult Op = Actions.ActOnBinOp(getCurScope(), LogicalAndLoc,
tok::ampamp, LHS.get(), RHS.get());
if (!Op.isUsable()) {
Actions.CorrectDelayedTyposInExpr(RHS);
Actions.CorrectDelayedTyposInExpr(LHS);
return ExprError();
}
LHS = Op;
}
return LHS;
}
ExprResult
Parser::ParseConstraintLogicalOrExpression(bool IsTrailingRequiresClause) {
ExprResult LHS(ParseConstraintLogicalAndExpression(IsTrailingRequiresClause));
if (!LHS.isUsable())
return ExprError();
while (Tok.is(tok::pipepipe)) {
SourceLocation LogicalOrLoc = ConsumeToken();
ExprResult RHS =
ParseConstraintLogicalAndExpression(IsTrailingRequiresClause);
if (!RHS.isUsable()) {
Actions.CorrectDelayedTyposInExpr(LHS);
return ExprError();
}
ExprResult Op = Actions.ActOnBinOp(getCurScope(), LogicalOrLoc,
tok::pipepipe, LHS.get(), RHS.get());
if (!Op.isUsable()) {
Actions.CorrectDelayedTyposInExpr(RHS);
Actions.CorrectDelayedTyposInExpr(LHS);
return ExprError();
}
LHS = Op;
}
return LHS;
}
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;
return isKnownToBeDeclarationSpecifier();
}
bool Parser::isFoldOperator(prec::Level Level) const {
return Level > prec::Unknown && Level != prec::Conditional &&
Level != prec::Spaceship;
}
bool Parser::isFoldOperator(tok::TokenKind Kind) const {
return isFoldOperator(getBinOpPrecedence(Kind, GreaterThanIsOperator, true));
}
ExprResult
Parser::ParseRHSOfBinaryExpression(ExprResult LHS, prec::Level MinPrec) {
prec::Level NextTokPrec = getBinOpPrecedence(Tok.getKind(),
GreaterThanIsOperator,
getLangOpts().CPlusPlus11);
SourceLocation ColonLoc;
auto SavedType = PreferredType;
while (true) {
PreferredType = SavedType;
if (NextTokPrec < MinPrec)
return LHS;
Token OpToken = Tok;
ConsumeToken();
if (OpToken.is(tok::caretcaret)) {
return ExprError(Diag(Tok, diag::err_opencl_logical_exclusive_or));
}
if (OpToken.isOneOf(tok::comma, tok::greater, tok::greatergreater,
tok::greatergreatergreater) &&
checkPotentialAngleBracketDelimiter(OpToken))
return ExprError();
if (OpToken.is(tok::comma) && isNotExpressionStart()) {
PP.EnterToken(Tok, true);
Tok = OpToken;
return LHS;
}
if (isFoldOperator(NextTokPrec) && Tok.is(tok::ellipsis)) {
PP.EnterToken(Tok, true);
Tok = OpToken;
return LHS;
}
if (getLangOpts().ObjC && getLangOpts().CPlusPlus &&
Tok.isOneOf(tok::colon, tok::r_square) &&
OpToken.getIdentifierInfo() != nullptr) {
PP.EnterToken(Tok, true);
Tok = OpToken;
return LHS;
}
ExprResult TernaryMiddle(true);
if (NextTokPrec == prec::Conditional) {
if (getLangOpts().CPlusPlus11 && Tok.is(tok::l_brace)) {
SourceLocation BraceLoc = Tok.getLocation();
TernaryMiddle = ParseBraceInitializer();
if (!TernaryMiddle.isInvalid()) {
Diag(BraceLoc, diag::err_init_list_bin_op)
<< 1 << PP.getSpelling(OpToken)
<< Actions.getExprRange(TernaryMiddle.get());
TernaryMiddle = ExprError();
}
} else if (Tok.isNot(tok::colon)) {
ColonProtectionRAIIObject X(*this);
TernaryMiddle = ParseExpression();
} else {
TernaryMiddle = nullptr;
Diag(Tok, diag::ext_gnu_conditional_expr);
}
if (TernaryMiddle.isInvalid()) {
Actions.CorrectDelayedTyposInExpr(LHS);
LHS = ExprError();
TernaryMiddle = nullptr;
}
if (!TryConsumeToken(tok::colon, ColonLoc)) {
SourceLocation FILoc = Tok.getLocation();
const char *FIText = ": ";
const SourceManager &SM = PP.getSourceManager();
if (FILoc.isFileID() || PP.isAtStartOfMacroExpansion(FILoc, &FILoc)) {
assert(FILoc.isFileID());
bool IsInvalid = false;
const char *SourcePtr =
SM.getCharacterData(FILoc.getLocWithOffset(-1), &IsInvalid);
if (!IsInvalid && *SourcePtr == ' ') {
SourcePtr =
SM.getCharacterData(FILoc.getLocWithOffset(-2), &IsInvalid);
if (!IsInvalid && *SourcePtr == ' ') {
FILoc = FILoc.getLocWithOffset(-1);
FIText = ":";
}
}
}
Diag(Tok, diag::err_expected)
<< tok::colon << FixItHint::CreateInsertion(FILoc, FIText);
Diag(OpToken, diag::note_matching) << tok::question;
ColonLoc = Tok.getLocation();
}
}
PreferredType.enterBinary(Actions, Tok.getLocation(), LHS.get(),
OpToken.getKind());
ExprResult RHS;
bool RHSIsInitList = false;
if (getLangOpts().CPlusPlus11 && Tok.is(tok::l_brace)) {
RHS = ParseBraceInitializer();
RHSIsInitList = true;
} else if (getLangOpts().CPlusPlus && NextTokPrec <= prec::Conditional)
RHS = ParseAssignmentExpression();
else
RHS = ParseCastExpression(AnyCastExpr);
if (RHS.isInvalid()) {
Actions.CorrectDelayedTyposInExpr(LHS);
if (TernaryMiddle.isUsable())
TernaryMiddle = Actions.CorrectDelayedTyposInExpr(TernaryMiddle);
LHS = ExprError();
}
prec::Level ThisPrec = NextTokPrec;
NextTokPrec = getBinOpPrecedence(Tok.getKind(), GreaterThanIsOperator,
getLangOpts().CPlusPlus11);
bool isRightAssoc = ThisPrec == prec::Conditional ||
ThisPrec == prec::Assignment;
if (ThisPrec < NextTokPrec ||
(ThisPrec == NextTokPrec && isRightAssoc)) {
if (!RHS.isInvalid() && RHSIsInitList) {
Diag(Tok, diag::err_init_list_bin_op)
<< 0 << PP.getSpelling(Tok) << Actions.getExprRange(RHS.get());
RHS = ExprError();
}
RHS = ParseRHSOfBinaryExpression(RHS,
static_cast<prec::Level>(ThisPrec + !isRightAssoc));
RHSIsInitList = false;
if (RHS.isInvalid()) {
Actions.CorrectDelayedTyposInExpr(LHS);
if (TernaryMiddle.isUsable())
TernaryMiddle = Actions.CorrectDelayedTyposInExpr(TernaryMiddle);
LHS = ExprError();
}
NextTokPrec = getBinOpPrecedence(Tok.getKind(), GreaterThanIsOperator,
getLangOpts().CPlusPlus11);
}
if (!RHS.isInvalid() && RHSIsInitList) {
if (ThisPrec == prec::Assignment) {
Diag(OpToken, diag::warn_cxx98_compat_generalized_initializer_lists)
<< Actions.getExprRange(RHS.get());
} else if (ColonLoc.isValid()) {
Diag(ColonLoc, diag::err_init_list_bin_op)
<< 1 << ":"
<< Actions.getExprRange(RHS.get());
LHS = ExprError();
} else {
Diag(OpToken, diag::err_init_list_bin_op)
<< 1 << PP.getSpelling(OpToken)
<< Actions.getExprRange(RHS.get());
LHS = ExprError();
}
}
ExprResult OrigLHS = LHS;
if (!LHS.isInvalid()) {
if (TernaryMiddle.isInvalid()) {
if (!GreaterThanIsOperator && OpToken.is(tok::greatergreater))
SuggestParentheses(OpToken.getLocation(),
diag::warn_cxx11_right_shift_in_template_arg,
SourceRange(Actions.getExprRange(LHS.get()).getBegin(),
Actions.getExprRange(RHS.get()).getEnd()));
ExprResult BinOp =
Actions.ActOnBinOp(getCurScope(), OpToken.getLocation(),
OpToken.getKind(), LHS.get(), RHS.get());
if (BinOp.isInvalid())
BinOp = Actions.CreateRecoveryExpr(LHS.get()->getBeginLoc(),
RHS.get()->getEndLoc(),
{LHS.get(), RHS.get()});
LHS = BinOp;
} else {
ExprResult CondOp = Actions.ActOnConditionalOp(
OpToken.getLocation(), ColonLoc, LHS.get(), TernaryMiddle.get(),
RHS.get());
if (CondOp.isInvalid()) {
std::vector<clang::Expr *> Args;
if (TernaryMiddle.get())
Args = {LHS.get(), TernaryMiddle.get(), RHS.get()};
else
Args = {LHS.get(), RHS.get()};
CondOp = Actions.CreateRecoveryExpr(LHS.get()->getBeginLoc(),
RHS.get()->getEndLoc(), Args);
}
LHS = CondOp;
}
if (!getLangOpts().CPlusPlus)
continue;
}
if (LHS.isInvalid()) {
Actions.CorrectDelayedTyposInExpr(OrigLHS);
Actions.CorrectDelayedTyposInExpr(TernaryMiddle);
Actions.CorrectDelayedTyposInExpr(RHS);
}
}
}
ExprResult Parser::ParseCastExpression(CastParseKind ParseKind,
bool isAddressOfOperand,
TypeCastState isTypeCast,
bool isVectorLiteral,
bool *NotPrimaryExpression) {
bool NotCastExpr;
ExprResult Res = ParseCastExpression(ParseKind,
isAddressOfOperand,
NotCastExpr,
isTypeCast,
isVectorLiteral,
NotPrimaryExpression);
if (NotCastExpr)
Diag(Tok, diag::err_expected_expression);
return Res;
}
namespace {
class CastExpressionIdValidator final : public CorrectionCandidateCallback {
public:
CastExpressionIdValidator(Token Next, bool AllowTypes, bool AllowNonTypes)
: NextToken(Next), AllowNonTypes(AllowNonTypes) {
WantTypeSpecifiers = WantFunctionLikeCasts = AllowTypes;
}
bool ValidateCandidate(const TypoCorrection &candidate) override {
NamedDecl *ND = candidate.getCorrectionDecl();
if (!ND)
return candidate.isKeyword();
if (isa<TypeDecl>(ND))
return WantTypeSpecifiers;
if (!AllowNonTypes || !CorrectionCandidateCallback::ValidateCandidate(candidate))
return false;
if (!NextToken.isOneOf(tok::equal, tok::arrow, tok::period))
return true;
for (auto *C : candidate) {
NamedDecl *ND = C->getUnderlyingDecl();
if (isa<ValueDecl>(ND) && !isa<FunctionDecl>(ND))
return true;
}
return false;
}
std::unique_ptr<CorrectionCandidateCallback> clone() override {
return std::make_unique<CastExpressionIdValidator>(*this);
}
private:
Token NextToken;
bool AllowNonTypes;
};
}
ExprResult Parser::ParseCastExpression(CastParseKind ParseKind,
bool isAddressOfOperand,
bool &NotCastExpr,
TypeCastState isTypeCast,
bool isVectorLiteral,
bool *NotPrimaryExpression) {
ExprResult Res;
tok::TokenKind SavedKind = Tok.getKind();
auto SavedType = PreferredType;
NotCastExpr = false;
bool AllowSuffix = true;
switch (SavedKind) {
case tok::l_paren: {
ParenParseOption ParenExprType;
switch (ParseKind) {
case CastParseKind::UnaryExprOnly:
if (!getLangOpts().CPlusPlus)
ParenExprType = CompoundLiteral;
LLVM_FALLTHROUGH;
case CastParseKind::AnyCastExpr:
ParenExprType = ParenParseOption::CastExpr;
break;
case CastParseKind::PrimaryExprOnly:
ParenExprType = FoldExpr;
break;
}
ParsedType CastTy;
SourceLocation RParenLoc;
Res = ParseParenExpression(ParenExprType, false,
isTypeCast == IsTypeCast, CastTy, RParenLoc);
if (isVectorLiteral)
return Res;
switch (ParenExprType) {
case SimpleExpr: break; case CompoundStmt: break; case CompoundLiteral:
break;
case CastExpr:
return Res;
case FoldExpr:
break;
}
break;
}
case tok::numeric_constant:
Res = Actions.ActOnNumericConstant(Tok, getCurScope());
ConsumeToken();
break;
case tok::kw_true:
case tok::kw_false:
Res = ParseCXXBoolLiteral();
break;
case tok::kw___objc_yes:
case tok::kw___objc_no:
Res = ParseObjCBoolLiteral();
break;
case tok::kw_nullptr:
Diag(Tok, diag::warn_cxx98_compat_nullptr);
Res = Actions.ActOnCXXNullPtrLiteral(ConsumeToken());
break;
case tok::annot_primary_expr:
case tok::annot_overload_set:
Res = getExprAnnotation(Tok);
if (!Res.isInvalid() && Tok.getKind() == tok::annot_overload_set)
Res = Actions.ActOnNameClassifiedAsOverloadSet(getCurScope(), Res.get());
ConsumeAnnotationToken();
if (!Res.isInvalid() && Tok.is(tok::less))
checkPotentialAngleBracket(Res);
break;
case tok::annot_non_type:
case tok::annot_non_type_dependent:
case tok::annot_non_type_undeclared: {
CXXScopeSpec SS;
Token Replacement;
Res = tryParseCXXIdExpression(SS, isAddressOfOperand, Replacement);
assert(!Res.isUnset() &&
"should not perform typo correction on annotation token");
break;
}
case tok::kw___super:
case tok::kw_decltype:
if (TryAnnotateTypeOrScopeToken())
return ExprError();
assert(Tok.isNot(tok::kw_decltype) && Tok.isNot(tok::kw___super));
return ParseCastExpression(ParseKind, isAddressOfOperand, isTypeCast,
isVectorLiteral, NotPrimaryExpression);
case tok::identifier: { if (getLangOpts().CPlusPlus) {
const Token &Next = NextToken();
if (Next.is(tok::l_paren) &&
Tok.is(tok::identifier) &&
Tok.getIdentifierInfo()->hasRevertedTokenIDToIdentifier()) {
IdentifierInfo *II = Tok.getIdentifierInfo();
if (RevertibleTypeTraits.empty()) {
#define RTT_JOIN(X,Y) X##Y
#define REVERTIBLE_TYPE_TRAIT(Name) \
RevertibleTypeTraits[PP.getIdentifierInfo(#Name)] \
= RTT_JOIN(tok::kw_,Name)
REVERTIBLE_TYPE_TRAIT(__is_abstract);
REVERTIBLE_TYPE_TRAIT(__is_aggregate);
REVERTIBLE_TYPE_TRAIT(__is_arithmetic);
REVERTIBLE_TYPE_TRAIT(__is_array);
REVERTIBLE_TYPE_TRAIT(__is_assignable);
REVERTIBLE_TYPE_TRAIT(__is_base_of);
REVERTIBLE_TYPE_TRAIT(__is_class);
REVERTIBLE_TYPE_TRAIT(__is_complete_type);
REVERTIBLE_TYPE_TRAIT(__is_compound);
REVERTIBLE_TYPE_TRAIT(__is_const);
REVERTIBLE_TYPE_TRAIT(__is_constructible);
REVERTIBLE_TYPE_TRAIT(__is_convertible);
REVERTIBLE_TYPE_TRAIT(__is_convertible_to);
REVERTIBLE_TYPE_TRAIT(__is_destructible);
REVERTIBLE_TYPE_TRAIT(__is_empty);
REVERTIBLE_TYPE_TRAIT(__is_enum);
REVERTIBLE_TYPE_TRAIT(__is_floating_point);
REVERTIBLE_TYPE_TRAIT(__is_final);
REVERTIBLE_TYPE_TRAIT(__is_function);
REVERTIBLE_TYPE_TRAIT(__is_fundamental);
REVERTIBLE_TYPE_TRAIT(__is_integral);
REVERTIBLE_TYPE_TRAIT(__is_interface_class);
REVERTIBLE_TYPE_TRAIT(__is_literal);
REVERTIBLE_TYPE_TRAIT(__is_lvalue_expr);
REVERTIBLE_TYPE_TRAIT(__is_lvalue_reference);
REVERTIBLE_TYPE_TRAIT(__is_member_function_pointer);
REVERTIBLE_TYPE_TRAIT(__is_member_object_pointer);
REVERTIBLE_TYPE_TRAIT(__is_member_pointer);
REVERTIBLE_TYPE_TRAIT(__is_nothrow_assignable);
REVERTIBLE_TYPE_TRAIT(__is_nothrow_constructible);
REVERTIBLE_TYPE_TRAIT(__is_nothrow_destructible);
REVERTIBLE_TYPE_TRAIT(__is_object);
REVERTIBLE_TYPE_TRAIT(__is_pod);
REVERTIBLE_TYPE_TRAIT(__is_pointer);
REVERTIBLE_TYPE_TRAIT(__is_polymorphic);
REVERTIBLE_TYPE_TRAIT(__is_reference);
REVERTIBLE_TYPE_TRAIT(__is_rvalue_expr);
REVERTIBLE_TYPE_TRAIT(__is_rvalue_reference);
REVERTIBLE_TYPE_TRAIT(__is_same);
REVERTIBLE_TYPE_TRAIT(__is_scalar);
REVERTIBLE_TYPE_TRAIT(__is_sealed);
REVERTIBLE_TYPE_TRAIT(__is_signed);
REVERTIBLE_TYPE_TRAIT(__is_standard_layout);
REVERTIBLE_TYPE_TRAIT(__is_trivial);
REVERTIBLE_TYPE_TRAIT(__is_trivially_assignable);
REVERTIBLE_TYPE_TRAIT(__is_trivially_constructible);
REVERTIBLE_TYPE_TRAIT(__is_trivially_copyable);
REVERTIBLE_TYPE_TRAIT(__is_union);
REVERTIBLE_TYPE_TRAIT(__is_unsigned);
REVERTIBLE_TYPE_TRAIT(__is_void);
REVERTIBLE_TYPE_TRAIT(__is_volatile);
#undef REVERTIBLE_TYPE_TRAIT
#undef RTT_JOIN
}
llvm::SmallDenseMap<IdentifierInfo *, tok::TokenKind>::iterator Known
= RevertibleTypeTraits.find(II);
if (Known != RevertibleTypeTraits.end()) {
Tok.setKind(Known->second);
return ParseCastExpression(ParseKind, isAddressOfOperand,
NotCastExpr, isTypeCast,
isVectorLiteral, NotPrimaryExpression);
}
}
if ((!ColonIsSacred && Next.is(tok::colon)) ||
Next.isOneOf(tok::coloncolon, tok::less, tok::l_paren,
tok::l_brace)) {
if (TryAnnotateTypeOrScopeToken())
return ExprError();
if (!Tok.is(tok::identifier))
return ParseCastExpression(ParseKind, isAddressOfOperand,
NotCastExpr, isTypeCast,
isVectorLiteral,
NotPrimaryExpression);
}
}
IdentifierInfo &II = *Tok.getIdentifierInfo();
SourceLocation ILoc = ConsumeToken();
if (getLangOpts().ObjC && Tok.is(tok::period) &&
(Actions.getTypeName(II, ILoc, getCurScope()) ||
(&II == Ident_super && getCurScope()->isInObjcMethodScope()))) {
ConsumeToken();
if (Tok.is(tok::code_completion) && &II != Ident_super) {
cutOffParsing();
Actions.CodeCompleteObjCClassPropertyRefExpr(
getCurScope(), II, ILoc, ExprStatementTokLoc == ILoc);
return ExprError();
}
if (Tok.isNot(tok::identifier) &&
!(getLangOpts().CPlusPlus && Tok.is(tok::kw_class))) {
Diag(Tok, diag::err_expected_property_name);
return ExprError();
}
IdentifierInfo &PropertyName = *Tok.getIdentifierInfo();
SourceLocation PropertyLoc = ConsumeToken();
Res = Actions.ActOnClassPropertyRefExpr(II, PropertyName,
ILoc, PropertyLoc);
break;
}
if (getLangOpts().ObjC && &II == Ident_super && !InMessageExpression &&
getCurScope()->isInObjcMethodScope() &&
((Tok.is(tok::identifier) &&
(NextToken().is(tok::colon) || NextToken().is(tok::r_square))) ||
Tok.is(tok::code_completion))) {
Res = ParseObjCMessageExpressionBody(SourceLocation(), ILoc, nullptr,
nullptr);
break;
}
if (getLangOpts().ObjC &&
((Tok.is(tok::identifier) && !InMessageExpression) ||
Tok.is(tok::code_completion))) {
const Token& Next = NextToken();
if (Tok.is(tok::code_completion) ||
Next.is(tok::colon) || Next.is(tok::r_square))
if (ParsedType Typ = Actions.getTypeName(II, ILoc, getCurScope()))
if (Typ.get()->isObjCObjectOrInterfaceType()) {
DeclSpec DS(AttrFactory);
DS.SetRangeStart(ILoc);
DS.SetRangeEnd(ILoc);
const char *PrevSpec = nullptr;
unsigned DiagID;
DS.SetTypeSpecType(TST_typename, ILoc, PrevSpec, DiagID, Typ,
Actions.getASTContext().getPrintingPolicy());
Declarator DeclaratorInfo(DS, ParsedAttributesView::none(),
DeclaratorContext::TypeName);
TypeResult Ty = Actions.ActOnTypeName(getCurScope(),
DeclaratorInfo);
if (Ty.isInvalid())
break;
Res = ParseObjCMessageExpressionBody(SourceLocation(),
SourceLocation(),
Ty.get(), nullptr);
break;
}
}
if (isAddressOfOperand && isPostfixExpressionSuffixStart())
isAddressOfOperand = false;
UnqualifiedId Name;
CXXScopeSpec ScopeSpec;
SourceLocation TemplateKWLoc;
Token Replacement;
CastExpressionIdValidator Validator(
Tok,
isTypeCast != NotTypeCast,
isTypeCast != IsTypeCast);
Validator.IsAddressOfOperand = isAddressOfOperand;
if (Tok.isOneOf(tok::periodstar, tok::arrowstar)) {
Validator.WantExpressionKeywords = false;
Validator.WantRemainingKeywords = false;
} else {
Validator.WantRemainingKeywords = Tok.isNot(tok::r_paren);
}
Name.setIdentifier(&II, ILoc);
Res = Actions.ActOnIdExpression(
getCurScope(), ScopeSpec, TemplateKWLoc, Name, Tok.is(tok::l_paren),
isAddressOfOperand, &Validator,
false,
Tok.is(tok::r_paren) ? nullptr : &Replacement);
if (!Res.isInvalid() && Res.isUnset()) {
UnconsumeToken(Replacement);
return ParseCastExpression(ParseKind, isAddressOfOperand,
NotCastExpr, isTypeCast,
false,
NotPrimaryExpression);
}
if (!Res.isInvalid() && Tok.is(tok::less))
checkPotentialAngleBracket(Res);
break;
}
case tok::char_constant: case tok::wide_char_constant:
case tok::utf8_char_constant:
case tok::utf16_char_constant:
case tok::utf32_char_constant:
Res = Actions.ActOnCharacterConstant(Tok, getCurScope());
ConsumeToken();
break;
case tok::kw___func__: case tok::kw___FUNCTION__: case tok::kw___FUNCDNAME__: case tok::kw___FUNCSIG__: case tok::kw_L__FUNCTION__: case tok::kw_L__FUNCSIG__: case tok::kw___PRETTY_FUNCTION__: Res = Actions.ActOnPredefinedExpr(Tok.getLocation(), SavedKind);
ConsumeToken();
break;
case tok::string_literal: case tok::wide_string_literal:
case tok::utf8_string_literal:
case tok::utf16_string_literal:
case tok::utf32_string_literal:
Res = ParseStringLiteralExpression(true);
break;
case tok::kw__Generic: Res = ParseGenericSelectionExpression();
break;
case tok::kw___builtin_available:
Res = ParseAvailabilityCheckExpr(Tok.getLocation());
break;
case tok::kw___builtin_va_arg:
case tok::kw___builtin_offsetof:
case tok::kw___builtin_choose_expr:
case tok::kw___builtin_astype: case tok::kw___builtin_convertvector:
case tok::kw___builtin_COLUMN:
case tok::kw___builtin_FILE:
case tok::kw___builtin_FUNCTION:
case tok::kw___builtin_LINE:
case tok::kw___builtin_source_location:
if (NotPrimaryExpression)
*NotPrimaryExpression = true;
return ParseBuiltinPrimaryExpression();
case tok::kw___null:
Res = Actions.ActOnGNUNullExpr(ConsumeToken());
break;
case tok::plusplus: case tok::minusminus: { if (NotPrimaryExpression)
*NotPrimaryExpression = true;
Token SavedTok = Tok;
ConsumeToken();
PreferredType.enterUnary(Actions, Tok.getLocation(), SavedTok.getKind(),
SavedTok.getLocation());
Res = ParseCastExpression(getLangOpts().CPlusPlus ?
UnaryExprOnly : AnyCastExpr,
false, NotCastExpr,
NotTypeCast);
if (NotCastExpr) {
assert(Res.isInvalid());
UnconsumeToken(SavedTok);
return ExprError();
}
if (!Res.isInvalid()) {
Expr *Arg = Res.get();
Res = Actions.ActOnUnaryOp(getCurScope(), SavedTok.getLocation(),
SavedKind, Arg);
if (Res.isInvalid())
Res = Actions.CreateRecoveryExpr(SavedTok.getLocation(),
Arg->getEndLoc(), Arg);
}
return Res;
}
case tok::amp: { if (NotPrimaryExpression)
*NotPrimaryExpression = true;
SourceLocation SavedLoc = ConsumeToken();
PreferredType.enterUnary(Actions, Tok.getLocation(), tok::amp, SavedLoc);
Res = ParseCastExpression(AnyCastExpr, true);
if (!Res.isInvalid()) {
Expr *Arg = Res.get();
Res = Actions.ActOnUnaryOp(getCurScope(), SavedLoc, SavedKind, Arg);
if (Res.isInvalid())
Res = Actions.CreateRecoveryExpr(Tok.getLocation(), Arg->getEndLoc(),
Arg);
}
return Res;
}
case tok::star: case tok::plus: case tok::minus: case tok::tilde: case tok::exclaim: case tok::kw___real: case tok::kw___imag: { if (NotPrimaryExpression)
*NotPrimaryExpression = true;
SourceLocation SavedLoc = ConsumeToken();
PreferredType.enterUnary(Actions, Tok.getLocation(), SavedKind, SavedLoc);
Res = ParseCastExpression(AnyCastExpr);
if (!Res.isInvalid()) {
Expr *Arg = Res.get();
Res = Actions.ActOnUnaryOp(getCurScope(), SavedLoc, SavedKind, Arg);
if (Res.isInvalid())
Res = Actions.CreateRecoveryExpr(SavedLoc, Arg->getEndLoc(), Arg);
}
return Res;
}
case tok::kw_co_await: { if (NotPrimaryExpression)
*NotPrimaryExpression = true;
SourceLocation CoawaitLoc = ConsumeToken();
Res = ParseCastExpression(AnyCastExpr);
if (!Res.isInvalid())
Res = Actions.ActOnCoawaitExpr(getCurScope(), CoawaitLoc, Res.get());
return Res;
}
case tok::kw___extension__:{ if (NotPrimaryExpression)
*NotPrimaryExpression = true;
ExtensionRAIIObject O(Diags); SourceLocation SavedLoc = ConsumeToken();
Res = ParseCastExpression(AnyCastExpr);
if (!Res.isInvalid())
Res = Actions.ActOnUnaryOp(getCurScope(), SavedLoc, SavedKind, Res.get());
return Res;
}
case tok::kw__Alignof: if (!getLangOpts().C11)
Diag(Tok, diag::ext_c11_feature) << Tok.getName();
LLVM_FALLTHROUGH;
case tok::kw_alignof: case tok::kw___alignof: case tok::kw_sizeof: case tok::kw_vec_step: case tok::kw___builtin_omp_required_simd_align:
if (NotPrimaryExpression)
*NotPrimaryExpression = true;
AllowSuffix = false;
Res = ParseUnaryExprOrTypeTraitExpression();
break;
case tok::ampamp: { if (NotPrimaryExpression)
*NotPrimaryExpression = true;
SourceLocation AmpAmpLoc = ConsumeToken();
if (Tok.isNot(tok::identifier))
return ExprError(Diag(Tok, diag::err_expected) << tok::identifier);
if (getCurScope()->getFnParent() == nullptr)
return ExprError(Diag(Tok, diag::err_address_of_label_outside_fn));
Diag(AmpAmpLoc, diag::ext_gnu_address_of_label);
LabelDecl *LD = Actions.LookupOrCreateLabel(Tok.getIdentifierInfo(),
Tok.getLocation());
Res = Actions.ActOnAddrLabel(AmpAmpLoc, Tok.getLocation(), LD);
ConsumeToken();
AllowSuffix = false;
break;
}
case tok::kw_const_cast:
case tok::kw_dynamic_cast:
case tok::kw_reinterpret_cast:
case tok::kw_static_cast:
case tok::kw_addrspace_cast:
if (NotPrimaryExpression)
*NotPrimaryExpression = true;
Res = ParseCXXCasts();
break;
case tok::kw___builtin_bit_cast:
if (NotPrimaryExpression)
*NotPrimaryExpression = true;
Res = ParseBuiltinBitCast();
break;
case tok::kw_typeid:
if (NotPrimaryExpression)
*NotPrimaryExpression = true;
Res = ParseCXXTypeid();
break;
case tok::kw___uuidof:
if (NotPrimaryExpression)
*NotPrimaryExpression = true;
Res = ParseCXXUuidof();
break;
case tok::kw_this:
Res = ParseCXXThis();
break;
case tok::kw___builtin_sycl_unique_stable_name:
Res = ParseSYCLUniqueStableNameExpression();
break;
case tok::annot_typename:
if (isStartOfObjCClassMessageMissingOpenBracket()) {
TypeResult Type = getTypeAnnotation(Tok);
DeclSpec DS(AttrFactory);
DS.SetRangeStart(Tok.getLocation());
DS.SetRangeEnd(Tok.getLastLoc());
const char *PrevSpec = nullptr;
unsigned DiagID;
DS.SetTypeSpecType(TST_typename, Tok.getAnnotationEndLoc(),
PrevSpec, DiagID, Type,
Actions.getASTContext().getPrintingPolicy());
Declarator DeclaratorInfo(DS, ParsedAttributesView::none(),
DeclaratorContext::TypeName);
TypeResult Ty = Actions.ActOnTypeName(getCurScope(), DeclaratorInfo);
if (Ty.isInvalid())
break;
ConsumeAnnotationToken();
Res = ParseObjCMessageExpressionBody(SourceLocation(), SourceLocation(),
Ty.get(), nullptr);
break;
}
LLVM_FALLTHROUGH;
case tok::annot_decltype:
case tok::kw_char:
case tok::kw_wchar_t:
case tok::kw_char8_t:
case tok::kw_char16_t:
case tok::kw_char32_t:
case tok::kw_bool:
case tok::kw_short:
case tok::kw_int:
case tok::kw_long:
case tok::kw___int64:
case tok::kw___int128:
case tok::kw__ExtInt:
case tok::kw__BitInt:
case tok::kw_signed:
case tok::kw_unsigned:
case tok::kw_half:
case tok::kw_float:
case tok::kw_double:
case tok::kw___bf16:
case tok::kw__Float16:
case tok::kw___float128:
case tok::kw___ibm128:
case tok::kw_void:
case tok::kw_auto:
case tok::kw_typename:
case tok::kw_typeof:
case tok::kw___vector:
#define GENERIC_IMAGE_TYPE(ImgType, Id) case tok::kw_##ImgType##_t:
#include "clang/Basic/OpenCLImageTypes.def"
{
if (!getLangOpts().CPlusPlus) {
Diag(Tok, diag::err_expected_expression);
return ExprError();
}
if (NotPrimaryExpression)
*NotPrimaryExpression = true;
if (SavedKind == tok::kw_typename) {
if (TryAnnotateTypeOrScopeToken())
return ExprError();
if (!Actions.isSimpleTypeSpecifier(Tok.getKind()))
return ExprError();
}
DeclSpec DS(AttrFactory);
ParseCXXSimpleTypeSpecifier(DS);
if (Tok.isNot(tok::l_paren) &&
(!getLangOpts().CPlusPlus11 || Tok.isNot(tok::l_brace)))
return ExprError(Diag(Tok, diag::err_expected_lparen_after_type)
<< DS.getSourceRange());
if (Tok.is(tok::l_brace))
Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists);
Res = ParseCXXTypeConstructExpression(DS);
break;
}
case tok::annot_cxxscope: { if (TryAnnotateTypeOrScopeToken())
return ExprError();
if (!Tok.is(tok::annot_cxxscope))
return ParseCastExpression(ParseKind, isAddressOfOperand, NotCastExpr,
isTypeCast, isVectorLiteral,
NotPrimaryExpression);
Token Next = NextToken();
if (Next.is(tok::annot_template_id)) {
TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Next);
if (TemplateId->Kind == TNK_Type_template) {
CXXScopeSpec SS;
ParseOptionalCXXScopeSpecifier(SS, nullptr,
false,
false);
AnnotateTemplateIdTokenAsType(SS);
return ParseCastExpression(ParseKind, isAddressOfOperand, NotCastExpr,
isTypeCast, isVectorLiteral,
NotPrimaryExpression);
}
}
Res = ParseCXXIdExpression(isAddressOfOperand);
break;
}
case tok::annot_template_id: { TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Tok);
if (TemplateId->Kind == TNK_Type_template) {
CXXScopeSpec SS;
AnnotateTemplateIdTokenAsType(SS);
return ParseCastExpression(ParseKind, isAddressOfOperand,
NotCastExpr, isTypeCast, isVectorLiteral,
NotPrimaryExpression);
}
LLVM_FALLTHROUGH;
}
case tok::kw_operator: Res = ParseCXXIdExpression(isAddressOfOperand);
break;
case tok::coloncolon: {
if (TryAnnotateTypeOrScopeToken())
return ExprError();
if (!Tok.is(tok::coloncolon))
return ParseCastExpression(ParseKind, isAddressOfOperand, isTypeCast,
isVectorLiteral, NotPrimaryExpression);
SourceLocation CCLoc = ConsumeToken();
if (Tok.is(tok::kw_new)) {
if (NotPrimaryExpression)
*NotPrimaryExpression = true;
Res = ParseCXXNewExpression(true, CCLoc);
AllowSuffix = false;
break;
}
if (Tok.is(tok::kw_delete)) {
if (NotPrimaryExpression)
*NotPrimaryExpression = true;
Res = ParseCXXDeleteExpression(true, CCLoc);
AllowSuffix = false;
break;
}
Diag(CCLoc, diag::err_expected_expression);
return ExprError();
}
case tok::kw_new: if (NotPrimaryExpression)
*NotPrimaryExpression = true;
Res = ParseCXXNewExpression(false, Tok.getLocation());
AllowSuffix = false;
break;
case tok::kw_delete: if (NotPrimaryExpression)
*NotPrimaryExpression = true;
Res = ParseCXXDeleteExpression(false, Tok.getLocation());
AllowSuffix = false;
break;
case tok::kw_requires: Res = ParseRequiresExpression();
AllowSuffix = false;
break;
case tok::kw_noexcept: { if (NotPrimaryExpression)
*NotPrimaryExpression = true;
Diag(Tok, diag::warn_cxx98_compat_noexcept_expr);
SourceLocation KeyLoc = ConsumeToken();
BalancedDelimiterTracker T(*this, tok::l_paren);
if (T.expectAndConsume(diag::err_expected_lparen_after, "noexcept"))
return ExprError();
EnterExpressionEvaluationContext Unevaluated(
Actions, Sema::ExpressionEvaluationContext::Unevaluated);
Res = ParseExpression();
T.consumeClose();
if (!Res.isInvalid())
Res = Actions.ActOnNoexceptExpr(KeyLoc, T.getOpenLocation(), Res.get(),
T.getCloseLocation());
AllowSuffix = false;
break;
}
#define TYPE_TRAIT(N,Spelling,K) \
case tok::kw_##Spelling:
#include "clang/Basic/TokenKinds.def"
Res = ParseTypeTrait();
break;
case tok::kw___array_rank:
case tok::kw___array_extent:
if (NotPrimaryExpression)
*NotPrimaryExpression = true;
Res = ParseArrayTypeTrait();
break;
case tok::kw___is_lvalue_expr:
case tok::kw___is_rvalue_expr:
if (NotPrimaryExpression)
*NotPrimaryExpression = true;
Res = ParseExpressionTrait();
break;
case tok::at: {
if (NotPrimaryExpression)
*NotPrimaryExpression = true;
SourceLocation AtLoc = ConsumeToken();
return ParseObjCAtExpression(AtLoc);
}
case tok::caret:
Res = ParseBlockLiteralExpression();
break;
case tok::code_completion: {
cutOffParsing();
Actions.CodeCompleteExpression(getCurScope(),
PreferredType.get(Tok.getLocation()));
return ExprError();
}
case tok::l_square:
if (getLangOpts().CPlusPlus11) {
if (getLangOpts().ObjC) {
Res = TryParseLambdaExpression();
if (!Res.isInvalid() && !Res.get()) {
if (NotPrimaryExpression)
*NotPrimaryExpression = true;
Res = ParseObjCMessageExpression();
}
break;
}
Res = ParseLambdaExpression();
break;
}
if (getLangOpts().ObjC) {
Res = ParseObjCMessageExpression();
break;
}
LLVM_FALLTHROUGH;
default:
NotCastExpr = true;
return ExprError();
}
if (ParseKind == PrimaryExprOnly)
return Res;
if (!AllowSuffix) {
if (Res.isInvalid())
return Res;
switch (Tok.getKind()) {
case tok::l_square:
case tok::l_paren:
case tok::plusplus:
case tok::minusminus:
if (Tok.isAtStartOfLine())
return Res;
LLVM_FALLTHROUGH;
case tok::period:
case tok::arrow:
break;
default:
return Res;
}
Diag(Tok.getLocation(), diag::err_postfix_after_unary_requires_parens)
<< Tok.getKind() << Res.get()->getSourceRange()
<< FixItHint::CreateInsertion(Res.get()->getBeginLoc(), "(")
<< FixItHint::CreateInsertion(PP.getLocForEndOfToken(PrevTokLocation),
")");
}
PreferredType = SavedType;
Res = ParsePostfixExpressionSuffix(Res);
if (getLangOpts().OpenCL &&
!getActions().getOpenCLOptions().isAvailableOption(
"__cl_clang_function_pointers", getLangOpts()))
if (Expr *PostfixExpr = Res.get()) {
QualType Ty = PostfixExpr->getType();
if (!Ty.isNull() && Ty->isFunctionType()) {
Diag(PostfixExpr->getExprLoc(),
diag::err_opencl_taking_function_address_parser);
return ExprError();
}
}
return Res;
}
ExprResult
Parser::ParsePostfixExpressionSuffix(ExprResult LHS) {
SourceLocation Loc;
auto SavedType = PreferredType;
while (true) {
PreferredType = SavedType;
switch (Tok.getKind()) {
case tok::code_completion:
if (InMessageExpression)
return LHS;
cutOffParsing();
Actions.CodeCompletePostfixExpression(
getCurScope(), LHS, PreferredType.get(Tok.getLocation()));
return ExprError();
case tok::identifier:
if (getLangOpts().ObjC && !InMessageExpression &&
(NextToken().is(tok::colon) || NextToken().is(tok::r_square))) {
LHS = ParseObjCMessageExpressionBody(SourceLocation(), SourceLocation(),
nullptr, LHS.get());
break;
}
LLVM_FALLTHROUGH;
default: return LHS;
case tok::l_square: { if (getLangOpts().ObjC && Tok.isAtStartOfLine() &&
isSimpleObjCMessageExpression())
return LHS;
if (CheckProhibitedCXX11Attribute()) {
(void)Actions.CorrectDelayedTyposInExpr(LHS);
return ExprError();
}
BalancedDelimiterTracker T(*this, tok::l_square);
T.consumeOpen();
Loc = T.getOpenLocation();
ExprResult Length, Stride;
SourceLocation ColonLocFirst, ColonLocSecond;
ExprVector ArgExprs;
bool HasError = false;
PreferredType.enterSubscript(Actions, Tok.getLocation(), LHS.get());
if (!getLangOpts().OpenMP || Tok.isNot(tok::colon)) {
if (!getLangOpts().CPlusPlus2b) {
ExprResult Idx;
if (getLangOpts().CPlusPlus11 && Tok.is(tok::l_brace)) {
Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists);
Idx = ParseBraceInitializer();
} else {
Idx = ParseExpression(); }
LHS = Actions.CorrectDelayedTyposInExpr(LHS);
Idx = Actions.CorrectDelayedTyposInExpr(Idx);
if (Idx.isInvalid()) {
HasError = true;
} else {
ArgExprs.push_back(Idx.get());
}
} else if (Tok.isNot(tok::r_square)) {
CommaLocsTy CommaLocs;
if (ParseExpressionList(ArgExprs, CommaLocs)) {
LHS = Actions.CorrectDelayedTyposInExpr(LHS);
HasError = true;
}
assert(
(ArgExprs.empty() || ArgExprs.size() == CommaLocs.size() + 1) &&
"Unexpected number of commas!");
}
}
if (ArgExprs.size() <= 1 && getLangOpts().OpenMP) {
ColonProtectionRAIIObject RAII(*this);
if (Tok.is(tok::colon)) {
ColonLocFirst = ConsumeToken();
if (Tok.isNot(tok::r_square) &&
(getLangOpts().OpenMP < 50 ||
((Tok.isNot(tok::colon) && getLangOpts().OpenMP >= 50)))) {
Length = ParseExpression();
Length = Actions.CorrectDelayedTyposInExpr(Length);
}
}
if (getLangOpts().OpenMP >= 50 &&
(OMPClauseKind == llvm::omp::Clause::OMPC_to ||
OMPClauseKind == llvm::omp::Clause::OMPC_from) &&
Tok.is(tok::colon)) {
ColonLocSecond = ConsumeToken();
if (Tok.isNot(tok::r_square)) {
Stride = ParseExpression();
}
}
}
SourceLocation RLoc = Tok.getLocation();
LHS = Actions.CorrectDelayedTyposInExpr(LHS);
if (!LHS.isInvalid() && !HasError && !Length.isInvalid() &&
!Stride.isInvalid() && Tok.is(tok::r_square)) {
if (ColonLocFirst.isValid() || ColonLocSecond.isValid()) {
LHS = Actions.ActOnOMPArraySectionExpr(
LHS.get(), Loc, ArgExprs.empty() ? nullptr : ArgExprs[0],
ColonLocFirst, ColonLocSecond, Length.get(), Stride.get(), RLoc);
} else {
LHS = Actions.ActOnArraySubscriptExpr(getCurScope(), LHS.get(), Loc,
ArgExprs, RLoc);
}
} else {
LHS = ExprError();
}
T.consumeClose();
break;
}
case tok::l_paren: case tok::lesslessless: { tok::TokenKind OpKind = Tok.getKind();
InMessageExpressionRAIIObject InMessage(*this, false);
Expr *ExecConfig = nullptr;
BalancedDelimiterTracker PT(*this, tok::l_paren);
if (OpKind == tok::lesslessless) {
ExprVector ExecConfigExprs;
CommaLocsTy ExecConfigCommaLocs;
SourceLocation OpenLoc = ConsumeToken();
if (ParseSimpleExpressionList(ExecConfigExprs, ExecConfigCommaLocs)) {
(void)Actions.CorrectDelayedTyposInExpr(LHS);
LHS = ExprError();
}
SourceLocation CloseLoc;
if (TryConsumeToken(tok::greatergreatergreater, CloseLoc)) {
} else if (LHS.isInvalid()) {
SkipUntil(tok::greatergreatergreater, StopAtSemi);
} else {
Diag(Tok, diag::err_expected) << tok::greatergreatergreater;
Diag(OpenLoc, diag::note_matching) << tok::lesslessless;
SkipUntil(tok::greatergreatergreater, StopAtSemi);
LHS = ExprError();
}
if (!LHS.isInvalid()) {
if (ExpectAndConsume(tok::l_paren))
LHS = ExprError();
else
Loc = PrevTokLocation;
}
if (!LHS.isInvalid()) {
ExprResult ECResult = Actions.ActOnCUDAExecConfigExpr(getCurScope(),
OpenLoc,
ExecConfigExprs,
CloseLoc);
if (ECResult.isInvalid())
LHS = ExprError();
else
ExecConfig = ECResult.get();
}
} else {
PT.consumeOpen();
Loc = PT.getOpenLocation();
}
ExprVector ArgExprs;
CommaLocsTy CommaLocs;
auto RunSignatureHelp = [&]() -> QualType {
QualType PreferredType = Actions.ProduceCallSignatureHelp(
LHS.get(), ArgExprs, PT.getOpenLocation());
CalledSignatureHelp = true;
return PreferredType;
};
if (OpKind == tok::l_paren || !LHS.isInvalid()) {
if (Tok.isNot(tok::r_paren)) {
if (ParseExpressionList(ArgExprs, CommaLocs, [&] {
PreferredType.enterFunctionArgument(Tok.getLocation(),
RunSignatureHelp);
})) {
(void)Actions.CorrectDelayedTyposInExpr(LHS);
if (PP.isCodeCompletionReached() && !CalledSignatureHelp)
RunSignatureHelp();
LHS = ExprError();
} else if (LHS.isInvalid()) {
for (auto &E : ArgExprs)
Actions.CorrectDelayedTyposInExpr(E);
}
}
}
if (LHS.isInvalid()) {
SkipUntil(tok::r_paren, StopAtSemi);
} else if (Tok.isNot(tok::r_paren)) {
bool HadDelayedTypo = false;
if (Actions.CorrectDelayedTyposInExpr(LHS).get() != LHS.get())
HadDelayedTypo = true;
for (auto &E : ArgExprs)
if (Actions.CorrectDelayedTyposInExpr(E).get() != E)
HadDelayedTypo = true;
if (HadDelayedTypo)
SkipUntil(tok::r_paren, StopAtSemi);
else
PT.consumeClose();
LHS = ExprError();
} else {
assert(
(ArgExprs.size() == 0 || ArgExprs.size() - 1 == CommaLocs.size()) &&
"Unexpected number of commas!");
Expr *Fn = LHS.get();
SourceLocation RParLoc = Tok.getLocation();
LHS = Actions.ActOnCallExpr(getCurScope(), Fn, Loc, ArgExprs, RParLoc,
ExecConfig);
if (LHS.isInvalid()) {
ArgExprs.insert(ArgExprs.begin(), Fn);
LHS =
Actions.CreateRecoveryExpr(Fn->getBeginLoc(), RParLoc, ArgExprs);
}
PT.consumeClose();
}
break;
}
case tok::arrow:
case tok::period: {
tok::TokenKind OpKind = Tok.getKind();
SourceLocation OpLoc = ConsumeToken();
CXXScopeSpec SS;
ParsedType ObjectType;
bool MayBePseudoDestructor = false;
Expr* OrigLHS = !LHS.isInvalid() ? LHS.get() : nullptr;
PreferredType.enterMemAccess(Actions, Tok.getLocation(), OrigLHS);
if (getLangOpts().CPlusPlus && !LHS.isInvalid()) {
Expr *Base = OrigLHS;
const Type* BaseType = Base->getType().getTypePtrOrNull();
if (BaseType && Tok.is(tok::l_paren) &&
(BaseType->isFunctionType() ||
BaseType->isSpecificPlaceholderType(BuiltinType::BoundMember))) {
Diag(OpLoc, diag::err_function_is_not_record)
<< OpKind << Base->getSourceRange()
<< FixItHint::CreateRemoval(OpLoc);
return ParsePostfixExpressionSuffix(Base);
}
LHS = Actions.ActOnStartCXXMemberReference(getCurScope(), Base, OpLoc,
OpKind, ObjectType,
MayBePseudoDestructor);
if (LHS.isInvalid()) {
if (Tok.is(tok::code_completion)) {
cutOffParsing();
return ExprError();
}
break;
}
ParseOptionalCXXScopeSpecifier(
SS, ObjectType, LHS.get() && LHS.get()->containsErrors(),
false, &MayBePseudoDestructor);
if (SS.isNotEmpty())
ObjectType = nullptr;
}
if (Tok.is(tok::code_completion)) {
tok::TokenKind CorrectedOpKind =
OpKind == tok::arrow ? tok::period : tok::arrow;
ExprResult CorrectedLHS(true);
if (getLangOpts().CPlusPlus && OrigLHS) {
Sema::TentativeAnalysisScope Trap(Actions);
CorrectedLHS = Actions.ActOnStartCXXMemberReference(
getCurScope(), OrigLHS, OpLoc, CorrectedOpKind, ObjectType,
MayBePseudoDestructor);
}
Expr *Base = LHS.get();
Expr *CorrectedBase = CorrectedLHS.get();
if (!CorrectedBase && !getLangOpts().CPlusPlus)
CorrectedBase = Base;
cutOffParsing();
Actions.CodeCompleteMemberReferenceExpr(
getCurScope(), Base, CorrectedBase, OpLoc, OpKind == tok::arrow,
Base && ExprStatementTokLoc == Base->getBeginLoc(),
PreferredType.get(Tok.getLocation()));
return ExprError();
}
if (MayBePseudoDestructor && !LHS.isInvalid()) {
LHS = ParseCXXPseudoDestructor(LHS.get(), OpLoc, OpKind, SS,
ObjectType);
break;
}
SourceLocation TemplateKWLoc;
UnqualifiedId Name;
if (getLangOpts().ObjC && OpKind == tok::period &&
Tok.is(tok::kw_class)) {
IdentifierInfo *Id = Tok.getIdentifierInfo();
SourceLocation Loc = ConsumeToken();
Name.setIdentifier(Id, Loc);
} else if (ParseUnqualifiedId(
SS, ObjectType, LHS.get() && LHS.get()->containsErrors(),
false,
true,
getLangOpts().MicrosoftExt && SS.isNotEmpty(),
false, &TemplateKWLoc, Name)) {
(void)Actions.CorrectDelayedTyposInExpr(LHS);
LHS = ExprError();
}
if (!LHS.isInvalid())
LHS = Actions.ActOnMemberAccessExpr(getCurScope(), LHS.get(), OpLoc,
OpKind, SS, TemplateKWLoc, Name,
CurParsedObjCImpl ? CurParsedObjCImpl->Dcl
: nullptr);
if (!LHS.isInvalid()) {
if (Tok.is(tok::less))
checkPotentialAngleBracket(LHS);
} else if (OrigLHS && Name.isValid()) {
LHS = Actions.CreateRecoveryExpr(OrigLHS->getBeginLoc(),
Name.getEndLoc(), {OrigLHS});
}
break;
}
case tok::plusplus: case tok::minusminus: if (!LHS.isInvalid()) {
Expr *Arg = LHS.get();
LHS = Actions.ActOnPostfixUnaryOp(getCurScope(), Tok.getLocation(),
Tok.getKind(), Arg);
if (LHS.isInvalid())
LHS = Actions.CreateRecoveryExpr(Arg->getBeginLoc(),
Tok.getLocation(), Arg);
}
ConsumeToken();
break;
}
}
}
ExprResult
Parser::ParseExprAfterUnaryExprOrTypeTrait(const Token &OpTok,
bool &isCastExpr,
ParsedType &CastTy,
SourceRange &CastRange) {
assert(OpTok.isOneOf(tok::kw_typeof, tok::kw_sizeof, tok::kw___alignof,
tok::kw_alignof, tok::kw__Alignof, tok::kw_vec_step,
tok::kw___builtin_omp_required_simd_align) &&
"Not a typeof/sizeof/alignof/vec_step expression!");
ExprResult Operand;
if (Tok.isNot(tok::l_paren)) {
if (OpTok.isOneOf(tok::kw_sizeof, tok::kw___alignof, tok::kw_alignof,
tok::kw__Alignof)) {
if (isTypeIdUnambiguously()) {
DeclSpec DS(AttrFactory);
ParseSpecifierQualifierList(DS);
Declarator DeclaratorInfo(DS, ParsedAttributesView::none(),
DeclaratorContext::TypeName);
ParseDeclarator(DeclaratorInfo);
SourceLocation LParenLoc = PP.getLocForEndOfToken(OpTok.getLocation());
SourceLocation RParenLoc = PP.getLocForEndOfToken(PrevTokLocation);
if (LParenLoc.isInvalid() || RParenLoc.isInvalid()) {
Diag(OpTok.getLocation(),
diag::err_expected_parentheses_around_typename)
<< OpTok.getName();
} else {
Diag(LParenLoc, diag::err_expected_parentheses_around_typename)
<< OpTok.getName() << FixItHint::CreateInsertion(LParenLoc, "(")
<< FixItHint::CreateInsertion(RParenLoc, ")");
}
isCastExpr = true;
return ExprEmpty();
}
}
isCastExpr = false;
if (OpTok.is(tok::kw_typeof) && !getLangOpts().CPlusPlus) {
Diag(Tok, diag::err_expected_after) << OpTok.getIdentifierInfo()
<< tok::l_paren;
return ExprError();
}
Operand = ParseCastExpression(UnaryExprOnly);
} else {
ParenParseOption ExprType = CastExpr;
SourceLocation LParenLoc = Tok.getLocation(), RParenLoc;
Operand = ParseParenExpression(ExprType, true,
false, CastTy, RParenLoc);
CastRange = SourceRange(LParenLoc, RParenLoc);
if (ExprType == CastExpr) {
isCastExpr = true;
return ExprEmpty();
}
if (getLangOpts().CPlusPlus || OpTok.isNot(tok::kw_typeof)) {
if (!Operand.isInvalid())
Operand = ParsePostfixExpressionSuffix(Operand.get());
}
}
isCastExpr = false;
return Operand;
}
ExprResult Parser::ParseSYCLUniqueStableNameExpression() {
assert(Tok.is(tok::kw___builtin_sycl_unique_stable_name) &&
"Not __builtin_sycl_unique_stable_name");
SourceLocation OpLoc = ConsumeToken();
BalancedDelimiterTracker T(*this, tok::l_paren);
if (T.expectAndConsume(diag::err_expected_lparen_after,
"__builtin_sycl_unique_stable_name"))
return ExprError();
TypeResult Ty = ParseTypeName();
if (Ty.isInvalid()) {
T.skipToEnd();
return ExprError();
}
if (T.consumeClose())
return ExprError();
return Actions.ActOnSYCLUniqueStableNameExpr(OpLoc, T.getOpenLocation(),
T.getCloseLocation(), Ty.get());
}
ExprResult Parser::ParseUnaryExprOrTypeTraitExpression() {
assert(Tok.isOneOf(tok::kw_sizeof, tok::kw___alignof, tok::kw_alignof,
tok::kw__Alignof, tok::kw_vec_step,
tok::kw___builtin_omp_required_simd_align) &&
"Not a sizeof/alignof/vec_step expression!");
Token OpTok = Tok;
ConsumeToken();
if (Tok.is(tok::ellipsis) && OpTok.is(tok::kw_sizeof)) {
SourceLocation EllipsisLoc = ConsumeToken();
SourceLocation LParenLoc, RParenLoc;
IdentifierInfo *Name = nullptr;
SourceLocation NameLoc;
if (Tok.is(tok::l_paren)) {
BalancedDelimiterTracker T(*this, tok::l_paren);
T.consumeOpen();
LParenLoc = T.getOpenLocation();
if (Tok.is(tok::identifier)) {
Name = Tok.getIdentifierInfo();
NameLoc = ConsumeToken();
T.consumeClose();
RParenLoc = T.getCloseLocation();
if (RParenLoc.isInvalid())
RParenLoc = PP.getLocForEndOfToken(NameLoc);
} else {
Diag(Tok, diag::err_expected_parameter_pack);
SkipUntil(tok::r_paren, StopAtSemi);
}
} 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();
EnterExpressionEvaluationContext Unevaluated(
Actions, Sema::ExpressionEvaluationContext::Unevaluated,
Sema::ReuseLambdaContextDecl);
return Actions.ActOnSizeofParameterPackExpr(getCurScope(),
OpTok.getLocation(),
*Name, NameLoc,
RParenLoc);
}
if (OpTok.isOneOf(tok::kw_alignof, tok::kw__Alignof))
Diag(OpTok, diag::warn_cxx98_compat_alignof);
EnterExpressionEvaluationContext Unevaluated(
Actions, Sema::ExpressionEvaluationContext::Unevaluated,
Sema::ReuseLambdaContextDecl);
bool isCastExpr;
ParsedType CastTy;
SourceRange CastRange;
ExprResult Operand = ParseExprAfterUnaryExprOrTypeTrait(OpTok,
isCastExpr,
CastTy,
CastRange);
UnaryExprOrTypeTrait ExprKind = UETT_SizeOf;
if (OpTok.isOneOf(tok::kw_alignof, tok::kw__Alignof))
ExprKind = UETT_AlignOf;
else if (OpTok.is(tok::kw___alignof))
ExprKind = UETT_PreferredAlignOf;
else if (OpTok.is(tok::kw_vec_step))
ExprKind = UETT_VecStep;
else if (OpTok.is(tok::kw___builtin_omp_required_simd_align))
ExprKind = UETT_OpenMPRequiredSimdAlign;
if (isCastExpr)
return Actions.ActOnUnaryExprOrTypeTraitExpr(OpTok.getLocation(),
ExprKind,
true,
CastTy.getAsOpaquePtr(),
CastRange);
if (OpTok.isOneOf(tok::kw_alignof, tok::kw__Alignof))
Diag(OpTok, diag::ext_alignof_expr) << OpTok.getIdentifierInfo();
if (!Operand.isInvalid())
Operand = Actions.ActOnUnaryExprOrTypeTraitExpr(OpTok.getLocation(),
ExprKind,
false,
Operand.get(),
CastRange);
return Operand;
}
ExprResult Parser::ParseBuiltinPrimaryExpression() {
ExprResult Res;
const IdentifierInfo *BuiltinII = Tok.getIdentifierInfo();
tok::TokenKind T = Tok.getKind();
SourceLocation StartLoc = ConsumeToken();
if (Tok.isNot(tok::l_paren))
return ExprError(Diag(Tok, diag::err_expected_after) << BuiltinII
<< tok::l_paren);
BalancedDelimiterTracker PT(*this, tok::l_paren);
PT.consumeOpen();
switch (T) {
default: llvm_unreachable("Not a builtin primary expression!");
case tok::kw___builtin_va_arg: {
ExprResult Expr(ParseAssignmentExpression());
if (ExpectAndConsume(tok::comma)) {
SkipUntil(tok::r_paren, StopAtSemi);
Expr = ExprError();
}
TypeResult Ty = ParseTypeName();
if (Tok.isNot(tok::r_paren)) {
Diag(Tok, diag::err_expected) << tok::r_paren;
Expr = ExprError();
}
if (Expr.isInvalid() || Ty.isInvalid())
Res = ExprError();
else
Res = Actions.ActOnVAArg(StartLoc, Expr.get(), Ty.get(), ConsumeParen());
break;
}
case tok::kw___builtin_offsetof: {
SourceLocation TypeLoc = Tok.getLocation();
TypeResult Ty = ParseTypeName();
if (Ty.isInvalid()) {
SkipUntil(tok::r_paren, StopAtSemi);
return ExprError();
}
if (ExpectAndConsume(tok::comma)) {
SkipUntil(tok::r_paren, StopAtSemi);
return ExprError();
}
if (Tok.isNot(tok::identifier)) {
Diag(Tok, diag::err_expected) << tok::identifier;
SkipUntil(tok::r_paren, StopAtSemi);
return ExprError();
}
SmallVector<Sema::OffsetOfComponent, 4> Comps;
Comps.push_back(Sema::OffsetOfComponent());
Comps.back().isBrackets = false;
Comps.back().U.IdentInfo = Tok.getIdentifierInfo();
Comps.back().LocStart = Comps.back().LocEnd = ConsumeToken();
while (true) {
if (Tok.is(tok::period)) {
Comps.push_back(Sema::OffsetOfComponent());
Comps.back().isBrackets = false;
Comps.back().LocStart = ConsumeToken();
if (Tok.isNot(tok::identifier)) {
Diag(Tok, diag::err_expected) << tok::identifier;
SkipUntil(tok::r_paren, StopAtSemi);
return ExprError();
}
Comps.back().U.IdentInfo = Tok.getIdentifierInfo();
Comps.back().LocEnd = ConsumeToken();
} else if (Tok.is(tok::l_square)) {
if (CheckProhibitedCXX11Attribute())
return ExprError();
Comps.push_back(Sema::OffsetOfComponent());
Comps.back().isBrackets = true;
BalancedDelimiterTracker ST(*this, tok::l_square);
ST.consumeOpen();
Comps.back().LocStart = ST.getOpenLocation();
Res = ParseExpression();
if (Res.isInvalid()) {
SkipUntil(tok::r_paren, StopAtSemi);
return Res;
}
Comps.back().U.E = Res.get();
ST.consumeClose();
Comps.back().LocEnd = ST.getCloseLocation();
} else {
if (Tok.isNot(tok::r_paren)) {
PT.consumeClose();
Res = ExprError();
} else if (Ty.isInvalid()) {
Res = ExprError();
} else {
PT.consumeClose();
Res = Actions.ActOnBuiltinOffsetOf(getCurScope(), StartLoc, TypeLoc,
Ty.get(), Comps,
PT.getCloseLocation());
}
break;
}
}
break;
}
case tok::kw___builtin_choose_expr: {
ExprResult Cond(ParseAssignmentExpression());
if (Cond.isInvalid()) {
SkipUntil(tok::r_paren, StopAtSemi);
return Cond;
}
if (ExpectAndConsume(tok::comma)) {
SkipUntil(tok::r_paren, StopAtSemi);
return ExprError();
}
ExprResult Expr1(ParseAssignmentExpression());
if (Expr1.isInvalid()) {
SkipUntil(tok::r_paren, StopAtSemi);
return Expr1;
}
if (ExpectAndConsume(tok::comma)) {
SkipUntil(tok::r_paren, StopAtSemi);
return ExprError();
}
ExprResult Expr2(ParseAssignmentExpression());
if (Expr2.isInvalid()) {
SkipUntil(tok::r_paren, StopAtSemi);
return Expr2;
}
if (Tok.isNot(tok::r_paren)) {
Diag(Tok, diag::err_expected) << tok::r_paren;
return ExprError();
}
Res = Actions.ActOnChooseExpr(StartLoc, Cond.get(), Expr1.get(),
Expr2.get(), ConsumeParen());
break;
}
case tok::kw___builtin_astype: {
ExprResult Expr(ParseAssignmentExpression());
if (Expr.isInvalid()) {
SkipUntil(tok::r_paren, StopAtSemi);
return ExprError();
}
if (ExpectAndConsume(tok::comma)) {
SkipUntil(tok::r_paren, StopAtSemi);
return ExprError();
}
TypeResult DestTy = ParseTypeName();
if (DestTy.isInvalid())
return ExprError();
if (Tok.isNot(tok::r_paren)) {
Diag(Tok, diag::err_expected) << tok::r_paren;
SkipUntil(tok::r_paren, StopAtSemi);
return ExprError();
}
Res = Actions.ActOnAsTypeExpr(Expr.get(), DestTy.get(), StartLoc,
ConsumeParen());
break;
}
case tok::kw___builtin_convertvector: {
ExprResult Expr(ParseAssignmentExpression());
if (Expr.isInvalid()) {
SkipUntil(tok::r_paren, StopAtSemi);
return ExprError();
}
if (ExpectAndConsume(tok::comma)) {
SkipUntil(tok::r_paren, StopAtSemi);
return ExprError();
}
TypeResult DestTy = ParseTypeName();
if (DestTy.isInvalid())
return ExprError();
if (Tok.isNot(tok::r_paren)) {
Diag(Tok, diag::err_expected) << tok::r_paren;
SkipUntil(tok::r_paren, StopAtSemi);
return ExprError();
}
Res = Actions.ActOnConvertVectorExpr(Expr.get(), DestTy.get(), StartLoc,
ConsumeParen());
break;
}
case tok::kw___builtin_COLUMN:
case tok::kw___builtin_FILE:
case tok::kw___builtin_FUNCTION:
case tok::kw___builtin_LINE:
case tok::kw___builtin_source_location: {
if (Tok.isNot(tok::r_paren)) {
Diag(Tok, diag::err_expected) << tok::r_paren;
SkipUntil(tok::r_paren, StopAtSemi);
return ExprError();
}
SourceLocExpr::IdentKind Kind = [&] {
switch (T) {
case tok::kw___builtin_FILE:
return SourceLocExpr::File;
case tok::kw___builtin_FUNCTION:
return SourceLocExpr::Function;
case tok::kw___builtin_LINE:
return SourceLocExpr::Line;
case tok::kw___builtin_COLUMN:
return SourceLocExpr::Column;
case tok::kw___builtin_source_location:
return SourceLocExpr::SourceLocStruct;
default:
llvm_unreachable("invalid keyword");
}
}();
Res = Actions.ActOnSourceLocExpr(Kind, StartLoc, ConsumeParen());
break;
}
}
if (Res.isInvalid())
return ExprError();
return ParsePostfixExpressionSuffix(Res.get());
}
bool Parser::tryParseOpenMPArrayShapingCastPart() {
assert(Tok.is(tok::l_square) && "Expected open bracket");
bool ErrorFound = true;
TentativeParsingAction TPA(*this);
do {
if (Tok.isNot(tok::l_square))
break;
ConsumeBracket();
while (!SkipUntil(tok::r_square, tok::annot_pragma_openmp_end,
StopAtSemi | StopBeforeMatch))
;
if (Tok.isNot(tok::r_square))
break;
ConsumeBracket();
if (Tok.is(tok::r_paren)) {
ErrorFound = false;
break;
}
} while (Tok.isNot(tok::annot_pragma_openmp_end));
TPA.Revert();
return !ErrorFound;
}
ExprResult
Parser::ParseParenExpression(ParenParseOption &ExprType, bool stopIfCastExpr,
bool isTypeCast, ParsedType &CastTy,
SourceLocation &RParenLoc) {
assert(Tok.is(tok::l_paren) && "Not a paren expr!");
ColonProtectionRAIIObject ColonProtection(*this, false);
BalancedDelimiterTracker T(*this, tok::l_paren);
if (T.consumeOpen())
return ExprError();
SourceLocation OpenLoc = T.getOpenLocation();
PreferredType.enterParenExpr(Tok.getLocation(), OpenLoc);
ExprResult Result(true);
bool isAmbiguousTypeId;
CastTy = nullptr;
if (Tok.is(tok::code_completion)) {
cutOffParsing();
Actions.CodeCompleteExpression(
getCurScope(), PreferredType.get(Tok.getLocation()),
ExprType >= CompoundLiteral);
return ExprError();
}
bool BridgeCast = (getLangOpts().ObjC &&
Tok.isOneOf(tok::kw___bridge,
tok::kw___bridge_transfer,
tok::kw___bridge_retained,
tok::kw___bridge_retain));
if (BridgeCast && !getLangOpts().ObjCAutoRefCount) {
if (!TryConsumeToken(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, "");
}
BridgeCast = false;
}
if (ExprType >= CompoundStmt && Tok.is(tok::l_brace)) {
Diag(Tok, OpenLoc.isMacroID() ? diag::ext_gnu_statement_expr_macro
: diag::ext_gnu_statement_expr);
checkCompoundToken(OpenLoc, tok::l_paren, CompoundToken::StmtExprBegin);
if (!getCurScope()->getFnParent() && !getCurScope()->getBlockParent()) {
Result = ExprError(Diag(OpenLoc, diag::err_stmtexpr_file_scope));
} else {
DeclContext *CodeDC = Actions.CurContext;
while (CodeDC->isRecord() || isa<EnumDecl>(CodeDC)) {
CodeDC = CodeDC->getParent();
assert(CodeDC && !CodeDC->isFileContext() &&
"statement expr not in code context");
}
Sema::ContextRAII SavedContext(Actions, CodeDC, false);
Actions.ActOnStartStmtExpr();
StmtResult Stmt(ParseCompoundStatement(true));
ExprType = CompoundStmt;
if (!Stmt.isInvalid()) {
Result = Actions.ActOnStmtExpr(getCurScope(), OpenLoc, Stmt.get(),
Tok.getLocation());
} else {
Actions.ActOnStmtExprError();
}
}
} else if (ExprType >= CompoundLiteral && BridgeCast) {
tok::TokenKind tokenKind = Tok.getKind();
SourceLocation BridgeKeywordLoc = ConsumeToken();
ObjCBridgeCastKind Kind;
if (tokenKind == tok::kw___bridge)
Kind = OBC_Bridge;
else if (tokenKind == tok::kw___bridge_transfer)
Kind = OBC_BridgeTransfer;
else if (tokenKind == tok::kw___bridge_retained)
Kind = OBC_BridgeRetained;
else {
assert(tokenKind == tok::kw___bridge_retain);
Kind = OBC_BridgeRetained;
if (!PP.getSourceManager().isInSystemHeader(BridgeKeywordLoc))
Diag(BridgeKeywordLoc, diag::err_arc_bridge_retain)
<< FixItHint::CreateReplacement(BridgeKeywordLoc,
"__bridge_retained");
}
TypeResult Ty = ParseTypeName();
T.consumeClose();
ColonProtection.restore();
RParenLoc = T.getCloseLocation();
PreferredType.enterTypeCast(Tok.getLocation(), Ty.get().get());
ExprResult SubExpr = ParseCastExpression(AnyCastExpr);
if (Ty.isInvalid() || SubExpr.isInvalid())
return ExprError();
return Actions.ActOnObjCBridgedCast(getCurScope(), OpenLoc, Kind,
BridgeKeywordLoc, Ty.get(),
RParenLoc, SubExpr.get());
} else if (ExprType >= CompoundLiteral &&
isTypeIdInParens(isAmbiguousTypeId)) {
if (isAmbiguousTypeId && !stopIfCastExpr) {
ExprResult res = ParseCXXAmbiguousParenExpression(ExprType, CastTy, T,
ColonProtection);
RParenLoc = T.getCloseLocation();
return res;
}
DeclSpec DS(AttrFactory);
ParseSpecifierQualifierList(DS);
Declarator DeclaratorInfo(DS, ParsedAttributesView::none(),
DeclaratorContext::TypeName);
ParseDeclarator(DeclaratorInfo);
if (!DeclaratorInfo.isInvalidType() && Tok.is(tok::identifier) &&
!InMessageExpression && getLangOpts().ObjC &&
(NextToken().is(tok::colon) || NextToken().is(tok::r_square))) {
TypeResult Ty;
{
InMessageExpressionRAIIObject InMessage(*this, false);
Ty = Actions.ActOnTypeName(getCurScope(), DeclaratorInfo);
}
Result = ParseObjCMessageExpressionBody(SourceLocation(),
SourceLocation(),
Ty.get(), nullptr);
} else {
T.consumeClose();
ColonProtection.restore();
RParenLoc = T.getCloseLocation();
if (Tok.is(tok::l_brace)) {
ExprType = CompoundLiteral;
TypeResult Ty;
{
InMessageExpressionRAIIObject InMessage(*this, false);
Ty = Actions.ActOnTypeName(getCurScope(), DeclaratorInfo);
}
return ParseCompoundLiteralExpression(Ty.get(), OpenLoc, RParenLoc);
}
if (Tok.is(tok::l_paren)) {
if (getLangOpts().OpenCL)
{
TypeResult Ty;
{
InMessageExpressionRAIIObject InMessage(*this, false);
Ty = Actions.ActOnTypeName(getCurScope(), DeclaratorInfo);
}
if(Ty.isInvalid())
{
return ExprError();
}
QualType QT = Ty.get().get().getCanonicalType();
if (QT->isVectorType())
{
Result = ParseCastExpression(AnyCastExpr,
false,
IsTypeCast,
true);
if (!Result.isInvalid()) {
Result = Actions.ActOnCastExpr(getCurScope(), OpenLoc,
DeclaratorInfo, CastTy,
RParenLoc, Result.get());
}
if (!Result.isInvalid()) {
Result = ParsePostfixExpressionSuffix(Result);
}
return Result;
}
}
}
if (ExprType == CastExpr) {
if (DeclaratorInfo.isInvalidType())
return ExprError();
if (stopIfCastExpr) {
TypeResult Ty;
{
InMessageExpressionRAIIObject InMessage(*this, false);
Ty = Actions.ActOnTypeName(getCurScope(), DeclaratorInfo);
}
CastTy = Ty.get();
return ExprResult();
}
if (Tok.is(tok::identifier) && getLangOpts().ObjC &&
Tok.getIdentifierInfo() == Ident_super &&
getCurScope()->isInObjcMethodScope() &&
GetLookAheadToken(1).isNot(tok::period)) {
Diag(Tok.getLocation(), diag::err_illegal_super_cast)
<< SourceRange(OpenLoc, RParenLoc);
return ExprError();
}
PreferredType.enterTypeCast(Tok.getLocation(), CastTy.get());
Result = ParseCastExpression(AnyCastExpr,
false,
IsTypeCast);
if (!Result.isInvalid()) {
Result = Actions.ActOnCastExpr(getCurScope(), OpenLoc,
DeclaratorInfo, CastTy,
RParenLoc, Result.get());
}
return Result;
}
Diag(Tok, diag::err_expected_lbrace_in_compound_literal);
return ExprError();
}
} else if (ExprType >= FoldExpr && Tok.is(tok::ellipsis) &&
isFoldOperator(NextToken().getKind())) {
ExprType = FoldExpr;
return ParseFoldExpression(ExprResult(), T);
} else if (isTypeCast) {
InMessageExpressionRAIIObject InMessage(*this, false);
ExprVector ArgExprs;
CommaLocsTy CommaLocs;
if (!ParseSimpleExpressionList(ArgExprs, CommaLocs)) {
if (ExprType >= FoldExpr && ArgExprs.size() == 1 &&
isFoldOperator(Tok.getKind()) && NextToken().is(tok::ellipsis)) {
ExprType = FoldExpr;
return ParseFoldExpression(ArgExprs[0], T);
}
ExprType = SimpleExpr;
Result = Actions.ActOnParenListExpr(OpenLoc, Tok.getLocation(),
ArgExprs);
}
} else if (getLangOpts().OpenMP >= 50 && OpenMPDirectiveParsing &&
ExprType == CastExpr && Tok.is(tok::l_square) &&
tryParseOpenMPArrayShapingCastPart()) {
bool ErrorFound = false;
SmallVector<Expr *, 4> OMPDimensions;
SmallVector<SourceRange, 4> OMPBracketsRanges;
do {
BalancedDelimiterTracker TS(*this, tok::l_square);
TS.consumeOpen();
ExprResult NumElements =
Actions.CorrectDelayedTyposInExpr(ParseExpression());
if (!NumElements.isUsable()) {
ErrorFound = true;
while (!SkipUntil(tok::r_square, tok::r_paren,
StopAtSemi | StopBeforeMatch))
;
}
TS.consumeClose();
OMPDimensions.push_back(NumElements.get());
OMPBracketsRanges.push_back(TS.getRange());
} while (Tok.isNot(tok::r_paren));
T.consumeClose();
RParenLoc = T.getCloseLocation();
Result = Actions.CorrectDelayedTyposInExpr(ParseAssignmentExpression());
if (ErrorFound) {
Result = ExprError();
} else if (!Result.isInvalid()) {
Result = Actions.ActOnOMPArrayShapingExpr(
Result.get(), OpenLoc, RParenLoc, OMPDimensions, OMPBracketsRanges);
}
return Result;
} else {
InMessageExpressionRAIIObject InMessage(*this, false);
Result = ParseExpression(MaybeTypeCast);
if (!getLangOpts().CPlusPlus && MaybeTypeCast && Result.isUsable()) {
Result = Actions.CorrectDelayedTyposInExpr(Result);
}
if (ExprType >= FoldExpr && isFoldOperator(Tok.getKind()) &&
NextToken().is(tok::ellipsis)) {
ExprType = FoldExpr;
return ParseFoldExpression(Result, T);
}
ExprType = SimpleExpr;
if (!Result.isInvalid() && Tok.is(tok::r_paren))
Result =
Actions.ActOnParenExpr(OpenLoc, Tok.getLocation(), Result.get());
}
if (Result.isInvalid()) {
SkipUntil(tok::r_paren, StopAtSemi);
return ExprError();
}
T.consumeClose();
RParenLoc = T.getCloseLocation();
return Result;
}
ExprResult
Parser::ParseCompoundLiteralExpression(ParsedType Ty,
SourceLocation LParenLoc,
SourceLocation RParenLoc) {
assert(Tok.is(tok::l_brace) && "Not a compound literal!");
if (!getLangOpts().C99) Diag(LParenLoc, diag::ext_c99_compound_literal);
PreferredType.enterTypeCast(Tok.getLocation(), Ty.get());
ExprResult Result = ParseInitializer();
if (!Result.isInvalid() && Ty)
return Actions.ActOnCompoundLiteral(LParenLoc, Ty, RParenLoc, Result.get());
return Result;
}
ExprResult Parser::ParseStringLiteralExpression(bool AllowUserDefinedLiteral) {
assert(isTokenStringLiteral() && "Not a string literal!");
SmallVector<Token, 4> StringToks;
do {
StringToks.push_back(Tok);
ConsumeStringToken();
} while (isTokenStringLiteral());
return Actions.ActOnStringLiteral(StringToks,
AllowUserDefinedLiteral ? getCurScope()
: nullptr);
}
ExprResult Parser::ParseGenericSelectionExpression() {
assert(Tok.is(tok::kw__Generic) && "_Generic keyword expected");
if (!getLangOpts().C11)
Diag(Tok, diag::ext_c11_feature) << Tok.getName();
SourceLocation KeyLoc = ConsumeToken();
BalancedDelimiterTracker T(*this, tok::l_paren);
if (T.expectAndConsume())
return ExprError();
ExprResult ControllingExpr;
{
EnterExpressionEvaluationContext Unevaluated(
Actions, Sema::ExpressionEvaluationContext::Unevaluated);
ControllingExpr =
Actions.CorrectDelayedTyposInExpr(ParseAssignmentExpression());
if (ControllingExpr.isInvalid()) {
SkipUntil(tok::r_paren, StopAtSemi);
return ExprError();
}
}
if (ExpectAndConsume(tok::comma)) {
SkipUntil(tok::r_paren, StopAtSemi);
return ExprError();
}
SourceLocation DefaultLoc;
TypeVector Types;
ExprVector Exprs;
do {
ParsedType Ty;
if (Tok.is(tok::kw_default)) {
if (!DefaultLoc.isInvalid()) {
Diag(Tok, diag::err_duplicate_default_assoc);
Diag(DefaultLoc, diag::note_previous_default_assoc);
SkipUntil(tok::r_paren, StopAtSemi);
return ExprError();
}
DefaultLoc = ConsumeToken();
Ty = nullptr;
} else {
ColonProtectionRAIIObject X(*this);
TypeResult TR = ParseTypeName(nullptr, DeclaratorContext::Association);
if (TR.isInvalid()) {
SkipUntil(tok::r_paren, StopAtSemi);
return ExprError();
}
Ty = TR.get();
}
Types.push_back(Ty);
if (ExpectAndConsume(tok::colon)) {
SkipUntil(tok::r_paren, StopAtSemi);
return ExprError();
}
ExprResult ER(
Actions.CorrectDelayedTyposInExpr(ParseAssignmentExpression()));
if (ER.isInvalid()) {
SkipUntil(tok::r_paren, StopAtSemi);
return ExprError();
}
Exprs.push_back(ER.get());
} while (TryConsumeToken(tok::comma));
T.consumeClose();
if (T.getCloseLocation().isInvalid())
return ExprError();
return Actions.ActOnGenericSelectionExpr(KeyLoc, DefaultLoc,
T.getCloseLocation(),
ControllingExpr.get(),
Types, Exprs);
}
ExprResult Parser::ParseFoldExpression(ExprResult LHS,
BalancedDelimiterTracker &T) {
if (LHS.isInvalid()) {
T.skipToEnd();
return true;
}
tok::TokenKind Kind = tok::unknown;
SourceLocation FirstOpLoc;
if (LHS.isUsable()) {
Kind = Tok.getKind();
assert(isFoldOperator(Kind) && "missing fold-operator");
FirstOpLoc = ConsumeToken();
}
assert(Tok.is(tok::ellipsis) && "not a fold-expression");
SourceLocation EllipsisLoc = ConsumeToken();
ExprResult RHS;
if (Tok.isNot(tok::r_paren)) {
if (!isFoldOperator(Tok.getKind()))
return Diag(Tok.getLocation(), diag::err_expected_fold_operator);
if (Kind != tok::unknown && Tok.getKind() != Kind)
Diag(Tok.getLocation(), diag::err_fold_operator_mismatch)
<< SourceRange(FirstOpLoc);
Kind = Tok.getKind();
ConsumeToken();
RHS = ParseExpression();
if (RHS.isInvalid()) {
T.skipToEnd();
return true;
}
}
Diag(EllipsisLoc, getLangOpts().CPlusPlus17
? diag::warn_cxx14_compat_fold_expression
: diag::ext_fold_expression);
T.consumeClose();
return Actions.ActOnCXXFoldExpr(getCurScope(), T.getOpenLocation(), LHS.get(),
Kind, EllipsisLoc, RHS.get(),
T.getCloseLocation());
}
bool Parser::ParseExpressionList(SmallVectorImpl<Expr *> &Exprs,
SmallVectorImpl<SourceLocation> &CommaLocs,
llvm::function_ref<void()> ExpressionStarts,
bool FailImmediatelyOnInvalidExpr,
bool EarlyTypoCorrection) {
bool SawError = false;
while (true) {
if (ExpressionStarts)
ExpressionStarts();
ExprResult Expr;
if (getLangOpts().CPlusPlus11 && Tok.is(tok::l_brace)) {
Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists);
Expr = ParseBraceInitializer();
} else
Expr = ParseAssignmentExpression();
if (EarlyTypoCorrection)
Expr = Actions.CorrectDelayedTyposInExpr(Expr);
if (Tok.is(tok::ellipsis))
Expr = Actions.ActOnPackExpansion(Expr.get(), ConsumeToken());
else if (Tok.is(tok::code_completion)) {
SawError = true;
cutOffParsing();
break;
}
if (Expr.isInvalid()) {
SawError = true;
if (FailImmediatelyOnInvalidExpr)
break;
SkipUntil(tok::comma, tok::r_paren, StopBeforeMatch);
} else {
Exprs.push_back(Expr.get());
}
if (Tok.isNot(tok::comma))
break;
Token Comma = Tok;
CommaLocs.push_back(ConsumeToken());
checkPotentialAngleBracketDelimiter(Comma);
}
if (SawError) {
for (auto &E : Exprs) {
ExprResult Expr = Actions.CorrectDelayedTyposInExpr(E);
if (Expr.isUsable()) E = Expr.get();
}
}
return SawError;
}
bool
Parser::ParseSimpleExpressionList(SmallVectorImpl<Expr*> &Exprs,
SmallVectorImpl<SourceLocation> &CommaLocs) {
while (true) {
ExprResult Expr = ParseAssignmentExpression();
if (Expr.isInvalid())
return true;
Exprs.push_back(Expr.get());
if (Tok.isNot(tok::comma))
return false;
Token Comma = Tok;
CommaLocs.push_back(ConsumeToken());
checkPotentialAngleBracketDelimiter(Comma);
}
}
void Parser::ParseBlockId(SourceLocation CaretLoc) {
if (Tok.is(tok::code_completion)) {
cutOffParsing();
Actions.CodeCompleteOrdinaryName(getCurScope(), Sema::PCC_Type);
return;
}
DeclSpec DS(AttrFactory);
ParseSpecifierQualifierList(DS);
Declarator DeclaratorInfo(DS, ParsedAttributesView::none(),
DeclaratorContext::BlockLiteral);
DeclaratorInfo.setFunctionDefinitionKind(FunctionDefinitionKind::Definition);
ParseDeclarator(DeclaratorInfo);
MaybeParseGNUAttributes(DeclaratorInfo);
Actions.ActOnBlockArguments(CaretLoc, DeclaratorInfo, getCurScope());
}
ExprResult Parser::ParseBlockLiteralExpression() {
assert(Tok.is(tok::caret) && "block literal starts with ^");
SourceLocation CaretLoc = ConsumeToken();
PrettyStackTraceLoc CrashInfo(PP.getSourceManager(), CaretLoc,
"block literal parsing");
ParseScope BlockScope(this, Scope::BlockScope | Scope::FnScope |
Scope::CompoundStmtScope | Scope::DeclScope);
Actions.ActOnBlockStart(CaretLoc, getCurScope());
DeclSpec DS(AttrFactory);
Declarator ParamInfo(DS, ParsedAttributesView::none(),
DeclaratorContext::BlockLiteral);
ParamInfo.setFunctionDefinitionKind(FunctionDefinitionKind::Definition);
ParamInfo.SetSourceRange(SourceRange(Tok.getLocation(), Tok.getLocation()));
if (Tok.is(tok::l_paren)) {
ParseParenDeclarator(ParamInfo);
SourceLocation Tmp = ParamInfo.getSourceRange().getEnd();
ParamInfo.SetIdentifier(nullptr, CaretLoc);
ParamInfo.SetRangeEnd(Tmp);
if (ParamInfo.isInvalidType()) {
Actions.ActOnBlockError(CaretLoc, getCurScope());
return ExprError();
}
MaybeParseGNUAttributes(ParamInfo);
Actions.ActOnBlockArguments(CaretLoc, ParamInfo, getCurScope());
} else if (!Tok.is(tok::l_brace)) {
ParseBlockId(CaretLoc);
} else {
SourceLocation NoLoc;
ParamInfo.AddTypeInfo(
DeclaratorChunk::getFunction(true,
false,
NoLoc,
nullptr,
0,
NoLoc,
NoLoc,
true,
NoLoc,
NoLoc, EST_None,
SourceRange(),
nullptr,
nullptr,
0,
nullptr,
nullptr,
None, CaretLoc,
CaretLoc, ParamInfo),
CaretLoc);
MaybeParseGNUAttributes(ParamInfo);
Actions.ActOnBlockArguments(CaretLoc, ParamInfo, getCurScope());
}
ExprResult Result(true);
if (!Tok.is(tok::l_brace)) {
Diag(Tok, diag::err_expected_expression);
Actions.ActOnBlockError(CaretLoc, getCurScope());
return ExprError();
}
StmtResult Stmt(ParseCompoundStatementBody());
BlockScope.Exit();
if (!Stmt.isInvalid())
Result = Actions.ActOnBlockStmtExpr(CaretLoc, Stmt.get(), getCurScope());
else
Actions.ActOnBlockError(CaretLoc, getCurScope());
return Result;
}
ExprResult Parser::ParseObjCBoolLiteral() {
tok::TokenKind Kind = Tok.getKind();
return Actions.ActOnObjCBoolLiteral(ConsumeToken(), Kind);
}
static bool CheckAvailabilitySpecList(Parser &P,
ArrayRef<AvailabilitySpec> AvailSpecs) {
llvm::SmallSet<StringRef, 4> Platforms;
bool HasOtherPlatformSpec = false;
bool Valid = true;
for (const auto &Spec : AvailSpecs) {
if (Spec.isOtherPlatformSpec()) {
if (HasOtherPlatformSpec) {
P.Diag(Spec.getBeginLoc(), diag::err_availability_query_repeated_star);
Valid = false;
}
HasOtherPlatformSpec = true;
continue;
}
bool Inserted = Platforms.insert(Spec.getPlatform()).second;
if (!Inserted) {
StringRef Platform = Spec.getPlatform();
P.Diag(Spec.getBeginLoc(), diag::err_availability_query_repeated_platform)
<< Spec.getEndLoc() << Platform;
Valid = false;
}
}
if (!HasOtherPlatformSpec) {
SourceLocation InsertWildcardLoc = AvailSpecs.back().getEndLoc();
P.Diag(InsertWildcardLoc, diag::err_availability_query_wildcard_required)
<< FixItHint::CreateInsertion(InsertWildcardLoc, ", *");
return true;
}
return !Valid;
}
Optional<AvailabilitySpec> Parser::ParseAvailabilitySpec() {
if (Tok.is(tok::star)) {
return AvailabilitySpec(ConsumeToken());
} else {
if (Tok.is(tok::code_completion)) {
cutOffParsing();
Actions.CodeCompleteAvailabilityPlatformName();
return None;
}
if (Tok.isNot(tok::identifier)) {
Diag(Tok, diag::err_avail_query_expected_platform_name);
return None;
}
IdentifierLoc *PlatformIdentifier = ParseIdentifierLoc();
SourceRange VersionRange;
VersionTuple Version = ParseVersionTuple(VersionRange);
if (Version.empty())
return None;
StringRef GivenPlatform = PlatformIdentifier->Ident->getName();
StringRef Platform =
AvailabilityAttr::canonicalizePlatformName(GivenPlatform);
if (AvailabilityAttr::getPrettyPlatformName(Platform).empty()) {
Diag(PlatformIdentifier->Loc,
diag::err_avail_query_unrecognized_platform_name)
<< GivenPlatform;
return None;
}
return AvailabilitySpec(Version, Platform, PlatformIdentifier->Loc,
VersionRange.getEnd());
}
}
ExprResult Parser::ParseAvailabilityCheckExpr(SourceLocation BeginLoc) {
assert(Tok.is(tok::kw___builtin_available) ||
Tok.isObjCAtKeyword(tok::objc_available));
ConsumeToken();
BalancedDelimiterTracker Parens(*this, tok::l_paren);
if (Parens.expectAndConsume())
return ExprError();
SmallVector<AvailabilitySpec, 4> AvailSpecs;
bool HasError = false;
while (true) {
Optional<AvailabilitySpec> Spec = ParseAvailabilitySpec();
if (!Spec)
HasError = true;
else
AvailSpecs.push_back(*Spec);
if (!TryConsumeToken(tok::comma))
break;
}
if (HasError) {
SkipUntil(tok::r_paren, StopAtSemi);
return ExprError();
}
CheckAvailabilitySpecList(*this, AvailSpecs);
if (Parens.consumeClose())
return ExprError();
return Actions.ActOnObjCAvailabilityCheckExpr(AvailSpecs, BeginLoc,
Parens.getCloseLocation());
}