return r_any_inlined;
}
-void ExpressionInliner::visit_and_record(RefPtr<Expression> &ptr)
-{
- r_ref_info = 0;
- ptr->visit(*this);
- if(r_ref_info && r_ref_info->expression && r_ref_info->available)
- {
- if(iteration_body && !r_ref_info->trivial)
- {
- /* Don't inline non-trivial expressions which were assigned outside
- an iteration statement. The iteration may run multiple times, which
- would cause the expression to also be evaluated multiple times. */
- Block *i = r_ref_info->assign_scope;
- for(; (i && i!=iteration_body); i=i->parent) ;
- if(!i)
- return;
- }
-
- if(r_ref_info->trivial)
- inline_expression(*r_ref_info->expression, ptr);
- else
- /* Record the inline point for a non-trivial expression but don't
- inline it yet. It might turn out it shouldn't be inlined after all. */
- r_ref_info->inline_point = &ptr;
- }
- r_ref_info = 0;
-}
-
void ExpressionInliner::inline_expression(Expression &expr, RefPtr<Expression> &ptr)
{
ptr = expr.clone();
void ExpressionInliner::visit(RefPtr<Expression> &expr)
{
- visit_and_record(expr);
+ r_ref_info = 0;
+ expr->visit(*this);
+ if(r_ref_info && r_ref_info->expression && r_ref_info->available)
+ {
+ if(iteration_body && !r_ref_info->trivial)
+ {
+ /* Don't inline non-trivial expressions which were assigned outside
+ an iteration statement. The iteration may run multiple times, which
+ would cause the expression to also be evaluated multiple times. */
+ Block *i = r_ref_info->assign_scope;
+ for(; (i && i!=iteration_body); i=i->parent) ;
+ if(!i)
+ return;
+ }
+
+ if(r_ref_info->trivial)
+ inline_expression(*r_ref_info->expression, expr);
+ else
+ /* Record the inline point for a non-trivial expression but don't
+ inline it yet. It might turn out it shouldn't be inlined after all. */
+ r_ref_info->inline_point = &expr;
+ }
+ r_oper = expr->oper;
+ r_ref_info = 0;
}
void ExpressionInliner::visit(VariableReference &var)
void ExpressionInliner::visit(MemberAccess &memacc)
{
- visit_and_record(memacc.left);
- r_oper = memacc.oper;
+ visit(memacc.left);
r_trivial = false;
}
void ExpressionInliner::visit(Swizzle &swizzle)
{
- visit_and_record(swizzle.left);
- r_oper = swizzle.oper;
+ visit(swizzle.left);
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);
- r_oper = unary.oper;
+ visit(unary.expression);
r_trivial = false;
}
void ExpressionInliner::visit(BinaryExpression &binary)
{
- visit_and_record(binary.left);
+ visit(binary.left);
{
SetFlag clear_target(mutating, false);
- visit_and_record(binary.right);
+ visit(binary.right);
}
- r_oper = binary.oper;
r_trivial = false;
}
{
{
SetFlag set_target(mutating);
- visit_and_record(assign.left);
+ visit(assign.left);
}
r_oper = 0;
- visit_and_record(assign.right);
+ visit(assign.right);
map<Assignment::Target, ExpressionInfo>::iterator i = expressions.find(assign.target);
if(i!=expressions.end())
i->second.available = true;
}
- r_oper = assign.oper;
r_trivial = false;
}
void ExpressionInliner::visit(TernaryExpression &ternary)
{
- visit_and_record(ternary.condition);
- visit_and_record(ternary.true_expr);
- visit_and_record(ternary.false_expr);
- r_oper = ternary.oper;
+ visit(ternary.condition);
+ visit(ternary.true_expr);
+ visit(ternary.false_expr);
r_trivial = false;
}
void ExpressionInliner::visit(FunctionCall &call)
{
TraversingVisitor::visit(call);
- r_oper = 0;
r_trivial = false;
}