From: Mikko Rasa Date: Sat, 27 Nov 2021 00:49:14 +0000 (+0200) Subject: Refactor adding types in SL::Parser X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=4d292eadc135b07e8e0996deb539b1984d7d38d3;p=libs%2Fgl.git Refactor adding types in SL::Parser --- diff --git a/source/glsl/parser.cpp b/source/glsl/parser.cpp index 4e8ff97a..46bee183 100644 --- a/source/glsl/parser.cpp +++ b/source/glsl/parser.cpp @@ -605,6 +605,15 @@ RefPtr Parser::parse_function_call(const VariableReference &var) return call; } +void Parser::add_type(TypeDeclaration &type) +{ + cur_stage->types[type.name] = &type; + if(cur_stage->type==Stage::SHARED) + global_types.insert(type.name); + else + stage_types.insert(type.name); +} + RefPtr Parser::parse_type_declaration() { tokenizer.expect("typedef"); @@ -616,11 +625,7 @@ RefPtr Parser::parse_type_declaration() type = parse_basic_type_declaration(); tokenizer.expect(";"); - cur_stage->types[type->name] = type.get(); - if(cur_stage->type==Stage::SHARED) - global_types.insert(type->name); - else - stage_types.insert(type->name); + add_type(*type); return type; } @@ -710,11 +715,7 @@ RefPtr Parser::parse_struct_declaration() parse_block(strct->members, true, &Parser::parse_variable_declaration); tokenizer.expect(";"); - cur_stage->types[strct->name] = strct.get(); - if(cur_stage->type==Stage::SHARED) - global_types.insert(strct->name); - else - stage_types.insert(strct->name); + add_type(*strct); return strct; } diff --git a/source/glsl/parser.h b/source/glsl/parser.h index a935356e..b35b8bbe 100644 --- a/source/glsl/parser.h +++ b/source/glsl/parser.h @@ -79,6 +79,7 @@ private: RefPtr parse_binary(const RefPtr &, const Operator &); RefPtr parse_ternary(const RefPtr &, const Operator &); RefPtr parse_function_call(const VariableReference &); + void add_type(TypeDeclaration &); RefPtr parse_type_declaration(); RefPtr parse_basic_type_declaration(); RefPtr parse_image_type_declaration();