From df6eeb93c1718334779ae328db277cdf7a9d7b04 Mon Sep 17 00:00:00 2001 From: Yong He Date: Fri, 12 Jan 2018 14:15:56 -0800 Subject: Refactor substitution representation in DeclRefBase (#363) This commit changes the type of `DeclRefBase::substitutions` from `RefPtr` to `SubstitutionSet`, which is a new type defined as following: ``` struct SubstitutionSet { RefPtr genericSubstitutions; RefPtr thisTypeSubstitution; RefPtr globalGenParamSubstitutions; } ``` This change get rid of most helper functions to retreive the substitution of a certain type, as well as surgery operations to insert a `ThisTypeSubstitution` or `GlobalGenericTypeSubstittuion` at top or bottom of the substitution chain. It also simplies type comparison when certain type of substitution should not be considered as part of type definition. --- source/slang/mangle.cpp | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) (limited to 'source/slang/mangle.cpp') diff --git a/source/slang/mangle.cpp b/source/slang/mangle.cpp index 5b8e519b9..070c2b172 100644 --- a/source/slang/mangle.cpp +++ b/source/slang/mangle.cpp @@ -186,7 +186,7 @@ namespace Slang // TODO: this needs to be centralized RefPtr getOutermostGenericSubst( - RefPtr inSubst) + RefPtr inSubst) { for (auto subst = inSubst; subst; subst = subst->outer) { @@ -233,7 +233,7 @@ namespace Slang // There are two cases here: either we have specializations // in place for the parent generic declaration, or we don't. - auto subst = getOutermostGenericSubst(declRef.substitutions); + auto subst = getOutermostGenericSubst(declRef.substitutions.genericSubstitutions); if( subst && subst->genericDecl == parentGenericDeclRef.getDecl() ) { // This is the case where we *do* have substitutions. @@ -378,20 +378,15 @@ namespace Slang DeclRef(declRef.decl, declRef.substitutions)); } - String mangleSpecializedFuncName(String baseName, RefPtr subst) + String mangleSpecializedFuncName(String baseName, SubstitutionSet subst) { ManglingContext context; emitRaw(&context, baseName.Buffer()); emitRaw(&context, "_G"); - while (subst) + if (auto genSubst = subst.genericSubstitutions) { - if (auto genSubst = subst.As()) - { - for (auto a : genSubst->args) - emitVal(&context, a); - break; - } - subst = subst->outer; + for (auto a : genSubst->args) + emitVal(&context, a); } return context.sb.ProduceString(); } -- cgit v1.2.3