]> git.tdb.fi Git - libs/gl.git/commitdiff
Refactor adding types in SL::Parser
authorMikko Rasa <tdb@tdb.fi>
Sat, 27 Nov 2021 00:49:14 +0000 (02:49 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sat, 27 Nov 2021 10:19:21 +0000 (12:19 +0200)
source/glsl/parser.cpp
source/glsl/parser.h

index 4e8ff97aa894864632fcb47e044b3102d04b9f70..46bee183f9c061330dc984efd3e88d7ef6773202 100644 (file)
@@ -605,6 +605,15 @@ RefPtr<FunctionCall> 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<TypeDeclaration> Parser::parse_type_declaration()
 {
        tokenizer.expect("typedef");
@@ -616,11 +625,7 @@ RefPtr<TypeDeclaration> 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<StructDeclaration> 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;
 }
 
index a935356ecd1339e68e6bb82f2752a5d47e6a25fb..b35b8bbe084d73b888efbb7431f3e57b82ca660c 100644 (file)
@@ -79,6 +79,7 @@ private:
        RefPtr<BinaryExpression> parse_binary(const RefPtr<Expression> &, const Operator &);
        RefPtr<TernaryExpression> parse_ternary(const RefPtr<Expression> &, const Operator &);
        RefPtr<FunctionCall> parse_function_call(const VariableReference &);
+       void add_type(TypeDeclaration &);
        RefPtr<TypeDeclaration> parse_type_declaration();
        RefPtr<BasicTypeDeclaration> parse_basic_type_declaration();
        RefPtr<ImageTypeDeclaration> parse_image_type_declaration();