X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fglsl%2Foutput.cpp;h=52371d1bfdd79f9f7de91ff457d10001952f6c62;hp=44acd634d388e1d3f9c7ab86081e43e4368f01ee;hb=041ba4b1acd55337239c5ce24cc310118c621206;hpb=bd8816692056230c36504dcccd76c6946dff47b1 diff --git a/source/glsl/output.cpp b/source/glsl/output.cpp index 44acd634..52371d1b 100644 --- a/source/glsl/output.cpp +++ b/source/glsl/output.cpp @@ -82,6 +82,32 @@ void Formatter::set_source(unsigned index, unsigned line) source_line = line; } +void Formatter::visit(Block &block) +{ + unsigned brace_indent = indent; + bool use_braces = (block.use_braces || (indent && block.body.size()!=1)); + if(use_braces) + append(format("%s{\n", string(brace_indent*2, ' '))); + + SetForScope set(indent, indent+(indent>0 || use_braces)); + string spaces(indent*2, ' '); + bool first = true; + for(NodeList::iterator i=block.body.begin(); i!=block.body.end(); ++i) + { + if((*i)->source<=BUILTIN_SOURCE) + continue; + if(!first) + append('\n'); + first = false; + set_source((*i)->source, (*i)->line); + append(spaces); + (*i)->visit(*this); + } + + if(use_braces) + append(format("\n%s}", string(brace_indent*2, ' '))); +} + void Formatter::visit(Literal &literal) { append(literal.token); @@ -112,25 +138,26 @@ void Formatter::visit(MemberAccess &memacc) void Formatter::visit(UnaryExpression &unary) { - if(unary.prefix) - append(unary.oper); + if(unary.oper->type==Operator::PREFIX) + append(unary.oper->token); unary.expression->visit(*this); - if(!unary.prefix) - append(unary.oper); + if(unary.oper->type==Operator::POSTFIX) + append(unary.oper->token); } void Formatter::visit(BinaryExpression &binary) { binary.left->visit(*this); - append(binary.oper); + append(binary.oper->token); binary.right->visit(*this); - append(binary.after); + if(binary.oper->token[0]=='[') + append(']'); } void Formatter::visit(Assignment &assign) { assign.left->visit(*this); - append(format(" %s ", assign.oper)); + append(format(" %s ", assign.oper->token)); assign.right->visit(*this); } @@ -152,28 +179,6 @@ void Formatter::visit(ExpressionStatement &expr) append(';'); } -void Formatter::visit(Block &block) -{ - unsigned brace_indent = indent; - bool use_braces = (block.use_braces || (indent && block.body.size()!=1)); - if(use_braces) - append(format("%s{\n", string(brace_indent*2, ' '))); - - SetForScope set(indent, indent+(indent>0 || use_braces)); - string spaces(indent*2, ' '); - for(NodeList::iterator i=block.body.begin(); i!=block.body.end(); ++i) - { - if(i!=block.body.begin()) - append('\n'); - set_source((*i)->source, (*i)->line); - append(spaces); - (*i)->visit(*this); - } - - if(use_braces) - append(format("\n%s}", string(brace_indent*2, ' '))); -} - void Formatter::visit(Import &import) { append(format("import %s;", import.module)); @@ -224,7 +229,7 @@ void Formatter::visit(VariableDeclaration &var) append(format("%s ", var.interpolation)); if(!var.sampling.empty()) append(format("%s ", var.sampling)); - if(!var.interface.empty() && var.interface!=block_interface) + if(!var.interface.empty()) { string interface = var.interface; if(mode==Compiler::PROGRAM && stage && stage->required_features.glsl_versionname; + if(var.array) + type_name = type_name.substr(0, type_name.find('[')); + append(format("%s %s", type_name, var.name)); if(var.array) { append('['); @@ -257,9 +265,9 @@ void Formatter::visit(VariableDeclaration &var) void Formatter::visit(InterfaceBlock &iface) { - SetForScope set(block_interface, iface.interface); append(format("%s %s\n", iface.interface, iface.name)); - iface.members.visit(*this); + if(iface.struct_declaration) + iface.struct_declaration->members.visit(*this); if(!iface.instance_name.empty()) { append(' '); @@ -272,7 +280,7 @@ void Formatter::visit(InterfaceBlock &iface) void Formatter::visit(FunctionDeclaration &func) { - append(format("%s %s(", func.return_type, func.name)); + append(format("%s %s(", func.return_type_declaration->name, func.name)); for(NodeArray::iterator i=func.parameters.begin(); i!=func.parameters.end(); ++i) { if(i!=func.parameters.begin())