aggregate(0),
assignment(0),
assignment_target(false),
- assign_to_subscript(false)
+ assign_to_subscript(false),
+ side_effects(false)
{ }
bool UnusedVariableRemover::apply(Stage &stage)
unused_nodes.erase(memacc.declaration);
}
+void UnusedVariableRemover::visit(UnaryExpression &unary)
+{
+ TraversingVisitor::visit(unary);
+ if(unary.oper=="++" || unary.oper=="--")
+ side_effects = true;
+}
+
void UnusedVariableRemover::visit(BinaryExpression &binary)
{
if(binary.oper=="[")
}
assign.right->visit(*this);
assignment = &assign;
+ side_effects = true;
+}
+
+void UnusedVariableRemover::visit(FunctionCall &call)
+{
+ TraversingVisitor::visit(call);
+ side_effects = true;
}
void UnusedVariableRemover::record_assignment(VariableDeclaration &var, Node &node, bool chained)
void UnusedVariableRemover::visit(ExpressionStatement &expr)
{
assignment = 0;
+ side_effects = false;
TraversingVisitor::visit(expr);
if(assignment && assignment->target_declaration)
record_assignment(*assignment->target_declaration, expr, (assignment->self_referencing || assign_to_subscript));
+ if(!side_effects)
+ unused_nodes.insert(&expr);
}
void UnusedVariableRemover::visit(StructDeclaration &strct)
Assignment *assignment;
bool assignment_target;
bool assign_to_subscript;
+ bool side_effects;
public:
UnusedVariableRemover();
virtual void visit(VariableReference &);
virtual void visit(InterfaceBlockReference &);
virtual void visit(MemberAccess &);
+ virtual void visit(UnaryExpression &);
virtual void visit(BinaryExpression &);
virtual void visit(Assignment &);
void record_assignment(VariableDeclaration &, Node &, bool);
void clear_assignments(VariableInfo &, bool);
+ virtual void visit(FunctionCall &);
virtual void visit(ExpressionStatement &);
virtual void visit(StructDeclaration &);
virtual void visit(VariableDeclaration &);