summaryrefslogtreecommitdiff
path: root/source/slang/slang-ast-type.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/slang/slang-ast-type.cpp')
-rw-r--r--source/slang/slang-ast-type.cpp39
1 files changed, 4 insertions, 35 deletions
diff --git a/source/slang/slang-ast-type.cpp b/source/slang/slang-ast-type.cpp
index 077d6de0a..39b7a8e04 100644
--- a/source/slang/slang-ast-type.cpp
+++ b/source/slang/slang-ast-type.cpp
@@ -196,6 +196,8 @@ Type* DeclRefType::_createCanonicalTypeOverride()
return this;
}
+Val* maybeSubstituteGenericParam(Val* paramVal, Decl* paramDecl, SubstitutionSet subst, int* ioDiff);
+
Val* DeclRefType::_substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff)
{
if (!subst) return this;
@@ -204,41 +206,8 @@ Val* DeclRefType::_substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSe
// of a generic parameter, since that is what we might be substituting...
if (auto genericTypeParamDecl = as<GenericTypeParamDecl>(declRef.getDecl()))
{
- // search for a substitution that might apply to us
- for (auto s = subst.substitutions; s; s = s->outer)
- {
- auto genericSubst = as<GenericSubstitution>(s);
- if (!genericSubst)
- continue;
-
- // the generic decl associated with the substitution list must be
- // the generic decl that declared this parameter
- auto genericDecl = genericSubst->genericDecl;
- if (genericDecl != genericTypeParamDecl->parentDecl)
- continue;
-
- int index = 0;
- for (auto m : genericDecl->members)
- {
- if (m == genericTypeParamDecl)
- {
- // We've found it, so return the corresponding specialization argument
- (*ioDiff)++;
- return genericSubst->getArgs()[index];
- }
- else if (auto typeParam = as<GenericTypeParamDecl>(m))
- {
- index++;
- }
- else if (auto valParam = as<GenericValueParamDecl>(m))
- {
- index++;
- }
- else
- {
- }
- }
- }
+ if (auto result = maybeSubstituteGenericParam(this, genericTypeParamDecl, subst, ioDiff))
+ return result;
}
int diff = 0;
DeclRef<Decl> substDeclRef = declRef.substituteImpl(astBuilder, subst, &diff);