From: Mikko Rasa Date: Mon, 5 Apr 2021 13:54:49 +0000 (+0300) Subject: Refactor layout qualifier creation with constructors X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=eb7ffda6876bd2eeeb64dcb7c82236f36fe5cf43;p=libs%2Fgl.git Refactor layout qualifier creation with constructors --- diff --git a/source/glsl/finalize.cpp b/source/glsl/finalize.cpp index 94007b8f..192baec5 100644 --- a/source/glsl/finalize.cpp +++ b/source/glsl/finalize.cpp @@ -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(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, 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) diff --git a/source/glsl/parser.cpp b/source/glsl/parser.cpp index 56e4b1b5..6a055c0c 100644 --- a/source/glsl/parser.cpp +++ b/source/glsl/parser.cpp @@ -397,9 +397,8 @@ RefPtr 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("="))) { diff --git a/source/glsl/syntax.h b/source/glsl/syntax.h index 3518cb4c..2a9dcf84 100644 --- a/source/glsl/syntax.h +++ b/source/glsl/syntax.h @@ -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 qualifiers;