Use explicit visit function for the walker.

This commit is contained in:
chriseth 2017-12-20 14:12:52 +01:00
parent 0c20b6da6b
commit 937b95cbe5
2 changed files with 25 additions and 15 deletions

View File

@ -44,31 +44,31 @@ void ASTWalker::operator()(FunctionCall const& _funCall)
void ASTWalker::operator()(ExpressionStatement const& _statement)
{
boost::apply_visitor(*this, _statement.expression);
visit(_statement.expression);
}
void ASTWalker::operator()(Assignment const& _assignment)
{
for (auto const& name: _assignment.variableNames)
(*this)(name);
boost::apply_visitor(*this, *_assignment.value);
visit(*_assignment.value);
}
void ASTWalker::operator()(VariableDeclaration const& _varDecl)
{
if (_varDecl.value)
boost::apply_visitor(*this, *_varDecl.value);
visit(*_varDecl.value);
}
void ASTWalker::operator()(If const& _if)
{
boost::apply_visitor(*this, *_if.condition);
visit(*_if.condition);
(*this)(_if.body);
}
void ASTWalker::operator()(Switch const& _switch)
{
boost::apply_visitor(*this, *_switch.expression);
visit(*_switch.expression);
for (auto const& _case: _switch.cases)
{
if (_case.value)
@ -85,7 +85,7 @@ void ASTWalker::operator()(FunctionDefinition const& _fun)
void ASTWalker::operator()(ForLoop const& _for)
{
(*this)(_for.pre);
boost::apply_visitor(*this, *_for.condition);
visit(*_for.condition);
(*this)(_for.post);
(*this)(_for.body);
}
@ -107,7 +107,7 @@ void ASTModifier::operator()(FunctionCall& _funCall)
void ASTModifier::operator()(ExpressionStatement& _statement)
{
boost::apply_visitor(*this, _statement.expression);
visit(_statement.expression);
}
void ASTModifier::operator()(Assignment& _assignment)

View File

@ -58,12 +58,21 @@ public:
virtual void operator()(ForLoop const&);
virtual void operator()(Block const& _block);
virtual void visit(Statement const& _st)
{
boost::apply_visitor(*this, _st);
}
virtual void visit(Expression const& _e)
{
boost::apply_visitor(*this, _e);
}
protected:
template <class T>
void walkVector(T const& _statements)
{
for (auto const& st: _statements)
boost::apply_visitor(*this, st);
visit(st);
}
};
@ -89,13 +98,6 @@ public:
virtual void operator()(ForLoop&);
virtual void operator()(Block& _block);
protected:
template <class T>
void walkVector(T&& _statements)
{
for (auto& st: _statements)
visit(st);
}
virtual void visit(Statement& _st)
{
boost::apply_visitor(*this, _st);
@ -104,6 +106,14 @@ protected:
{
boost::apply_visitor(*this, _e);
}
protected:
template <class T>
void walkVector(T&& _statements)
{
for (auto& st: _statements)
visit(st);
}
};
}