本文整理汇总了C++中SubstitutionMap::addSubstitution方法的典型用法代码示例。如果您正苦于以下问题:C++ SubstitutionMap::addSubstitution方法的具体用法?C++ SubstitutionMap::addSubstitution怎么用?C++ SubstitutionMap::addSubstitution使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SubstitutionMap
的用法示例。
在下文中一共展示了SubstitutionMap::addSubstitution方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: MakeAbstractConformanceForGenericType
SubstitutionMap GenericEnvironment::
getSubstitutionMap(SubstitutionList subs) const {
SubstitutionMap result;
for (auto depTy : getGenericSignature()->getAllDependentTypes()) {
// Map the interface type to a context type.
auto contextTy = depTy.subst(QueryInterfaceTypeSubstitutions(this),
MakeAbstractConformanceForGenericType());
auto sub = subs.front();
subs = subs.slice(1);
// Record the replacement type and its conformances.
if (auto *archetype = contextTy->getAs<ArchetypeType>()) {
result.addSubstitution(CanArchetypeType(archetype), sub.getReplacement());
for (auto conformance : sub.getConformances())
result.addConformance(CanType(archetype), conformance);
continue;
}
// FIXME: getAllDependentTypes() includes generic type parameters that
// have been made concrete.
assert(contextTy->hasError() || depTy->is<GenericTypeParamType>());
}
assert(subs.empty() && "did not use all substitutions?!");
populateParentMap(result);
return result;
}
示例2: makeFreshSkolems
void AbstractionModule::makeFreshSkolems(TNode node, SubstitutionMap& map, SubstitutionMap& reverse_map) {
if (map.hasSubstitution(node)) {
return;
}
if (node.getMetaKind() == kind::metakind::VARIABLE) {
Node skolem = utils::mkVar(utils::getSize(node));
map.addSubstitution(node, skolem);
reverse_map.addSubstitution(skolem, node);
return;
}
if (node.isConst())
return;
for (unsigned i = 0; i < node.getNumChildren(); ++i) {
makeFreshSkolems(node[i], map, reverse_map);
}
}
示例3: SubstOptions
void GenericEnvironment::
getSubstitutionMap(ModuleDecl *mod,
GenericSignature *sig,
ArrayRef<Substitution> subs,
SubstitutionMap &result) const {
for (auto depTy : sig->getAllDependentTypes()) {
// Map the interface type to a context type.
auto contextTy = depTy.subst(mod, InterfaceToArchetypeMap, SubstOptions());
auto *archetype = contextTy->castTo<ArchetypeType>();
auto sub = subs.front();
subs = subs.slice(1);
// Record the replacement type and its conformances.
result.addSubstitution(CanType(archetype), sub.getReplacement());
result.addConformances(CanType(archetype), sub.getConformances());
}
for (auto reqt : sig->getRequirements()) {
if (reqt.getKind() != RequirementKind::SameType)
continue;
auto first = reqt.getFirstType()->getAs<DependentMemberType>();
auto second = reqt.getSecondType()->getAs<DependentMemberType>();
if (!first || !second)
continue;
auto archetype = mapTypeIntoContext(mod, first)->getAs<ArchetypeType>();
if (!archetype)
continue;
auto firstBase = first->getBase();
auto secondBase = second->getBase();
auto firstBaseArchetype = mapTypeIntoContext(mod, firstBase)->getAs<ArchetypeType>();
auto secondBaseArchetype = mapTypeIntoContext(mod, secondBase)->getAs<ArchetypeType>();
if (!firstBaseArchetype || !secondBaseArchetype)
continue;
if (archetype->getParent() != firstBaseArchetype)
result.addParent(CanType(archetype),
CanType(firstBaseArchetype),
first->getAssocType());
if (archetype->getParent() != secondBaseArchetype)
result.addParent(CanType(archetype),
CanType(secondBaseArchetype),
second->getAssocType());
}
assert(subs.empty() && "did not use all substitutions?!");
}
示例4: ppAssert
Theory::PPAssertStatus TheoryBool::ppAssert(TNode in, SubstitutionMap& outSubstitutions) {
if (in.getKind() == kind::CONST_BOOLEAN && !in.getConst<bool>()) {
// If we get a false literal, we're in conflict
return PP_ASSERT_STATUS_CONFLICT;
}
// Add the substitution from the variable to its value
if (in.getKind() == kind::NOT) {
if (in[0].getKind() == kind::VARIABLE) {
outSubstitutions.addSubstitution(in[0], NodeManager::currentNM()->mkConst<bool>(false));
} else {
return PP_ASSERT_STATUS_UNSOLVED;
}
} else {
if (in.getKind() == kind::VARIABLE) {
outSubstitutions.addSubstitution(in, NodeManager::currentNM()->mkConst<bool>(true));
} else {
return PP_ASSERT_STATUS_UNSOLVED;
}
}
return PP_ASSERT_STATUS_SOLVED;
}
示例5: ppAssert
Theory::PPAssertStatus Theory::ppAssert(TNode in, SubstitutionMap& outSubstitutions)
{
if (in.getKind() == kind::EQUAL) {
// (and (= x t) phi) can be replaced by phi[x/t] if
// 1) x is a variable
// 2) x is not in the term t
// 3) x : T and t : S, then S <: T
if (in[0].isVar() && !in[1].hasSubterm(in[0]) && (in[1].getType()).isSubtypeOf(in[0].getType()) ){
outSubstitutions.addSubstitution(in[0], in[1]);
return PP_ASSERT_STATUS_SOLVED;
}
if (in[1].isVar() && !in[0].hasSubterm(in[1]) && (in[0].getType()).isSubtypeOf(in[1].getType())){
outSubstitutions.addSubstitution(in[1], in[0]);
return PP_ASSERT_STATUS_SOLVED;
}
if (in[0].isConst() && in[1].isConst()) {
if (in[0] != in[1]) {
return PP_ASSERT_STATUS_CONFLICT;
}
}
}
return PP_ASSERT_STATUS_UNSOLVED;
}
示例6: getGenericSignature
SubstitutionMap
GenericEnvironment::
getSubstitutionMap(TypeSubstitutionFn subs,
GenericSignature::LookupConformanceFn lookupConformance) const {
SubstitutionMap subMap;
getGenericSignature()->enumeratePairedRequirements(
[&](Type depTy, ArrayRef<Requirement> reqs) -> bool {
// Map the interface type to a context type.
auto contextTy = depTy.subst(QueryInterfaceTypeSubstitutions(this),
MakeAbstractConformanceForGenericType());
// Compute the replacement type.
Type currentReplacement = contextTy.subst(subs, lookupConformance,
SubstFlags::UseErrorType);
if (auto archetypeTy = contextTy->getAs<ArchetypeType>()) {
subMap.addSubstitution(CanArchetypeType(archetypeTy),
currentReplacement);
// Collect the conformances.
for (auto req: reqs) {
assert(req.getKind() == RequirementKind::Conformance);
auto protoType = req.getSecondType()->castTo<ProtocolType>();
auto conformance = lookupConformance(CanArchetypeType(archetypeTy),
currentReplacement,
protoType);
if (conformance)
subMap.addConformance(CanArchetypeType(archetypeTy), *conformance);
}
}
return false;
});
populateParentMap(subMap);
return subMap;
}
示例7: LookUpConformanceInModule
void GenericEnvironment::
getSubstitutionMap(ModuleDecl *mod,
ArrayRef<Substitution> subs,
SubstitutionMap &result) const {
for (auto depTy : getGenericSignature()->getAllDependentTypes()) {
// Map the interface type to a context type.
auto contextTy = depTy.subst(QueryInterfaceTypeSubstitutions(this),
LookUpConformanceInModule(mod),
SubstOptions());
auto sub = subs.front();
subs = subs.slice(1);
// Record the replacement type and its conformances.
if (auto *archetype = contextTy->getAs<ArchetypeType>()) {
result.addSubstitution(CanArchetypeType(archetype), sub.getReplacement());
for (auto conformance : sub.getConformances())
result.addConformance(CanType(archetype), conformance);
continue;
}
assert(contextTy->is<ErrorType>());
}
for (auto reqt : getGenericSignature()->getRequirements()) {
if (reqt.getKind() != RequirementKind::SameType)
continue;
auto first = reqt.getFirstType();
auto second = reqt.getSecondType();
auto archetype = mapTypeIntoContext(mod, first)->getAs<ArchetypeType>();
if (!archetype)
continue;
#ifndef NDEBUG
auto secondArchetype = mapTypeIntoContext(mod, second)->getAs<ArchetypeType>();
assert(secondArchetype == archetype);
#endif
if (auto *firstMemTy = first->getAs<DependentMemberType>()) {
auto parent = mapTypeIntoContext(mod, firstMemTy->getBase())
->getAs<ArchetypeType>();
if (parent && archetype->getParent() != parent) {
result.addParent(CanType(archetype),
CanType(parent),
firstMemTy->getAssocType());
}
}
if (auto *secondMemTy = second->getAs<DependentMemberType>()) {
auto parent = mapTypeIntoContext(mod, secondMemTy->getBase())
->getAs<ArchetypeType>();
if (parent && archetype->getParent() != parent) {
result.addParent(CanType(archetype),
CanType(parent),
secondMemTy->getAssocType());
}
}
}
assert(subs.empty() && "did not use all substitutions?!");
}
示例8: getWitnessMethodSubstitutions
/// Compute substitutions for making a direct call to a SIL function with
/// @convention(witness_method) convention.
///
/// Such functions have a substituted generic signature where the
/// abstract `Self` parameter from the original type of the protocol
/// requirement is replaced by a concrete type.
///
/// Thus, the original substitutions of the apply instruction that
/// are written in terms of the requirement's generic signature need
/// to be remapped to substitutions suitable for the witness signature.
///
/// \param conformanceRef The (possibly-specialized) conformance
/// \param requirementSig The generic signature of the requirement
/// \param witnessThunkSig The generic signature of the witness method
/// \param origSubs The substitutions from the call instruction
/// \param newSubs New substitutions are stored here
static void getWitnessMethodSubstitutions(
SILModule &M,
ProtocolConformanceRef conformanceRef,
GenericSignature *requirementSig,
GenericSignature *witnessThunkSig,
ArrayRef<Substitution> origSubs,
bool isDefaultWitness,
SmallVectorImpl<Substitution> &newSubs) {
if (witnessThunkSig == nullptr)
return;
assert(!conformanceRef.isAbstract());
auto conformance = conformanceRef.getConcrete();
// Otherwise, we need to build new caller-side substitutions
// written in terms of the witness thunk's generic signature,
// mapping to the archetypes of the caller.
SubstitutionMap subMap;
// Take apart substitutions from the conforming type.
ArrayRef<Substitution> witnessSubs;
auto *rootConformance = conformance->getRootNormalConformance();
auto *witnessSig = rootConformance->getGenericSignature();
unsigned depth = 0;
if (isDefaultWitness) {
// For default witnesses, we substitute all of Self.
auto gp = witnessThunkSig->getGenericParams().front()->getCanonicalType();
subMap.addSubstitution(gp, origSubs.front().getReplacement());
subMap.addConformances(gp, origSubs.front().getConformances());
// For default witnesses, innermost generic parameters are always at
// depth 1.
depth = 1;
} else {
// If `Self` maps to a bound generic type, this gives us the
// substitutions for the concrete type's generic parameters.
witnessSubs = getSubstitutionsForProtocolConformance(conformanceRef);
if (!witnessSubs.empty()) {
witnessSig->getSubstitutionMap(witnessSubs, subMap);
depth = witnessSig->getGenericParams().back()->getDepth() + 1;
}
}
// Next, take apart caller-side substitutions.
//
// Note that the Self-derived dependent types appearing on the left
// hand side of the map are dropped.
// FIXME: This won't be correct if the requirement itself adds 'Self'
// requirements. We should be working from the substitutions in the witness.
//
// Also note that we rebuild the generic parameters in the requirement
// to provide them with the required depth for the thunk itself.
if (requirementSig->getGenericParams().back()->getDepth() > 0) {
// Local function to replace generic parameters within the requirement
// signature with the generic parameter we want to use in the substitution
// map:
// - If the generic parameter is 'Self', return a null type so we don't
// add any substitution.
// - Otherwise, reset the generic parameter's depth one level deeper than
// the deepest generic parameter in the conformance.
//
// This local function is meant to be used with Type::transform();
auto replaceGenericParameter = [&](Type type) -> Type {
if (auto gp = type->getAs<GenericTypeParamType>()) {
if (gp->getDepth() == 0) return Type();
return GenericTypeParamType::get(depth, gp->getIndex(),
M.getASTContext());
}
return type;
};
// Walk through the substitutions and dependent types.
ArrayRef<Substitution> subs = origSubs;
for (auto origDepTy : requirementSig->getAllDependentTypes()) {
// Grab the next substitution.
auto sub = subs.front();
subs = subs.slice(1);
// Map the generic parameters in the dependent type into the witness
// thunk's depth.
//.........这里部分代码省略.........
示例9: CanType
// Start with the substitutions from the apply.
// Try to propagate them to find out the real substitutions required
// to invoke the method.
static void
getSubstitutionsForCallee(SILModule &M,
CanSILFunctionType baseCalleeType,
CanType derivedSelfType,
FullApplySite AI,
SmallVectorImpl<Substitution> &newSubs) {
// If the base method is not polymorphic, no substitutions are required,
// even if we originally had substitutions for calling the derived method.
if (!baseCalleeType->isPolymorphic())
return;
auto derivedClass = derivedSelfType;
if (auto metatypeType = dyn_cast<MetatypeType>(derivedClass))
derivedClass = CanType(metatypeType->getInstanceType());
SubstitutionMap subMap;
if (auto origCalleeSig = AI.getOrigCalleeType()->getGenericSignature()) {
auto calleeSelfType = AI.getSubstCalleeType()->getSelfParameter().getType();
if (auto metatypeType = dyn_cast<MetatypeType>(calleeSelfType))
calleeSelfType = CanType(metatypeType->getInstanceType());
auto *calleeClassDecl = calleeSelfType->getClassOrBoundGenericClass();
assert(calleeClassDecl && "self is not a class type");
auto origSubs = AI.getSubstitutions();
// Add generic parameters from the method itself, ignoring any generic
// parameters from the derived class.
unsigned minDepth = 0;
if (auto derivedClassSig = calleeClassDecl->getGenericSignatureOfContext())
minDepth = derivedClassSig->getGenericParams().back()->getDepth() + 1;
for (auto depTy : origCalleeSig->getAllDependentTypes()) {
// Grab the next substitution.
auto sub = origSubs.front();
origSubs = origSubs.slice(1);
// If the dependent type doesn't contain any generic parameter with
// a depth of at least the minimum, skip this type.
auto canTy = depTy->getCanonicalType();
auto hasInnerGenericParameter = [minDepth](Type type) -> bool {
if (auto gp = type->getAs<GenericTypeParamType>()) {
return gp->getDepth() >= minDepth;
}
return false;
};
if (!Type(canTy.getPointer()).findIf(hasInnerGenericParameter))
continue;
// Otherwise, record the replacement and conformances for the mapped
// type.
subMap.addSubstitution(canTy, sub.getReplacement());
subMap.addConformances(canTy, sub.getConformances());
}
assert(origSubs.empty());
}
// Add any generic substitutions for the base class.
auto baseSelfType = baseCalleeType->getSelfParameter().getType();
if (auto metatypeType = dyn_cast<MetatypeType>(baseSelfType))
baseSelfType = CanType(metatypeType->getInstanceType());
auto *baseClassDecl = baseSelfType.getClassOrBoundGenericClass();
assert(baseClassDecl && "not a class method");
if (auto baseClassSig = baseClassDecl->getGenericSignatureOfContext()) {
// Compute the type of the base class, starting from the
// derived class type and the type of the method's self
// parameter.
auto baseClass = derivedClass->getSuperclassForDecl(baseClassDecl, nullptr)
->getCanonicalType();
auto baseClassSubs = baseClass->gatherAllSubstitutions(
M.getSwiftModule(), nullptr);
// Decompose the base class substitutions, adding them to the same
// substitution maps as above.
baseClassSig->getSubstitutionMap(baseClassSubs, subMap);
}
// Build the new substitutions using the base method signature.
auto baseCalleeSig = baseCalleeType->getGenericSignature();
baseCalleeSig->getSubstitutions(subMap, newSubs);
}