本文整理汇总了C++中SILGenFunction::emitForeignErrorBlock方法的典型用法代码示例。如果您正苦于以下问题:C++ SILGenFunction::emitForeignErrorBlock方法的具体用法?C++ SILGenFunction::emitForeignErrorBlock怎么用?C++ SILGenFunction::emitForeignErrorBlock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SILGenFunction
的用法示例。
在下文中一共展示了SILGenFunction::emitForeignErrorBlock方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
/// Perform a foreign error check by testing whether the error was nil.
static void
emitErrorIsNonNilErrorCheck(SILGenFunction &gen, SILLocation loc,
ManagedValue errorSlot, bool suppressErrorCheck) {
// If we're suppressing the check, just don't check.
if (suppressErrorCheck) return;
SILValue optionalError = gen.B.createLoad(loc, errorSlot.getValue());
OptionalTypeKind optKind;
optionalError->getType().getAnyOptionalObjectType(gen.SGM.M, optKind);
ASTContext &ctx = gen.getASTContext();
// Switch on the optional error.
SILBasicBlock *errorBB = gen.createBasicBlock(FunctionSection::Postmatter);
SILBasicBlock *contBB = gen.createBasicBlock();
gen.B.createSwitchEnum(loc, optionalError, /*default*/ nullptr,
{ { ctx.getOptionalSomeDecl(optKind), errorBB },
{ ctx.getOptionalNoneDecl(optKind), contBB } });
// Emit the error block. Just be lazy and reload the error there.
gen.emitForeignErrorBlock(loc, errorBB, errorSlot);
// Return the result.
gen.B.emitBlock(contBB);
return;
}
示例2:
/// Perform a foreign error check by testing whether the error was nil.
static void
emitErrorIsNonNilErrorCheck(SILGenFunction &gen, SILLocation loc,
ManagedValue errorSlot, bool suppressErrorCheck) {
// If we're suppressing the check, just don't check.
if (suppressErrorCheck) return;
SILValue optionalError = gen.B.emitLoadValueOperation(
loc, errorSlot.forward(gen), LoadOwnershipQualifier::Take);
ASTContext &ctx = gen.getASTContext();
// Switch on the optional error.
SILBasicBlock *errorBB = gen.createBasicBlock(FunctionSection::Postmatter);
errorBB->createArgument(optionalError->getType().unwrapAnyOptionalType());
SILBasicBlock *contBB = gen.createBasicBlock();
gen.B.createSwitchEnum(loc, optionalError, /*default*/ nullptr,
{ { ctx.getOptionalSomeDecl(), errorBB },
{ ctx.getOptionalNoneDecl(), contBB } });
// Emit the error block. Pass in none for the errorSlot since we have passed
// in the errorSlot as our BB argument so we can pass ownership correctly. In
// emitForeignErrorBlock, we will create the appropriate cleanup for the
// argument.
gen.emitForeignErrorBlock(loc, errorBB, None);
// Return the result.
gen.B.emitBlock(contBB);
return;
}
示例3: emitUnwrapIntegerResult
/// Perform a foreign error check by testing whether the call result is zero.
/// The call result is otherwise ignored.
static void
emitResultIsZeroErrorCheck(SILGenFunction &gen, SILLocation loc,
ManagedValue result, ManagedValue errorSlot,
bool suppressErrorCheck, bool zeroIsError) {
// Just ignore the call result if we're suppressing the error check.
if (suppressErrorCheck) {
return;
}
SILValue resultValue =
emitUnwrapIntegerResult(gen, loc, result.getUnmanagedValue());
SILValue zero =
gen.B.createIntegerLiteral(loc, resultValue->getType(), 0);
ASTContext &ctx = gen.getASTContext();
SILValue resultIsError =
gen.B.createBuiltinBinaryFunction(loc,
zeroIsError ? "cmp_eq" : "cmp_ne",
resultValue->getType(),
SILType::getBuiltinIntegerType(1, ctx),
{resultValue, zero});
SILBasicBlock *errorBB = gen.createBasicBlock(FunctionSection::Postmatter);
SILBasicBlock *contBB = gen.createBasicBlock();
gen.B.createCondBranch(loc, resultIsError, errorBB, contBB);
gen.emitForeignErrorBlock(loc, errorBB, errorSlot);
gen.B.emitBlock(contBB);
}
示例4: emitUnwrapIntegerResult
/// Perform a foreign error check by testing whether the call result is zero.
/// The call result is otherwise ignored.
static void
emitResultIsZeroErrorCheck(SILGenFunction &SGF, SILLocation loc,
ManagedValue result, ManagedValue errorSlot,
bool suppressErrorCheck, bool zeroIsError) {
// Just ignore the call result if we're suppressing the error check.
if (suppressErrorCheck) {
return;
}
SILValue resultValue =
emitUnwrapIntegerResult(SGF, loc, result.getUnmanagedValue());
CanType resultType = resultValue->getType().getSwiftRValueType();
if (!resultType->isBuiltinIntegerType(1)) {
SILValue zero =
SGF.B.createIntegerLiteral(loc, resultValue->getType(), 0);
ASTContext &ctx = SGF.getASTContext();
resultValue =
SGF.B.createBuiltinBinaryFunction(loc,
"cmp_ne",
resultValue->getType(),
SILType::getBuiltinIntegerType(1, ctx),
{resultValue, zero});
}
SILBasicBlock *errorBB = SGF.createBasicBlock(FunctionSection::Postmatter);
SILBasicBlock *contBB = SGF.createBasicBlock();
if (zeroIsError)
SGF.B.createCondBranch(loc, resultValue, contBB, errorBB);
else
SGF.B.createCondBranch(loc, resultValue, errorBB, contBB);
SGF.emitForeignErrorBlock(loc, errorBB, errorSlot);
SGF.B.emitBlock(contBB);
}