}
+ProgramCompiler::BlockModifier::BlockModifier():
+ remove_node(false)
+{ }
+
+void ProgramCompiler::BlockModifier::flatten_block(Block &block)
+{
+ insert_nodes.insert(insert_nodes.end(), block.body.begin(), block.body.end());
+ remove_node = true;
+}
+
+void ProgramCompiler::BlockModifier::apply_and_increment(Block &block, list<RefPtr<Node> >::iterator &i)
+{
+ block.body.insert(i, insert_nodes.begin(), insert_nodes.end());
+ insert_nodes.clear();
+
+ if(remove_node)
+ block.body.erase(i++);
+ else
+ ++i;
+ remove_node = false;
+}
+
+void ProgramCompiler::BlockModifier::visit(Block &block)
+{
+ for(list<RefPtr<Node> >::iterator i=block.body.begin(); i!=block.body.end(); )
+ {
+ (*i)->visit(*this);
+ apply_and_increment(block, i);
+ }
+}
+
+
ProgramCompiler::Formatter::Formatter():
indent(0),
parameter_list(false),
ProgramCompiler::DeclarationCombiner::DeclarationCombiner():
- toplevel(true),
- remove_node(false)
+ toplevel(true)
{ }
void ProgramCompiler::DeclarationCombiner::visit(Block &block)
return;
SetForScope<bool> set(toplevel, false);
- for(list<RefPtr<Node> >::iterator i=block.body.begin(); i!=block.body.end(); )
- {
- remove_node = false;
- (*i)->visit(*this);
- if(remove_node)
- block.body.erase(i++);
- else
- ++i;
- }
+ BlockModifier::visit(block);
}
void ProgramCompiler::DeclarationCombiner::visit(FunctionDeclaration &func)
}
-ProgramCompiler::BlockModifier::BlockModifier():
- remove_node(false)
-{ }
-
-void ProgramCompiler::BlockModifier::flatten_block(Block &block)
-{
- insert_nodes.insert(insert_nodes.end(), block.body.begin(), block.body.end());
- remove_node = true;
-}
-
-void ProgramCompiler::BlockModifier::apply_and_increment(Block &block, list<RefPtr<Node> >::iterator &i)
-{
- block.body.insert(i, insert_nodes.begin(), insert_nodes.end());
- insert_nodes.clear();
-
- if(remove_node)
- block.body.erase(i++);
- else
- ++i;
- remove_node = false;
-}
-
-void ProgramCompiler::BlockModifier::visit(Block &block)
-{
- for(list<RefPtr<Node> >::iterator i=block.body.begin(); i!=block.body.end(); )
- {
- (*i)->visit(*this);
- apply_and_increment(block, i);
- }
-}
-
-
ProgramCompiler::InterfaceGenerator::InterfaceGenerator():
scope_level(0)
{ }
void get_result() const { }
};
+ struct BlockModifier: Visitor
+ {
+ bool remove_node;
+ std::list<RefPtr<ProgramSyntax::Node> > insert_nodes;
+
+ BlockModifier();
+
+ void flatten_block(ProgramSyntax::Block &);
+ void apply_and_increment(ProgramSyntax::Block &, std::list<RefPtr<ProgramSyntax::Node> >::iterator &);
+ using Visitor::visit;
+ virtual void visit(ProgramSyntax::Block &);
+ };
+
struct Formatter: Visitor
{
typedef std::string ResultType;
virtual void visit(T &n) { nodes.push_back(&n); }
};
- struct DeclarationCombiner: Visitor
+ struct DeclarationCombiner: BlockModifier
{
bool toplevel;
std::map<std::string, std::vector<ProgramSyntax::FunctionDeclaration *> > functions;
std::map<std::string, ProgramSyntax::VariableDeclaration *> variables;
- bool remove_node;
DeclarationCombiner();
virtual void visit(ProgramSyntax::FunctionDeclaration &);
};
- struct BlockModifier: Visitor
- {
- bool remove_node;
- std::list<RefPtr<ProgramSyntax::Node> > insert_nodes;
-
- BlockModifier();
-
- void flatten_block(ProgramSyntax::Block &);
- void apply_and_increment(ProgramSyntax::Block &, std::list<RefPtr<ProgramSyntax::Node> >::iterator &);
- using Visitor::visit;
- virtual void visit(ProgramSyntax::Block &);
- };
-
struct InterfaceGenerator: BlockModifier
{
std::string in_prefix;