summaryrefslogtreecommitdiff
path: root/source/slang/slang-check-conversion.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/slang/slang-check-conversion.cpp')
-rw-r--r--source/slang/slang-check-conversion.cpp42
1 files changed, 39 insertions, 3 deletions
diff --git a/source/slang/slang-check-conversion.cpp b/source/slang/slang-check-conversion.cpp
index 8f2ea3ca7..705da89e3 100644
--- a/source/slang/slang-check-conversion.cpp
+++ b/source/slang/slang-check-conversion.cpp
@@ -97,7 +97,17 @@ bool SemanticsVisitor::shouldUseInitializerDirectly(Type* toType, Expr* fromExpr
// we want to check for is whether a direct initialization
// is possible (a type conversion exists).
//
- return canCoerce(toType, fromExpr->type, fromExpr);
+ ConversionCost cost;
+ if (canCoerce(toType, fromExpr->type, fromExpr, &cost))
+ {
+ if (cost >= kConversionCost_Explicit)
+ {
+ return false;
+ }
+ return true;
+ }
+
+ return false;
}
bool SemanticsVisitor::_readValueFromInitializerList(
@@ -526,6 +536,19 @@ bool SemanticsVisitor::_readAggregateValueFromInitializerList(
}
else
{
+ auto isLinkTimeVal =
+ as<TypeCastIntVal>(toElementCount) || as<DeclRefIntVal>(toElementCount) ||
+ as<PolynomialIntVal>(toElementCount) || as<FuncCallIntVal>(toElementType);
+ if (isLinkTimeVal)
+ {
+ auto defaultConstructExpr = m_astBuilder->create<DefaultConstructExpr>();
+ defaultConstructExpr->loc = fromInitializerListExpr->loc;
+ defaultConstructExpr->type = QualType(toType);
+
+ *outToExpr = defaultConstructExpr;
+ return true;
+ }
+
// We don't know the element count statically,
// so what are we supposed to be doing?
//
@@ -702,12 +725,26 @@ bool SemanticsVisitor::_readAggregateValueFromInitializerList(
auto toRowType =
createVectorType(toMatrixType->getElementType(), toMatrixType->getColumnCount());
- if (auto constRowCount = as<ConstantIntVal>(toMatrixType->getRowCount()))
+ auto rowCountIntVal = toMatrixType->getRowCount();
+ if (auto constRowCount = as<ConstantIntVal>(rowCountIntVal))
{
rowCount = (UInt)constRowCount->getValue();
}
else
{
+ auto isLinkTimeVal =
+ as<TypeCastIntVal>(rowCountIntVal) || as<DeclRefIntVal>(rowCountIntVal) ||
+ as<PolynomialIntVal>(rowCountIntVal) || as<FuncCallIntVal>(rowCountIntVal);
+ if (isLinkTimeVal)
+ {
+ auto defaultConstructExpr = m_astBuilder->create<DefaultConstructExpr>();
+ defaultConstructExpr->loc = fromInitializerListExpr->loc;
+ defaultConstructExpr->type = QualType(toType);
+
+ *outToExpr = defaultConstructExpr;
+ return true;
+ }
+
// We don't know the element count statically,
// so what are we supposed to be doing?
//
@@ -1545,7 +1582,6 @@ bool SemanticsVisitor::_coerce(
return true;
}
-
// The main general-purpose approach for conversion is
// using suitable marked initializer ("constructor")
// declarations on the target type.