summaryrefslogtreecommitdiff
path: root/source/slang/ast-legalize.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2018-01-12 14:15:56 -0800
committerTim Foley <tfoleyNV@users.noreply.github.com>2018-01-12 14:15:56 -0800
commitdf6eeb93c1718334779ae328db277cdf7a9d7b04 (patch)
treef4d53d3106cdc717727701e46411a1ebe23105fb /source/slang/ast-legalize.cpp
parent8daafcc2e4bf7b2dfb66d7a3b7ac60c86b2d926c (diff)
Refactor substitution representation in DeclRefBase (#363)
This commit changes the type of `DeclRefBase::substitutions` from `RefPtr<Substitutions>` to `SubstitutionSet`, which is a new type defined as following: ``` struct SubstitutionSet { RefPtr<GenericSubstitution> genericSubstitutions; RefPtr<ThisTypeSubstitution> thisTypeSubstitution; RefPtr<GlobalGenericParamSubstitution> 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.
Diffstat (limited to 'source/slang/ast-legalize.cpp')
-rw-r--r--source/slang/ast-legalize.cpp28
1 files changed, 17 insertions, 11 deletions
diff --git a/source/slang/ast-legalize.cpp b/source/slang/ast-legalize.cpp
index c6f42d4da..996a66eac 100644
--- a/source/slang/ast-legalize.cpp
+++ b/source/slang/ast-legalize.cpp
@@ -2629,11 +2629,12 @@ struct LoweringVisitor
SLANG_UNEXPECTED("unhandled value kind");
}
- RefPtr<Substitutions> translateSubstitutions(
- Substitutions* inSubstitutions)
+ SubstitutionSet translateSubstitutions(
+ SubstitutionSet inSubstitutions)
{
- if (!inSubstitutions) return nullptr;
- if (auto genSubst = dynamic_cast<GenericSubstitution*>(inSubstitutions))
+ if (!inSubstitutions) return SubstitutionSet();
+ SubstitutionSet rs;
+ if (auto genSubst = inSubstitutions.genericSubstitutions)
{
RefPtr<GenericSubstitution> result = new GenericSubstitution();
result->genericDecl = translateDeclRef(genSubst->genericDecl)->As<GenericDecl>();
@@ -2641,16 +2642,16 @@ struct LoweringVisitor
{
result->args.Add(translateVal(arg));
}
- return result;
+ rs.genericSubstitutions = result;
}
- else if (auto thisSubst = dynamic_cast<ThisTypeSubstitution*>(inSubstitutions))
+ if (auto thisSubst = inSubstitutions.thisTypeSubstitution)
{
RefPtr<ThisTypeSubstitution> result = new ThisTypeSubstitution();
if (result->sourceType)
result->sourceType = translateVal(result->sourceType);
- return result;
+ rs.thisTypeSubstitution = result;
}
- return nullptr;
+ return rs;
}
static Decl* getModifiedDecl(Decl* decl)
@@ -2673,7 +2674,7 @@ struct LoweringVisitor
RefPtr<Decl> translateDeclRef(
Decl* decl)
{
- return translateDeclRefImpl(DeclRef<Decl>(decl, nullptr));
+ return translateDeclRefImpl(DeclRef<Decl>(decl, SubstitutionSet()));
}
LegalExpr translateSimpleLegalValToLegalExpr(IRValue* irVal)
@@ -4943,11 +4944,16 @@ struct FindIRDeclUsedByASTVisitor
// If this is a specialized declaration reference, then any
// of the arguments also need to be walked.
- for(auto subst = declRef.substitutions; subst; subst = subst->outer)
+ for(auto subst = declRef.substitutions.genericSubstitutions; subst; subst = subst->outer)
{
walkSubst(subst);
}
-
+ for (auto subst = declRef.substitutions.globalGenParamSubstitutions; subst; subst = subst->outer)
+ {
+ walkSubst(subst);
+ }
+ if (declRef.substitutions.thisTypeSubstitution)
+ walkSubst(declRef.substitutions.thisTypeSubstitution);
// If any parent of the declaration was in the stdlib, or
// is registered as a builtin, then skip it.
for (auto pp = decl; pp; pp = pp->ParentDecl)