]> git.tdb.fi Git - libs/gl.git/blobdiff - source/glsl/builtin.cpp
Improve handling of types in GLSL parser
[libs/gl.git] / source / glsl / builtin.cpp
index c9483151823f973088229cbbab9f2307c0a21816..b9fe487c7bb2f810360918167df628d05a5acbfb 100644 (file)
@@ -1,7 +1,6 @@
 #include <msp/gl/resources.h>
 #include <msp/io/seekable.h>
 #include "builtin.h"
-#include "generate.h"
 #include "parser.h"
 
 using namespace std;
@@ -10,6 +9,13 @@ namespace Msp {
 namespace GL {
 namespace SL {
 
+void populate_types(Stage &stage)
+{
+       for(NodeList<Statement>::const_iterator i=stage.content.body.begin(); i!=stage.content.body.end(); ++i)
+               if(TypeDeclaration *type = dynamic_cast<TypeDeclaration *>(i->get()))
+                       stage.types[type->name] = type;
+}
+
 Module *get_builtins_module()
 {
        static RefPtr<Module> builtins_module;
@@ -22,8 +28,9 @@ Module *get_builtins_module()
                if(!io)
                        return 0;
 
-               Parser parser;
-               Module *module = new Module(parser.parse(*io, "<builtin>", BUILTIN_SOURCE));
+               RefPtr<Module> module = new Module;
+               Parser parser(0);
+               parser.parse(*module, *io, "<builtin>", BUILTIN_SOURCE);
 
                NodeList<Statement> &shared_body = module->shared.content.body;
                NodeList<Statement>::iterator insert_point = shared_body.begin();
@@ -48,6 +55,14 @@ Module *get_builtins_module()
                type->kind = BasicTypeDeclaration::INT;
                shared_body.insert(insert_point, type);
 
+               type = new BasicTypeDeclaration;
+               type->source = BUILTIN_SOURCE;
+               type->name = "uint";
+               type->size = 32;
+               type->sign = false;
+               type->kind = BasicTypeDeclaration::INT;
+               shared_body.insert(insert_point, type);
+
                type = new BasicTypeDeclaration;
                type->source = BUILTIN_SOURCE;
                type->name = "float";
@@ -55,11 +70,11 @@ Module *get_builtins_module()
                type->kind = BasicTypeDeclaration::FLOAT;
                shared_body.insert(insert_point, type);
 
-               TypeResolver().apply(module->shared);
+               populate_types(module->shared);
                for(list<Stage>::iterator i=module->stages.begin(); i!=module->stages.end(); ++i)
-                       TypeResolver().apply(*i);
+                       populate_types(*i);
 
-               builtins_module = module;
+               builtins_module = module.release();
        }
        return builtins_module.get();
 }