X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fprogramcompiler.cpp;h=fbcc6598d3bcd5e7e74bf50bdf3762e51de9e343;hp=e102349a6482f0dc4a679ee325561210948dd52b;hb=573ea4e5602c4321cc1d75daf9ed0beed5cde280;hpb=35646cafcdff8be76f6ef96018415d9ddec6f77c diff --git a/source/programcompiler.cpp b/source/programcompiler.cpp index e102349a..fbcc6598 100644 --- a/source/programcompiler.cpp +++ b/source/programcompiler.cpp @@ -35,6 +35,8 @@ namespace GL { using namespace ProgramSyntax; +// XXX For some reason global declarations are emitted for otherwise undeclared local variables + ProgramCompiler::ProgramCompiler(): resources(0), module(0) @@ -130,8 +132,8 @@ Stage *ProgramCompiler::get_builtins(StageType type) void ProgramCompiler::append_module(ProgramSyntax::Module &mod) { - list imports = apply >(mod.shared); - for(list::iterator i=imports.begin(); i!=imports.end(); ++i) + vector imports = apply >(mod.shared); + for(vector::iterator i=imports.begin(); i!=imports.end(); ++i) import((*i)->module); apply(mod.shared, set(imports.begin(), imports.end())); @@ -205,7 +207,6 @@ void ProgramCompiler::generate(Stage &stage) apply(stage); apply(stage); apply(stage); - apply(stage); apply(stage); apply(stage); } @@ -861,6 +862,7 @@ void ProgramCompiler::InterfaceGenerator::insert_assignment(const string &left, ExpressionStatement *stmt = new ExpressionStatement; stmt->expression = assign; + stmt->visit(*this); insert_nodes.push_back(stmt); } @@ -876,7 +878,10 @@ void ProgramCompiler::InterfaceGenerator::visit(VariableReference &var) if(i==prev_out.end()) i = prev_out.find(in_prefix+var.name); if(i!=prev_out.end()) - generate_interface(*i->second, "in", var.name); + { + generate_interface(*i->second, "in", i->second->name); + var.name = i->second->name; + } } void ProgramCompiler::InterfaceGenerator::visit(VariableDeclaration &var) @@ -889,7 +894,10 @@ void ProgramCompiler::InterfaceGenerator::visit(VariableDeclaration &var) { remove_node = true; if(var.init_expression) + { insert_assignment(var.name, var.init_expression->clone()); + return; + } } } else if(var.interface=="in") @@ -978,20 +986,6 @@ void ProgramCompiler::InterfaceGenerator::visit(Passthrough &pass) } -void ProgramCompiler::VariableRenamer::visit(VariableReference &var) -{ - if(var.declaration) - var.name = var.declaration->name; -} - -void ProgramCompiler::VariableRenamer::visit(VariableDeclaration &var) -{ - if(var.linked_declaration) - var.name = var.linked_declaration->name; - TraversingVisitor::visit(var); -} - - ProgramCompiler::DeclarationReorderer::DeclarationReorderer(): kind(NO_DECLARATION) { }