Renderer/ShaderAst: Add support for expression type

This commit is contained in:
Lynix
2017-01-05 16:41:48 +01:00
parent 12321bc59a
commit a84391cf08
3 changed files with 55 additions and 6 deletions

View File

@@ -31,6 +31,11 @@ namespace Nz { namespace ShaderAst
}
ExpressionType Variable::GetExpressionType() const
{
return type;
}
void NamedVariable::Register(ShaderWriter& visitor)
{
visitor.RegisterVariable(kind, name, type);
@@ -52,6 +57,11 @@ namespace Nz { namespace ShaderAst
}
ExpressionType AssignOp::GetExpressionType() const
{
return variable->GetExpressionType();
}
void AssignOp::Register(ShaderWriter& visitor)
{
variable->Register(visitor);
@@ -64,6 +74,28 @@ namespace Nz { namespace ShaderAst
}
ExpressionType BinaryOp::GetExpressionType() const
{
ShaderAst::ExpressionType exprType = ShaderAst::ExpressionType::None;
switch (op)
{
case ShaderAst::BinaryType::Add:
case ShaderAst::BinaryType::Divide:
case ShaderAst::BinaryType::Multiply:
case ShaderAst::BinaryType::Substract:
exprType = left->GetExpressionType();
break;
case ShaderAst::BinaryType::Equality:
exprType = ExpressionType::Boolean;
}
NazaraAssert(exprType != ShaderAst::ExpressionType::None, "Unhandled builtin");
return exprType;
}
void BinaryOp::Register(ShaderWriter& visitor)
{
left->Register(visitor);
@@ -94,6 +126,11 @@ namespace Nz { namespace ShaderAst
}
ExpressionType Constant::GetExpressionType() const
{
return exprType;
}
void Constant::Register(ShaderWriter&)
{
}