Shader: Rename ConstantExpression to ConstantValueExpression

This commit is contained in:
Jérôme Leclercq 2021-07-08 15:22:08 +02:00
parent a895e553d4
commit 3a31c77524
23 changed files with 77 additions and 77 deletions

View File

@ -47,7 +47,7 @@ namespace Nz::ShaderAst
virtual ExpressionPtr Clone(CastExpression& node); virtual ExpressionPtr Clone(CastExpression& node);
virtual ExpressionPtr Clone(ConditionalExpression& node); virtual ExpressionPtr Clone(ConditionalExpression& node);
virtual ExpressionPtr Clone(ConstantIndexExpression& node); virtual ExpressionPtr Clone(ConstantIndexExpression& node);
virtual ExpressionPtr Clone(ConstantExpression& node); virtual ExpressionPtr Clone(ConstantValueExpression& node);
virtual ExpressionPtr Clone(IdentifierExpression& node); virtual ExpressionPtr Clone(IdentifierExpression& node);
virtual ExpressionPtr Clone(IntrinsicExpression& node); virtual ExpressionPtr Clone(IntrinsicExpression& node);
virtual ExpressionPtr Clone(SwizzleExpression& node); virtual ExpressionPtr Clone(SwizzleExpression& node);

View File

@ -34,7 +34,7 @@ NAZARA_SHADERAST_EXPRESSION(CallFunctionExpression)
NAZARA_SHADERAST_EXPRESSION(CallMethodExpression) NAZARA_SHADERAST_EXPRESSION(CallMethodExpression)
NAZARA_SHADERAST_EXPRESSION(CastExpression) NAZARA_SHADERAST_EXPRESSION(CastExpression)
NAZARA_SHADERAST_EXPRESSION(ConditionalExpression) NAZARA_SHADERAST_EXPRESSION(ConditionalExpression)
NAZARA_SHADERAST_EXPRESSION(ConstantExpression) NAZARA_SHADERAST_EXPRESSION(ConstantValueExpression)
NAZARA_SHADERAST_EXPRESSION(ConstantIndexExpression) NAZARA_SHADERAST_EXPRESSION(ConstantIndexExpression)
NAZARA_SHADERAST_EXPRESSION(IdentifierExpression) NAZARA_SHADERAST_EXPRESSION(IdentifierExpression)
NAZARA_SHADERAST_EXPRESSION(IntrinsicExpression) NAZARA_SHADERAST_EXPRESSION(IntrinsicExpression)

View File

@ -48,9 +48,9 @@ namespace Nz::ShaderAst
StatementPtr Clone(BranchStatement& node) override; StatementPtr Clone(BranchStatement& node) override;
StatementPtr Clone(ConditionalStatement& node) override; StatementPtr Clone(ConditionalStatement& node) override;
template<BinaryType Type> ExpressionPtr PropagateBinaryConstant(std::unique_ptr<ConstantExpression>&& lhs, std::unique_ptr<ConstantExpression>&& rhs); template<BinaryType Type> ExpressionPtr PropagateBinaryConstant(std::unique_ptr<ConstantValueExpression>&& lhs, std::unique_ptr<ConstantValueExpression>&& rhs);
template<typename TargetType> ExpressionPtr PropagateSingleValueCast(std::unique_ptr<ConstantExpression>&& operand); template<typename TargetType> ExpressionPtr PropagateSingleValueCast(std::unique_ptr<ConstantValueExpression>&& operand);
template<UnaryType Type> ExpressionPtr PropagateUnaryConstant(std::unique_ptr<ConstantExpression>&& operand); template<UnaryType Type> ExpressionPtr PropagateUnaryConstant(std::unique_ptr<ConstantValueExpression>&& operand);
template<typename TargetType> ExpressionPtr PropagateVec2Cast(TargetType v1, TargetType v2); template<typename TargetType> ExpressionPtr PropagateVec2Cast(TargetType v1, TargetType v2);
template<typename TargetType> ExpressionPtr PropagateVec3Cast(TargetType v1, TargetType v2, TargetType v3); template<typename TargetType> ExpressionPtr PropagateVec3Cast(TargetType v1, TargetType v2, TargetType v3);
template<typename TargetType> ExpressionPtr PropagateVec4Cast(TargetType v1, TargetType v2, TargetType v3, TargetType v4); template<typename TargetType> ExpressionPtr PropagateVec4Cast(TargetType v1, TargetType v2, TargetType v3, TargetType v4);

View File

