From 64108c88836ed6b0335b000d4d127113f6840010 Mon Sep 17 00:00:00 2001 From: Yong He Date: Tue, 21 Nov 2017 19:26:17 -0500 Subject: Add logic to propagate GlobalGenericParamSubstitution --- source/slang/syntax.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'source/slang/syntax.cpp') diff --git a/source/slang/syntax.cpp b/source/slang/syntax.cpp index badfaea4f..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(destSubst)) + { + if (globalParamSubst->paramDecl == genSubst->paramDecl) + return true; + } + destSubst = destSubst->outer; + } + return false; + } + void insertGlobalGenericSubstitutions(RefPtr & destSubst, Substitutions * srcSubst) + { + while (srcSubst) + { + if (auto globalGenSubst = dynamic_cast(srcSubst)) + { + if (!hasGlobalGenericSubst(destSubst, globalGenSubst)) + { + RefPtr 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; -- cgit v1.2.3