]> git.tdb.fi Git - libs/gl.git/commitdiff
Refactor layout qualifier creation with constructors
authorMikko Rasa <tdb@tdb.fi>
Mon, 5 Apr 2021 13:54:49 +0000 (16:54 +0300)
committerMikko Rasa <tdb@tdb.fi>
Mon, 5 Apr 2021 13:54:49 +0000 (16:54 +0300)
source/glsl/finalize.cpp
source/glsl/parser.cpp
source/glsl/syntax.h

index 94007b8fc3eda25f24b91deff5425549de70ce15..192baec550e111313c76a5cde659e37c6604fba8 100644 (file)
@@ -55,11 +55,7 @@ void StructOrganizer::visit(VariableDeclaration &var)
                        if(!var.layout)
                                var.layout = new Layout;
 
-                       Layout::Qualifier qual;
-                       qual.name = "offset";
-                       qual.has_value = true;
-                       qual.value = offset;
-                       var.layout->qualifiers.push_back(qual);
+                       var.layout->qualifiers.push_back(Layout::Qualifier("offset", offset));
                }
 
                if(!has_matrix_order)
@@ -68,11 +64,7 @@ void StructOrganizer::visit(VariableDeclaration &var)
                        while(basic && basic->kind==BasicTypeDeclaration::ARRAY)
                                basic = dynamic_cast<const BasicTypeDeclaration *>(basic->base_type);
                        if(basic && basic->kind==BasicTypeDeclaration::MATRIX)
-                       {
-                               Layout::Qualifier qual;
-                               qual.name = "column_major";
-                               var.layout->qualifiers.push_back(qual);
-                       }
+                               var.layout->qualifiers.push_back(Layout::Qualifier("column_major"));
                }
 
                offset += mem_reqs.size;
@@ -177,11 +169,7 @@ void LocationAllocator::add_layout_value(RefPtr<Layout> &layout, const string &n
        if(!layout)
                layout = new Layout;
 
-       Layout::Qualifier qual;
-       qual.name = name;
-       qual.has_value = true;
-       qual.value = value;
-       layout->qualifiers.push_back(qual);
+       layout->qualifiers.push_back(Layout::Qualifier(name, value));
 }
 
 void LocationAllocator::visit(VariableDeclaration &var)
index 56e4b1b50fcf75573230c949256e0c5c33655d64..6a055c0cd3ebb718830e65175efa15aa3bf10ca1 100644 (file)
@@ -397,9 +397,8 @@ RefPtr<Layout> Parser::parse_layout()
                if(token==")")
                        throw parse_error(tokenizer.get_location(), token, "a layout qualifier name");
 
-               layout->qualifiers.push_back(Layout::Qualifier());
+               layout->qualifiers.push_back(token);
                Layout::Qualifier &qual = layout->qualifiers.back();
-               qual.name = token;
 
                if((qual.has_value = check("=")))
                {
index 3518cb4c3e3145b281661aad152be938120cc556..2a9dcf84869261298d404248c3fd138de41fc498 100644 (file)
@@ -315,7 +315,8 @@ struct Layout: Node
                bool has_value;
                int value;
 
-               Qualifier(): has_value(false), value(0) { }
+               Qualifier(const std::string &n = std::string()): name(n), has_value(false), value(0) { }
+               Qualifier(const std::string &n, int v): name(n), has_value(true), value(v) { }
        };
 
        std::vector<Qualifier> qualifiers;