summaryrefslogtreecommitdiff
path: root/source/slang/slang-ast-val.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2025-02-20 14:48:51 -0800
committerGitHub <noreply@github.com>2025-02-20 14:48:51 -0800
commit19867ffca6dca7995c799354081219c9e76f13d1 (patch)
treeb9153428fc8b7b6f3069931cf816ad374a2e7c52 /source/slang/slang-ast-val.cpp
parent9580e311e0cefb0f8e11afc316783a67201654eb (diff)
Simplify implicit cast ctors for vector & matrix. (#6408)
* Simplify implicit cast ctors for vector & matrix. * Fix formatting. * Fix tests. * Fix Falcor test. * Mark __builtin_cast as internal.
Diffstat (limited to 'source/slang/slang-ast-val.cpp')
-rw-r--r--source/slang/slang-ast-val.cpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/source/slang/slang-ast-val.cpp b/source/slang/slang-ast-val.cpp
index 9bcfd21bc..7613dbe80 100644
--- a/source/slang/slang-ast-val.cpp
+++ b/source/slang/slang-ast-val.cpp
@@ -845,6 +845,58 @@ void ExtractFromConjunctionSubtypeWitness::_toTextOverride(StringBuilder& out)
out << ")";
}
+void TypeCoercionWitness::_toTextOverride(StringBuilder& out)
+{
+ out << "TypeCoercionWitness(";
+ if (getFromType())
+ out << getFromType();
+ if (getToType())
+ out << getToType();
+ out << ")";
+}
+
+Val* TypeCoercionWitness::_substituteImplOverride(
+ ASTBuilder* astBuilder,
+ SubstitutionSet subst,
+ int* ioDiff)
+{
+ int diff = 0;
+
+ auto substDeclRef = getDeclRef().substituteImpl(astBuilder, subst, &diff);
+ auto substFrom = as<Type>(getFromType()->substituteImpl(astBuilder, subst, &diff));
+ auto substTo = as<Type>(getToType()->substituteImpl(astBuilder, subst, &diff));
+
+ if (!diff)
+ return this;
+
+ (*ioDiff)++;
+
+ TypeCoercionWitness* substValue =
+ astBuilder->getTypeCoercionWitness(substFrom, substTo, substDeclRef);
+ return substValue;
+}
+
+Val* TypeCoercionWitness::_resolveImplOverride()
+{
+ Val* resolvedDeclRef = nullptr;
+ if (getDeclRef())
+ resolvedDeclRef = getDeclRef().declRefBase->resolve();
+ if (auto resolvedVal = as<Witness>(resolvedDeclRef))
+ return resolvedVal;
+
+ auto newFrom = as<Type>(getFromType()->resolve());
+ auto newTo = as<Type>(getToType()->resolve());
+
+ auto newDeclRef = as<DeclRefBase>(resolvedDeclRef);
+ if (!newDeclRef)
+ newDeclRef = getDeclRef().declRefBase;
+ if (newFrom != getFromType() || newTo != getToType() || newDeclRef != getDeclRef())
+ {
+ return getCurrentASTBuilder()->getTypeCoercionWitness(newFrom, newTo, newDeclRef);
+ }
+ return this;
+}
+
// UNormModifierVal
void UNormModifierVal::_toTextOverride(StringBuilder& out)