本文整理汇总了C++中SILGenFunction::emitApplyOfLibraryIntrinsic方法的典型用法代码示例。如果您正苦于以下问题:C++ SILGenFunction::emitApplyOfLibraryIntrinsic方法的具体用法?C++ SILGenFunction::emitApplyOfLibraryIntrinsic怎么用?C++ SILGenFunction::emitApplyOfLibraryIntrinsic使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SILGenFunction
的用法示例。
在下文中一共展示了SILGenFunction::emitApplyOfLibraryIntrinsic方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: emitCollectionDowncastExpr
/// Emit a collection downcast expression.
///
/// \param conditional Whether to emit a conditional downcast; if
/// false, this will emit a forced downcast.
static RValue emitCollectionDowncastExpr(SILGenFunction &SGF,
ManagedValue source,
Type sourceType,
SILLocation loc,
Type destType,
SGFContext C,
bool conditional) {
// Compute substitutions for the intrinsic call.
auto fromCollection = cast<BoundGenericStructType>(
sourceType->getCanonicalType());
auto toCollection = cast<BoundGenericStructType>(
destType->getCanonicalType());
// Get the intrinsic function.
auto &ctx = SGF.getASTContext();
FuncDecl *fn = nullptr;
if (fromCollection->getDecl() == ctx.getArrayDecl()) {
fn = conditional ? SGF.SGM.getArrayConditionalCast(loc)
: SGF.SGM.getArrayForceCast(loc);
} else if (fromCollection->getDecl() == ctx.getDictionaryDecl()) {
fn = (conditional
? SGF.SGM.getDictionaryDownCastConditional(loc)
: SGF.SGM.getDictionaryDownCast(loc));
} else if (fromCollection->getDecl() == ctx.getSetDecl()) {
fn = (conditional
? SGF.SGM.getSetDownCastConditional(loc)
: SGF.SGM.getSetDownCast(loc));
} else {
llvm_unreachable("unsupported collection upcast kind");
}
// This will have been diagnosed by the accessors above.
if (!fn) return SGF.emitUndefRValue(loc, destType);
auto fnGenericParams = fn->getGenericSignature()->getGenericParams();
auto fromSubsts = fromCollection->gatherAllSubstitutions(
SGF.SGM.SwiftModule, nullptr);
auto toSubsts = toCollection->gatherAllSubstitutions(
SGF.SGM.SwiftModule, nullptr);
assert(fnGenericParams.size() == fromSubsts.size() + toSubsts.size() &&
"wrong number of generic collection parameters");
(void) fnGenericParams;
// Form type parameter substitutions.
SmallVector<Substitution, 4> subs;
subs.append(fromSubsts.begin(), fromSubsts.end());
subs.append(toSubsts.begin(), toSubsts.end());
return SGF.emitApplyOfLibraryIntrinsic(loc, fn, subs, {source}, C);
}