X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fglsl%2Fparser.cpp;h=4e8ff97aa894864632fcb47e044b3102d04b9f70;hb=25bf9ac36bccada6895dd09ce9abc3d503b672a5;hp=cbfa593ac590671b04f077f4bd2e44136f1312c7;hpb=f901fcf41d8ca544085f448227f84bc6f966660d;p=libs%2Fgl.git diff --git a/source/glsl/parser.cpp b/source/glsl/parser.cpp index cbfa593a..4e8ff97a 100644 --- a/source/glsl/parser.cpp +++ b/source/glsl/parser.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -55,19 +56,10 @@ void Parser::parse_source(const string &name, int index) if(index>=0) source_reference(1, name); - // TODO Need to somehow get type names from imports if(const Stage *builtin = get_builtins(Stage::SHARED)) { - for(map::const_iterator i=builtin->types.begin(); i!=builtin->types.end(); ++i) - declared_types.insert(i->first); - } - else - { - declared_types.insert("void"); - declared_types.insert("bool"); - declared_types.insert("int"); - declared_types.insert("uint"); - declared_types.insert("float"); + for(const auto &kvp: builtin->types) + global_types.insert(kvp.first); } tokenizer.begin(source, name); @@ -105,6 +97,17 @@ void Parser::stage_change(Stage::Type stage) if(cur_stage->type!=Stage::SHARED) module->stages.back().previous = cur_stage; cur_stage = &module->stages.back(); + + stage_types.clear(); + for(const Module *m: imported_modules) + { + auto j = find_member(m->stages, stage, &Stage::type); + if(j!=m->stages.end()) + { + for(const auto &kvp: j->types) + stage_types.insert(kvp.first); + } + } } void Parser::line_change(int index, unsigned line) @@ -185,13 +188,13 @@ bool Parser::is_qualifier(const string &token) bool Parser::is_type(const string &token) { - return declared_types.count(token); + return global_types.count(token) || stage_types.count(token); } bool Parser::is_identifier(const string &token) { static Regex re("^[a-zA-Z_][a-zA-Z0-9_]*$"); - return re.match(token); + return static_cast(re.match(token)); } template @@ -361,6 +364,15 @@ RefPtr Parser::parse_import() RefPtr import = create_node(); import->module = expect_identifier(); tokenizer.expect(";"); + + if(mod_cache) + { + const Module &imported_mod = mod_cache->get_module(import->module); + imported_modules.push_back(&imported_mod); + for(const auto &kvp: imported_mod.shared.types) + global_types.insert(kvp.first); + } + return import; } @@ -604,7 +616,11 @@ RefPtr Parser::parse_type_declaration() type = parse_basic_type_declaration(); tokenizer.expect(";"); - declared_types.insert(type->name); + cur_stage->types[type->name] = type.get(); + if(cur_stage->type==Stage::SHARED) + global_types.insert(type->name); + else + stage_types.insert(type->name); return type; } @@ -694,7 +710,11 @@ RefPtr Parser::parse_struct_declaration() parse_block(strct->members, true, &Parser::parse_variable_declaration); tokenizer.expect(";"); - declared_types.insert(strct->name); + cur_stage->types[strct->name] = strct.get(); + if(cur_stage->type==Stage::SHARED) + global_types.insert(strct->name); + else + stage_types.insert(strct->name); return strct; }