Shader: Serialize cached expression type
This commit is contained in:
parent
d45ba6696f
commit
ce93b61c91
|
|
@ -41,6 +41,7 @@ namespace Nz::ShaderAst
|
|||
void Serialize(SwizzleExpression& node);
|
||||
void Serialize(VariableValueExpression& node);
|
||||
void Serialize(UnaryExpression& node);
|
||||
void SerializeExpressionCommon(Expression& expr);
|
||||
|
||||
void Serialize(BranchStatement& node);
|
||||
void Serialize(ConditionalStatement& node);
|
||||
|
|
@ -67,6 +68,7 @@ namespace Nz::ShaderAst
|
|||
template<typename T> void Enum(T& enumVal);
|
||||
template<typename T> void ExprValue(ExpressionValue<T>& attribute);
|
||||
template<typename T> void OptEnum(std::optional<T>& optVal);
|
||||
inline void OptType(std::optional<ExpressionType>& optType);
|
||||
template<typename T> void OptVal(std::optional<T>& optVal);
|
||||
|
||||
virtual bool IsWriting() const = 0;
|
||||
|
|
|
|||
|
|
@ -126,6 +126,23 @@ namespace Nz::ShaderAst
|
|||
Enum(optVal.value());
|
||||
}
|
||||
|
||||
inline void AstSerializerBase::OptType(std::optional<ExpressionType>& optType)
|
||||
{
|
||||
bool isWriting = IsWriting();
|
||||
|
||||
bool hasValue;
|
||||
if (isWriting)
|
||||
hasValue = optType.has_value();
|
||||
|
||||
Value(hasValue);
|
||||
|
||||
if (!isWriting && hasValue)
|
||||
optType.emplace();
|
||||
|
||||
if (optType.has_value())
|
||||
Type(optType.value());
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void AstSerializerBase::OptVal(std::optional<T>& optVal)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -23,7 +23,13 @@ namespace Nz::ShaderAst
|
|||
{
|
||||
}
|
||||
|
||||
#define NAZARA_SHADERAST_NODE(Node) void Visit(Node& node) override \
|
||||
#define NAZARA_SHADERAST_EXPRESSION(Node) void Visit(Node& node) override \
|
||||
{ \
|
||||
m_serializer.Serialize(node); \
|
||||
m_serializer.SerializeExpressionCommon(node); \
|
||||
}
|
||||
|
||||
#define NAZARA_SHADERAST_STATEMENT(Node) void Visit(Node& node) override \
|
||||
{ \
|
||||
m_serializer.Serialize(node); \
|
||||
}
|
||||
|
|
@ -188,6 +194,10 @@ namespace Nz::ShaderAst
|
|||
Node(node.expression);
|
||||
}
|
||||
|
||||
void AstSerializerBase::SerializeExpressionCommon(Expression& expr)
|
||||
{
|
||||
OptType(expr.cachedExpressionType);
|
||||
}
|
||||
|
||||
void AstSerializerBase::Serialize(BranchStatement& node)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue