diff options
| author | Yong He <yonghe@outlook.com> | 2023-08-04 15:47:39 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-08-04 15:47:39 -0700 |
| commit | a2d90fb275962da84611160f8ddd74d934a68dbd (patch) | |
| tree | 066084537b9f4fe1f367de100ed6638a88a028c1 /source/slang/slang-ast-substitutions.cpp | |
| parent | 17da4f0dec2b86ba3a4bdaf8a2ae112047d23623 (diff) | |
Redesign `DeclRef` and systematic `Val` deduplication (#3049)
* Redesign DeclRef + Deduplicate Val.
* Update project files
* Fix warning.
* Fix.
* Fix.
* Remove `Val::_equalsImplOverride`.
* Rmove `Val::_getHashCodeOverride`.
* Remove `semanticVisitor` param from `resolve`.
* Cleanups.
---------
Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source/slang/slang-ast-substitutions.cpp')
| -rw-r--r-- | source/slang/slang-ast-substitutions.cpp | 163 |
1 files changed, 0 insertions, 163 deletions
diff --git a/source/slang/slang-ast-substitutions.cpp b/source/slang/slang-ast-substitutions.cpp deleted file mode 100644 index 7b052522e..000000000 --- a/source/slang/slang-ast-substitutions.cpp +++ /dev/null @@ -1,163 +0,0 @@ -// slang-ast-substitutions.cpp -#include "slang-ast-builder.h" -#include <assert.h> - -#include "slang-generated-ast-macro.h" - -namespace Slang { - -// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Substitutions !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - -Substitutions* Substitutions::applySubstitutionsShallow(ASTBuilder* astBuilder, SubstitutionSet substSet, Substitutions* substOuter, int* ioDiff) -{ - SLANG_AST_NODE_VIRTUAL_CALL(Substitutions, applySubstitutionsShallow, (astBuilder, substSet, substOuter, ioDiff)) -} - -bool Substitutions::equals(Substitutions* subst) -{ - SLANG_AST_NODE_VIRTUAL_CALL(Substitutions, equals, (subst)) -} - -HashCode Substitutions::getHashCode() const -{ - SLANG_AST_NODE_CONST_VIRTUAL_CALL(Substitutions, getHashCode, ()) -} - -Substitutions* Substitutions::_applySubstitutionsShallowOverride(ASTBuilder* astBuilder, SubstitutionSet substSet, Substitutions* substOuter, int* ioDiff) -{ - SLANG_UNUSED(astBuilder); - SLANG_UNUSED(substSet); - SLANG_UNUSED(substOuter); - SLANG_UNUSED(ioDiff); - SLANG_UNEXPECTED("Substitutions::_applySubstitutionsShallowOverride not overridden"); - //return Substitutions*(); -} - -bool Substitutions::_equalsOverride(Substitutions* subst) -{ - SLANG_UNUSED(subst); - SLANG_UNEXPECTED("Substitutions::_equalsOverride not overridden"); - //return false; -} - -HashCode Substitutions::_getHashCodeOverride() const -{ - SLANG_UNEXPECTED("Substitutions::_getHashCodeOverride not overridden"); - //return HashCode(0); -} - -// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! GenericSubstitution !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - -Substitutions* GenericSubstitution::_applySubstitutionsShallowOverride(ASTBuilder* astBuilder, SubstitutionSet substSet, Substitutions* substOuter, int* ioDiff) -{ - int diff = 0; - - if (substOuter != outer) diff++; - - List<Val*> substArgs; - for (auto a : args) - { - substArgs.add(a->substituteImpl(astBuilder, substSet, &diff)); - } - - if (!diff) return this; - - (*ioDiff)++; - - auto substSubst = astBuilder->getOrCreateGenericSubstitution(substOuter, genericDecl, substArgs); - return substSubst; -} - -bool GenericSubstitution::_equalsOverride(Substitutions* subst) -{ - // both must be NULL, or non-NULL - if (subst == nullptr) - return false; - if (this == subst) - return true; - - auto genericSubst = as<GenericSubstitution>(subst); - if (!genericSubst) - return false; - if (genericDecl != genericSubst->genericDecl) - return false; - - Index argCount = args.getCount(); - SLANG_RELEASE_ASSERT(args.getCount() == genericSubst->args.getCount()); - for (Index aa = 0; aa < argCount; ++aa) - { - if (!args[aa]->equalsVal(genericSubst->args[aa])) - return false; - } - - if (!outer) - return !genericSubst->outer; - - if (!outer->equals(genericSubst->outer)) - return false; - - return true; -} - -HashCode GenericSubstitution::_getHashCodeOverride() const -{ - HashCode rs = 0; - for (auto && v : args) - { - rs ^= v->getHashCode(); - rs *= 16777619; - } - return rs; -} - -// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ThisTypeSubstitution !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - -Substitutions* ThisTypeSubstitution::_applySubstitutionsShallowOverride(ASTBuilder* astBuilder, SubstitutionSet substSet, Substitutions* substOuter, int* ioDiff) -{ - int diff = 0; - - if (substOuter != outer) diff++; - - // NOTE: Must use .as because we must have a smart pointer here to keep in scope. - auto substWitness = as<SubtypeWitness>(witness->substituteImpl(astBuilder, substSet, &diff)); - - if (!diff) return this; - - (*ioDiff)++; - ThisTypeSubstitution* substSubst; - - substSubst = astBuilder->getOrCreateThisTypeSubstitution(interfaceDecl, substWitness, substOuter); - return substSubst; -} - -bool ThisTypeSubstitution::_equalsOverride(Substitutions* subst) -{ - if (!subst) - return false; - if (subst == this) - return true; - - if (auto thisTypeSubst = as<ThisTypeSubstitution>(subst)) - { - // For our purposes, two this-type substitutions are - // equivalent if they have the same type as `This`, - // even if the specific witness values they use - // might differ. - // - if (this->interfaceDecl != thisTypeSubst->interfaceDecl) - return false; - - if (!this->witness->sub->equals(thisTypeSubst->witness->sub)) - return false; - - return true; - } - return false; -} - -HashCode ThisTypeSubstitution::_getHashCodeOverride() const -{ - return witness->sub->getHashCode(); -} - -} // namespace Slang |
