summaryrefslogtreecommitdiff
path: root/source/slang/syntax-base-defs.h
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/syntax-base-defs.h
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/syntax-base-defs.h')
-rw-r--r--source/slang/syntax-base-defs.h30
1 files changed, 16 insertions, 14 deletions
diff --git a/source/slang/syntax-base-defs.h b/source/slang/syntax-base-defs.h
index de8b294d8..2eb130863 100644
--- a/source/slang/syntax-base-defs.h
+++ b/source/slang/syntax-base-defs.h
@@ -40,14 +40,14 @@ ABSTRACT_SYNTAX_CLASS(Val, NodeBase)
RAW(
// construct a new value by applying a set of parameter
// substitutions to this one
- RefPtr<Val> Substitute(Substitutions* subst);
+ RefPtr<Val> Substitute(SubstitutionSet subst);
// Lower-level interface for substition. Like the basic
// `Substitute` above, but also takes a by-reference
// integer parameter that should be incremented when
// returning a modified value (this can help the caller
// decide whether they need to do anything).
- virtual RefPtr<Val> SubstituteImpl(Substitutions* subst, int* ioDiff);
+ virtual RefPtr<Val> SubstituteImpl(SubstitutionSet subst, int* ioDiff);
virtual bool EqualsVal(Val* val) = 0;
virtual String ToString() = 0;
@@ -113,7 +113,7 @@ public:
bool IsClass();
Type* GetCanonicalType();
- virtual RefPtr<Val> SubstituteImpl(Substitutions* subst, int* ioDiff) override;
+ virtual RefPtr<Val> SubstituteImpl(SubstitutionSet subst, int* ioDiff) override;
virtual bool EqualsVal(Val* val) override;
protected:
@@ -132,12 +132,9 @@ END_SYNTAX_CLASS()
// type-level variables to concrete argument values
ABSTRACT_SYNTAX_CLASS(Substitutions, RefObject)
- // Any further substitutions, relating to outer generic declarations
- SYNTAX_FIELD(RefPtr<Substitutions>, outer)
-
RAW(
// Apply a set of substitutions to the bindings in this substitution
- virtual RefPtr<Substitutions> SubstituteImpl(Substitutions* subst, int* ioDiff) = 0;
+ virtual RefPtr<Substitutions> SubstituteImpl(SubstitutionSet subst, int* ioDiff) = 0;
// Check if these are equivalent substitutiosn to another set
virtual bool Equals(Substitutions* subst) = 0;
@@ -153,10 +150,13 @@ SYNTAX_CLASS(GenericSubstitution, Substitutions)
// The actual values of the arguments
SYNTAX_FIELD(List<RefPtr<Val>>, args)
-
+
+ // Any further substitutions, relating to outer generic declarations
+ SYNTAX_FIELD(RefPtr<GenericSubstitution>, outer)
+
RAW(
// Apply a set of substitutions to the bindings in this substitution
- virtual RefPtr<Substitutions> SubstituteImpl(Substitutions* subst, int* ioDiff) override;
+ virtual RefPtr<Substitutions> SubstituteImpl(SubstitutionSet subst, int* ioDiff) override;
// Check if these are equivalent substitutiosn to another set
virtual bool Equals(Substitutions* subst) override;
@@ -182,7 +182,7 @@ SYNTAX_CLASS(ThisTypeSubstitution, Substitutions)
SYNTAX_FIELD(RefPtr<Val>, sourceType)
RAW(
// Apply a set of substitutions to the bindings in this substitution
- virtual RefPtr<Substitutions> SubstituteImpl(Substitutions* subst, int* ioDiff) override;
+ virtual RefPtr<Substitutions> SubstituteImpl(SubstitutionSet subst, int* ioDiff) override;
// Check if these are equivalent substitutiosn to another set
virtual bool Equals(Substitutions* subst) override;
@@ -192,8 +192,9 @@ SYNTAX_CLASS(ThisTypeSubstitution, Substitutions)
}
virtual int GetHashCode() const override
{
- SLANG_ASSERT(sourceType);
- return sourceType->GetHashCode();
+ if (sourceType)
+ return sourceType->GetHashCode();
+ return 0;
}
)
END_SYNTAX_CLASS()
@@ -203,10 +204,11 @@ SYNTAX_CLASS(GlobalGenericParamSubstitution, Substitutions)
DECL_FIELD(GlobalGenericParamDecl*, paramDecl)
// the actual type to substitute in
SYNTAX_FIELD(RefPtr<Val>, actualType)
-
+ // Any further global type parameter substitutions
+ SYNTAX_FIELD(RefPtr<GlobalGenericParamSubstitution>, outer)
RAW(
// Apply a set of substitutions to the bindings in this substitution
- virtual RefPtr<Substitutions> SubstituteImpl(Substitutions* subst, int* ioDiff) override;
+ virtual RefPtr<Substitutions> SubstituteImpl(SubstitutionSet subst, int* ioDiff) override;
// Check if these are equivalent substitutiosn to another set
virtual bool Equals(Substitutions* subst) override;