本文整理汇总了C++中TypeLowering::getSemanticType方法的典型用法代码示例。如果您正苦于以下问题:C++ TypeLowering::getSemanticType方法的具体用法?C++ TypeLowering::getSemanticType怎么用?C++ TypeLowering::getSemanticType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TypeLowering
的用法示例。
在下文中一共展示了TypeLowering::getSemanticType方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: emitExistentialErasure
ManagedValue SILGenFunction::emitExistentialErasure(
SILLocation loc,
CanType concreteFormalType,
const TypeLowering &concreteTL,
const TypeLowering &existentialTL,
ArrayRef<ProtocolConformanceRef> conformances,
SGFContext C,
llvm::function_ref<ManagedValue (SGFContext)> F,
bool allowEmbeddedNSError) {
// Mark the needed conformances as used.
for (auto conformance : conformances)
SGM.useConformance(conformance);
// If we're erasing to the 'Error' type, we might be able to get an NSError
// representation more efficiently.
auto &ctx = getASTContext();
auto nsError = ctx.getNSErrorDecl();
if (allowEmbeddedNSError && nsError &&
existentialTL.getSemanticType().getSwiftRValueType()->getAnyNominal() ==
ctx.getErrorDecl()) {
// Check whether the concrete type conforms to the _BridgedStoredNSError
// protocol. In that case, call the _nsError witness getter to extract the
// NSError directly.
auto conformance =
SGM.getConformanceToBridgedStoredNSError(loc, concreteFormalType);
CanType nsErrorType =
nsError->getDeclaredInterfaceType()->getCanonicalType();
ProtocolConformanceRef nsErrorConformances[1] = {
ProtocolConformanceRef(SGM.getNSErrorConformanceToError())
};
if (conformance && nsError && SGM.getNSErrorConformanceToError()) {
if (auto witness =
conformance->getWitness(SGM.getNSErrorRequirement(loc), nullptr)) {
// Create a reference to the getter witness.
SILDeclRef getter =
getGetterDeclRef(cast<VarDecl>(witness.getDecl()),
/*isDirectAccessorUse=*/true);
// Compute the substitutions.
ArrayRef<Substitution> substitutions =
concreteFormalType->gatherAllSubstitutions(
SGM.SwiftModule, nullptr);
// Emit the erasure, through the getter to _nsError.
return emitExistentialErasure(
loc, nsErrorType,
getTypeLowering(nsErrorType),
existentialTL,
ctx.AllocateCopy(nsErrorConformances),
C,
[&](SGFContext innerC) -> ManagedValue {
// Call the getter.
return emitGetAccessor(loc, getter, substitutions,
ArgumentSource(loc,
RValue(*this, loc,
concreteFormalType,
F(SGFContext()))),
/*isSuper=*/false,
/*isDirectAccessorUse=*/true,
RValue(), innerC)
.getAsSingleValue(*this, loc);
});
}
}
// Check whether the concrete type is an archetype. If so, call the
// _getEmbeddedNSError() witness to try to dig out the embedded NSError.
if (auto archetypeType = concreteFormalType->getAs<ArchetypeType>()) {
if (std::find(archetypeType->getConformsTo().begin(),
archetypeType->getConformsTo().end(),
ctx.getErrorDecl())
!= archetypeType->getConformsTo().end()) {
auto contBB = createBasicBlock();
auto isNotPresentBB = createBasicBlock();
auto isPresentBB = createBasicBlock();
SILValue existentialResult =
contBB->createBBArg(existentialTL.getLoweredType());
ProtocolConformanceRef trivialErrorConformances[1] = {
ProtocolConformanceRef(ctx.getErrorDecl())
};
Substitution substitutions[1] = {
Substitution(concreteFormalType,
ctx.AllocateCopy(trivialErrorConformances))
};
// Call swift_stdlib_getErrorEmbeddedNSError to attempt to extract an
// NSError from the value.
ManagedValue concreteValue = F(SGFContext());
ManagedValue potentialNSError =
emitApplyOfLibraryIntrinsic(loc,
SGM.getGetErrorEmbeddedNSError(loc),
ctx.AllocateCopy(substitutions),
{ concreteValue },
SGFContext())
//.........这里部分代码省略.........