本文整理汇总了C++中ModuleDecl::getInterfaceType方法的典型用法代码示例。如果您正苦于以下问题:C++ ModuleDecl::getInterfaceType方法的具体用法?C++ ModuleDecl::getInterfaceType怎么用?C++ ModuleDecl::getInterfaceType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ModuleDecl
的用法示例。
在下文中一共展示了ModuleDecl::getInterfaceType方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: emitArtificialTopLevel
void SILGenFunction::emitArtificialTopLevel(ClassDecl *mainClass) {
// Load argc and argv from the entry point arguments.
SILValue argc = F.begin()->getArgument(0);
SILValue argv = F.begin()->getArgument(1);
switch (mainClass->getArtificialMainKind()) {
case ArtificialMainKind::UIApplicationMain: {
// Emit a UIKit main.
// return UIApplicationMain(C_ARGC, C_ARGV, nil, ClassName);
CanType NSStringTy = SGM.Types.getNSStringType();
CanType OptNSStringTy
= OptionalType::get(NSStringTy)->getCanonicalType();
CanType IUOptNSStringTy
= ImplicitlyUnwrappedOptionalType::get(NSStringTy)->getCanonicalType();
// Look up UIApplicationMain.
// FIXME: Doing an AST lookup here is gross and not entirely sound;
// we're getting away with it because the types are guaranteed to already
// be imported.
ASTContext &ctx = getASTContext();
ModuleDecl *UIKit = ctx.getLoadedModule(ctx.getIdentifier("UIKit"));
SmallVector<ValueDecl *, 1> results;
UIKit->lookupQualified(UIKit->getInterfaceType(),
ctx.getIdentifier("UIApplicationMain"),
NL_QualifiedDefault,
/*resolver*/nullptr,
results);
assert(!results.empty() && "couldn't find UIApplicationMain in UIKit");
assert(results.size() == 1 && "more than one UIApplicationMain?");
SILDeclRef mainRef{results.front(), ResilienceExpansion::Minimal,
SILDeclRef::ConstructAtNaturalUncurryLevel,
/*isForeign*/true};
auto UIApplicationMainFn = SGM.M.getOrCreateFunction(mainClass, mainRef,
NotForDefinition);
auto fnTy = UIApplicationMainFn->getLoweredFunctionType();
SILFunctionConventions fnConv(fnTy, SGM.M);
// Get the class name as a string using NSStringFromClass.
CanType mainClassTy = mainClass->getDeclaredInterfaceType()
->getCanonicalType();
CanType mainClassMetaty = CanMetatypeType::get(mainClassTy,
MetatypeRepresentation::ObjC);
ProtocolDecl *anyObjectProtocol =
ctx.getProtocol(KnownProtocolKind::AnyObject);
auto mainClassAnyObjectConformance = ProtocolConformanceRef(
*SGM.M.getSwiftModule()->lookupConformance(mainClassTy, anyObjectProtocol,
nullptr));
CanType anyObjectTy = anyObjectProtocol
->getDeclaredInterfaceType()
->getCanonicalType();
CanType anyObjectMetaTy = CanExistentialMetatypeType::get(anyObjectTy,
MetatypeRepresentation::ObjC);
auto NSStringFromClassType = SILFunctionType::get(nullptr,
SILFunctionType::ExtInfo()
.withRepresentation(SILFunctionType::Representation::
CFunctionPointer),
ParameterConvention::Direct_Unowned,
SILParameterInfo(anyObjectMetaTy,
ParameterConvention::Direct_Unowned),
SILResultInfo(OptNSStringTy,
ResultConvention::Autoreleased),
/*error result*/ None,
ctx);
auto NSStringFromClassFn
= SGM.M.getOrCreateFunction(mainClass, "NSStringFromClass",
SILLinkage::PublicExternal,
NSStringFromClassType,
IsBare, IsTransparent, IsNotSerialized);
auto NSStringFromClass = B.createFunctionRef(mainClass, NSStringFromClassFn);
SILValue metaTy = B.createMetatype(mainClass,
SILType::getPrimitiveObjectType(mainClassMetaty));
metaTy = B.createInitExistentialMetatype(mainClass, metaTy,
SILType::getPrimitiveObjectType(anyObjectMetaTy),
ctx.AllocateCopy(
llvm::makeArrayRef(mainClassAnyObjectConformance)));
SILValue optName = B.createApply(mainClass,
NSStringFromClass,
NSStringFromClass->getType(),
SILType::getPrimitiveObjectType(OptNSStringTy),
{}, metaTy);
// Fix up the string parameters to have the right type.
SILType nameArgTy = fnConv.getSILArgumentType(3);
assert(nameArgTy == fnConv.getSILArgumentType(2));
auto managedName = ManagedValue::forUnmanaged(optName);
SILValue nilValue;
if (optName->getType() == nameArgTy) {
nilValue = getOptionalNoneValue(mainClass,
getTypeLowering(OptNSStringTy));
} else {
assert(nameArgTy.getSwiftRValueType() == IUOptNSStringTy);
nilValue = getOptionalNoneValue(mainClass,
getTypeLowering(IUOptNSStringTy));
managedName = emitOptionalToOptional(
mainClass, managedName,
SILType::getPrimitiveObjectType(IUOptNSStringTy),
[](SILGenFunction &, SILLocation, ManagedValue input, SILType) {
//.........这里部分代码省略.........