}
}
-void UnusedVariableRemover::visit(FunctionDeclaration &func)
-{
- if(func.body.body.empty())
- return;
-
- BlockVariableMap saved_vars = variables;
- // Assignments from other functions should not be visible.
- for(BlockVariableMap::iterator i=variables.begin(); i!=variables.end(); ++i)
- i->second.assignments.resize(i->second.initialized);
- TraversingVisitor::visit(func);
- swap(variables, saved_vars);
- merge_variables(saved_vars);
-
- /* Always treat function parameters as referenced. Removing unused
- parameters is not currently supported. */
- for(NodeArray<VariableDeclaration>::iterator i=func.parameters.begin(); i!=func.parameters.end(); ++i)
- {
- BlockVariableMap::iterator j = variables.find(i->get());
- if(j!=variables.end())
- j->second.referenced = true;
- }
-}
-
void UnusedVariableRemover::merge_variables(const BlockVariableMap &other_vars)
{
for(BlockVariableMap::const_iterator i=other_vars.begin(); i!=other_vars.end(); ++i)
}
}
+void UnusedVariableRemover::visit(FunctionDeclaration &func)
+{
+ if(func.body.body.empty())
+ return;
+
+ BlockVariableMap saved_vars = variables;
+ // Assignments from other functions should not be visible.
+ for(BlockVariableMap::iterator i=variables.begin(); i!=variables.end(); ++i)
+ i->second.assignments.resize(i->second.initialized);
+ TraversingVisitor::visit(func);
+ swap(variables, saved_vars);
+ merge_variables(saved_vars);
+
+ /* Always treat function parameters as referenced. Removing unused
+ parameters is not currently supported. */
+ for(NodeArray<VariableDeclaration>::iterator i=func.parameters.begin(); i!=func.parameters.end(); ++i)
+ {
+ BlockVariableMap::iterator j = variables.find(i->get());
+ if(j!=variables.end())
+ j->second.referenced = true;
+ }
+}
+
void UnusedVariableRemover::visit(Conditional &cond)
{
cond.condition->visit(*this);
virtual void visit(UnaryExpression &);
virtual void visit(BinaryExpression &);
virtual void visit(Assignment &);
- void record_assignment(const Assignment::Target &, Node &);
virtual void visit(FunctionCall &);
+ void record_assignment(const Assignment::Target &, Node &);
virtual void visit(ExpressionStatement &);
// Ignore structs because their members can't be accessed directly.
virtual void visit(StructDeclaration &) { }
virtual void visit(VariableDeclaration &);
virtual void visit(InterfaceBlock &);
- virtual void visit(FunctionDeclaration &);
void merge_variables(const BlockVariableMap &);
+ virtual void visit(FunctionDeclaration &);
virtual void visit(Conditional &);
virtual void visit(Iteration &);
};