summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2017-11-08 12:08:13 -0500
committerYong He <yonghe@outlook.com>2017-11-08 12:08:13 -0500
commitf408165a88e12467c4993199a0e515a8808083c3 (patch)
treedd343bb6533d303792a68c8a0d10a884ec09467c /source
parentef19b423b46bed4739a1e86a26cfbb18c221d497 (diff)
Cleanup substitution of DeclaredSubtypeWitness.
Now using DeclaredSubtypeWitness::declRef to determine the proper argument index in a GenericSubstitution.
Diffstat (limited to 'source')
-rw-r--r--source/slang/syntax.cpp67
1 files changed, 27 insertions, 40 deletions
diff --git a/source/slang/syntax.cpp b/source/slang/syntax.cpp
index 70730ff95..81df49713 100644
--- a/source/slang/syntax.cpp
+++ b/source/slang/syntax.cpp
@@ -1529,54 +1529,41 @@ 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];
- }
}
}
RefPtr<DeclaredSubtypeWitness> rs = new DeclaredSubtypeWitness();