Replace const ShaderAst::StatementPtr& by ShaderAst::Statement& in input

This commit is contained in:
Jérôme Leclercq
2021-06-14 22:31:12 +02:00
parent 54d56abc56
commit 815a7b0c62
27 changed files with 101 additions and 94 deletions

View File

@@ -8,17 +8,17 @@
namespace Nz::ShaderAst
{
ExpressionPtr AstCloner::Clone(const ExpressionPtr& expr)
ExpressionPtr AstCloner::Clone(Expression& expr)
{
expr->Visit(*this);
expr.Visit(*this);
assert(m_statementStack.empty() && m_expressionStack.size() == 1);
return PopExpression();
}
StatementPtr AstCloner::Clone(const StatementPtr& statement)
StatementPtr AstCloner::Clone(Statement& statement)
{
statement->Visit(*this);
statement.Visit(*this);
assert(m_expressionStack.empty() && m_statementStack.size() == 1);
return PopStatement();

View File

@@ -531,13 +531,13 @@ namespace Nz::ShaderAst
#undef EnableOptimisation
}
StatementPtr AstOptimizer::Optimise(const StatementPtr& statement)
StatementPtr AstOptimizer::Optimise(Statement& statement)
{
m_enabledOptions.reset();
return CloneStatement(statement);
}
StatementPtr AstOptimizer::Optimise(const StatementPtr& statement, UInt64 enabledConditions)
StatementPtr AstOptimizer::Optimise(Statement& statement, UInt64 enabledConditions)
{
m_enabledOptions = enabledConditions;
@@ -751,7 +751,7 @@ namespace Nz::ShaderAst
if (statements.empty())
{
// First condition is true, dismiss the branch
return AstCloner::Clone(condStatement.statement);
return AstCloner::Clone(*condStatement.statement);
}
else
{
@@ -772,7 +772,7 @@ namespace Nz::ShaderAst
{
// All conditions have been removed, replace by else statement or no-op
if (node.elseStatement)
return AstCloner::Clone(node.elseStatement);
return AstCloner::Clone(*node.elseStatement);
else
return ShaderBuilder::NoOp();
}
@@ -789,9 +789,9 @@ namespace Nz::ShaderAst
return AstCloner::Clone(node);
if (TestBit<UInt64>(*m_enabledOptions, node.optionIndex))
return AstCloner::Clone(node.truePath);
return AstCloner::Clone(*node.truePath);
else
return AstCloner::Clone(node.falsePath);
return AstCloner::Clone(*node.falsePath);
}
ExpressionPtr AstOptimizer::Clone(UnaryExpression& node)

View File

@@ -8,12 +8,10 @@
namespace Nz::ShaderAst
{
void AstReflect::Reflect(const StatementPtr& statement, const Callbacks& callbacks)
void AstReflect::Reflect(Statement& statement, const Callbacks& callbacks)
{
assert(statement);
m_callbacks = &callbacks;
statement->Visit(*this);
statement.Visit(*this);
}
void AstReflect::Visit(DeclareOptionStatement& node)

View File

@@ -45,7 +45,7 @@ namespace Nz::ShaderAst
FunctionData* currentFunction = nullptr;
};
StatementPtr SanitizeVisitor::Sanitize(const StatementPtr& nodePtr, const Options& options, std::string* error)
StatementPtr SanitizeVisitor::Sanitize(Statement& statement, const Options& options, std::string* error)
{
StatementPtr clone;
@@ -65,21 +65,21 @@ namespace Nz::ShaderAst
RegisterIntrinsic("pow", IntrinsicType::Pow);
// Collect function name and their types
if (nodePtr->GetType() == NodeType::MultiStatement)
if (statement.GetType() == NodeType::MultiStatement)
{
const MultiStatement& multiStatement = static_cast<const MultiStatement&>(*nodePtr);
const MultiStatement& multiStatement = static_cast<const MultiStatement&>(statement);
for (auto& statementPtr : multiStatement.statements)
{
if (statementPtr->GetType() == NodeType::DeclareFunctionStatement)
DeclareFunction(static_cast<DeclareFunctionStatement*>(statementPtr.get()));
DeclareFunction(static_cast<DeclareFunctionStatement&>(*statementPtr));
}
}
else if (nodePtr->GetType() == NodeType::DeclareFunctionStatement)
DeclareFunction(static_cast<DeclareFunctionStatement*>(nodePtr.get()));
else if (statement.GetType() == NodeType::DeclareFunctionStatement)
DeclareFunction(static_cast<DeclareFunctionStatement&>(statement));
try
{
clone = AstCloner::Clone(nodePtr);
clone = AstCloner::Clone(statement);
}
catch (const AstError& err)
{
@@ -962,11 +962,11 @@ namespace Nz::ShaderAst
m_scopeSizes.pop_back();
}
std::size_t SanitizeVisitor::DeclareFunction(DeclareFunctionStatement* funcDecl)
std::size_t SanitizeVisitor::DeclareFunction(DeclareFunctionStatement& funcDecl)
{
std::size_t functionIndex = m_functions.size();
auto& funcData = m_functions.emplace_back();
funcData.node = funcDecl;
funcData.node = &funcDecl;
return functionIndex;
}
@@ -1027,7 +1027,7 @@ namespace Nz::ShaderAst
std::move(name),
intrinsicIndex,
Identifier::Type::Intrinsic
});
});
return intrinsicIndex;
}
@@ -1044,7 +1044,7 @@ namespace Nz::ShaderAst
std::move(name),
optionIndex,
Identifier::Type::Option
});
});
return optionIndex;
}
@@ -1079,7 +1079,7 @@ namespace Nz::ShaderAst
std::move(name),
varIndex,
Identifier::Type::Variable
});
});
return varIndex;
}