Skip to content

Commit

Permalink
Use explicit visit function for the walker.
Browse files Browse the repository at this point in the history
  • Loading branch information
chriseth committed Jan 12, 2018
1 parent 0c20b6d commit 937b95c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
14 changes: 7 additions & 7 deletions libjulia/optimiser/ASTWalker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
}
Expand All @@ -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)
Expand Down
26 changes: 18 additions & 8 deletions libjulia/optimiser/ASTWalker.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,21 @@ class ASTWalker: public boost::static_visitor<>
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);
}
};

Expand All @@ -89,13 +98,6 @@ class ASTModifier: public boost::static_visitor<>
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);
Expand All @@ -104,6 +106,14 @@ class ASTModifier: public boost::static_visitor<>
{
boost::apply_visitor(*this, _e);
}

protected:
template <class T>
void walkVector(T&& _statements)
{
for (auto& st: _statements)
visit(st);
}
};

}
Expand Down

0 comments on commit 937b95c

Please sign in to comment.