if(!i->second.referenced)
{
unused_nodes.insert(i->first);
- for(vector<Node *>::iterator j=i->second.assignments.begin(); j!=i->second.assignments.end(); ++j)
- unused_nodes.insert(*j);
+ clear_assignments(i->second, true);
}
}
variables.pop_back();
{
VariableInfo &var_info = variables.back()[&var];
if(!self_ref)
- var_info.assignments.clear();
+ clear_assignments(var_info, true);
var_info.assignments.push_back(&node);
var_info.conditionally_assigned = false;
}
+void ProgramCompiler::UnusedVariableLocator::clear_assignments(VariableInfo &var_info, bool mark_unused)
+{
+ if(mark_unused)
+ {
+ for(vector<Node *>::iterator i=var_info.assignments.begin(); i!=var_info.assignments.end(); ++i)
+ unused_nodes.insert(*i);
+ }
+ var_info.assignments.clear();
+}
+
void ProgramCompiler::UnusedVariableLocator::visit(ExpressionStatement &expr)
{
assignment = 0;
{
if(!i->second.referenced)
unused_nodes.insert(i->first);
- for(vector<Node *>::iterator j=i->second.assignments.begin(); j!=i->second.assignments.end(); ++j)
- unused_nodes.insert(*j);
+ clear_assignments(i->second, true);
continue;
}
parent_variables.insert(*i);
else
{
- if(!i->second.conditionally_assigned)
- {
- j->second.assignments.clear();
- j->second.conditionally_assigned = true;
- }
+ if(i->second.referenced || !i->second.conditionally_assigned)
+ clear_assignments(j->second, !i->second.referenced);
+ j->second.conditionally_assigned = i->second.conditionally_assigned;
j->second.referenced |= i->second.referenced;
j->second.assignments.insert(j->second.assignments.end(), i->second.assignments.begin(), i->second.assignments.end());
}
virtual void visit(ProgramSyntax::BinaryExpression &);
virtual void visit(ProgramSyntax::Assignment &);
void record_assignment(ProgramSyntax::VariableDeclaration &, ProgramSyntax::Node &, bool);
+ void clear_assignments(VariableInfo &, bool);
virtual void visit(ProgramSyntax::ExpressionStatement &);
virtual void visit(ProgramSyntax::StructDeclaration &);
virtual void visit(ProgramSyntax::VariableDeclaration &);