本文整理汇总了C++中mangle::Mangler::mangleProtocolConformance方法的典型用法代码示例。如果您正苦于以下问题:C++ Mangler::mangleProtocolConformance方法的具体用法?C++ Mangler::mangleProtocolConformance怎么用?C++ Mangler::mangleProtocolConformance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mangle::Mangler
的用法示例。
在下文中一共展示了Mangler::mangleProtocolConformance方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: closure
SILFunction *MaterializeForSetEmitter::createCallback(SILFunction &F, GeneratorFn generator) {
auto &ctx = SGM.getASTContext();
// Mangle this as if it were a conformance thunk for a closure
// within the witness.
std::string name;
{
ClosureExpr closure(/*patterns*/ nullptr,
/*throws*/ SourceLoc(),
/*arrow*/ SourceLoc(),
/*in*/ SourceLoc(),
/*result*/ TypeLoc(),
/*discriminator*/ 0,
/*context*/ Witness);
closure.setType(getMaterializeForSetCallbackType(ctx,
getSelfTypeForCallbackDeclaration(Witness)));
closure.getCaptureInfo().setGenericParamCaptures(true);
Mangle::Mangler mangler;
if (Conformance) {
mangler.append("_TTW");
mangler.mangleProtocolConformance(Conformance);
} else {
mangler.append("_T");
}
mangler.mangleClosureEntity(&closure, /*uncurryLevel=*/1);
name = mangler.finalize();
}
// Get lowered formal types for callback parameters.
Type selfType = SelfInterfaceType;
Type selfMetatypeType = MetatypeType::get(SelfInterfaceType,
MetatypeRepresentation::Thick);
{
GenericContextScope scope(SGM.Types, GenericSig);
// If 'self' is a metatype, make it @thin or @thick as needed, but not inside
// selfMetatypeType.
if (auto metatype = selfType->getAs<MetatypeType>()) {
if (!metatype->hasRepresentation())
selfType = SGM.getLoweredType(metatype).getSwiftRValueType();
}
}
// Create the SILFunctionType for the callback.
SILParameterInfo params[] = {
{ ctx.TheRawPointerType, ParameterConvention::Direct_Unowned },
{ ctx.TheUnsafeValueBufferType, ParameterConvention::Indirect_Inout },
{ selfType->getCanonicalType(), ParameterConvention::Indirect_Inout },
{ selfMetatypeType->getCanonicalType(), ParameterConvention::Direct_Unowned },
};
SILResultInfo result = {
TupleType::getEmpty(ctx), ResultConvention::Unowned
};
auto extInfo =
SILFunctionType::ExtInfo()
.withRepresentation(SILFunctionTypeRepresentation::Thin);
auto callbackType = SILFunctionType::get(GenericSig, extInfo,
/*callee*/ ParameterConvention::Direct_Unowned,
params, result, None, ctx);
auto callback =
SGM.M.getOrCreateFunction(Witness, name, Linkage, callbackType,
IsBare,
F.isTransparent(),
F.isFragile());
callback->setContextGenericParams(GenericParams);
callback->setDebugScope(new (SGM.M) SILDebugScope(Witness, *callback));
PrettyStackTraceSILFunction X("silgen materializeForSet callback", callback);
{
SILGenFunction gen(SGM, *callback);
auto makeParam = [&](unsigned index) -> SILArgument* {
SILType type = gen.F.mapTypeIntoContext(params[index].getSILType());
return new (SGM.M) SILArgument(gen.F.begin(), type);
};
// Add arguments for all the parameters.
auto valueBuffer = makeParam(0);
auto storageBuffer = makeParam(1);
auto self = makeParam(2);
(void) makeParam(3);
SILLocation loc = Witness;
loc.markAutoGenerated();
// Call the generator function we were provided.
{
LexicalScope scope(gen.Cleanups, gen, CleanupLocation::get(loc));
generator(gen, loc, valueBuffer, storageBuffer, self);
}
// Return void.
auto result = gen.emitEmptyTuple(loc);
gen.B.createReturn(loc, result);
}
//.........这里部分代码省略.........