- r_ref_info->inline_point = &ptr;
- r_ref_info->inline_on_rhs = on_rhs;
- }
- }
-}
-
-void ExpressionInliner::inline_expression(Expression &expr, RefPtr<Expression> &ptr, const Operator *outer_oper, const Operator *inner_oper, bool on_rhs)
-{
- unsigned outer_precedence = (outer_oper ? outer_oper->precedence : 20);
- unsigned inner_precedence = (inner_oper ? inner_oper->precedence : 0);
-
- bool needs_parentheses = (inner_precedence>=outer_precedence);
- if(inner_oper && inner_oper==outer_oper)
- // Omit parentheses if the operator's natural grouping works out.
- needs_parentheses = (inner_oper->assoc!=Operator::ASSOCIATIVE && on_rhs!=(inner_oper->assoc==Operator::RIGHT_TO_LEFT));
-
- if(needs_parentheses)
- {
- RefPtr<ParenthesizedExpression> parexpr = new ParenthesizedExpression;
- parexpr->expression = expr.clone();
- ptr = parexpr;
- }
- else
- ptr = expr.clone();
-
- r_any_inlined = true;
-}
-
-void ExpressionInliner::visit(Block &block)
-{
- TraversingVisitor::visit(block);
-
- for(map<VariableDeclaration *, ExpressionInfo>::iterator i=expressions.begin(); i!=expressions.end(); )
- {
- map<string, VariableDeclaration *>::iterator j = block.variables.find(i->first->name);
- if(j!=block.variables.end() && j->second==i->first)
- {
- 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);
-
- 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;
- }