block.variables.clear();
}
+void VariableResolver::visit_and_replace(RefPtr<Expression> &expr)
+{
+ r_replacement_expr = 0;
+ expr->visit(*this);
+ if(r_replacement_expr)
+ expr = r_replacement_expr;
+ r_replacement_expr = 0;
+}
+
void VariableResolver::visit(VariableReference &var)
{
VariableDeclaration *declaration = 0;
{
/* The name refers to an interface block with an instance name rather
than a variable. Prepare a new syntax tree node accordingly. */
- r_iface_ref = new InterfaceBlockReference;
- r_iface_ref->source = var.source;
- r_iface_ref->line = var.line;
- r_iface_ref->name = var.name;
- r_iface_ref->declaration = i->second;
+ InterfaceBlockReference *iface_ref = new InterfaceBlockReference;
+ iface_ref->source = var.source;
+ iface_ref->line = var.line;
+ iface_ref->name = var.name;
+ iface_ref->declaration = i->second;
+ r_replacement_expr = iface_ref;
}
else
{
void VariableResolver::visit(MemberAccess &memacc)
{
- r_iface_ref = 0;
- memacc.left->visit(*this);
- if(r_iface_ref)
- memacc.left = r_iface_ref;
- r_iface_ref = 0;
+ visit_and_replace(memacc.left);
map<string, VariableDeclaration *> *members = 0;
if(StructDeclaration *strct = dynamic_cast<StructDeclaration *>(memacc.left->type))
void VariableResolver::visit(UnaryExpression &unary)
{
- TraversingVisitor::visit(unary);
- r_iface_ref = 0;
+ visit_and_replace(unary.expression);
}
void VariableResolver::visit(BinaryExpression &binary)
/* The subscript expression is not a part of the primary assignment
target. */
SetFlag set(record_target, false);
- binary.right->visit(*this);
+ visit_and_replace(binary.right);
}
- r_iface_ref = 0;
- binary.left->visit(*this);
- if(r_iface_ref)
- binary.left = r_iface_ref;
+ visit_and_replace(binary.left);
}
else
- TraversingVisitor::visit(binary);
-
- r_iface_ref = 0;
+ {
+ visit_and_replace(binary.left);
+ visit_and_replace(binary.right);
+ }
}
void VariableResolver::visit(Assignment &assign)
{
SetFlag set(record_target);
r_assignment_target = 0;
- assign.left->visit(*this);
+ visit_and_replace(assign.left);
r_any_resolved |= (r_assignment_target!=assign.target_declaration);
assign.target_declaration = r_assignment_target;
}
r_self_referencing = false;
- assign.right->visit(*this);
+ visit_and_replace(assign.right);
assign.self_referencing = (r_self_referencing || assign.oper->token[0]!='=');
-
- r_iface_ref = 0;
}
void VariableResolver::visit(FunctionCall &call)
{
- TraversingVisitor::visit(call);
- r_iface_ref = 0;
+ for(NodeArray<Expression>::iterator i=call.arguments.begin(); i!=call.arguments.end(); ++i)
+ visit_and_replace(*i);
}
void VariableResolver::visit(VariableDeclaration &var)
ptr = r_inline_result;
r_any_inlined = true;
}
+ r_inline_result = 0;
}
void FunctionInliner::visit(Block &block)
void FunctionInliner::visit(UnaryExpression &unary)
{
visit_and_inline(unary.expression);
- r_inline_result = 0;
}
void FunctionInliner::visit(BinaryExpression &binary)
{
visit_and_inline(binary.left);
visit_and_inline(binary.right);
- r_inline_result = 0;
}
void FunctionInliner::visit(MemberAccess &memacc)
{
visit_and_inline(memacc.left);
- r_inline_result = 0;
}
void FunctionInliner::visit(FunctionCall &call)
inlined further. */
inlineable.erase(current_function);
}
- else
- r_inline_result = 0;
}
void FunctionInliner::visit(ExpressionStatement &expr)
{
if(var.init_expression)
visit_and_inline(var.init_expression);
- r_inline_result = 0;
}
void FunctionInliner::visit(FunctionDeclaration &func)
r_ref_info->inline_on_rhs = on_rhs;
}
}
+ r_ref_info = 0;
}
void ExpressionInliner::inline_expression(Expression &expr, RefPtr<Expression> &ptr, const Operator *outer_oper, const Operator *inner_oper, bool on_rhs)
void ExpressionInliner::visit(MemberAccess &memacc)
{
visit_and_record(memacc.left, memacc.oper, false);
- r_ref_info = 0;
r_oper = memacc.oper;
r_trivial = false;
}
{
SetFlag set_target(mutating, mutating || unary.oper->token[1]=='+' || unary.oper->token[1]=='-');
visit_and_record(unary.expression, unary.oper, false);
- r_ref_info = 0;
r_oper = unary.oper;
r_trivial = false;
}
SetFlag clear_target(mutating, false);
visit_and_record(binary.right, binary.oper, true);
}
- r_ref_info = 0;
r_oper = binary.oper;
r_trivial = false;
}
}
}
- r_ref_info = 0;
r_oper = assign.oper;
r_trivial = false;
}
{
for(NodeArray<Expression>::iterator i=call.arguments.begin(); i!=call.arguments.end(); ++i)
visit_and_record(*i, 0, false);
- r_ref_info = 0;
r_oper = 0;
r_trivial = false;
}