1 #include <msp/core/raii.h>
10 void NodeVisitor::visit(Assignment &assign)
12 visit(static_cast<BinaryExpression &>(assign));
16 void TraversingVisitor::visit(Block &block)
18 for(NodeList<Statement>::iterator i=block.body.begin(); i!=block.body.end(); ++i)
22 void TraversingVisitor::visit(ParenthesizedExpression &parexpr)
24 parexpr.expression->visit(*this);
27 void TraversingVisitor::visit(MemberAccess &memacc)
29 memacc.left->visit(*this);
32 void TraversingVisitor::visit(UnaryExpression &unary)
34 unary.expression->visit(*this);
37 void TraversingVisitor::visit(BinaryExpression &binary)
39 binary.left->visit(*this);
40 binary.right->visit(*this);
43 void TraversingVisitor::visit(FunctionCall &call)
45 for(NodeArray<Expression>::iterator i=call.arguments.begin(); i!=call.arguments.end(); ++i)
49 void TraversingVisitor::visit(ExpressionStatement &expr)
51 expr.expression->visit(*this);
54 void TraversingVisitor::visit(InterfaceLayout &layout)
56 layout.layout.visit(*this);
59 void TraversingVisitor::visit(StructDeclaration &strct)
61 strct.members.visit(*this);
64 void TraversingVisitor::visit(VariableDeclaration &var)
67 var.layout->visit(*this);
68 if(var.init_expression)
69 var.init_expression->visit(*this);
71 var.array_size->visit(*this);
74 void TraversingVisitor::visit(InterfaceBlock &iface)
76 iface.members.visit(*this);
79 void TraversingVisitor::visit(FunctionDeclaration &func)
81 for(NodeArray<VariableDeclaration>::iterator i=func.parameters.begin(); i!=func.parameters.end(); ++i)
83 func.body.visit(*this);
86 void TraversingVisitor::visit(Conditional &cond)
88 cond.condition->visit(*this);
89 cond.body.visit(*this);
90 cond.else_body.visit(*this);
93 void TraversingVisitor::visit(Iteration &iter)
95 if(iter.init_statement)
96 iter.init_statement->visit(*this);
98 iter.condition->visit(*this);
99 if(iter.loop_expression)
100 iter.loop_expression->visit(*this);
101 iter.body.visit(*this);
104 void TraversingVisitor::visit(Passthrough &pass)
107 pass.subscript->visit(*this);
110 void TraversingVisitor::visit(Return &ret)
113 ret.expression->visit(*this);
117 BlockModifier::BlockModifier():
121 void BlockModifier::flatten_block(Block &block)
123 insert_nodes.insert(insert_nodes.end(), block.body.begin(), block.body.end());
127 void BlockModifier::apply_and_increment(Block &block, NodeList<Statement>::iterator &i)
129 block.body.insert(i, insert_nodes.begin(), insert_nodes.end());
130 insert_nodes.clear();
133 block.body.erase(i++);
139 void BlockModifier::visit(Block &block)
141 for(NodeList<Statement>::iterator i=block.body.begin(); i!=block.body.end(); )
144 apply_and_increment(block, i);
149 NodeRemover::NodeRemover(const set<Node *> &r):
154 void NodeRemover::apply(Stage &s)
156 SetForScope<Stage *> set_stage(stage, &s);
160 void NodeRemover::visit(Block &block)
162 for(NodeList<Statement>::iterator i=block.body.begin(); i!=block.body.end(); )
165 if(to_remove.count(i->get()))
166 block.body.erase(i++);
172 void NodeRemover::visit(VariableDeclaration &var)
174 if(to_remove.count(&var))
176 stage->in_variables.erase(var.name);
177 stage->out_variables.erase(var.name);
178 stage->locations.erase(var.name);
179 if(var.linked_declaration)
180 var.linked_declaration->linked_declaration = 0;
182 else if(var.init_expression && to_remove.count(var.init_expression.get()))
183 var.init_expression = 0;
186 void NodeRemover::visit(Iteration &iter)
188 if(to_remove.count(iter.init_statement.get()))
189 iter.init_statement = 0;
190 TraversingVisitor::visit(iter);