{
TraversingVisitor::visit(block);
- for(map<VariableDeclaration *, ExpressionInfo>::iterator i=expressions.begin(); i!=expressions.end(); )
+ for(map<string, VariableDeclaration *>::iterator i=block.variables.begin(); i!=block.variables.end(); ++i)
{
- map<string, VariableDeclaration *>::iterator j = block.variables.find(i->first->name);
- if(j!=block.variables.end() && j->second==i->first)
+ map<Assignment::Target, ExpressionInfo>::iterator j = expressions.lower_bound(i->second);
+ for(; (j!=expressions.end() && j->first.declaration==i->second); )
{
- if(i->second.expression && i->second.inline_point)
- inline_expression(*i->second.expression, *i->second.inline_point, i->second.outer_oper, i->second.inner_oper, i->second.inline_on_rhs);
+ if(j->second.expression && j->second.inline_point)
+ inline_expression(*j->second.expression, *j->second.inline_point, j->second.outer_oper, j->second.inner_oper, j->second.inline_on_rhs);
- expressions.erase(i++);
- }
- else
- {
- /* The expression was assigned in this block and may depend on local
- variables of the block. If this is a conditionally executed block,
- the assignment might not always happen. Mark the expression as not
- available to any outer blocks. */
- if(i->second.assign_scope==&block)
- i->second.available = false;
-
- ++i;
+ expressions.erase(j++);
}
}
+
+ /* Expressions assigned in this block may depend on local variables of the
+ block. If this is a conditionally executed block, the assignments might not
+ always happen. Mark the expressions as not available to any outer blocks. */
+ for(map<Assignment::Target, ExpressionInfo>::iterator i=expressions.begin(); i!=expressions.end(); ++i)
+ if(i->second.assign_scope==&block)
+ i->second.available = false;
}
void ExpressionInliner::visit(VariableReference &var)
{
if(var.declaration)
{
- map<VariableDeclaration *, ExpressionInfo>::iterator i = expressions.find(var.declaration);
+ map<Assignment::Target, ExpressionInfo>::iterator i = expressions.find(var.declaration);
if(i!=expressions.end())
{
/* If a non-trivial expression is referenced multiple times, don't
r_oper = 0;
visit_and_record(assign.right, assign.oper, true);
- if(VariableDeclaration *target_var = dynamic_cast<VariableDeclaration *>(assign.target.declaration))
+ map<Assignment::Target, ExpressionInfo>::iterator i = expressions.find(assign.target);
+ if(i!=expressions.end())
{
- map<VariableDeclaration *, ExpressionInfo>::iterator i = expressions.find(target_var);
- if(i!=expressions.end())
- {
- /* Self-referencing assignments can't be inlined without additional
- work. Just clear any previous expression. */
- i->second.expression = (assign.self_referencing ? 0 : assign.right.get());
- i->second.assign_scope = current_block;
- i->second.inline_point = 0;
- i->second.inner_oper = r_oper;
- i->second.available = true;
- }
+ /* Self-referencing assignments can't be inlined without additional
+ work. Just clear any previous expression. */
+ i->second.expression = (assign.self_referencing ? 0 : assign.right.get());
+ i->second.assign_scope = current_block;
+ i->second.inline_point = 0;
+ i->second.inner_oper = r_oper;
+ i->second.available = true;
}
r_oper = assign.oper;