本文整理汇总了C++中LValue::dropLastTranslationComponent方法的典型用法代码示例。如果您正苦于以下问题:C++ LValue::dropLastTranslationComponent方法的具体用法?C++ LValue::dropLastTranslationComponent怎么用?C++ LValue::dropLastTranslationComponent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LValue
的用法示例。
在下文中一共展示了LValue::dropLastTranslationComponent方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: emitMemberInitializers
void SILGenFunction::emitMemberInitializers(DeclContext *dc,
VarDecl *selfDecl,
NominalTypeDecl *nominal) {
for (auto member : nominal->getMembers()) {
// Find instance pattern binding declarations that have initializers.
if (auto pbd = dyn_cast<PatternBindingDecl>(member)) {
if (pbd->isStatic()) continue;
for (auto entry : pbd->getPatternList()) {
auto init = entry.getInit();
if (!init) continue;
// Cleanup after this initialization.
FullExpr scope(Cleanups, entry.getPattern());
// Get the substitutions for the constructor context.
ArrayRef<Substitution> subs;
auto *genericEnv = dc->getGenericEnvironmentOfContext();
if (genericEnv) {
auto *genericSig = dc->getGenericSignatureOfContext();
subs = genericEnv->getForwardingSubstitutions(
SGM.SwiftModule, genericSig);
}
// Get the type of the initialization result, in terms
// of the constructor context's archetypes.
CanType resultType = getInitializationTypeInContext(
pbd->getDeclContext(), dc, init)->getCanonicalType();
AbstractionPattern origResultType(resultType);
// FIXME: Can emitMemberInit() share code with
// InitializationForPattern in SILGenDecl.cpp?
RValue result = emitApplyOfStoredPropertyInitializer(
init, entry, subs,
resultType, origResultType,
SGFContext());
emitMemberInit(*this, selfDecl, entry.getPattern(), std::move(result));
}
}
// Introduce behavior initialization markers for properties that need them.
if (auto var = dyn_cast<VarDecl>(member)) {
if (var->isStatic()) continue;
if (!var->hasBehaviorNeedingInitialization()) continue;
// Get the initializer method for behavior.
auto init = var->getBehavior()->InitStorageDecl;
SILValue initFn = getBehaviorInitStorageFn(*this, var);
// Get the behavior's storage we need to initialize.
auto storage = var->getBehavior()->StorageDecl;
LValue storageRef = emitLValueForMemberInit(*this, var, selfDecl,storage);
// Shed any reabstraction over the member.
while (storageRef.isLastComponentTranslation())
storageRef.dropLastTranslationComponent();
auto storageAddr = emitAddressOfLValue(var, std::move(storageRef),
AccessKind::ReadWrite);
// Get the setter.
auto setterFn = getBehaviorSetterFn(*this, var);
auto self = emitSelfForMemberInit(*this, var, selfDecl);
auto mark = B.createMarkUninitializedBehavior(var,
initFn, init.getSubstitutions(), storageAddr.getValue(),
setterFn, getForwardingSubstitutions(), self.getValue(),
getLoweredType(var->getType()).getAddressType());
// The mark instruction stands in for the behavior property.
VarLocs[var].value = mark;
}
}
}
示例2: emitMemberInitializers
void SILGenFunction::emitMemberInitializers(DeclContext *dc,
VarDecl *selfDecl,
NominalTypeDecl *nominal) {
for (auto member : nominal->getMembers()) {
// Find instance pattern binding declarations that have initializers.
if (auto pbd = dyn_cast<PatternBindingDecl>(member)) {
if (pbd->isStatic()) continue;
for (auto entry : pbd->getPatternList()) {
auto init = entry.getInit();
if (!init) continue;
// Cleanup after this initialization.
FullExpr scope(Cleanups, entry.getPattern());
// We want a substitution list written in terms of the generic
// signature of the type, with replacement archetypes from the
// constructor's context (which might be in an extension of
// the type, which adds additional generic requirements).
SubstitutionList subs;
auto *genericEnv = dc->getGenericEnvironmentOfContext();
auto typeGenericSig = nominal->getGenericSignatureOfContext();
if (genericEnv && typeGenericSig) {
// Generate a set of substitutions for the initialization function,
// whose generic signature is that of the type context, and whose
// replacement types are the archetypes of the initializer itself.
auto subMap = typeGenericSig->getSubstitutionMap(
[&](SubstitutableType *type) {
if (auto gp = type->getAs<GenericTypeParamType>()) {
return genericEnv->mapTypeIntoContext(gp);
}
return Type(type);
},
[](CanType dependentType,
Type conformingReplacementType,
ProtocolType *conformedProtocol) {
return ProtocolConformanceRef(
conformedProtocol->getDecl());
});
SmallVector<Substitution, 4> subsVec;
typeGenericSig->getSubstitutions(subMap, subsVec);
subs = SGM.getASTContext().AllocateCopy(subsVec);
}
// Get the type of the initialization result, in terms
// of the constructor context's archetypes.
CanType resultType = getInitializationTypeInContext(
pbd->getDeclContext(), dc, entry.getPattern())->getCanonicalType();
AbstractionPattern origResultType(resultType);
// FIXME: Can emitMemberInit() share code with
// InitializationForPattern in SILGenDecl.cpp?
RValue result = emitApplyOfStoredPropertyInitializer(
init, entry, subs,
resultType, origResultType,
SGFContext());
emitMemberInit(*this, selfDecl, entry.getPattern(), std::move(result));
}
}
// Introduce behavior initialization markers for properties that need them.
if (auto var = dyn_cast<VarDecl>(member)) {
if (var->isStatic()) continue;
if (!var->hasBehaviorNeedingInitialization()) continue;
// Get the initializer method for behavior.
auto init = var->getBehavior()->InitStorageDecl;
SILValue initFn = getBehaviorInitStorageFn(*this, var);
// Get the behavior's storage we need to initialize.
auto storage = var->getBehavior()->StorageDecl;
LValue storageRef = emitLValueForMemberInit(*this, var, selfDecl,storage);
// Shed any reabstraction over the member.
while (storageRef.isLastComponentTranslation())
storageRef.dropLastTranslationComponent();
auto storageAddr = emitAddressOfLValue(var, std::move(storageRef),
AccessKind::ReadWrite);
// Get the setter.
auto setterFn = getBehaviorSetterFn(*this, var);
auto self = emitSelfForMemberInit(*this, var, selfDecl);
auto mark = B.createMarkUninitializedBehavior(var,
initFn, init.getSubstitutions(),
storageAddr.getValue(),
setterFn, getForwardingSubstitutionMap(), self.getValue(),
getLoweredType(var->getType()).getAddressType());
// The mark instruction stands in for the behavior property.
VarLocs[var].value = mark;
}
}
}