]> git.tdb.fi Git - libs/gl.git/blobdiff - source/glsl/output.cpp
Store a pointer to operator info rather than the token in expressions
[libs/gl.git] / source / glsl / output.cpp
index ef7910f17bd2de93e8de4cc742ff68ee90c1e2b4..7d502739903a6cd8708cfc758aac470cad2fa17f 100644 (file)
@@ -99,6 +99,11 @@ void Formatter::visit(VariableReference &var)
        append(var.name);
 }
 
+void Formatter::visit(InterfaceBlockReference &iface)
+{
+       append(iface.name);
+}
+
 void Formatter::visit(MemberAccess &memacc)
 {
        memacc.left->visit(*this);
@@ -107,25 +112,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);
 }
 
@@ -156,10 +162,14 @@ void Formatter::visit(Block &block)
 
        SetForScope<unsigned> set(indent, indent+(indent>0 || use_braces));
        string spaces(indent*2, ' ');
+       bool first = true;
        for(NodeList<Statement>::iterator i=block.body.begin(); i!=block.body.end(); ++i)
        {
-               if(i!=block.body.begin())
+               if((*i)->source==BUILTIN_SOURCE)
+                       continue;
+               if(!first)
                        append('\n');
+               first = false;
                set_source((*i)->source, (*i)->line);
                append(spaces);
                (*i)->visit(*this);
@@ -255,6 +265,13 @@ void Formatter::visit(InterfaceBlock &iface)
        SetForScope<string> set(block_interface, iface.interface);
        append(format("%s %s\n", iface.interface, iface.name));
        iface.members.visit(*this);
+       if(!iface.instance_name.empty())
+       {
+               append(' ');
+               append(iface.instance_name);
+               if(iface.array)
+                       append("[]");
+       }
        append(';');
 }