本文整理汇总了C++中ExprResult::get方法的典型用法代码示例。如果您正苦于以下问题:C++ ExprResult::get方法的具体用法?C++ ExprResult::get怎么用?C++ ExprResult::get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ExprResult
的用法示例。
在下文中一共展示了ExprResult::get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ParseConcatParenExpr
// FIXME: Rewrite to only accept binary form. Make type optional.
ExprResult ParserImpl::ParseConcatParenExpr(const Token &Name,
Expr::Width ResTy) {
std::vector<ExprHandle> Kids;
unsigned Width = 0;
while (Tok.kind != Token::RParen) {
ExprResult E = ParseExpr(TypeResult());
// Skip to end of expr on error.
if (!E.isValid()) {
SkipUntilRParen();
return Builder->Constant(0, ResTy);
}
Kids.push_back(E.get());
Width += E.get()->getWidth();
}
ConsumeRParen();
if (Width != ResTy) {
Error("concat does not match expected result size.");
return Builder->Constant(0, ResTy);
}
// FIXME: Use builder!
return ConcatExpr::createN(Kids.size(), &Kids[0]);
}
示例2: BuildCoreturnStmt
StmtResult Sema::BuildCoreturnStmt(SourceLocation Loc, Expr *E) {
auto *Coroutine = checkCoroutineContext(*this, Loc, "co_return");
if (!Coroutine)
return StmtError();
if (E && E->getType()->isPlaceholderType() &&
!E->getType()->isSpecificPlaceholderType(BuiltinType::Overload)) {
ExprResult R = CheckPlaceholderExpr(E);
if (R.isInvalid()) return StmtError();
E = R.get();
}
// FIXME: If the operand is a reference to a variable that's about to go out
// ot scope, we should treat the operand as an xvalue for this overload
// resolution.
ExprResult PC;
if (E && !E->getType()->isVoidType()) {
PC = buildPromiseCall(*this, Coroutine, Loc, "return_value", E);
} else {
E = MakeFullDiscardedValueExpr(E).get();
PC = buildPromiseCall(*this, Coroutine, Loc, "return_void", None);
}
if (PC.isInvalid())
return StmtError();
Expr *PCE = ActOnFinishFullExpr(PC.get()).get();
Stmt *Res = new (Context) CoreturnStmt(Loc, E, PCE);
Coroutine->CoroutineStmts.push_back(Res);
return Res;
}
示例3: BuildCoreturnStmt
StmtResult Sema::BuildCoreturnStmt(SourceLocation Loc, Expr *E,
bool IsImplicit) {
auto *FSI = checkCoroutineContext(*this, Loc, "co_return", IsImplicit);
if (!FSI)
return StmtError();
if (E && E->getType()->isPlaceholderType() &&
!E->getType()->isSpecificPlaceholderType(BuiltinType::Overload)) {
ExprResult R = CheckPlaceholderExpr(E);
if (R.isInvalid()) return StmtError();
E = R.get();
}
// FIXME: If the operand is a reference to a variable that's about to go out
// of scope, we should treat the operand as an xvalue for this overload
// resolution.
VarDecl *Promise = FSI->CoroutinePromise;
ExprResult PC;
if (E && (isa<InitListExpr>(E) || !E->getType()->isVoidType())) {
PC = buildPromiseCall(*this, Promise, Loc, "return_value", E);
} else {
E = MakeFullDiscardedValueExpr(E).get();
PC = buildPromiseCall(*this, Promise, Loc, "return_void", None);
}
if (PC.isInvalid())
return StmtError();
Expr *PCE = ActOnFinishFullExpr(PC.get()).get();
Stmt *Res = new (Context) CoreturnStmt(Loc, E, PCE, IsImplicit);
return Res;
}
示例4: ActOnDATAConstantExpr
ExprResult Sema::ActOnDATAConstantExpr(ASTContext &C,
SourceLocation RepeatLoc,
ExprResult RepeatCount,
ExprResult Value) {
IntegerConstantExpr *RepeatExpr = nullptr;
bool HasErrors = false;
if(RepeatCount.isUsable()) {
RepeatExpr = dyn_cast<IntegerConstantExpr>(RepeatCount.get());
if(!RepeatExpr ||
!RepeatExpr->getValue().isStrictlyPositive()) {
Diags.Report(RepeatCount.get()->getLocation(),
diag::err_expected_integer_gt_0)
<< RepeatCount.get()->getSourceRange();
HasErrors = true;
RepeatExpr = nullptr;
}
}
if(!CheckConstantExpression(Value.get()))
HasErrors = true;
if(HasErrors) return ExprError();
return RepeatExpr? RepeatedConstantExpr::Create(C, RepeatLoc,
RepeatExpr, Value.take())
: Value;
}
示例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.get());
else
InitExprsOk = false;
if (Tok.is(tok::comma)) {
ConsumeToken();
trailingComma = true;
}
if (Tok.is(tok::r_brace))
break;
}
Braces.consumeClose();
return !trailingComma;
}
示例6: buildCoawaitCalls
/// Build calls to await_ready, await_suspend, and await_resume for a co_await
/// expression.
static ReadySuspendResumeResult buildCoawaitCalls(Sema &S, VarDecl *CoroPromise,
SourceLocation Loc, Expr *E) {
OpaqueValueExpr *Operand = new (S.Context)
OpaqueValueExpr(Loc, E->getType(), VK_LValue, E->getObjectKind(), E);
// Assume invalid until we see otherwise.
ReadySuspendResumeResult Calls = {{}, Operand, /*IsInvalid=*/true};
ExprResult CoroHandleRes = buildCoroutineHandle(S, CoroPromise->getType(), Loc);
if (CoroHandleRes.isInvalid())
return Calls;
Expr *CoroHandle = CoroHandleRes.get();
const StringRef Funcs[] = {"await_ready", "await_suspend", "await_resume"};
MultiExprArg Args[] = {None, CoroHandle, None};
for (size_t I = 0, N = llvm::array_lengthof(Funcs); I != N; ++I) {
ExprResult Result = buildMemberCall(S, Operand, Loc, Funcs[I], Args[I]);
if (Result.isInvalid())
return Calls;
Calls.Results[I] = Result.get();
}
// Assume the calls are valid; all further checking should make them invalid.
Calls.IsInvalid = false;
using ACT = ReadySuspendResumeResult::AwaitCallType;
CallExpr *AwaitReady = cast<CallExpr>(Calls.Results[ACT::ACT_Ready]);
if (!AwaitReady->getType()->isDependentType()) {
// [expr.await]p3 [...]
// — await-ready is the expression e.await_ready(), contextually converted
// to bool.
ExprResult Conv = S.PerformContextuallyConvertToBool(AwaitReady);
if (Conv.isInvalid()) {
S.Diag(AwaitReady->getDirectCallee()->getLocStart(),
diag::note_await_ready_no_bool_conversion);
S.Diag(Loc, diag::note_coroutine_promise_call_implicitly_required)
<< AwaitReady->getDirectCallee() << E->getSourceRange();
Calls.IsInvalid = true;
}
Calls.Results[ACT::ACT_Ready] = Conv.get();
}
CallExpr *AwaitSuspend = cast<CallExpr>(Calls.Results[ACT::ACT_Suspend]);
if (!AwaitSuspend->getType()->isDependentType()) {
// [expr.await]p3 [...]
// - await-suspend is the expression e.await_suspend(h), which shall be
// a prvalue of type void or bool.
QualType RetType = AwaitSuspend->getType();
if (RetType != S.Context.BoolTy && RetType != S.Context.VoidTy) {
S.Diag(AwaitSuspend->getCalleeDecl()->getLocation(),
diag::err_await_suspend_invalid_return_type)
<< RetType;
S.Diag(Loc, diag::note_coroutine_promise_call_implicitly_required)
<< AwaitSuspend->getDirectCallee();
Calls.IsInvalid = true;
}
}
return Calls;
}
示例7: ExprResult
C2::ExprResult C2Sema::ActOnArrayDesignatorExpr(SourceLocation left, ExprResult Designator, ExprResult InitValue) {
#ifdef SEMA_DEBUG
std::cerr << COL_SEMA"SEMA: ArrayDesignatorExpr at ";
left_.dump(SourceMgr);
std::cerr << ANSI_NORMAL"\n";
#endif
return ExprResult(new DesignatedInitExpr(left, Designator.get(), InitValue.get()));
}
示例8: LookupInlineAsmIdentifier
ExprResult Sema::LookupInlineAsmIdentifier(CXXScopeSpec &SS,
SourceLocation TemplateKWLoc,
UnqualifiedId &Id,
llvm::InlineAsmIdentifierInfo &Info,
bool IsUnevaluatedContext) {
Info.clear();
if (IsUnevaluatedContext)
PushExpressionEvaluationContext(UnevaluatedAbstract,
ReuseLambdaContextDecl);
ExprResult Result = ActOnIdExpression(getCurScope(), SS, TemplateKWLoc, Id,
/*trailing lparen*/ false,
/*is & operand*/ false,
/*CorrectionCandidateCallback=*/nullptr,
/*IsInlineAsmIdentifier=*/ true);
if (IsUnevaluatedContext)
PopExpressionEvaluationContext();
if (!Result.isUsable()) return Result;
Result = CheckPlaceholderExpr(Result.get());
if (!Result.isUsable()) return Result;
QualType T = Result.get()->getType();
// For now, reject dependent types.
if (T->isDependentType()) {
Diag(Id.getLocStart(), diag::err_asm_incomplete_type) << T;
return ExprError();
}
// Any sort of function type is fine.
if (T->isFunctionType()) {
return Result;
}
// Otherwise, it needs to be a complete type.
if (RequireCompleteExprType(Result.get(), diag::err_asm_incomplete_type)) {
return ExprError();
}
// Compute the type size (and array length if applicable?).
Info.Type = Info.Size = Context.getTypeSizeInChars(T).getQuantity();
if (T->isArrayType()) {
const ArrayType *ATy = Context.getAsArrayType(T);
Info.Type = Context.getTypeSizeInChars(ATy->getElementType()).getQuantity();
Info.Length = Info.Size / Info.Type;
}
// We can work with the expression as long as it's not an r-value.
if (!Result.get()->isRValue())
Info.IsVarDecl = true;
return Result;
}
示例9: T
/// \brief Parsing of OpenMP clauses with single expressions and some additional
/// argument like 'schedule' or 'dist_schedule'.
///
/// schedule-clause:
/// 'schedule' '(' kind [',' expression ] ')'
///
/// if-clause:
/// 'if' '(' [ directive-name-modifier ':' ] expression ')'
///
OMPClause *Parser::ParseOpenMPSingleExprWithArgClause(OpenMPClauseKind Kind) {
SourceLocation Loc = ConsumeToken();
SourceLocation DelimLoc;
// Parse '('.
BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
if (T.expectAndConsume(diag::err_expected_lparen_after,
getOpenMPClauseName(Kind)))
return nullptr;
ExprResult Val;
unsigned Arg;
SourceLocation KLoc;
if (Kind == OMPC_schedule) {
Arg = getOpenMPSimpleClauseType(
Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok));
KLoc = Tok.getLocation();
if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
Tok.isNot(tok::annot_pragma_openmp_end))
ConsumeAnyToken();
if ((Arg == OMPC_SCHEDULE_static || Arg == OMPC_SCHEDULE_dynamic ||
Arg == OMPC_SCHEDULE_guided) &&
Tok.is(tok::comma))
DelimLoc = ConsumeAnyToken();
} else {
assert(Kind == OMPC_if);
KLoc = Tok.getLocation();
Arg = ParseOpenMPDirectiveKind(*this);
if (Arg != OMPD_unknown) {
ConsumeToken();
if (Tok.is(tok::colon))
DelimLoc = ConsumeToken();
else
Diag(Tok, diag::warn_pragma_expected_colon)
<< "directive name modifier";
}
}
bool NeedAnExpression =
(Kind == OMPC_schedule && DelimLoc.isValid()) || Kind == OMPC_if;
if (NeedAnExpression) {
SourceLocation ELoc = Tok.getLocation();
ExprResult LHS(ParseCastExpression(false, false, NotTypeCast));
Val = ParseRHSOfBinaryExpression(LHS, prec::Conditional);
Val = Actions.ActOnFinishFullExpr(Val.get(), ELoc);
}
// Parse ')'.
T.consumeClose();
if (NeedAnExpression && Val.isInvalid())
return nullptr;
return Actions.ActOnOpenMPSingleExprWithArgClause(
Kind, Arg, Val.get(), Loc, T.getOpenLocation(), KLoc, DelimLoc,
T.getCloseLocation());
}
示例10: LookupInlineAsmIdentifier
ExprResult Sema::LookupInlineAsmIdentifier(CXXScopeSpec &SS,
SourceLocation TemplateKWLoc,
UnqualifiedId &Id,
llvm::InlineAsmIdentifierInfo &Info,
bool IsUnevaluatedContext) {
Info.clear();
if (IsUnevaluatedContext)
PushExpressionEvaluationContext(UnevaluatedAbstract,
ReuseLambdaContextDecl);
ExprResult Result = ActOnIdExpression(getCurScope(), SS, TemplateKWLoc, Id,
/*trailing lparen*/ false,
/*is & operand*/ false,
/*CorrectionCandidateCallback=*/nullptr,
/*IsInlineAsmIdentifier=*/ true);
if (IsUnevaluatedContext)
PopExpressionEvaluationContext();
if (!Result.isUsable()) return Result;
Result = CheckPlaceholderExpr(Result.get());
if (!Result.isUsable()) return Result;
// Referring to parameters is not allowed in naked functions.
if (CheckNakedParmReference(Result.get(), *this))
return ExprError();
QualType T = Result.get()->getType();
// For now, reject dependent types.
if (T->isDependentType()) {
Diag(Id.getLocStart(), diag::err_asm_incomplete_type) << T;
return ExprError();
}
// Any sort of function type is fine.
if (T->isFunctionType()) {
return Result;
}
// Otherwise, it needs to be a complete type.
if (RequireCompleteExprType(Result.get(), diag::err_asm_incomplete_type)) {
return ExprError();
}
fillInlineAsmTypeInfo(Context, T, Info);
// We can work with the expression as long as it's not an r-value.
if (!Result.get()->isRValue())
Info.IsVarDecl = true;
return Result;
}
示例11: ActOnCoawaitExpr
ExprResult Sema::ActOnCoawaitExpr(Scope *S, SourceLocation Loc, Expr *E) {
if (E->getType()->isPlaceholderType()) {
ExprResult R = CheckPlaceholderExpr(E);
if (R.isInvalid()) return ExprError();
E = R.get();
}
ExprResult Awaitable = buildOperatorCoawaitCall(*this, S, Loc, E);
if (Awaitable.isInvalid())
return ExprError();
return BuildCoawaitExpr(Loc, Awaitable.get());
}
示例12: ParseMatchedBinaryArgs
/// ParseMatchedBinaryArgs - Parse a pair of arguments who are
/// expected to be of the same type. Upon return, if both LHS and RHS
/// are valid then they are guaranteed to have the same type.
///
/// Name - The name token of the expression, for diagnostics.
/// ExpectType - The expected type of the arguments, if known.
void ParserImpl::ParseMatchedBinaryArgs(const Token &Name,
TypeResult ExpectType,
ExprResult &LHS, ExprResult &RHS) {
if (Tok.kind == Token::RParen) {
Error("unexpected end of arguments.", Name);
ConsumeRParen();
return;
}
// Avoid NumberOrExprResult overhead and give more precise
// diagnostics when we know the type.
if (ExpectType.isValid()) {
LHS = ParseExpr(ExpectType);
if (Tok.kind == Token::RParen) {
Error("unexpected end of arguments.", Name);
ConsumeRParen();
return;
}
RHS = ParseExpr(ExpectType);
} else {
NumberOrExprResult LHS_NOE = ParseNumberOrExpr();
if (Tok.kind == Token::RParen) {
Error("unexpected end of arguments.", Name);
ConsumeRParen();
return;
}
if (LHS_NOE.isNumber()) {
NumberOrExprResult RHS_NOE = ParseNumberOrExpr();
if (RHS_NOE.isNumber()) {
Error("ambiguous arguments to expression.", Name);
} else {
RHS = RHS_NOE.getExpr();
if (RHS.isValid())
LHS = ParseNumberToken(RHS.get()->getWidth(), LHS_NOE.getNumber());
}
} else {
LHS = LHS_NOE.getExpr();
if (!LHS.isValid()) {
// FIXME: Should suppress ambiguity warnings here.
RHS = ParseExpr(TypeResult());
} else {
RHS = ParseExpr(LHS.get()->getWidth());
}
}
}
ExpectRParen("unexpected argument to expression.");
}
示例13: 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;
}
示例14: CreateArrayElementExprInitializer
void DataStmtEngine::CreateArrayElementExprInitializer(ArrayElementExpr *E,
Expr *Parent) {
auto Target = dyn_cast<VarExpr>(E->getTarget());
if(!Target)
return VisitExpr(E);
if(CheckVar(Target))
return;
auto VD = Target->getVarDecl();
auto ATy = VD->getType()->asArrayType();
auto ElementType = ATy->getElementType();
uint64_t ArraySize;
if(!ATy->EvaluateSize(ArraySize, Context))
return VisitExpr(E);
SmallVector<Expr*, 32> Items(ArraySize);
if(VD->hasInit()) {
assert(isa<ArrayConstructorExpr>(VD->getInit()));
auto InsertPoint = cast<ArrayConstructorExpr>(VD->getInit())->getItems();
for(uint64_t I = 0; I < ArraySize; ++I)
Items[I] = InsertPoint[I];
} else {
for(uint64_t I = 0; I < ArraySize; ++I)
Items[I] = nullptr;
}
uint64_t Offset;
if(!E->EvaluateOffset(Context, Offset, &ImpliedDoEvaluator))
return VisitExpr(E);
ExprResult Val;
if(Parent) {
if(auto SE = dyn_cast<SubstringExpr>(Parent)) {
Val = CreateSubstringExprInitializer(SE, ElementType);
} else if(auto ME = dyn_cast<MemberExpr>(Parent)) {
if(Offset < Items.size()) {
const TypeConstructorExpr *Init = Items[Offset]? cast<TypeConstructorExpr>(Items[Offset]) : nullptr;
Val = CreateMemberExprInitializer(ME, Init);
}
} else llvm_unreachable("invalid expression");
} else Val = getAndCheckAnyValue(ElementType, E);
if(Val.isUsable() && Offset < Items.size()) {
Items[Offset] = Val.get();
VD->setInit(ArrayConstructorExpr::Create(Context, Val.get()->getLocation(),
Items, VD->getType()));
}
}
示例15: assert
C2::ExprResult C2Sema::ActOnTypeQualifier(ExprResult R, unsigned int qualifier) {
assert(R.get());
if (qualifier) {
#ifdef SEMA_DEBUG
std::cerr << COL_SEMA"SEMA: Qualifier Type"ANSI_NORMAL"\n";
#endif
TypeExpr* typeExpr = cast<TypeExpr>(R.get());
// TODO use typeExpr.addConst() and just return QualType (not ref) in getType()
QualType& qt = typeExpr->getType();
if (qualifier & TYPE_CONST) qt.addConst();
if (qualifier & TYPE_VOLATILE) qt.addVolatile();
if (qualifier & TYPE_LOCAL) typeExpr->setLocalQualifier();
}
return R;
}