X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fglsl%2Fparser.cpp;h=46bee183f9c061330dc984efd3e88d7ef6773202;hb=4d292eadc135b07e8e0996deb539b1984d7d38d3;hp=cbfa593ac590671b04f077f4bd2e44136f1312c7;hpb=f901fcf41d8ca544085f448227f84bc6f966660d;p=libs%2Fgl.git diff --git a/source/glsl/parser.cpp b/source/glsl/parser.cpp index cbfa593a..46bee183 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; } @@ -593,6 +605,15 @@ RefPtr Parser::parse_function_call(const VariableReference &var) return call; } +void Parser::add_type(TypeDeclaration &type) +{ + cur_stage->types[type.name] = &type; + if(cur_stage->type==Stage::SHARED) + global_types.insert(type.name); + else + stage_types.insert(type.name); +} + RefPtr Parser::parse_type_declaration() { tokenizer.expect("typedef"); @@ -604,7 +625,7 @@ RefPtr Parser::parse_type_declaration() type = parse_basic_type_declaration(); tokenizer.expect(";"); - declared_types.insert(type->name); + add_type(*type); return type; } @@ -694,7 +715,7 @@ RefPtr Parser::parse_struct_declaration() parse_block(strct->members, true, &Parser::parse_variable_declaration); tokenizer.expect(";"); - declared_types.insert(strct->name); + add_type(*strct); return strct; }