本文整理汇总了C++中SILGenFunction::emitApply方法的典型用法代码示例。如果您正苦于以下问题:C++ SILGenFunction::emitApply方法的具体用法?C++ SILGenFunction::emitApply怎么用?C++ SILGenFunction::emitApply使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SILGenFunction
的用法示例。
在下文中一共展示了SILGenFunction::emitApply方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: witnessConstant
/// Bridge the given Objective-C object to its corresponding Swift
/// value, using the appropriate witness for the
/// _ObjectiveCBridgeable._unconditionallyBridgeFromObjectiveC requirement.
static Optional<ManagedValue>
emitBridgeObjectiveCToNative(SILGenFunction &gen,
SILLocation loc,
ManagedValue objcValue,
ProtocolConformance *conformance) {
// Find the _unconditionallyBridgeFromObjectiveC requirement.
auto requirement =
gen.SGM.getUnconditionallyBridgeFromObjectiveCRequirement(loc);
if (!requirement) return None;
// Retrieve the _unconditionallyBridgeFromObjectiveC witness.
auto witness = conformance->getWitness(requirement, nullptr);
assert(witness);
// Create a reference to the witness.
SILDeclRef witnessConstant(witness.getDecl());
auto witnessRef = gen.emitGlobalFunctionRef(loc, witnessConstant);
// Determine the substitutions.
ArrayRef<Substitution> substitutions;
auto witnessFnTy = witnessRef->getType().castTo<SILFunctionType>();
Type swiftValueType = conformance->getType();
if (auto valueTypeBGT = swiftValueType->getAs<BoundGenericType>()) {
// Compute the substitutions.
substitutions = valueTypeBGT->getSubstitutions(gen.SGM.SwiftModule,
nullptr);
}
// Substitute into the witness function type.
if (!substitutions.empty())
witnessFnTy = witnessFnTy->substGenericArgs(gen.SGM.M, gen.SGM.SwiftModule,
substitutions);
// If the Objective-C value isn't optional, wrap it in an optional.
Type objcValueType = objcValue.getType().getSwiftRValueType();
if (!objcValueType->getOptionalObjectType()) {
SILType loweredOptTy =
gen.SGM.getLoweredType(OptionalType::get(objcValueType));
auto *someDecl = gen.getASTContext().getOptionalSomeDecl();
auto *enumInst = gen.B.createEnum(loc, objcValue.getValue(), someDecl,
loweredOptTy);
objcValue = ManagedValue(enumInst, objcValue.getCleanup());
}
// Call the witness.
Type metatype = MetatypeType::get(swiftValueType);
SILValue metatypeValue = gen.B.createMetatype(loc,
gen.getLoweredType(metatype));
auto witnessCI = gen.getConstantInfo(witnessConstant);
CanType formalResultTy = witnessCI.LoweredInterfaceType.getResult();
// Set up the generic signature.
CanGenericSignature witnessGenericSignature;
if (auto genericSig =
cast<AbstractFunctionDecl>(witness.getDecl())->getGenericSignature())
witnessGenericSignature = genericSig->getCanonicalSignature();
GenericContextScope genericContextScope(gen.SGM.Types,
witnessGenericSignature);
return gen.emitApply(loc, ManagedValue::forUnmanaged(witnessRef),
substitutions,
{ objcValue, ManagedValue::forUnmanaged(metatypeValue) },
witnessFnTy,
AbstractionPattern(witnessGenericSignature,
formalResultTy),
swiftValueType->getCanonicalType(),
ApplyOptions::None, None, None,
SGFContext())
.getAsSingleValue(gen, loc);
}