]> git.tdb.fi Git - libs/gl.git/commitdiff
Minor, largely cosmetic tweaks
authorMikko Rasa <tdb@tdb.fi>
Wed, 3 Mar 2021 17:55:55 +0000 (19:55 +0200)
committerMikko Rasa <tdb@tdb.fi>
Thu, 4 Mar 2021 00:26:15 +0000 (02:26 +0200)
source/glsl/debug.cpp
source/glsl/generate.cpp
source/glsl/generate.h
source/glsl/optimize.cpp
source/glsl/output.cpp
source/glsl/visitor.cpp
source/glsl/visitor.h

index 04d7aac8ca2c442755efcc1c376f103e6fd3220d..06bf1925cea7e4102015f999cd198d3b67f4615c 100644 (file)
@@ -312,10 +312,10 @@ void DumpTree::visit(FunctionDeclaration &func)
        for(NodeArray<VariableDeclaration>::const_iterator i=func.parameters.begin(); i!=func.parameters.end(); ++i)
                (*i)->visit(*this);
        last_branch();
-       if(func.definition!=&func)
-               append(format("Definition: %%%d", get_label(*func.definition)));
-       else
+       if(func.definition==&func)
                func.body.visit(*this);
+       else if(func.definition)
+               append(format("Definition: %%%d", get_label(*func.definition)));
        end_sub();
 }
 
index 4230a402a0dc413b23e331a5248f3671dc412ff4..90128a18e1a7bbdfcaa023579c9665cac27c9a78 100644 (file)
@@ -118,8 +118,8 @@ VariableResolver::VariableResolver():
        stage(0),
        r_members(0),
        record_target(false),
-       r_assignment_target(0),
-       r_self_referencing(false)
+       r_self_referencing(false),
+       r_assignment_target(0)
 { }
 
 void VariableResolver::apply(Stage &s)
@@ -240,7 +240,7 @@ void VariableResolver::visit(BinaryExpression &binary)
        if(binary.oper->token[0]=='[')
        {
                {
-                       SetForScope<bool> set(record_target, false);
+                       SetFlag set(record_target, false);
                        binary.right->visit(*this);
                }
                r_members = 0;
@@ -264,13 +264,13 @@ void VariableResolver::visit(Assignment &assign)
                SetFlag set(record_target);
                r_assignment_target = 0;
                assign.left->visit(*this);
+               assign.target_declaration = r_assignment_target;
        }
 
        r_self_referencing = false;
        assign.right->visit(*this);
-
        assign.self_referencing = (r_self_referencing || assign.oper->token[0]!='=');
-       assign.target_declaration = r_assignment_target;
+
        r_members = 0;
        r_iface_ref = 0;
 }
index f76c2c2d8fba55d7231f95dfd487d20e897b3061..2cf5c54a3735a611070f1314762a165de7a24b6d 100644 (file)
@@ -65,8 +65,8 @@ private:
        RefPtr<InterfaceBlockReference> r_iface_ref;
        std::string block_interface;
        bool record_target;
-       VariableDeclaration *r_assignment_target;
        bool r_self_referencing;
+       VariableDeclaration *r_assignment_target;
 
 public:
        VariableResolver();
index 56ff34d2fd883eb93dcb3dee629c678814e86e0a..3356a3c9aa6282c59dc1e0fa707f8224c44fa4f8 100644 (file)
@@ -68,9 +68,9 @@ InlineContentInjector::InlineContentInjector():
        deps_only(false)
 { }
 
