diff options
| author | Yong He <yonghe@outlook.com> | 2017-11-22 17:32:15 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-11-22 17:32:15 -0500 |
| commit | 83d49ce376185f7dc3f40eb531f01ee350220959 (patch) | |
| tree | 7e96f26c6b6e6bf6a8b15ba1820e844e78a31394 /source/slang/syntax.cpp | |
| parent | 56e49feea3956d66e41b819c26628c65b3c28197 (diff) | |
| parent | 581b30dd5a4263c90539a8c5cc6063b2485885cd (diff) | |
Merge pull request #293 from csyonghe/generic-param-fix
Fixup global generic parameters
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) { |
