]> git.tdb.fi Git - libs/gl.git/blobdiff - source/glsl/syntax.cpp
Mark constant data as const
[libs/gl.git] / source / glsl / syntax.cpp
index c94e2e27042c63a6a7f0b2c91f3d26c5b00f1e30..bb8d7dab046f2ea1293927d93aa3e415818e12d4 100644 (file)
@@ -1,3 +1,4 @@
+#include <msp/core/algorithm.h>
 #include <msp/core/maputils.h>
 #include "syntax.h"
 #include "visitor.h"
@@ -69,8 +70,8 @@ template<typename C>
 NodeContainer<C>::NodeContainer(const NodeContainer &c):
        C(c)
 {
-       for(typename C::iterator i=this->begin(); i!=this->end(); ++i)
-               *i = (*i)->clone();
+       for(auto &i: *this)
+               i = i->clone();
 }
 
 
@@ -138,14 +139,16 @@ void InterfaceBlockReference::visit(NodeVisitor &visitor)
 
 
 MemberAccess::MemberAccess():
-       declaration(0)
+       declaration(0),
+       index(-1)
 { }
 
 MemberAccess::MemberAccess(const MemberAccess &other):
        Expression(other),
        left(other.left),
        member(other.member),
-       declaration(0)
+       declaration(0),
+       index(-1)
 { }
 
 void MemberAccess::visit(NodeVisitor &visitor)
@@ -269,6 +272,7 @@ void InterfaceLayout::visit(NodeVisitor &visitor)
 BasicTypeDeclaration::BasicTypeDeclaration():
        kind(ALIAS),
        size(0),
+       sign(true),
        base_type(0)
 { }
 
@@ -276,6 +280,7 @@ BasicTypeDeclaration::BasicTypeDeclaration(const BasicTypeDeclaration &other):
        TypeDeclaration(other),
        kind(other.kind),
        size(other.size),
+       sign(other.sign),
        base(other.base),
        base_type(0)
 { }
@@ -369,7 +374,7 @@ InterfaceBlock::InterfaceBlock():
 InterfaceBlock::InterfaceBlock(const InterfaceBlock &other):
        Statement(other),
        interface(other.interface),
-       name(other.name),
+       block_name(other.block_name),
        members(other.members),
        instance_name(other.instance_name),
        array(other.array),
@@ -455,7 +460,7 @@ Stage::Stage(Stage::Type t):
 
 const char *Stage::get_stage_name(Type type)
 {
-       static const char *names[] = { "shared", "vertex", "geometry", "fragment" };
+       static const char *const names[] = { "shared", "vertex", "geometry", "fragment" };
        return names[type];
 }
 
@@ -465,13 +470,12 @@ Module::Module():
 { }
 
 
-string get_unused_variable_name(const Block &block, const string &base, const string &prefix_hint)
+string get_unused_variable_name(const Block &block, const string &base)
 {
        string name = base;
 
-       bool prefixed = false;
        unsigned number = 1;
-       unsigned size_without_number = name.size();
+       unsigned base_size = name.size();
        while(1)
        {
                bool unused = true;
@@ -480,25 +484,25 @@ string get_unused_variable_name(const Block &block, const string &base, const st
                if(unused)
                        return name;
 
-               if(!prefixed && !prefix_hint.empty())
-               {
-                       if(name.front()!='_')
-                               name = "_"+name;
-                       name = prefix_hint+name;
-                       if(name.front()!='_')
-                               name = "_"+name;
-                       prefixed = true;
-                       size_without_number = name.size();
-               }
-               else
-               {
-                       name.erase(size_without_number);
-                       name += format("_%d", number);
-                       ++number;
-               }
+               name.erase(base_size);
+               name += format("_%d", number);
+               ++number;
        }
 }
 
+int get_layout_value(const Layout &layout, const string &name, int def_value)
+{
+       auto i = find_member(layout.qualifiers, name, &Layout::Qualifier::name);
+       return (i!=layout.qualifiers.end() ? i->value : 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