summaryrefslogtreecommitdiffstats
path: root/source/slang/syntax.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/slang/syntax.cpp')
-rw-r--r--source/slang/syntax.cpp73
1 files changed, 32 insertions, 41 deletions
diff --git a/source/slang/syntax.cpp b/source/slang/syntax.cpp
index 4e1778e6e..81df49713 100644
--- a/source/slang/syntax.cpp
+++ b/source/slang/syntax.cpp
@@ -1529,57 +1529,48 @@ void Type::accept(IValVisitor* visitor, void* extra)
RefPtr<Val> DeclaredSubtypeWitness::SubstituteImpl(Substitutions* subst, int * ioDiff)
{
- DeclRef<GenericTypeParamDecl> genParamDeclRef;
- if (auto subDeclRefType = this->sub.As<DeclRefType>())
+ if (auto genConstraintDecl = declRef.As<GenericTypeConstraintDecl>())
{
- genParamDeclRef = subDeclRefType->declRef.As<GenericTypeParamDecl>();
- }
- if (!genParamDeclRef)
- return this;
- auto genParamDecl = genParamDeclRef.getDecl();
- // search for a substitution that might apply to us
- for (auto s = subst; s; s = s->outer.Ptr())
- {
- if (auto genericSubst = dynamic_cast<GenericSubstitution*>(s))
+ // search for a substitution that might apply to us
+ for (auto s = subst; s; s = s->outer.Ptr())
{
- // the generic decl associated with the substitution list must be
- // the generic decl that declared this parameter
- auto genericDecl = genericSubst->genericDecl;
- if (genericDecl != genParamDecl->ParentDecl)
- continue;
- bool found = false;
- int index = 0;
- for (auto m : genericDecl->Members)
+ if (auto genericSubst = dynamic_cast<GenericSubstitution*>(s))
{
- if (m.Ptr() == genParamDecl)
- {
- // We've found it, so return the corresponding specialization argument
- (*ioDiff)++;
- found = true;
- break;
- }
- else if (auto typeParam = m.As<GenericTypeParamDecl>())
- {
- index++;
- }
- else if (auto valParam = m.As<GenericValueParamDecl>())
+ // the generic decl associated with the substitution list must be
+ // the generic decl that declared this parameter
+ auto genericDecl = genericSubst->genericDecl;
+ if (genericDecl != genConstraintDecl.getDecl()->ParentDecl)
+ continue;
+ bool found = false;
+ UInt index = 0;
+ for (auto m : genericDecl->Members)
{
- index++;
+ if (auto constraintParam = m.As<GenericTypeConstraintDecl>())
+ {
+ if (constraintParam.Ptr() == declRef.getDecl())
+ {
+ found = true;
+ break;
+ }
+ index++;
+ }
}
- else
+ if (found)
{
+ (*ioDiff)++;
+ auto ordinaryParamCount = genericDecl->getMembersOfType<GenericTypeParamDecl>().Count() +
+ genericDecl->getMembersOfType<GenericValueParamDecl>().Count();
+ SLANG_ASSERT(index + ordinaryParamCount < genericSubst->args.Count());
+ return genericSubst->args[index + ordinaryParamCount];
}
}
- if (found)
- {
- auto ordinaryParamCount = genericDecl->getMembersOfType<GenericTypeParamDecl>().Count() +
- genericDecl->getMembersOfType<GenericValueParamDecl>().Count();
- SLANG_ASSERT(ordinaryParamCount + index < genericSubst->args.Count());
- return genericSubst->args[ordinaryParamCount + index];
- }
}
}
- return this;
+ RefPtr<DeclaredSubtypeWitness> rs = new DeclaredSubtypeWitness();
+ rs->sub = sub->SubstituteImpl(subst, ioDiff).As<Type>();
+ rs->sup = sup->SubstituteImpl(subst, ioDiff).As<Type>();
+ rs->declRef = declRef.SubstituteImpl(subst, ioDiff);
+ return rs;
}
String DeclaredSubtypeWitness::ToString()