X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fglsl%2Fgenerate.cpp;h=6b336f3179de690b2967cd85fe5da0cafff130ab;hb=223e295e4404a3913b8243d3b7eb12da39a68144;hp=fe053ade254c3105d80771a72d575b264583946a;hpb=bc8fd45feac14504b67db9de6fc487fac9fcbaf3;p=libs%2Fgl.git diff --git a/source/glsl/generate.cpp b/source/glsl/generate.cpp index fe053ade..6b336f31 100644 --- a/source/glsl/generate.cpp +++ b/source/glsl/generate.cpp @@ -116,7 +116,6 @@ void BlockHierarchyResolver::enter(Block &block) VariableResolver::VariableResolver(): stage(0), - builtins(0), members(0), record_target(false), assignment_target(0), @@ -128,16 +127,9 @@ void VariableResolver::apply(Stage &s) stage = &s; s.types.clear(); s.interface_blocks.clear(); - Stage *builtin_stage = get_builtins(s.type); - builtins = (builtin_stage ? &builtin_stage->content : 0); s.content.visit(*this); } -Block *VariableResolver::next_block(Block &block) -{ - return block.parent ? block.parent : &block!=builtins ? builtins : 0; -} - void VariableResolver::enter(Block &block) { block.variables.clear(); @@ -147,7 +139,7 @@ void VariableResolver::visit(VariableReference &var) { var.declaration = 0; members = 0; - for(Block *block=current_block; (!var.declaration && block); block=next_block(*block)) + for(Block *block=current_block; (!var.declaration && block); block=block->parent) { map::iterator i = block->variables.find(var.name); if(i!=block->variables.end()) @@ -199,7 +191,7 @@ void VariableResolver::visit(VariableReference &var) void VariableResolver::visit(InterfaceBlockReference &iface) { iface.declaration = 0; - for(Block *block=current_block; block; block=next_block(*block)) + for(Block *block=current_block; block; block=block->parent) { map::iterator i = stage->interface_blocks.find(iface.name); if(i!=stage->interface_blocks.end()) @@ -238,7 +230,7 @@ void VariableResolver::visit(MemberAccess &memacc) void VariableResolver::visit(BinaryExpression &binary) { - if(binary.oper=="[") + if(binary.oper->token[0]=='[') { { SetForScope set(record_target, false); @@ -269,7 +261,7 @@ void VariableResolver::visit(Assignment &assign) self_referencing = false; assign.right->visit(*this); - assign.self_referencing = (self_referencing || assign.oper!="="); + assign.self_referencing = (self_referencing || assign.oper->token[0]!='='); assign.target_declaration = assignment_target; } @@ -337,10 +329,11 @@ void FunctionResolver::visit(FunctionDeclaration &func) } else { + func.definition = 0; if(!stage_decl) stage_decl = &func; - - func.definition = stage_decl->definition; + else + func.definition = stage_decl->definition; } decls.push_back(&func); @@ -467,7 +460,7 @@ ExpressionStatement &InterfaceGenerator::insert_assignment(const string &left, E VariableReference *ref = new VariableReference; ref->name = left; assign->left = ref; - assign->oper = "="; + assign->oper = &Operator::get_operator("=", Operator::BINARY); assign->right = right; ExpressionStatement *stmt = new ExpressionStatement; @@ -629,9 +622,8 @@ void InterfaceGenerator::visit(Passthrough &pass) BinaryExpression *subscript = new BinaryExpression; subscript->left = ref; - subscript->oper = "["; + subscript->oper = &Operator::get_operator("[", Operator::BINARY); subscript->right = pass.subscript; - subscript->after = "]"; MemberAccess *memacc = new MemberAccess; memacc->left = subscript; @@ -651,9 +643,8 @@ void InterfaceGenerator::visit(Passthrough &pass) { BinaryExpression *subscript = new BinaryExpression; subscript->left = ref; - subscript->oper = "["; + subscript->oper = &Operator::get_operator("[", Operator::BINARY); subscript->right = pass.subscript; - subscript->after = "]"; insert_assignment(out_name, subscript); } else @@ -663,111 +654,6 @@ void InterfaceGenerator::visit(Passthrough &pass) nodes_to_remove.insert(&pass); } - -DeclarationReorderer::DeclarationReorderer(): - kind(NO_DECLARATION) -{ } - -void DeclarationReorderer::visit(FunctionCall &call) -{ - FunctionDeclaration *def = call.declaration; - if(def) - def = def->definition; - if(def && !ordered_funcs.count(def)) - needed_funcs.insert(def); -} - -void DeclarationReorderer::visit(Block &block) -{ - if(block.parent) - return TraversingVisitor::visit(block); - - NodeList::iterator struct_insert_point = block.body.end(); - NodeList::iterator variable_insert_point = block.body.end(); - NodeList::iterator function_insert_point = block.body.end(); - unsigned unordered_func_count = 0; - bool ordered_any_funcs = false; - - for(NodeList::iterator i=block.body.begin(); i!=block.body.end(); ) - { - kind = NO_DECLARATION; - (*i)->visit(*this); - - bool moved = false; - if(kind==STRUCT && struct_insert_point!=block.body.end()) - { - block.body.insert(struct_insert_point, *i); - moved = true; - } - else if(kind>STRUCT && struct_insert_point==block.body.end()) - struct_insert_point = i; - - if(kind==VARIABLE && variable_insert_point!=block.body.end()) - { - block.body.insert(variable_insert_point, *i); - moved = true; - } - else if(kind>VARIABLE && variable_insert_point==block.body.end()) - variable_insert_point = i; - - if(kind==FUNCTION) - { - if(function_insert_point==block.body.end()) - function_insert_point = i; - - if(needed_funcs.empty()) - { - ordered_funcs.insert(i->get()); - if(i!=function_insert_point) - { - block.body.insert(function_insert_point, *i); - moved = true; - } - else - ++function_insert_point; - ordered_any_funcs = true; - } - else - ++unordered_func_count; - } - - if(moved) - { - if(function_insert_point==i) - ++function_insert_point; - block.body.erase(i++); - } - else - ++i; - - if(i==block.body.end() && unordered_func_count) - { - if(!ordered_any_funcs) - // A subset of the remaining functions forms a recursive loop - /* TODO pick a function and move it up, adding any necessary - declarations */ - break; - - i = function_insert_point; - unordered_func_count = 0; - } - } -} - -void DeclarationReorderer::visit(VariableDeclaration &var) -{ - TraversingVisitor::visit(var); - kind = VARIABLE; -} - -void DeclarationReorderer::visit(FunctionDeclaration &func) -{ - needed_funcs.clear(); - func.body.visit(*this); - needed_funcs.erase(&func); - kind = FUNCTION; -} - } // namespace SL } // namespace GL } // namespace Msp