-const string &InlineContentInjector::apply(Stage &stage, FunctionDeclaration &target_func, Block &tgtb, const NodeList<Statement>::iterator &ins_pt, FunctionDeclaration &src)
+const string &InlineContentInjector::apply(Stage &stage, FunctionDeclaration &target_func, Block &tgt_blk, const NodeList<Statement>::iterator &ins_pt, FunctionDeclaration &src)
 {
-       target_block = &tgtb;
+       target_block = &tgt_blk;
        source_func = &src;
        for(NodeList<Statement>::iterator i=src.body.body.begin(); i!=src.body.body.end(); ++i)
        {
@@ -81,7 +81,7 @@ const string &InlineContentInjector::apply(Stage &stage, FunctionDeclaration &ta
 
                SetFlag set_remap(remap_names);
                r_inlined_statement->visit(*this);
-               tgtb.body.insert(ins_pt, r_inlined_statement);
+               tgt_blk.body.insert(ins_pt, r_inlined_statement);
        }
 
        NodeReorderer().apply(stage, target_func, dependencies);
@@ -474,7 +474,7 @@ void UnusedVariableRemover::visit(BinaryExpression &binary)
                if(assignment_target)
                        r_assign_to_subfield = true;
                binary.left->visit(*this);
-               SetForScope<bool> set(assignment_target, false);
+               SetFlag set(assignment_target, false);
                binary.right->visit(*this);
        }
        else
@@ -484,7 +484,7 @@ void UnusedVariableRemover::visit(BinaryExpression &binary)
 void UnusedVariableRemover::visit(Assignment &assign)
 {
        {
-               SetForScope<bool> set(assignment_target, !assign.self_referencing);
+               SetFlag set(assignment_target, !assign.self_referencing);
                assign.left->visit(*this);
        }
        assign.right->visit(*this);
@@ -567,7 +567,8 @@ void UnusedVariableRemover::visit(FunctionDeclaration &func)
 
        BlockVariableMap &block_variables = variables.back();
        for(BlockVariableMap::iterator i=block_variables.begin(); i!=block_variables.end(); ++i)
-               i->second.conditionally_assigned = true;
+               if(!i->second.local)
+                       i->second.conditionally_assigned = true;
        for(NodeArray<VariableDeclaration>::iterator i=func.parameters.begin(); i!=func.parameters.end(); ++i)
                block_variables[i->get()].referenced = true;
        merge_down_variables();
index 7d502739903a6cd8708cfc758aac470cad2fa17f..72af837958e77a712196b97cc9279258e8c08555 100644 (file)
@@ -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<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)->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);
@@ -153,32 +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<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)->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(Import &import)
 {
        append(format("import %s;", import.module));
index f4b2a8d01c25294ca153e1a629d86de0260b1cc8..3d832c73789b635e25978d23be803ff7ad164507 100644 (file)
@@ -7,12 +7,6 @@ namespace Msp {
 namespace GL {
 namespace SL {
 
-void NodeVisitor::visit(Assignment &assign)
-{
-       visit(static_cast<BinaryExpression &>(assign));
-}
-
-
 void TraversingVisitor::visit(Block &block)
 {
        if(&block!=current_block)
@@ -43,6 +37,11 @@ void TraversingVisitor::visit(BinaryExpression &binary)
        binary.right->visit(*this);
 }
 
+void TraversingVisitor::visit(Assignment &assign)
+{
+       visit(static_cast<BinaryExpression &>(assign));
+}
+
 void TraversingVisitor::visit(FunctionCall &call)
 {
        for(NodeArray<Expression>::iterator i=call.arguments.begin(); i!=call.arguments.end(); ++i)
index e0d74f6226927299913e3e9d41892042eb52f6bb..cd9dafb0b016338eb2f8a12c58e1eb94eeb48a8c 100644 (file)
@@ -25,7 +25,7 @@ public:
        virtual void visit(MemberAccess &) { }
        virtual void visit(UnaryExpression &) { }
        virtual void visit(BinaryExpression &) { }
-       virtual void visit(Assignment &);
+       virtual void visit(Assignment &) { }
        virtual void visit(FunctionCall &) { }
        virtual void visit(ExpressionStatement &) { }
        virtual void visit(Import &) { }
@@ -58,6 +58,7 @@ public:
        virtual void visit(MemberAccess &);
        virtual void visit(UnaryExpression &);
        virtual void visit(BinaryExpression &);
+       virtual void visit(Assignment &);
        virtual void visit(FunctionCall &);
        virtual void visit(ExpressionStatement &);
        virtual void visit(InterfaceLayout &);