@ -28,7 +28,7 @@ namespace Nz::ShaderAst
void Visit(CallMethodExpression& node) override; void Visit(CallMethodExpression& node) override;
void Visit(CastExpression& node) override; void Visit(CastExpression& node) override;
void Visit(ConditionalExpression& node) override; void Visit(ConditionalExpression& node) override;
void Visit(ConstantExpression& node) override; void Visit(ConstantValueExpression& node) override;
void Visit(ConstantIndexExpression& node) override; void Visit(ConstantIndexExpression& node) override;
void Visit(IdentifierExpression& node) override; void Visit(IdentifierExpression& node) override;
void Visit(IntrinsicExpression& node) override; void Visit(IntrinsicExpression& node) override;

View File

@ -32,7 +32,7 @@ namespace Nz::ShaderAst
void Serialize(CastExpression& node); void Serialize(CastExpression& node);
void Serialize(ConstantIndexExpression& node); void Serialize(ConstantIndexExpression& node);
void Serialize(ConditionalExpression& node); void Serialize(ConditionalExpression& node);
void Serialize(ConstantExpression& node); void Serialize(ConstantValueExpression& node);
void Serialize(IdentifierExpression& node); void Serialize(IdentifierExpression& node);
void Serialize(IntrinsicExpression& node); void Serialize(IntrinsicExpression& node);
void Serialize(SwizzleExpression& node); void Serialize(SwizzleExpression& node);

View File

@ -39,7 +39,7 @@ namespace Nz::ShaderAst
void Visit(CallMethodExpression& node) override; void Visit(CallMethodExpression& node) override;
void Visit(CastExpression& node) override; void Visit(CastExpression& node) override;
void Visit(ConditionalExpression& node) override; void Visit(ConditionalExpression& node) override;
void Visit(ConstantExpression& node) override; void Visit(ConstantValueExpression& node) override;
void Visit(ConstantIndexExpression& node) override; void Visit(ConstantIndexExpression& node) override;
void Visit(IdentifierExpression& node) override; void Visit(IdentifierExpression& node) override;
void Visit(IntrinsicExpression& node) override; void Visit(IntrinsicExpression& node) override;

View File

