aboutsummaryrefslogtreecommitdiffstats
path: root/libjulia
diff options
context:
space:
mode:
Diffstat (limited to 'libjulia')
-rw-r--r--libjulia/optimiser/ASTWalker.cpp14
-rw-r--r--libjulia/optimiser/ASTWalker.h26
2 files changed, 25 insertions, 15 deletions
diff --git a/libjulia/optimiser/ASTWalker.cpp b/libjulia/optimiser/ASTWalker.cpp
index 499b4bf2..6386b29d 100644
--- a/libjulia/optimiser/ASTWalker.cpp
+++ b/libjulia/optimiser/ASTWalker.cpp
@@ -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)
diff --git a/libjulia/optimiser/ASTWalker.h b/libjulia/optimiser/ASTWalker.h
index 4652a353..dbf8194b 100644
--- a/libjulia/optimiser/ASTWalker.h
+++ b/libjulia/optimiser/ASTWalker.h
@@ -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);
+ }
};
}