本文整理汇总了C++中ExprResult::isInvalid方法的典型用法代码示例。如果您正苦于以下问题:C++ ExprResult::isInvalid方法的具体用法?C++ ExprResult::isInvalid怎么用?C++ ExprResult::isInvalid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ExprResult
的用法示例。
在下文中一共展示了ExprResult::isInvalid方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ParseEquivOperand
Parser::ExprResult Parser::ParseEquivOperand() {
ExprResult E = ParseOrOperand();
if (E.isInvalid()) return ExprResult();
while (Tok.getKind() == tok::kw_OR) {
llvm::SMLoc OpLoc = Tok.getLocation();
Lex();
ExprResult OrOp = ParseOrOperand();
if (OrOp.isInvalid()) return ExprResult();
E = BinaryExpr::Create(Context, OpLoc, BinaryExpr::Or, E, OrOp);
}
return E;
}
示例2: ParseAssignmentStmt
/// ParseAssignmentStmt
/// [R732]:
/// assignment-stmt :=
/// variable = expr
Parser::StmtResult Parser::ParseAssignmentStmt() {
ExprResult LHS = ParsePrimaryExpr(true);
if(LHS.isInvalid()) return StmtError();
SourceLocation Loc = Tok.getLocation();
if(!ConsumeIfPresent(tok::equal)) {
Diag.Report(getExpectedLoc(),diag::err_expected_equal);
return StmtError();
}
ExprResult RHS = ParseExpectedFollowupExpression("=");
if(RHS.isInvalid()) return StmtError();
return Actions.ActOnAssignmentStmt(Context, Loc, LHS, RHS, StmtLabel);
}
示例3: actOnCoroutineBodyStart
static bool actOnCoroutineBodyStart(Sema &S, Scope *SC, SourceLocation KWLoc,
StringRef Keyword) {
if (!checkCoroutineContext(S, KWLoc, Keyword))
return false;
auto *ScopeInfo = S.getCurFunction();
assert(ScopeInfo->CoroutinePromise);
// If we have existing coroutine statements then we have already built
// the initial and final suspend points.
if (!ScopeInfo->NeedsCoroutineSuspends)
return true;
ScopeInfo->setNeedsCoroutineSuspends(false);
auto *Fn = cast<FunctionDecl>(S.CurContext);
SourceLocation Loc = Fn->getLocation();
// Build the initial suspend point
auto buildSuspends = [&](StringRef Name) mutable -> StmtResult {
ExprResult Suspend =
buildPromiseCall(S, ScopeInfo->CoroutinePromise, Loc, Name, None);
if (Suspend.isInvalid())
return StmtError();
Suspend = buildOperatorCoawaitCall(S, SC, Loc, Suspend.get());
if (Suspend.isInvalid())
return StmtError();
Suspend = S.BuildResolvedCoawaitExpr(Loc, Suspend.get(),
/*IsImplicit*/ true);
Suspend = S.ActOnFinishFullExpr(Suspend.get());
if (Suspend.isInvalid()) {
S.Diag(Loc, diag::note_coroutine_promise_suspend_implicitly_required)
<< ((Name == "initial_suspend") ? 0 : 1);
S.Diag(KWLoc, diag::note_declared_coroutine_here) << Keyword;
return StmtError();
}
return cast<Stmt>(Suspend.get());
};
StmtResult InitSuspend = buildSuspends("initial_suspend");
if (InitSuspend.isInvalid())
return true;
StmtResult FinalSuspend = buildSuspends("final_suspend");
if (FinalSuspend.isInvalid())
return true;
ScopeInfo->setCoroutineSuspends(InitSuspend.get(), FinalSuspend.get());
return true;
}
示例4: ParseExpression
// ParseExpression - Expressions are level-5 expressions optionally involving
// defined binary operators.
//
// R722:
// expr :=
// [ expr defined-binary-op ] level-5-expr
//
// R723:
// defined-binary-op :=
// . letter [ letter ] ... .
Parser::ExprResult Parser::ParseExpression() {
ExprResult LHS = ParseLevel5Expr();
if (LHS.isInvalid()) return LHS;
if (!IsPresent(tok::defined_operator))
return LHS;
SourceLocation OpLoc = Tok.getLocation();
IdentifierInfo *II = Tok.getIdentifierInfo();
Lex();
ExprResult RHS = ParseLevel5Expr();
if (RHS.isInvalid()) return RHS;
return DefinedBinaryOperatorExpr::Create(Context, OpLoc, LHS.take(), RHS.take(), II);
}
示例5: ParseMicrosoftIfExistsBraceInitializer
// Return true if a comma (or closing brace) is necessary after the
// __if_exists/if_not_exists statement.
bool Parser::ParseMicrosoftIfExistsBraceInitializer(ExprVector &InitExprs,
bool &InitExprsOk) {
bool trailingComma = false;
IfExistsCondition Result;
if (ParseMicrosoftIfExistsCondition(Result))
return false;
BalancedDelimiterTracker Braces(*this, tok::l_brace);
if (Braces.consumeOpen()) {
Diag(Tok, diag::err_expected) << tok::l_brace;
return false;
}
switch (Result.Behavior) {
case IEB_Parse:
// Parse the declarations below.
break;
case IEB_Dependent:
Diag(Result.KeywordLoc, diag::warn_microsoft_dependent_exists)
<< Result.IsIfExists;
// Fall through to skip.
case IEB_Skip:
Braces.skipToEnd();
return false;
}
while (!isEofOrEom()) {
trailingComma = false;
// If we know that this cannot be a designation, just parse the nested
// initializer directly.
ExprResult SubElt;
if (MayBeDesignationStart())
SubElt = ParseInitializerWithPotentialDesignator();
else
SubElt = ParseInitializer();
if (Tok.is(tok::ellipsis))
SubElt = Actions.ActOnPackExpansion(SubElt.get(), ConsumeToken());
// If we couldn't parse the subelement, bail out.
if (!SubElt.isInvalid())
InitExprs.push_back(SubElt.release());
else
InitExprsOk = false;
if (Tok.is(tok::comma)) {
ConsumeToken();
trailingComma = true;
}
if (Tok.is(tok::r_brace))
break;
}
Braces.consumeClose();
return !trailingComma;
}
示例6: Result
/// Look up the std::nothrow object.
static Expr *buildStdNoThrowDeclRef(Sema &S, SourceLocation Loc) {
NamespaceDecl *Std = S.getStdNamespace();
assert(Std && "Should already be diagnosed");
LookupResult Result(S, &S.PP.getIdentifierTable().get("nothrow"), Loc,
Sema::LookupOrdinaryName);
if (!S.LookupQualifiedName(Result, Std)) {
// FIXME: <experimental/coroutine> should have been included already.
// If we require it to include <new> then this diagnostic is no longer
// needed.
S.Diag(Loc, diag::err_implicit_coroutine_std_nothrow_type_not_found);
return nullptr;
}
// FIXME: Mark the variable as ODR used. This currently does not work
// likely due to the scope at in which this function is called.
auto *VD = Result.getAsSingle<VarDecl>();
if (!VD) {
Result.suppressDiagnostics();
// We found something weird. Complain about the first thing we found.
NamedDecl *Found = *Result.begin();
S.Diag(Found->getLocation(), diag::err_malformed_std_nothrow);
return nullptr;
}
ExprResult DR = S.BuildDeclRefExpr(VD, VD->getType(), VK_LValue, Loc);
if (DR.isInvalid())
return nullptr;
return DR.get();
}
示例7: ParseUnaryExpression
/// ParseUnaryExpression - Parse a unary-expression.
/// unary-expression:
/// inc-dec-expression
/// ++ unary-expression
/// -- unary-expression
/// unary-operator unary-expression
ExprResult Parser::ParseUnaryExpression() {
ExprResult Res;
tok::TokenKind SavedKind = Tok.getKind();
switch (SavedKind) {
case tok::DoubleAdd:
case tok::DoubleSub:
// unary operators
case tok::Addition:
case tok::Subtraction:
case tok::Tilde:
case tok::At: {
SourceLocation SavedLoc = ConsumeToken();
Res = ParsePostfixExpression();
if (!Res.isInvalid()) {
Res = Actions.ActOnUnaryOp(getCurScope(), SavedLoc, SavedKind,false,
Res.get());
}
return move(Res);
}
default:
break;
}
return ParsePostfixExpression();
}
示例8: buildCoroutineHandle
static ExprResult buildCoroutineHandle(Sema &S, QualType PromiseType,
SourceLocation Loc) {
QualType CoroHandleType = lookupCoroutineHandleType(S, PromiseType, Loc);
if (CoroHandleType.isNull())
return ExprError();
DeclContext *LookupCtx = S.computeDeclContext(CoroHandleType);
LookupResult Found(S, &S.PP.getIdentifierTable().get("from_address"), Loc,
Sema::LookupOrdinaryName);
if (!S.LookupQualifiedName(Found, LookupCtx)) {
S.Diag(Loc, diag::err_coroutine_handle_missing_member)
<< "from_address";
return ExprError();
}
Expr *FramePtr =
buildBuiltinCall(S, Loc, Builtin::BI__builtin_coro_frame, {});
CXXScopeSpec SS;
ExprResult FromAddr =
S.BuildDeclarationNameExpr(SS, Found, /*NeedsADL=*/false);
if (FromAddr.isInvalid())
return ExprError();
return S.ActOnCallExpr(nullptr, FromAddr.get(), Loc, FramePtr, Loc);
}
示例9: ParseExpression
// ParseExpression - Expressions are level-5 expresisons optionally involving
// defined binary operators.
//
// R722:
// expr :=
// [ expr defined-binary-op ] level-5-expr
//
// R723:
// defined-binary-op :=
// . letter [ letter ] ... .
Parser::ExprResult Parser::ParseExpression() {
ExprResult LHS = ParseLevel5Expr();
if (LHS.isInvalid()) return ExprResult();
if (Tok.isNot(tok::defined_operator))
return LHS;
llvm::SMLoc OpLoc = Tok.getLocation();
IdentifierInfo *II = Tok.getIdentifierInfo();
Lex();
ExprResult RHS = ParseLevel5Expr();
if (RHS.isInvalid()) return ExprResult();
return DefinedOperatorBinaryExpr::Create(Context, OpLoc, LHS, RHS, II);
}
示例10: BuildCoyieldExpr
ExprResult Sema::BuildCoyieldExpr(SourceLocation Loc, Expr *E) {
auto *Coroutine = checkCoroutineContext(*this, Loc, "co_yield");
if (!Coroutine)
return ExprError();
if (E->getType()->isPlaceholderType()) {
ExprResult R = CheckPlaceholderExpr(E);
if (R.isInvalid()) return ExprError();
E = R.get();
}
if (E->getType()->isDependentType()) {
Expr *Res = new (Context) CoyieldExpr(Loc, Context.DependentTy, E);
return Res;
}
// If the expression is a temporary, materialize it as an lvalue so that we
// can use it multiple times.
if (E->getValueKind() == VK_RValue)
E = CreateMaterializeTemporaryExpr(E->getType(), E, true);
// Build the await_ready, await_suspend, await_resume calls.
ReadySuspendResumeResult RSS =
buildCoawaitCalls(*this, Coroutine->CoroutinePromise, Loc, E);
if (RSS.IsInvalid)
return ExprError();
Expr *Res = new (Context) CoyieldExpr(Loc, E, RSS.Results[0], RSS.Results[1],
RSS.Results[2], RSS.OpaqueValue);
return Res;
}
示例11: ActOnCoyieldExpr
ExprResult Sema::ActOnCoyieldExpr(SourceLocation Loc, Expr *E) {
auto *Context = checkCoroutineContext(*this, Loc, "co_yield");
ExprResult Res = ExprError();
if (Context && !Res.isInvalid())
Context->CoroutineStmts.push_back(Res.get());
return Res;
}
示例12: buildOperatorCoawaitCall
static ExprResult buildOperatorCoawaitCall(Sema &SemaRef, Scope *S,
SourceLocation Loc, Expr *E) {
ExprResult R = buildOperatorCoawaitLookupExpr(SemaRef, S, Loc);
if (R.isInvalid())
return ExprError();
return buildOperatorCoawaitCall(SemaRef, Loc, E,
cast<UnresolvedLookupExpr>(R.get()));
}
示例13: ActOnCoawaitExpr
ExprResult Sema::ActOnCoawaitExpr(Scope *S, SourceLocation Loc, Expr *E) {
if (!actOnCoroutineBodyStart(*this, S, Loc, "co_await")) {
CorrectDelayedTyposInExpr(E);
return ExprError();
}
if (E->getType()->isPlaceholderType()) {
ExprResult R = CheckPlaceholderExpr(E);
if (R.isInvalid()) return ExprError();
E = R.get();
}
ExprResult Lookup = buildOperatorCoawaitLookupExpr(*this, S, Loc);
if (Lookup.isInvalid())
return ExprError();
return BuildUnresolvedCoawaitExpr(Loc, E,
cast<UnresolvedLookupExpr>(Lookup.get()));
}
示例14: ExprError
static ExprResult
BuildFieldReferenceExpr(Sema &S, Expr *BaseExpr, bool IsArrow,
const CXXScopeSpec &SS, FieldDecl *Field,
DeclAccessPair FoundDecl,
const DeclarationNameInfo &MemberNameInfo) {
// x.a is an l-value if 'a' has a reference type. Otherwise:
// x.a is an l-value/x-value/pr-value if the base is (and note
// that *x is always an l-value), except that if the base isn't
// an ordinary object then we must have an rvalue.
ExprValueKind VK = VK_LValue;
ExprObjectKind OK = OK_Ordinary;
if (!IsArrow) {
if (BaseExpr->getObjectKind() == OK_Ordinary)
VK = BaseExpr->getValueKind();
else
VK = VK_RValue;
}
if (VK != VK_RValue && Field->isBitField())
OK = OK_BitField;
// Figure out the type of the member; see C99 6.5.2.3p3, C++ [expr.ref]
QualType MemberType = Field->getType();
if (const ReferenceType *Ref = MemberType->getAs<ReferenceType>()) {
MemberType = Ref->getPointeeType();
VK = VK_LValue;
} else {
QualType BaseType = BaseExpr->getType();
if (IsArrow) BaseType = BaseType->getAs<PointerType>()->getPointeeType();
Qualifiers BaseQuals = BaseType.getQualifiers();
// CVR attributes from the base are picked up by members,
// except that 'mutable' members don't pick up 'const'.
if (Field->isMutable()) BaseQuals.removeConst();
Qualifiers MemberQuals
= S.Context.getCanonicalType(MemberType).getQualifiers();
assert(!MemberQuals.hasAddressSpace());
Qualifiers Combined = BaseQuals + MemberQuals;
if (Combined != MemberQuals)
MemberType = S.Context.getQualifiedType(MemberType, Combined);
}
S.UnusedPrivateFields.remove(Field);
ExprResult Base =
S.PerformObjectMemberConversion(BaseExpr, SS.getScopeRep(),
FoundDecl, Field);
if (Base.isInvalid())
return ExprError();
return S.Owned(BuildMemberExpr(S, S.Context, Base.take(), IsArrow,
Field, FoundDecl, MemberNameInfo,
MemberType, VK, OK));
}
示例15: ActOnCoyieldExpr
ExprResult Sema::ActOnCoyieldExpr(Scope *S, SourceLocation Loc, Expr *E) {
auto *Coroutine = checkCoroutineContext(*this, Loc, "co_yield");
if (!Coroutine)
return ExprError();
// Build yield_value call.
ExprResult Awaitable =
buildPromiseCall(*this, Coroutine, Loc, "yield_value", E);
if (Awaitable.isInvalid())
return ExprError();
// Build 'operator co_await' call.
Awaitable = buildOperatorCoawaitCall(*this, S, Loc, Awaitable.get());
if (Awaitable.isInvalid())
return ExprError();
return BuildCoyieldExpr(Loc, Awaitable.get());
}