@ -140,7 +140,7 @@ namespace Nz::ShaderAst
ExpressionPtr truePath; ExpressionPtr truePath;
}; };
struct NAZARA_SHADER_API ConstantExpression : Expression struct NAZARA_SHADER_API ConstantValueExpression : Expression
{ {
NodeType GetType() const override; NodeType GetType() const override;
void Visit(AstExpressionVisitor& visitor) override; void Visit(AstExpressionVisitor& visitor) override;

View File

@ -54,7 +54,7 @@ namespace Nz::ShaderAst
ExpressionPtr Clone(CallFunctionExpression& node) override; ExpressionPtr Clone(CallFunctionExpression& node) override;
ExpressionPtr Clone(CastExpression& node) override; ExpressionPtr Clone(CastExpression& node) override;
ExpressionPtr Clone(ConditionalExpression& node) override; ExpressionPtr Clone(ConditionalExpression& node) override;
ExpressionPtr Clone(ConstantExpression& node) override; ExpressionPtr Clone(ConstantValueExpression& node) override;
ExpressionPtr Clone(ConstantIndexExpression& node) override; ExpressionPtr Clone(ConstantIndexExpression& node) override;
ExpressionPtr Clone(IdentifierExpression& node) override; ExpressionPtr Clone(IdentifierExpression& node) override;
ExpressionPtr Clone(IntrinsicExpression& node) override; ExpressionPtr Clone(IntrinsicExpression& node) override;

View File

@ -86,7 +86,7 @@ namespace Nz
void Visit(ShaderAst::BinaryExpression& node) override; void Visit(ShaderAst::BinaryExpression& node) override;
void Visit(ShaderAst::CallFunctionExpression& node) override; void Visit(ShaderAst::CallFunctionExpression& node) override;
void Visit(ShaderAst::CastExpression& node) override; void Visit(ShaderAst::CastExpression& node) override;
void Visit(ShaderAst::ConstantExpression& node) override; void Visit(ShaderAst::ConstantValueExpression& node) override;
void Visit(ShaderAst::IntrinsicExpression& node) override; void Visit(ShaderAst::IntrinsicExpression& node) override;
void Visit(ShaderAst::SwizzleExpression& node) override; void Visit(ShaderAst::SwizzleExpression& node) override;
void Visit(ShaderAst::VariableExpression& node) override; void Visit(ShaderAst::VariableExpression& node) override;

View File

@ -89,7 +89,7 @@ namespace Nz
void Visit(ShaderAst::BinaryExpression& node) override; void Visit(ShaderAst::BinaryExpression& node) override;
void Visit(ShaderAst::CastExpression& node) override; void Visit(ShaderAst::CastExpression& node) override;
void Visit(ShaderAst::ConditionalExpression& node) override; void Visit(ShaderAst::ConditionalExpression& node) override;
void Visit(ShaderAst::ConstantExpression& node) override; void Visit(ShaderAst::ConstantValueExpression& node) override;
void Visit(ShaderAst::ConstantIndexExpression& node) override; void Visit(ShaderAst::ConstantIndexExpression& node) override;
void Visit(ShaderAst::IntrinsicExpression& node) override; void Visit(ShaderAst::IntrinsicExpression& node) override;
void Visit(ShaderAst::SwizzleExpression& node) override; void Visit(ShaderAst::SwizzleExpression& node) override;

View File

@ -68,7 +68,7 @@ namespace Nz::ShaderBuilder
struct Constant struct Constant
{ {
inline std::unique_ptr<ShaderAst::ConstantExpression> operator()(ShaderAst::ConstantValue value) const; inline std::unique_ptr<ShaderAst::ConstantValueExpression> operator()(ShaderAst::ConstantValue value) const;
}; };
struct DeclareConst struct DeclareConst

View File

@ -132,9 +132,9 @@ namespace Nz::ShaderBuilder
return condStatementNode; return condStatementNode;
} }
inline std::unique_ptr<ShaderAst::ConstantExpression> Impl::Constant::operator()(ShaderAst::ConstantValue value) const inline std::unique_ptr<ShaderAst::ConstantValueExpression> Impl::Constant::operator()(ShaderAst::ConstantValue value) const
{ {
auto constantNode = std::make_unique<ShaderAst::ConstantExpression>(); auto constantNode = std::make_unique<ShaderAst::ConstantValueExpression>();
constantNode->value = std::move(value); constantNode->value = std::move(value);
return constantNode; return constantNode;

View File

@ -47,7 +47,7 @@ namespace Nz
void Visit(ShaderAst::BranchStatement& node) override; void Visit(ShaderAst::BranchStatement& node) override;
void Visit(ShaderAst::CallFunctionExpression& node) override; void Visit(ShaderAst::CallFunctionExpression& node) override;
void Visit(ShaderAst::CastExpression& node) override; void Visit(ShaderAst::CastExpression& node) override;
void Visit(ShaderAst::ConstantExpression& node) override; void Visit(ShaderAst::ConstantValueExpression& node) override;
void Visit(ShaderAst::DeclareConstStatement& node) override; void Visit(ShaderAst::DeclareConstStatement& node) override;
void Visit(ShaderAst::DeclareExternalStatement& node) override; void Visit(ShaderAst::DeclareExternalStatement& node) override;
void Visit(ShaderAst::DeclareFunctionStatement& node) override; void Visit(ShaderAst::DeclareFunctionStatement& node) override;

View File

@ -313,9 +313,9 @@ namespace Nz::ShaderAst
return clone; return clone;
} }
ExpressionPtr AstCloner::Clone(ConstantExpression& node) ExpressionPtr AstCloner::Clone(ConstantValueExpression& node)
{ {
auto clone = std::make_unique<ConstantExpression>(); auto clone = std::make_unique<ConstantValueExpression>();
clone->value = node.value; clone->value = node.value;
clone->cachedExpressionType = node.cachedExpressionType; clone->cachedExpressionType = node.cachedExpressionType;

View File

@ -42,7 +42,7 @@ namespace Nz::ShaderAst
template<typename T1, typename T2> template<typename T1, typename T2>
struct BinaryCompEqBase struct BinaryCompEqBase
{ {
std::unique_ptr<ConstantExpression> operator()(const T1& lhs, const T2& rhs) std::unique_ptr<ConstantValueExpression> operator()(const T1& lhs, const T2& rhs)
{ {
return ShaderBuilder::Constant(lhs == rhs); return ShaderBuilder::Constant(lhs == rhs);
} }
@ -61,7 +61,7 @@ namespace Nz::ShaderAst
template<typename T1, typename T2> template<typename T1, typename T2>
struct BinaryCompGeBase struct BinaryCompGeBase
{ {
std::unique_ptr<ConstantExpression> operator()(const T1& lhs, const T2& rhs) std::unique_ptr<ConstantValueExpression> operator()(const T1& lhs, const T2& rhs)
{ {
return ShaderBuilder::Constant(lhs >= rhs); return ShaderBuilder::Constant(lhs >= rhs);
} }
@ -80,7 +80,7 @@ namespace Nz::ShaderAst
template<typename T1, typename T2> template<typename T1, typename T2>
struct BinaryCompGtBase struct BinaryCompGtBase
{ {
std::unique_ptr<ConstantExpression> operator()(const T1& lhs, const T2& rhs) std::unique_ptr<ConstantValueExpression> operator()(const T1& lhs, const T2& rhs)
{ {
return ShaderBuilder::Constant(lhs > rhs); return ShaderBuilder::Constant(lhs > rhs);
} }
@ -99,7 +99,7 @@ namespace Nz::ShaderAst
template<typename T1, typename T2> template<typename T1, typename T2>
struct BinaryCompLeBase struct BinaryCompLeBase
{ {
std::unique_ptr<ConstantExpression> operator()(const T1& lhs, const T2& rhs) std::unique_ptr<ConstantValueExpression> operator()(const T1& lhs, const T2& rhs)
{ {
return ShaderBuilder::Constant(lhs <= rhs); return ShaderBuilder::Constant(lhs <= rhs);
} }
@ -118,7 +118,7 @@ namespace Nz::ShaderAst
template<typename T1, typename T2> template<typename T1, typename T2>
struct BinaryCompLtBase struct BinaryCompLtBase
{ {
std::unique_ptr<ConstantExpression> operator()(const T1& lhs, const T2& rhs) std::unique_ptr<ConstantValueExpression> operator()(const T1& lhs, const T2& rhs)
{ {
return ShaderBuilder::Constant(lhs < rhs); return ShaderBuilder::Constant(lhs < rhs);
} }
@ -137,7 +137,7 @@ namespace Nz::ShaderAst
template<typename T1, typename T2> template<typename T1, typename T2>
struct BinaryCompNeBase struct BinaryCompNeBase
{ {
std::unique_ptr<ConstantExpression> operator()(const T1& lhs, const T2& rhs) std::unique_ptr<ConstantValueExpression> operator()(const T1& lhs, const T2& rhs)
{ {
return ShaderBuilder::Constant(lhs != rhs); return ShaderBuilder::Constant(lhs != rhs);
} }
@ -156,7 +156,7 @@ namespace Nz::ShaderAst
template<typename T1, typename T2> template<typename T1, typename T2>
struct BinaryLogicalAndBase struct BinaryLogicalAndBase
{ {
std::unique_ptr<ConstantExpression> operator()(const T1& lhs, const T2& rhs) std::unique_ptr<ConstantValueExpression> operator()(const T1& lhs, const T2& rhs)
{ {
return ShaderBuilder::Constant(lhs && rhs); return ShaderBuilder::Constant(lhs && rhs);
} }
@ -175,7 +175,7 @@ namespace Nz::ShaderAst
template<typename T1, typename T2> template<typename T1, typename T2>
struct BinaryLogicalOrBase struct BinaryLogicalOrBase
{ {
std::unique_ptr<ConstantExpression> operator()(const T1& lhs, const T2& rhs) std::unique_ptr<ConstantValueExpression> operator()(const T1& lhs, const T2& rhs)
{ {
return ShaderBuilder::Constant(lhs || rhs); return ShaderBuilder::Constant(lhs || rhs);
} }
@ -194,7 +194,7 @@ namespace Nz::ShaderAst
template<typename T1, typename T2> template<typename T1, typename T2>
struct BinaryAdditionBase struct BinaryAdditionBase
{ {
std::unique_ptr<ConstantExpression> operator()(const T1& lhs, const T2& rhs) std::unique_ptr<ConstantValueExpression> operator()(const T1& lhs, const T2& rhs)
{ {
return ShaderBuilder::Constant(lhs + rhs); return ShaderBuilder::Constant(lhs + rhs);
} }
@ -213,7 +213,7 @@ namespace Nz::ShaderAst
template<typename T1, typename T2> template<typename T1, typename T2>
struct BinaryDivisionBase struct BinaryDivisionBase
{ {
std::unique_ptr<ConstantExpression> operator()(const T1& lhs, const T2& rhs) std::unique_ptr<ConstantValueExpression> operator()(const T1& lhs, const T2& rhs)
{ {
return ShaderBuilder::Constant(lhs / rhs); return ShaderBuilder::Constant(lhs / rhs);
} }
@ -232,7 +232,7 @@ namespace Nz::ShaderAst
template<typename T1, typename T2> template<typename T1, typename T2>
struct BinaryMultiplicationBase struct BinaryMultiplicationBase
{ {
std::unique_ptr<ConstantExpression> operator()(const T1& lhs, const T2& rhs) std::unique_ptr<ConstantValueExpression> operator()(const T1& lhs, const T2& rhs)
{ {
return ShaderBuilder::Constant(lhs * rhs); return ShaderBuilder::Constant(lhs * rhs);
} }
@ -251,7 +251,7 @@ namespace Nz::ShaderAst
template<typename T1, typename T2> template<typename T1, typename T2>
struct BinarySubtractionBase struct BinarySubtractionBase
{ {
std::unique_ptr<ConstantExpression> operator()(const T1& lhs, const T2& rhs) std::unique_ptr<ConstantValueExpression> operator()(const T1& lhs, const T2& rhs)
{ {
return ShaderBuilder::Constant(lhs - rhs); return ShaderBuilder::Constant(lhs - rhs);
} }
@ -271,7 +271,7 @@ namespace Nz::ShaderAst
template<typename T, typename... Args> template<typename T, typename... Args>
struct CastConstantBase struct CastConstantBase
{ {
std::unique_ptr<ConstantExpression> operator()(const Args&... args) std::unique_ptr<ConstantValueExpression> operator()(const Args&... args)
{ {
return ShaderBuilder::Constant(T(args...)); return ShaderBuilder::Constant(T(args...));
} }
@ -295,7 +295,7 @@ namespace Nz::ShaderAst
template<typename T> template<typename T>
struct UnaryLogicalNotBase struct UnaryLogicalNotBase
{ {
std::unique_ptr<ConstantExpression> operator()(const T& arg) std::unique_ptr<ConstantValueExpression> operator()(const T& arg)
{ {
return ShaderBuilder::Constant(!arg); return ShaderBuilder::Constant(!arg);
} }
@ -314,7 +314,7 @@ namespace Nz::ShaderAst
template<typename T> template<typename T>
struct UnaryMinusBase struct UnaryMinusBase
{ {
std::unique_ptr<ConstantExpression> operator()(const T& arg) std::unique_ptr<ConstantValueExpression> operator()(const T& arg)
{ {
return ShaderBuilder::Constant(-arg); return ShaderBuilder::Constant(-arg);
} }
@ -333,7 +333,7 @@ namespace Nz::ShaderAst
template<typename T> template<typename T>
struct UnaryPlusBase struct UnaryPlusBase
{ {
std::unique_ptr<ConstantExpression> operator()(const T& arg) std::unique_ptr<ConstantValueExpression> operator()(const T& arg)
{ {
return ShaderBuilder::Constant(arg); return ShaderBuilder::Constant(arg);
} }
@ -573,10 +573,10 @@ namespace Nz::ShaderAst
auto lhs = CloneExpression(node.left); auto lhs = CloneExpression(node.left);
auto rhs = CloneExpression(node.right); auto rhs = CloneExpression(node.right);
if (lhs->GetType() == NodeType::ConstantExpression && rhs->GetType() == NodeType::ConstantExpression) if (lhs->GetType() == NodeType::ConstantValueExpression && rhs->GetType() == NodeType::ConstantValueExpression)
{ {
auto lhsConstant = static_unique_pointer_cast<ConstantExpression>(std::move(lhs)); auto lhsConstant = static_unique_pointer_cast<ConstantValueExpression>(std::move(lhs));
auto rhsConstant = static_unique_pointer_cast<ConstantExpression>(std::move(rhs)); auto rhsConstant = static_unique_pointer_cast<ConstantValueExpression>(std::move(rhs));
ExpressionPtr optimized; ExpressionPtr optimized;
switch (node.op) switch (node.op)
@ -657,9 +657,9 @@ namespace Nz::ShaderAst
ExpressionPtr optimized; ExpressionPtr optimized;
if (IsPrimitiveType(node.targetType)) if (IsPrimitiveType(node.targetType))
{ {
if (expressionCount == 1 && expressions.front()->GetType() == NodeType::ConstantExpression) if (expressionCount == 1 && expressions.front()->GetType() == NodeType::ConstantValueExpression)
{ {
auto constantExpr = static_unique_pointer_cast<ConstantExpression>(std::move(expressions.front())); auto constantExpr = static_unique_pointer_cast<ConstantValueExpression>(std::move(expressions.front()));
switch (std::get<PrimitiveType>(node.targetType)) switch (std::get<PrimitiveType>(node.targetType))
{ {
@ -678,13 +678,13 @@ namespace Nz::ShaderAst
std::vector<ConstantValue> constantValues; std::vector<ConstantValue> constantValues;
for (std::size_t i = 0; i < expressionCount; ++i) for (std::size_t i = 0; i < expressionCount; ++i)
{ {
if (expressions[i]->GetType() != NodeType::ConstantExpression) if (expressions[i]->GetType() != NodeType::ConstantValueExpression)
{ {
constantValues.clear(); constantValues.clear();
break; break;
} }
const auto& constantExpr = static_cast<ConstantExpression&>(*expressions[i]); const auto& constantExpr = static_cast<ConstantValueExpression&>(*expressions[i]);
if (!constantValues.empty() && GetExpressionType(constantValues.front()) != GetExpressionType(constantExpr.value)) if (!constantValues.empty() && GetExpressionType(constantValues.front()) != GetExpressionType(constantExpr.value))
{ {
@ -766,9 +766,9 @@ namespace Nz::ShaderAst
{ {
auto cond = CloneExpression(condStatement.condition); auto cond = CloneExpression(condStatement.condition);
if (cond->GetType() == NodeType::ConstantExpression) if (cond->GetType() == NodeType::ConstantValueExpression)
{ {
auto& constant = static_cast<ConstantExpression&>(*cond); auto& constant = static_cast<ConstantValueExpression&>(*cond);
assert(constant.cachedExpressionType); assert(constant.cachedExpressionType);
const ExpressionType& constantType = constant.cachedExpressionType.value(); const ExpressionType& constantType = constant.cachedExpressionType.value();
@ -821,10 +821,10 @@ namespace Nz::ShaderAst
return AstCloner::Clone(node); return AstCloner::Clone(node);
auto cond = CloneExpression(node.condition); auto cond = CloneExpression(node.condition);
if (cond->GetType() != NodeType::ConstantExpression) if (cond->GetType() != NodeType::ConstantValueExpression)
throw std::runtime_error("conditional expression condition must be a constant expression"); throw std::runtime_error("conditional expression condition must be a constant expression");
auto& constant = static_cast<ConstantExpression&>(*cond); auto& constant = static_cast<ConstantValueExpression&>(*cond);
assert(constant.cachedExpressionType); assert(constant.cachedExpressionType);
const ExpressionType& constantType = constant.cachedExpressionType.value(); const ExpressionType& constantType = constant.cachedExpressionType.value();
@ -854,9 +854,9 @@ namespace Nz::ShaderAst
{ {
auto expr = CloneExpression(node.expression); auto expr = CloneExpression(node.expression);
if (expr->GetType() == NodeType::ConstantExpression) if (expr->GetType() == NodeType::ConstantValueExpression)
{ {
auto constantExpr = static_unique_pointer_cast<ConstantExpression>(std::move(expr)); auto constantExpr = static_unique_pointer_cast<ConstantValueExpression>(std::move(expr));
ExpressionPtr optimized; ExpressionPtr optimized;
switch (node.op) switch (node.op)
@ -890,10 +890,10 @@ namespace Nz::ShaderAst
return AstCloner::Clone(node); return AstCloner::Clone(node);
auto cond = CloneExpression(node.condition); auto cond = CloneExpression(node.condition);
if (cond->GetType() != NodeType::ConstantExpression) if (cond->GetType() != NodeType::ConstantValueExpression)
throw std::runtime_error("conditional expression condition must be a constant expression"); throw std::runtime_error("conditional expression condition must be a constant expression");
auto& constant = static_cast<ConstantExpression&>(*cond); auto& constant = static_cast<ConstantValueExpression&>(*cond);
assert(constant.cachedExpressionType); assert(constant.cachedExpressionType);
const ExpressionType& constantType = constant.cachedExpressionType.value(); const ExpressionType& constantType = constant.cachedExpressionType.value();
@ -909,9 +909,9 @@ namespace Nz::ShaderAst
} }
template<BinaryType Type> template<BinaryType Type>
ExpressionPtr AstOptimizer::PropagateBinaryConstant(std::unique_ptr<ConstantExpression>&& lhs, std::unique_ptr<ConstantExpression>&& rhs) ExpressionPtr AstOptimizer::PropagateBinaryConstant(std::unique_ptr<ConstantValueExpression>&& lhs, std::unique_ptr<ConstantValueExpression>&& rhs)
{ {
std::unique_ptr<ConstantExpression> optimized; std::unique_ptr<ConstantValueExpression> optimized;
std::visit([&](auto&& arg1) std::visit([&](auto&& arg1)
{ {
using T1 = std::decay_t<decltype(arg1)>; using T1 = std::decay_t<decltype(arg1)>;
@ -938,9 +938,9 @@ namespace Nz::ShaderAst
} }
template<typename TargetType> template<typename TargetType>
ExpressionPtr AstOptimizer::PropagateSingleValueCast(std::unique_ptr<ConstantExpression>&& operand) ExpressionPtr AstOptimizer::PropagateSingleValueCast(std::unique_ptr<ConstantValueExpression>&& operand)
{ {
std::unique_ptr<ConstantExpression> optimized; std::unique_ptr<ConstantValueExpression> optimized;
std::visit([&](auto&& arg) std::visit([&](auto&& arg)
{ {
@ -959,9 +959,9 @@ namespace Nz::ShaderAst
} }
template<UnaryType Type> template<UnaryType Type>
ExpressionPtr AstOptimizer::PropagateUnaryConstant(std::unique_ptr<ConstantExpression>&& operand) ExpressionPtr AstOptimizer::PropagateUnaryConstant(std::unique_ptr<ConstantValueExpression>&& operand)
{ {
std::unique_ptr<ConstantExpression> optimized; std::unique_ptr<ConstantValueExpression> optimized;
std::visit([&](auto&& arg) std::visit([&](auto&& arg)
{ {
using T = std::decay_t<decltype(arg)>; using T = std::decay_t<decltype(arg)>;
@ -984,7 +984,7 @@ namespace Nz::ShaderAst
template<typename TargetType> template<typename TargetType>
ExpressionPtr AstOptimizer::PropagateVec2Cast(TargetType v1, TargetType v2) ExpressionPtr AstOptimizer::PropagateVec2Cast(TargetType v1, TargetType v2)
{ {
std::unique_ptr<ConstantExpression> optimized; std::unique_ptr<ConstantValueExpression> optimized;
using CCType = CastConstantPropagation<Vector2<TargetType>, TargetType, TargetType>; using CCType = CastConstantPropagation<Vector2<TargetType>, TargetType, TargetType>;
@ -1001,7 +1001,7 @@ namespace Nz::ShaderAst
template<typename TargetType> template<typename TargetType>
ExpressionPtr AstOptimizer::PropagateVec3Cast(TargetType v1, TargetType v2, TargetType v3) ExpressionPtr AstOptimizer::PropagateVec3Cast(TargetType v1, TargetType v2, TargetType v3)
{ {
std::unique_ptr<ConstantExpression> optimized; std::unique_ptr<ConstantValueExpression> optimized;
using CCType = CastConstantPropagation<Vector3<TargetType>, TargetType, TargetType, TargetType>; using CCType = CastConstantPropagation<Vector3<TargetType>, TargetType, TargetType, TargetType>;
@ -1018,7 +1018,7 @@ namespace Nz::ShaderAst
template<typename TargetType> template<typename TargetType>
ExpressionPtr AstOptimizer::PropagateVec4Cast(TargetType v1, TargetType v2, TargetType v3, TargetType v4) ExpressionPtr AstOptimizer::PropagateVec4Cast(TargetType v1, TargetType v2, TargetType v3, TargetType v4)
{ {
std::unique_ptr<ConstantExpression> optimized; std::unique_ptr<ConstantValueExpression> optimized;
using CCType = CastConstantPropagation<Vector3<TargetType>, TargetType, TargetType, TargetType, TargetType>; using CCType = CastConstantPropagation<Vector3<TargetType>, TargetType, TargetType, TargetType, TargetType>;

View File

@ -62,7 +62,7 @@ namespace Nz::ShaderAst
node.falsePath->Visit(*this); node.falsePath->Visit(*this);
} }
void AstRecursiveVisitor::Visit(ConstantExpression& /*node*/) void AstRecursiveVisitor::Visit(ConstantValueExpression& /*node*/)
{ {
/* Nothing to do */ /* Nothing to do */
} }

View File

@ -123,7 +123,7 @@ namespace Nz::ShaderAst
Node(node.falsePath); Node(node.falsePath);
} }
void AstSerializerBase::Serialize(ConstantExpression& node) void AstSerializerBase::Serialize(ConstantValueExpression& node)
{ {
UInt32 typeIndex; UInt32 typeIndex;
if (IsWriting()) if (IsWriting())

View File

@ -62,7 +62,7 @@ namespace Nz::ShaderAst
m_expressionCategory = ExpressionCategory::LValue; m_expressionCategory = ExpressionCategory::LValue;
} }
void ShaderAstValueCategory::Visit(ConstantExpression& /*node*/) void ShaderAstValueCategory::Visit(ConstantValueExpression& /*node*/)
{ {
m_expressionCategory = ExpressionCategory::RValue; m_expressionCategory = ExpressionCategory::RValue;
} }

View File

@ -569,9 +569,9 @@ namespace Nz::ShaderAst
return AstCloner::Clone(*node.falsePath); return AstCloner::Clone(*node.falsePath);
} }
ExpressionPtr SanitizeVisitor::Clone(ConstantExpression& node) ExpressionPtr SanitizeVisitor::Clone(ConstantValueExpression& node)
{ {
auto clone = static_unique_pointer_cast<ConstantExpression>(AstCloner::Clone(node)); auto clone = static_unique_pointer_cast<ConstantValueExpression>(AstCloner::Clone(node));
clone->cachedExpressionType = GetExpressionType(clone->value); clone->cachedExpressionType = GetExpressionType(clone->value);
return clone; return clone;
@ -792,10 +792,10 @@ namespace Nz::ShaderAst
throw AstError{ "const variables must have an expression" }; throw AstError{ "const variables must have an expression" };
clone->expression = Optimize(*clone->expression); clone->expression = Optimize(*clone->expression);
if (clone->expression->GetType() != NodeType::ConstantExpression) if (clone->expression->GetType() != NodeType::ConstantValueExpression)
throw AstError{ "const variable must have constant expressions " }; throw AstError{ "const variable must have constant expressions " };
const ConstantValue& value = static_cast<ConstantExpression&>(*clone->expression).value; const ConstantValue& value = static_cast<ConstantValueExpression&>(*clone->expression).value;
ExpressionType expressionType = ResolveType(GetExpressionType(value)); ExpressionType expressionType = ResolveType(GetExpressionType(value));
@ -1158,10 +1158,10 @@ namespace Nz::ShaderAst
{ {
// Run optimizer on constant value to hopefully retrieve a single constant value // Run optimizer on constant value to hopefully retrieve a single constant value
ExpressionPtr optimizedExpr = Optimize(expr); ExpressionPtr optimizedExpr = Optimize(expr);
if (optimizedExpr->GetType() != NodeType::ConstantExpression) if (optimizedExpr->GetType() != NodeType::ConstantValueExpression)
throw AstError{"expected a constant expression"}; throw AstError{"expected a constant expression"};
return static_cast<ConstantExpression&>(*optimizedExpr).value; return static_cast<ConstantValueExpression&>(*optimizedExpr).value;
} }
template<typename T> template<typename T>
@ -1447,10 +1447,10 @@ namespace Nz::ShaderAst
auto& indexExpr = node.indices[i]; auto& indexExpr = node.indices[i];
const ShaderAst::ExpressionType& indexType = GetExpressionType(*indexExpr); const ShaderAst::ExpressionType& indexType = GetExpressionType(*indexExpr);
if (indexExpr->GetType() != NodeType::ConstantExpression || indexType != ExpressionType{ PrimitiveType::Int32 }) if (indexExpr->GetType() != NodeType::ConstantValueExpression || indexType != ExpressionType{ PrimitiveType::Int32 })
throw AstError{ "struct can only be accessed with constant i32 indices" }; throw AstError{ "struct can only be accessed with constant i32 indices" };
ConstantExpression& constantExpr = static_cast<ConstantExpression&>(*indexExpr); ConstantValueExpression& constantExpr = static_cast<ConstantValueExpression&>(*indexExpr);
Int32 index = std::get<Int32>(constantExpr.value); Int32 index = std::get<Int32>(constantExpr.value);

View File

@ -387,8 +387,8 @@ namespace Nz
{ {
ShaderAst::StructDescription* structDesc = Retrieve(m_currentState->structs, structIndex); ShaderAst::StructDescription* structDesc = Retrieve(m_currentState->structs, structIndex);
assert((*memberIndices)->GetType() == ShaderAst::NodeType::ConstantExpression); assert((*memberIndices)->GetType() == ShaderAst::NodeType::ConstantValueExpression);
auto& constantValue = static_cast<ShaderAst::ConstantExpression&>(**memberIndices); auto& constantValue = static_cast<ShaderAst::ConstantValueExpression&>(**memberIndices);
Int32 index = std::get<Int32>(constantValue.value); Int32 index = std::get<Int32>(constantValue.value);
assert(index >= 0); assert(index >= 0);
@ -828,7 +828,7 @@ namespace Nz
Append(")"); Append(")");
} }
void GlslWriter::Visit(ShaderAst::ConstantExpression& node) void GlslWriter::Visit(ShaderAst::ConstantValueExpression& node)
{ {
std::visit([&](auto&& arg) std::visit([&](auto&& arg)
{ {

View File

@ -418,8 +418,8 @@ namespace Nz
{ {
ShaderAst::StructDescription* structDesc = Retrieve(m_currentState->structs, structIndex); ShaderAst::StructDescription* structDesc = Retrieve(m_currentState->structs, structIndex);
assert((*memberIndices)->GetType() == ShaderAst::NodeType::ConstantExpression); assert((*memberIndices)->GetType() == ShaderAst::NodeType::ConstantValueExpression);
auto& constantValue = static_cast<ShaderAst::ConstantExpression&>(**memberIndices); auto& constantValue = static_cast<ShaderAst::ConstantValueExpression&>(**memberIndices);
Int32 index = std::get<Int32>(constantValue.value); Int32 index = std::get<Int32>(constantValue.value);
const auto& member = structDesc->members[index]; const auto& member = structDesc->members[index];
@ -637,7 +637,7 @@ namespace Nz
node.statement->Visit(*this); node.statement->Visit(*this);
} }
void LangWriter::Visit(ShaderAst::ConstantExpression& node) void LangWriter::Visit(ShaderAst::ConstantValueExpression& node)
{ {
std::visit([&](auto&& arg) std::visit([&](auto&& arg)
{ {

View File

@ -576,7 +576,7 @@ namespace Nz
} }
} }
void SpirvAstVisitor::Visit(ShaderAst::ConstantExpression& node) void SpirvAstVisitor::Visit(ShaderAst::ConstantValueExpression& node)
{ {
std::visit([&] (const auto& value) std::visit([&] (const auto& value)
{ {

View File

@ -113,7 +113,7 @@ namespace Nz
throw std::runtime_error("unexpected conditional expression, did you forget to sanitize the shader?"); throw std::runtime_error("unexpected conditional expression, did you forget to sanitize the shader?");
} }
void Visit(ShaderAst::ConstantExpression& node) override void Visit(ShaderAst::ConstantValueExpression& node) override
{ {
std::visit([&](auto&& arg) std::visit([&](auto&& arg)
{ {