summaryrefslogtreecommitdiffstats
path: root/source/slang/syntax.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/slang/syntax.cpp')
-rw-r--r--source/slang/syntax.cpp48
1 files changed, 32 insertions, 16 deletions
diff --git a/source/slang/syntax.cpp b/source/slang/syntax.cpp
index 0af318c9e..709206278 100644
--- a/source/slang/syntax.cpp
+++ b/source/slang/syntax.cpp
@@ -330,7 +330,7 @@ void Type::accept(IValVisitor* visitor, void* extra)
- bool ArrayExpressionType::EqualsImpl(Type * type)
+ bool ArrayExpressionType::EqualsImpl(Type* type)
{
auto arrType = as<ArrayExpressionType>(type);
if (!arrType)
@@ -444,8 +444,13 @@ void Type::accept(IValVisitor* visitor, void* extra)
}
case RequirementWitness::Flavor::val:
- return RequirementWitness(
- getVal()->Substitute(subst));
+ {
+ auto val = getVal();
+ SLANG_ASSERT(val);
+
+ return RequirementWitness(
+ val->Substitute(subst));
+ }
}
}
@@ -1336,8 +1341,6 @@ void Type::accept(IValVisitor* visitor, void* extra)
RefPtr<Substitutions> GenericSubstitution::applySubstitutionsShallow(SubstitutionSet substSet, RefPtr<Substitutions> substOuter, int* ioDiff)
{
- SLANG_ASSERT(this);
-
int diff = 0;
if(substOuter != outer) diff++;
@@ -1361,8 +1364,11 @@ void Type::accept(IValVisitor* visitor, void* extra)
bool GenericSubstitution::Equals(Substitutions* subst)
{
// both must be NULL, or non-NULL
- if (!this || !subst)
- return !this && !subst;
+ if (subst == nullptr)
+ return false;
+ if (this == subst)
+ return true;
+
auto genericSubst = as<GenericSubstitution>(subst);
if (!genericSubst)
return false;
@@ -1388,8 +1394,6 @@ void Type::accept(IValVisitor* visitor, void* extra)
RefPtr<Substitutions> ThisTypeSubstitution::applySubstitutionsShallow(SubstitutionSet substSet, RefPtr<Substitutions> substOuter, int* ioDiff)
{
- SLANG_ASSERT(this);
-
int diff = 0;
if(substOuter != outer) diff++;
@@ -1409,9 +1413,10 @@ void Type::accept(IValVisitor* visitor, void* extra)
bool ThisTypeSubstitution::Equals(Substitutions* subst)
{
- SLANG_ASSERT(this);
if (!subst)
return false;
+ if (subst == this)
+ return true;
if (auto thisTypeSubst = as<ThisTypeSubstitution>(subst))
{
@@ -1462,6 +1467,9 @@ void Type::accept(IValVisitor* visitor, void* extra)
{
if (!subst)
return false;
+ if (subst == this)
+ return true;
+
if (auto genSubst = as<GlobalGenericParamSubstitution>(subst))
{
if (paramDecl != genSubst->paramDecl)
@@ -1485,13 +1493,16 @@ void Type::accept(IValVisitor* visitor, void* extra)
RefPtr<Type> DeclRefBase::Substitute(RefPtr<Type> type) const
{
+ // Note that type can be nullptr, and so this function can return nullptr (although only correctly when no substitutions)
+
// No substitutions? Easy.
if (!substitutions)
return type;
+ SLANG_ASSERT(type);
+
// Otherwise we need to recurse on the type structure
// and apply substitutions where it makes sense
-
return type->Substitute(substitutions).as<Type>();
}
@@ -1555,6 +1566,7 @@ void Type::accept(IValVisitor* visitor, void* extra)
RefPtr<Substitutions> restSubst,
int* ioDiff)
{
+ SLANG_ASSERT(substToSpecialize);
return substToSpecialize->applySubstitutionsShallow(substsToApply, restSubst, ioDiff);
}
@@ -1949,7 +1961,6 @@ void Type::accept(IValVisitor* visitor, void* extra)
RefPtr<Val> Val::Substitute(SubstitutionSet subst)
{
- SLANG_ASSERT(this);
if (!subst) return this;
int diff = 0;
return SubstituteImpl(subst, &diff);
@@ -2437,11 +2448,16 @@ void Type::accept(IValVisitor* visitor, void* extra)
return name->text;
}
- bool SubstitutionSet::Equals(SubstitutionSet substSet) const
+ bool SubstitutionSet::Equals(const SubstitutionSet& substSet) const
{
- if(!substitutions || !substSet.substitutions)
- return substitutions == substSet.substitutions;
-
+ if (substitutions == substSet.substitutions)
+ {
+ return true;
+ }
+ if (substitutions == nullptr || substSet.substitutions == nullptr)
+ {
+ return false;
+ }
return substitutions->Equals(substSet.substitutions);
}