target = &*i;
}
- for(NodeList<Node>::iterator i=stage.content.body.begin(); i!=stage.content.body.end(); ++i)
+ for(NodeList<Statement>::iterator i=stage.content.body.begin(); i!=stage.content.body.end(); ++i)
target->content.body.push_back(*i);
apply<DeclarationCombiner>(*target);
}
void ProgramCompiler::inject_block(Block &target, const Block &source)
{
- list<RefPtr<Node> >::iterator insert_point = target.body.begin();
- for(list<RefPtr<Node> >::const_iterator i=source.body.begin(); i!=source.body.end(); ++i)
+ list<RefPtr<Statement> >::iterator insert_point = target.body.begin();
+ for(list<RefPtr<Statement> >::const_iterator i=source.body.begin(); i!=source.body.end(); ++i)
target.body.insert(insert_point, (*i)->clone());
}
remove_node = true;
}
-void ProgramCompiler::BlockModifier::apply_and_increment(Block &block, list<RefPtr<Node> >::iterator &i)
+void ProgramCompiler::BlockModifier::apply_and_increment(Block &block, list<RefPtr<Statement> >::iterator &i)
{
block.body.insert(i, insert_nodes.begin(), insert_nodes.end());
insert_nodes.clear();
void ProgramCompiler::BlockModifier::visit(Block &block)
{
- for(list<RefPtr<Node> >::iterator i=block.body.begin(); i!=block.body.end(); )
+ for(list<RefPtr<Statement> >::iterator i=block.body.begin(); i!=block.body.end(); )
{
(*i)->visit(*this);
apply_and_increment(block, i);
SetForScope<unsigned> set(indent, indent+(indent>0 || use_braces));
string spaces(indent*2, ' ');
- for(list<RefPtr<Node> >::iterator i=block.body.begin(); i!=block.body.end(); ++i)
+ for(list<RefPtr<Statement> >::iterator i=block.body.begin(); i!=block.body.end(); ++i)
{
if(i!=block.body.begin())
formatted += '\n';
void ProgramCompiler::InterfaceGenerator::visit(Block &block)
{
SetForScope<unsigned> set(scope_level, scope_level+1);
- for(list<RefPtr<Node> >::iterator i=block.body.begin(); i!=block.body.end(); )
+ for(list<RefPtr<Statement> >::iterator i=block.body.begin(); i!=block.body.end(); )
{
(*i)->visit(*this);
{
for(map<string, RefPtr<VariableDeclaration> >::iterator j=iface_declarations.begin(); j!=iface_declarations.end(); ++j)
{
- list<RefPtr<Node> >::iterator k = block.body.insert(i, j->second);
+ list<RefPtr<Statement> >::iterator k = block.body.insert(i, j->second);
(*k)->visit(*this);
}
iface_declarations.clear();
if(scope_level>1)
return Visitor::visit(block);
- list<RefPtr<Node> >::iterator struct_insert_point = block.body.end();
- list<RefPtr<Node> >::iterator variable_insert_point = block.body.end();
- list<RefPtr<Node> >::iterator function_insert_point = block.body.end();
+ list<RefPtr<Statement> >::iterator struct_insert_point = block.body.end();
+ list<RefPtr<Statement> >::iterator variable_insert_point = block.body.end();
+ list<RefPtr<Statement> >::iterator function_insert_point = block.body.end();
unsigned unordered_func_count = 0;
bool ordered_any_funcs = false;
- for(list<RefPtr<Node> >::iterator i=block.body.begin(); i!=block.body.end(); )
+ for(list<RefPtr<Statement> >::iterator i=block.body.begin(); i!=block.body.end(); )
{
kind = NO_DECLARATION;
(*i)->visit(*this);
if(extract_result)
--extract_result;
- for(list<RefPtr<Node> >::iterator i=block.body.begin(); i!=block.body.end(); ++i)
+ for(list<RefPtr<Statement> >::iterator i=block.body.begin(); i!=block.body.end(); ++i)
{
(*i)->visit(*this);
if(extract_result)
void ProgramCompiler::NodeRemover::visit(Block &block)
{
- for(list<RefPtr<Node> >::iterator i=block.body.begin(); i!=block.body.end(); )
+ for(list<RefPtr<Statement> >::iterator i=block.body.begin(); i!=block.body.end(); )
{
(*i)->visit(*this);
if(to_remove.count(i->get()))
struct BlockModifier: Visitor
{
bool remove_node;
- std::vector<RefPtr<ProgramSyntax::Node> > insert_nodes;
+ std::vector<RefPtr<ProgramSyntax::Statement> > insert_nodes;
BlockModifier();
void flatten_block(ProgramSyntax::Block &);
- void apply_and_increment(ProgramSyntax::Block &, std::list<RefPtr<ProgramSyntax::Node> >::iterator &);
+ void apply_and_increment(ProgramSyntax::Block &, std::list<RefPtr<ProgramSyntax::Statement> >::iterator &);
using Visitor::visit;
virtual void visit(ProgramSyntax::Block &);
};
source_end = source.end();
current_line = 1;
allow_preprocess = true;
- while(RefPtr<Node> statement = parse_global_declaration())
+ while(RefPtr<Statement> statement = parse_global_declaration())
cur_stage->content.body.push_back(statement);
}
cur_stage = &module->stages.back();
}
-RefPtr<Node> ProgramParser::parse_global_declaration()
+RefPtr<Statement> ProgramParser::parse_global_declaration()
{
allow_stage_change = true;
string token = peek_token();
throw runtime_error(format_syntax_error("a global declaration"));
}
-RefPtr<Node> ProgramParser::parse_statement()
+RefPtr<Statement> ProgramParser::parse_statement()
{
string token = peek_token();
if(token=="if")
void preprocess_pragma_msp();
void preprocess_stage();
- RefPtr<ProgramSyntax::Node> parse_global_declaration();
- RefPtr<ProgramSyntax::Node> parse_statement();
+ RefPtr<ProgramSyntax::Statement> parse_global_declaration();
+ RefPtr<ProgramSyntax::Statement> parse_statement();
RefPtr<ProgramSyntax::Import> parse_import();
RefPtr<ProgramSyntax::Precision> parse_precision();
RefPtr<ProgramSyntax::Layout> parse_layout();
void TraversingVisitor::visit(Block &block)
{
- for(list<RefPtr<Node> >::iterator i=block.body.begin(); i!=block.body.end(); ++i)
+ for(list<RefPtr<Statement> >::iterator i=block.body.begin(); i!=block.body.end(); ++i)
(*i)->visit(*this);
}
struct VariableDeclaration;
struct FunctionDeclaration;
+struct Statement: Node
+{
+ virtual Statement *clone() const = 0;
+};
+
struct Block: Node
{
- NodeList<Node> body;
+ NodeList<Statement> body;
bool use_braces;
std::map<std::string, StructDeclaration *> types;
std::map<std::string, VariableDeclaration *> variables;
virtual void visit(NodeVisitor &);
};
-struct ExpressionStatement: Node
+struct ExpressionStatement: Statement
{
NodePtr<Expression> expression;
virtual void visit(NodeVisitor &);
};
-struct Import: Node
+struct Import: Statement
{
std::string module;
virtual void visit(NodeVisitor &);
};
-struct Precision: Node
+struct Precision: Statement
{
std::string precision;
std::string type;
virtual void visit(NodeVisitor &);
};
-struct InterfaceLayout: Node
+struct InterfaceLayout: Statement
{
std::string interface;
Layout layout;
virtual void visit(NodeVisitor &);
};
-struct StructDeclaration: Node
+struct StructDeclaration: Statement
{
std::string name;
Block members;
virtual void visit(NodeVisitor &);
};
-struct VariableDeclaration: Node
+struct VariableDeclaration: Statement
{
bool constant;
std::string sampling;
virtual void visit(NodeVisitor &);
};
-struct InterfaceBlock: Node
+struct InterfaceBlock: Statement
{
std::string interface;
std::string name;
virtual void visit(NodeVisitor &);
};
-struct FunctionDeclaration: Node
+struct FunctionDeclaration: Statement
{
std::string return_type;
std::string name;
virtual void visit(NodeVisitor &);
};
-struct Conditional: Node
+struct Conditional: Statement
{
NodePtr<Expression> condition;
Block body;
virtual void visit(NodeVisitor &);
};
-struct Iteration: Node
+struct Iteration: Statement
{
NodePtr<Node> init_statement;
NodePtr<Expression> condition;
virtual void visit(NodeVisitor &);
};
-struct Passthrough: Node
+struct Passthrough: Statement
{
NodePtr<Expression> subscript;
virtual void visit(NodeVisitor &);
};
-struct Return: Node
+struct Return: Statement
{
NodePtr<Expression> expression;
virtual void visit(NodeVisitor &);
};
-struct Jump: Node
+struct Jump: Statement
{
std::string keyword;