block.variables.clear();
}
-void VariableResolver::visit_and_replace(RefPtr<Expression> &expr)
+void VariableResolver::visit(RefPtr<Expression> &expr)
{
r_replacement_expr = 0;
expr->visit(*this);
void VariableResolver::visit(MemberAccess &memacc)
{
- visit_and_replace(memacc.left);
+ TraversingVisitor::visit(memacc);
VariableDeclaration *declaration = 0;
if(StructDeclaration *strct = dynamic_cast<StructDeclaration *>(memacc.left->type))
void VariableResolver::visit(Swizzle &swizzle)
{
- visit_and_replace(swizzle.left);
+ TraversingVisitor::visit(swizzle);
if(record_target)
{
}
}
-void VariableResolver::visit(UnaryExpression &unary)
-{
- visit_and_replace(unary.expression);
-}
-
void VariableResolver::visit(BinaryExpression &binary)
{
if(binary.oper->token[0]=='[')
/* The subscript expression is not a part of the primary assignment
target. */
SetFlag set(record_target, false);
- visit_and_replace(binary.right);
+ visit(binary.right);
}
- visit_and_replace(binary.left);
+ visit(binary.left);
if(record_target)
{
}
}
else
- {
- visit_and_replace(binary.left);
- visit_and_replace(binary.right);
- }
+ TraversingVisitor::visit(binary);
}
void VariableResolver::visit(Assignment &assign)
{
SetFlag set(record_target);
r_assignment_target = Assignment::Target();
- visit_and_replace(assign.left);
+ visit(assign.left);
r_any_resolved |= (r_assignment_target<assign.target || assign.target<r_assignment_target);
assign.target = r_assignment_target;
}
r_self_referencing = false;
- visit_and_replace(assign.right);
+ visit(assign.right);
assign.self_referencing = (r_self_referencing || assign.oper->token[0]!='=');
}
-void VariableResolver::visit(FunctionCall &call)
-{
- for(NodeArray<Expression>::iterator i=call.arguments.begin(); i!=call.arguments.end(); ++i)
- visit_and_replace(*i);
-}
-
void VariableResolver::visit(VariableDeclaration &var)
{
- if(var.layout)
- var.layout->visit(*this);
- if(var.array_size)
- visit_and_replace(var.array_size);
- if(var.init_expression)
- visit_and_replace(var.init_expression);
+ TraversingVisitor::visit(var);
current_block->variables.insert(make_pair(var.name, &var));
}
private:
virtual void enter(Block &);
- void visit_and_replace(RefPtr<Expression> &);
+ virtual void visit(RefPtr<Expression> &);
void check_assignment_target(Statement *);
virtual void visit(VariableReference &);
virtual void visit(InterfaceBlockReference &);
void add_to_chain(Assignment::Target::ChainType, unsigned);
virtual void visit(MemberAccess &);
virtual void visit(Swizzle &);
- virtual void visit(UnaryExpression &);
virtual void visit(BinaryExpression &);
virtual void visit(Assignment &);
- virtual void visit(FunctionCall &);
virtual void visit(VariableDeclaration &);
virtual void visit(InterfaceBlock &);
};
return r_any_inlined;
}
-void FunctionInliner::visit_and_inline(RefPtr<Expression> &ptr)
+void FunctionInliner::visit(RefPtr<Expression> &ptr)
{
r_inline_result = 0;
ptr->visit(*this);
}
}
-void FunctionInliner::visit(UnaryExpression &unary)
-{
- visit_and_inline(unary.expression);
-}
-
-void FunctionInliner::visit(BinaryExpression &binary)
-{
- visit_and_inline(binary.left);
- visit_and_inline(binary.right);
-}
-
-void FunctionInliner::visit(MemberAccess &memacc)
-{
- visit_and_inline(memacc.left);
-}
-
-void FunctionInliner::visit(Swizzle &swizzle)
-{
- visit_and_inline(swizzle.left);
-}
-
void FunctionInliner::visit(FunctionCall &call)
{
for(NodeArray<Expression>::iterator i=call.arguments.begin(); i!=call.arguments.end(); ++i)
- visit_and_inline(*i);
+ visit(*i);
FunctionDeclaration *def = call.declaration;
if(def)
}
}
-void FunctionInliner::visit(ExpressionStatement &expr)
-{
- visit_and_inline(expr.expression);
-}
-
-void FunctionInliner::visit(VariableDeclaration &var)
-{
- if(var.init_expression)
- visit_and_inline(var.init_expression);
-}
-
void FunctionInliner::visit(FunctionDeclaration &func)
{
SetForScope<FunctionDeclaration *> set_func(current_function, &func);
TraversingVisitor::visit(func);
}
-void FunctionInliner::visit(Conditional &cond)
-{
- visit_and_inline(cond.condition);
- cond.body.visit(*this);
-}
-
void FunctionInliner::visit(Iteration &iter)
{
/* Visit the initialization statement before entering the loop body so the
iter.body.visit(*this);
}
-void FunctionInliner::visit(Return &ret)
-{
- if(ret.expression)
- visit_and_inline(ret.expression);
-}
-
ExpressionInliner::ExpressionInfo::ExpressionInfo():
expression(0),
i->second.available = false;
}
+void ExpressionInliner::visit(RefPtr<Expression> &expr)
+{
+ visit_and_record(expr, 0, false);
+}
+
void ExpressionInliner::visit(VariableReference &var)
{
if(var.declaration)
void ExpressionInliner::visit(FunctionCall &call)
{
- for(NodeArray<Expression>::iterator i=call.arguments.begin(); i!=call.arguments.end(); ++i)
- visit_and_record(*i, 0, false);
+ TraversingVisitor::visit(call);
r_oper = 0;
r_trivial = false;
}
{
r_oper = 0;
r_trivial = true;
- if(var.init_expression)
- visit_and_record(var.init_expression, 0, false);
+ TraversingVisitor::visit(var);
bool constant = var.constant;
if(constant && var.layout)
}
}
-void ExpressionInliner::visit(Conditional &cond)
-{
- visit_and_record(cond.condition, 0, false);
- cond.body.visit(*this);
-}
-
void ExpressionInliner::visit(Iteration &iter)
{
SetForScope<Block *> set_block(current_block, &iter.body);
SetForScope<Block *> set_body(iteration_body, &iter.body);
if(iter.condition)
- iter.condition->visit(*this);
+ visit(iter.condition);
iter.body.visit(*this);
if(iter.loop_expression)
- iter.loop_expression->visit(*this);
-}
-
-void ExpressionInliner::visit(Return &ret)
-{
- if(ret.expression)
- visit_and_record(ret.expression, 0, false);
+ visit(iter.loop_expression);
}
bool apply(Stage &);
private:
- void visit_and_inline(RefPtr<Expression> &);
-
+ virtual void visit(RefPtr<Expression> &);
virtual void visit(Block &);
- virtual void visit(UnaryExpression &);
- virtual void visit(BinaryExpression &);
- virtual void visit(Assignment &a) { visit(static_cast<BinaryExpression &>(a)); }
- virtual void visit(MemberAccess &);
- virtual void visit(Swizzle &);
virtual void visit(FunctionCall &);
- virtual void visit(ExpressionStatement &);
- virtual void visit(VariableDeclaration &);
virtual void visit(FunctionDeclaration &);
- virtual void visit(Conditional &);
virtual void visit(Iteration &);
- virtual void visit(Return &);
};
/** Inlines variables into expressions. Variables with trivial values (those
void visit_and_record(RefPtr<Expression> &, const Operator *, bool);
void inline_expression(Expression &, RefPtr<Expression> &, const Operator *, const Operator *, bool);
virtual void visit(Block &);
+ virtual void visit(RefPtr<Expression> &);
virtual void visit(VariableReference &);
virtual void visit(MemberAccess &);
virtual void visit(Swizzle &);
virtual void visit(Assignment &);
virtual void visit(FunctionCall &);
virtual void visit(VariableDeclaration &);
- virtual void visit(Conditional &);
virtual void visit(Iteration &);
- virtual void visit(Return &);
};
/** Removes conditional statements and loops where the condition can be
(*i)->visit(*this);
}
+void TraversingVisitor::visit(RefPtr<Expression> &expr)
+{
+ expr->visit(*this);
+}
+
void TraversingVisitor::visit(ParenthesizedExpression &parexpr)
{
- parexpr.expression->visit(*this);
+ visit(parexpr.expression);
}
void TraversingVisitor::visit(MemberAccess &memacc)
{
- memacc.left->visit(*this);
+ visit(memacc.left);
}
void TraversingVisitor::visit(Swizzle &swizzle)
{
- swizzle.left->visit(*this);
+ visit(swizzle.left);
}
void TraversingVisitor::visit(UnaryExpression &unary)
{
- unary.expression->visit(*this);
+ visit(unary.expression);
}
void TraversingVisitor::visit(BinaryExpression &binary)
{
- binary.left->visit(*this);
- binary.right->visit(*this);
+ visit(binary.left);
+ visit(binary.right);
}
void TraversingVisitor::visit(Assignment &assign)
{
- assign.left->visit(*this);
- assign.right->visit(*this);
+ visit(assign.left);
+ visit(assign.right);
}
void TraversingVisitor::visit(FunctionCall &call)
{
for(NodeArray<Expression>::iterator i=call.arguments.begin(); i!=call.arguments.end(); ++i)
- (*i)->visit(*this);
+ visit(*i);
}
void TraversingVisitor::visit(ExpressionStatement &expr)
{
- expr.expression->visit(*this);
+ visit(expr.expression);
}
void TraversingVisitor::visit(InterfaceLayout &layout)
if(var.layout)
var.layout->visit(*this);
if(var.init_expression)
- var.init_expression->visit(*this);
+ visit(var.init_expression);
if(var.array_size)
- var.array_size->visit(*this);
+ visit(var.array_size);
}
void TraversingVisitor::visit(InterfaceBlock &iface)
void TraversingVisitor::visit(Conditional &cond)
{
- cond.condition->visit(*this);
+ visit(cond.condition);
cond.body.visit(*this);
cond.else_body.visit(*this);
}
if(iter.init_statement)
iter.init_statement->visit(*this);
if(iter.condition)
- iter.condition->visit(*this);
+ visit(iter.condition);
iter.body.visit(*this);
if(iter.loop_expression)
- iter.loop_expression->visit(*this);
+ visit(iter.loop_expression);
}
void TraversingVisitor::visit(Passthrough &pass)
{
if(pass.subscript)
- pass.subscript->visit(*this);
+ visit(pass.subscript);
}
void TraversingVisitor::visit(Return &ret)
{
if(ret.expression)
- ret.expression->visit(*this);
+ visit(ret.expression);
}
public:
virtual void enter(Block &) { }
virtual void visit(Block &);
+ virtual void visit(RefPtr<Expression> &);
virtual void visit(ParenthesizedExpression &);
virtual void visit(MemberAccess &);
virtual void visit(Swizzle &);