]> git.tdb.fi Git - libs/gl.git/blobdiff - source/glsl/generate.cpp
Store actual values for literals
[libs/gl.git] / source / glsl / generate.cpp
index 433d506e1a8ab762f50a0e930e314bf387c58be0..07181d3583e69fbc1067292bbaddc7855c58a5ac 100644 (file)
@@ -99,9 +99,15 @@ void ConstantSpecializer::visit(VariableDeclaration &var)
                {
                        RefPtr<Literal> literal = new Literal;
                        if(var.type=="bool")
+                       {
                                literal->token = (i->second ? "true" : "false");
+                               literal->value = static_cast<bool>(i->second);
+                       }
                        else if(var.type=="int")
+                       {
                                literal->token = lexical_cast<string>(i->second);
+                               literal->value = i->second;
+                       }
                        var.init_expression = literal;
                }
        }
@@ -125,10 +131,21 @@ void TypeResolver::apply(Stage &s)
        s.content.visit(*this);
 }
 
+TypeDeclaration *TypeResolver::resolve_type(const string &name)
+{
+       map<string, TypeDeclaration *>::iterator i = stage->types.find(name);
+       if(i!=stage->types.end())
+       {
+               map<TypeDeclaration *, TypeDeclaration *>::iterator j = alias_map.find(i->second);
+               return (j!=alias_map.end() ? j->second : i->second);
+       }
+       else
+               return 0;
+}
+
 void TypeResolver::visit(BasicTypeDeclaration &type)
 {
-       map<string, TypeDeclaration *>::iterator i = stage->types.find(type.base);
-       type.base_type = (i!=stage->types.end() ? i->second : 0);
+       type.base_type = resolve_type(type.base);
 
        if(type.kind==BasicTypeDeclaration::VECTOR && type.base_type)
                if(BasicTypeDeclaration *basic_base = dynamic_cast<BasicTypeDeclaration *>(type.base_type))
@@ -138,14 +155,15 @@ void TypeResolver::visit(BasicTypeDeclaration &type)
                                type.size |= basic_base->size<<16;
                        }
 
+       if(type.kind==BasicTypeDeclaration::ALIAS && type.base_type)
+               alias_map[&type] = type.base_type;
+
        stage->types.insert(make_pair(type.name, &type));
 }
 
 void TypeResolver::visit(ImageTypeDeclaration &type)
 {
-       map<string, TypeDeclaration *>::iterator i = stage->types.find(type.base);
-       type.base_type = (i!=stage->types.end() ? i->second : 0);
-
+       type.base_type = resolve_type(type.base);
        stage->types.insert(make_pair(type.name, &type));
 }
 
@@ -157,15 +175,12 @@ void TypeResolver::visit(StructDeclaration &strct)
 
 void TypeResolver::visit(VariableDeclaration &var)
 {
-       map<string, TypeDeclaration *>::iterator i = stage->types.find(var.type);
-       if(i!=stage->types.end())
-               var.type_declaration = i->second;
+       var.type_declaration = resolve_type(var.type);
 }
 
 void TypeResolver::visit(FunctionDeclaration &func)
 {
-       map<string, TypeDeclaration *>::iterator i = stage->types.find(func.return_type);
-       func.return_type_declaration = (i!=stage->types.end() ? i->second : 0);
+       func.return_type_declaration = resolve_type(func.return_type);
        TraversingVisitor::visit(func);
 }