From 19867ffca6dca7995c799354081219c9e76f13d1 Mon Sep 17 00:00:00 2001 From: Yong He Date: Thu, 20 Feb 2025 14:48:51 -0800 Subject: 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. --- source/slang/slang-ast-val.cpp | 52 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) (limited to 'source/slang/slang-ast-val.cpp') 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(getFromType()->substituteImpl(astBuilder, subst, &diff)); + auto substTo = as(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(resolvedDeclRef)) + return resolvedVal; + + auto newFrom = as(getFromType()->resolve()); + auto newTo = as(getToType()->resolve()); + + auto newDeclRef = as(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) -- cgit v1.2.3