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/syntax-base-defs.h | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'source/slang/syntax-base-defs.h') 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 Substitute(Substitutions* subst); + RefPtr 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 SubstituteImpl(Substitutions* subst, int* ioDiff); + virtual RefPtr 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 SubstituteImpl(Substitutions* subst, int* ioDiff) override; + virtual RefPtr 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, outer) - RAW( // Apply a set of substitutions to the bindings in this substitution - virtual RefPtr SubstituteImpl(Substitutions* subst, int* ioDiff) = 0; + virtual RefPtr 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>, args) - + + // Any further substitutions, relating to outer generic declarations + SYNTAX_FIELD(RefPtr, outer) + RAW( // Apply a set of substitutions to the bindings in this substitution - virtual RefPtr SubstituteImpl(Substitutions* subst, int* ioDiff) override; + virtual RefPtr 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, sourceType) RAW( // Apply a set of substitutions to the bindings in this substitution - virtual RefPtr SubstituteImpl(Substitutions* subst, int* ioDiff) override; + virtual RefPtr 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, actualType) - + // Any further global type parameter substitutions + SYNTAX_FIELD(RefPtr, outer) RAW( // Apply a set of substitutions to the bindings in this substitution - virtual RefPtr SubstituteImpl(Substitutions* subst, int* ioDiff) override; + virtual RefPtr SubstituteImpl(SubstitutionSet subst, int* ioDiff) override; // Check if these are equivalent substitutiosn to another set virtual bool Equals(Substitutions* subst) override; -- cgit v1.2.3