diff options
Diffstat (limited to 'source/slang/syntax.cpp')
| -rw-r--r-- | source/slang/syntax.cpp | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/source/slang/syntax.cpp b/source/slang/syntax.cpp index e43dd9074..2c214a332 100644 --- a/source/slang/syntax.cpp +++ b/source/slang/syntax.cpp @@ -1309,9 +1309,39 @@ void Type::accept(IValVisitor* visitor, void* extra) UNREACHABLE_RETURN(expr); } + bool hasGlobalGenericSubst(Substitutions * destSubst, GlobalGenericParamSubstitution * genSubst) + { + while (destSubst) + { + if (auto globalParamSubst = dynamic_cast<GlobalGenericParamSubstitution*>(destSubst)) + { + if (globalParamSubst->paramDecl == genSubst->paramDecl) + return true; + } + destSubst = destSubst->outer; + } + return false; + } + void insertGlobalGenericSubstitutions(RefPtr<Substitutions> & destSubst, Substitutions * srcSubst) + { + while (srcSubst) + { + if (auto globalGenSubst = dynamic_cast<GlobalGenericParamSubstitution*>(srcSubst)) + { + if (!hasGlobalGenericSubst(destSubst, globalGenSubst)) + { + RefPtr<GlobalGenericParamSubstitution> cpyGlobalGenSubst = new GlobalGenericParamSubstitution(*globalGenSubst); + cpyGlobalGenSubst->outer = nullptr; + insertSubstAtBottom(destSubst, cpyGlobalGenSubst); + } + } + srcSubst = srcSubst->outer; + } + } DeclRefBase DeclRefBase::SubstituteImpl(Substitutions* subst, int* ioDiff) { + insertGlobalGenericSubstitutions(substitutions, subst); if (!substitutions) return *this; int diff = 0; @@ -1709,7 +1739,22 @@ void Type::accept(IValVisitor* visitor, void* extra) return sb.ProduceString(); } - + void insertSubstAtBottom(RefPtr<Substitutions> & substHead, RefPtr<Substitutions> substToInsert) + { + if (!substHead) + { + substHead = substToInsert; + return; + } + auto subst = substHead; + RefPtr<Substitutions> lastSubst = subst; + while (subst->outer) + { + lastSubst = subst; + subst = subst->outer; + } + lastSubst->outer = substToInsert; + } void insertSubstAtTop(DeclRefBase & declRef, RefPtr<Substitutions> substToInsert) { |
