+ TraversingVisitor::visit(block);
+
+ for(map<string, VariableDeclaration *>::iterator i=block.variables.begin(); i!=block.variables.end(); ++i)
+ {
+ map<Assignment::Target, ExpressionInfo>::iterator j = expressions.lower_bound(i->second);
+ for(; (j!=expressions.end() && j->first.declaration==i->second); )
+ {
+ 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(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(RefPtr<Expression> &expr)
+{
+ visit_and_record(expr, 0, false);
+}
+
+void ExpressionInliner::visit(VariableReference &var)
+{
+ if(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
+ inline it. */
+ if(i->second.inline_point && !i->second.trivial)
+ i->second.expression = 0;
+ /* Mutating expressions are analogous to self-referencing assignments
+ and prevent inlining. */
+ if(mutating)
+ i->second.expression = 0;
+ r_ref_info = &i->second;
+ }
+ }
+}
+
+void ExpressionInliner::visit(MemberAccess &memacc)
+{
+ visit_and_record(memacc.left, memacc.oper, false);
+ r_oper = memacc.oper;
+ r_trivial = false;
+}
+
+void ExpressionInliner::visit(Swizzle &swizzle)
+{
+ visit_and_record(swizzle.left, swizzle.oper, false);
+ r_oper = swizzle.oper;
+ r_trivial = false;
+}
+
+void ExpressionInliner::visit(UnaryExpression &unary)
+{
+ SetFlag set_target(mutating, mutating || unary.oper->token[1]=='+' || unary.oper->token[1]=='-');
+ visit_and_record(unary.expression, unary.oper, false);
+ r_oper = unary.oper;
+ r_trivial = false;
+}
+
+void ExpressionInliner::visit(BinaryExpression &binary)
+{
+ visit_and_record(binary.left, binary.oper, false);
+ {
+ SetFlag clear_target(mutating, false);
+ visit_and_record(binary.right, binary.oper, true);
+ }
+ r_oper = binary.oper;
+ r_trivial = false;
+}
+
+void ExpressionInliner::visit(Assignment &assign)
+{
+ {
+ SetFlag set_target(mutating);
+ visit_and_record(assign.left, assign.oper, false);
+ }
+ r_oper = 0;
+ visit_and_record(assign.right, assign.oper, true);
+
+ map<Assignment::Target, ExpressionInfo>::iterator i = expressions.find(assign.target);
+ 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;
+ }
+
+ r_oper = assign.oper;
+ r_trivial = false;