]> git.tdb.fi Git - libs/gl.git/commitdiff
Refactor add_to_chain as a common utility function
authorMikko Rasa <tdb@tdb.fi>
Mon, 5 Apr 2021 13:44:16 +0000 (16:44 +0300)
committerMikko Rasa <tdb@tdb.fi>
Mon, 5 Apr 2021 13:45:00 +0000 (16:45 +0300)
source/glsl/resolve.cpp
source/glsl/resolve.h
source/glsl/syntax.cpp
source/glsl/syntax.h

index c5a507a222a96558a7582d72b8725216889d9fa7..bf32326f249defc16224efb11b10ed3a5a6c7244 100644 (file)
@@ -281,13 +281,6 @@ void VariableResolver::visit(InterfaceBlockReference &iface)
        check_assignment_target(iface.declaration);
 }
 
-void VariableResolver::add_to_chain(Assignment::Target::ChainType type, unsigned index)
-{
-       if(r_assignment_target.chain_len<7)
-               r_assignment_target.chain[r_assignment_target.chain_len] = type | min<unsigned>(index, 0x3F);
-       ++r_assignment_target.chain_len;
-}
-
 void VariableResolver::visit(MemberAccess &memacc)
 {
        TraversingVisitor::visit(memacc);
@@ -304,7 +297,7 @@ void VariableResolver::visit(MemberAccess &memacc)
                                ++index;
 
                        if(record_target)
-                               add_to_chain(Assignment::Target::MEMBER, index);
+                               add_to_chain(r_assignment_target, Assignment::Target::MEMBER, index);
                }
        }
        else if(BasicTypeDeclaration *basic = dynamic_cast<BasicTypeDeclaration *>(memacc.left->type))
@@ -349,7 +342,7 @@ void VariableResolver::visit(Swizzle &swizzle)
                unsigned mask = 0;
                for(unsigned i=0; i<swizzle.count; ++i)
                        mask |= 1<<swizzle.components[i];
-               add_to_chain(Assignment::Target::SWIZZLE, mask);
+               add_to_chain(r_assignment_target, Assignment::Target::SWIZZLE, mask);
        }
 }
 
@@ -371,7 +364,7 @@ void VariableResolver::visit(BinaryExpression &binary)
                        if(Literal *literal_subscript = dynamic_cast<Literal *>(binary.right.get()))
                                if(literal_subscript->value.check_type<int>())
                                        index = literal_subscript->value.value<int>();
-                       add_to_chain(Assignment::Target::ARRAY, index);
+                       add_to_chain(r_assignment_target, Assignment::Target::ARRAY, index);
                }
        }
        else
index bbd2d620217aeba08602854dcd6887a961463c70..9e1d4f51c8dd8a6f75f3bd601a45532bdf439917 100644 (file)
@@ -79,7 +79,6 @@ private:
        void check_assignment_target(Statement *);
        virtual void visit(VariableReference &);
        virtual void visit(InterfaceBlockReference &);
-       void add_to_chain(Assignment::Target::ChainType, unsigned);
        virtual void visit(MemberAccess &);
        virtual void visit(Swizzle &);
        virtual void visit(BinaryExpression &);
index c54a82979081cc03e3a2c4bbb66e55cb9b2aa934..b224763248f26aa20f2d7e537ccbc6aa224acdb7 100644 (file)
@@ -555,6 +555,13 @@ int get_layout_value(const Layout &layout, const string &name, int def_value)
        return def_value;
 }
 
+void add_to_chain(Assignment::Target &target, Assignment::Target::ChainType type, unsigned index)
+{
+       if(target.chain_len<7)
+               target.chain[target.chain_len] = type | min<unsigned>(index, 0x3F);
+       ++target.chain_len;
+}
+
 } // namespace SL
 } // namespace GL
 } // namespace Msp
index 66fed6e83f058d83b476d777a45cb43947703c72..3518cb4c3e3145b281661aad152be938120cc556 100644 (file)
@@ -558,6 +558,7 @@ std::string get_unused_variable_name(const Block &, const std::string &);
 
 bool is_same_type(const TypeDeclaration &, const TypeDeclaration &);
 int get_layout_value(const Layout &, const std::string &, int = -1);
+void add_to_chain(Assignment::Target &, Assignment::Target::ChainType, unsigned);
 
 } // namespace SL
 } // namespace GL