]> git.tdb.fi Git - libs/gl.git/blobdiff - source/glsl/generate.cpp
Create array type declarations as necessary
[libs/gl.git] / source / glsl / generate.cpp
index f5b6b7adb91769277f95de93d56d605e38cc88f7..c9803acc3b2afd5698b29f66c8d69a110ddfc18c 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;
                }
        }
@@ -137,6 +143,16 @@ TypeDeclaration *TypeResolver::resolve_type(const string &name)
                return 0;
 }
 
+void TypeResolver::visit(Block &block)
+{
+       for(NodeList<Statement>::iterator i=block.body.begin(); i!=block.body.end(); ++i)
+       {
+               if(!block.parent)
+                       type_insert_point = i;
+               (*i)->visit(*this);
+       }
+}
+
 void TypeResolver::visit(BasicTypeDeclaration &type)
 {
        type.base_type = resolve_type(type.base);
@@ -151,6 +167,8 @@ void TypeResolver::visit(BasicTypeDeclaration &type)
 
        if(type.kind==BasicTypeDeclaration::ALIAS && type.base_type)
                alias_map[&type] = type.base_type;
+       else if(type.kind==BasicTypeDeclaration::ARRAY && type.base_type)
+               array_types[type.base_type] = &type;
 
        stage->types.insert(make_pair(type.name, &type));
 }
@@ -169,7 +187,26 @@ void TypeResolver::visit(StructDeclaration &strct)
 
 void TypeResolver::visit(VariableDeclaration &var)
 {
-       var.type_declaration = resolve_type(var.type);
+       TypeDeclaration *type = resolve_type(var.type);
+       if(var.array && type)
+       {
+               map<TypeDeclaration *, TypeDeclaration *>::iterator i = array_types.find(type);
+               if(i==array_types.end())
+               {
+                       BasicTypeDeclaration *array = new BasicTypeDeclaration;
+                       array->source = BUILTIN_SOURCE;
+                       array->name = type->name+"[]";
+                       array->kind = BasicTypeDeclaration::ARRAY;
+                       array->base = type->name;
+                       array->base_type = type;
+                       stage->content.body.insert(type_insert_point, array);
+                       array->visit(*this);
+                       type = array;
+               }
+               else
+                       type = i->second;
+       }
+       var.type_declaration = type;
 }
 
 void TypeResolver::visit(FunctionDeclaration &func)