X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fglsl%2Fgenerate.cpp;h=c9803acc3b2afd5698b29f66c8d69a110ddfc18c;hb=de87bb70ae10de39a39b2415407a234ab28099cf;hp=433d506e1a8ab762f50a0e930e314bf387c58be0;hpb=d80750e7c20ea061f210b756196cc844b762b852;p=libs%2Fgl.git diff --git a/source/glsl/generate.cpp b/source/glsl/generate.cpp index 433d506e..c9803acc 100644 --- a/source/glsl/generate.cpp +++ b/source/glsl/generate.cpp @@ -99,9 +99,15 @@ void ConstantSpecializer::visit(VariableDeclaration &var) { RefPtr literal = new Literal; if(var.type=="bool") + { literal->token = (i->second ? "true" : "false"); + literal->value = static_cast(i->second); + } else if(var.type=="int") + { literal->token = lexical_cast(i->second); + literal->value = i->second; + } var.init_expression = literal; } } @@ -125,10 +131,31 @@ void TypeResolver::apply(Stage &s) s.content.visit(*this); } +TypeDeclaration *TypeResolver::resolve_type(const string &name) +{ + map::iterator i = stage->types.find(name); + if(i!=stage->types.end()) + { + map::iterator j = alias_map.find(i->second); + return (j!=alias_map.end() ? j->second : i->second); + } + else + return 0; +} + +void TypeResolver::visit(Block &block) +{ + for(NodeList::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) { - map::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(type.base_type)) @@ -138,14 +165,17 @@ 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; + else if(type.kind==BasicTypeDeclaration::ARRAY && type.base_type) + array_types[type.base_type] = &type; + stage->types.insert(make_pair(type.name, &type)); } void TypeResolver::visit(ImageTypeDeclaration &type) { - map::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 +187,31 @@ void TypeResolver::visit(StructDeclaration &strct) void TypeResolver::visit(VariableDeclaration &var) { - map::iterator i = stage->types.find(var.type); - if(i!=stage->types.end()) - var.type_declaration = i->second; + TypeDeclaration *type = resolve_type(var.type); + if(var.array && type) + { + map::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) { - map::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); }