X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fprogramparser.cpp;h=58649ec0d77cfb189aa352b003f65e6637109231;hb=961715848c111907b5f443c5b545a429b40583e6;hp=bf2d42daedbfd232dcc0dd194deb7c60ddf76625;hpb=73ce62f3b9c2bbfc1e655a9df343389a733dc795;p=libs%2Fgl.git diff --git a/source/programparser.cpp b/source/programparser.cpp index bf2d42da..58649ec0 100644 --- a/source/programparser.cpp +++ b/source/programparser.cpp @@ -81,14 +81,15 @@ Module &ProgramParser::parse(IO::Base &io) void ProgramParser::parse_source(Module &module) { cur_module = &module; + cur_context = &module.global_context; iter = source.begin(); - Context *cur_context = &module.global_context; while(1) { while(Node *statement = parse_global_declaration()) cur_context->content.body.push_back(statement); cur_context->present = !cur_context->content.body.empty(); + Context *prev_context = cur_context; parse_token(); string token = parse_token(); if(token.empty()) @@ -103,6 +104,7 @@ void ProgramParser::parse_source(Module &module) cur_context = &module.fragment_context; else throw runtime_error(format("Parse error at '%s': expected context identifier", token)); + cur_context->previous = prev_context; for(; (iter!=source.end() && *iter!='\n'); ++iter) ; } @@ -310,7 +312,7 @@ bool ProgramParser::is_builtin_type(const string &token) bool ProgramParser::is_type(const string &token) { - return is_builtin_type(token) || cur_module->structs.count(token); + return is_builtin_type(token) || declared_types.count(token); } bool ProgramParser::is_identifier(const string &token) @@ -355,6 +357,8 @@ Node *ProgramParser::parse_statement() return parse_conditional(); else if(token=="for") return parse_iteration(); + else if(token=="passthrough") + return parse_passthrough(); else if(token=="return") return parse_return(); else if(is_qualifier(token) || is_type(token)) @@ -550,7 +554,7 @@ StructDeclaration *ProgramParser::parse_struct_declaration() parse_block(strct->members, true); expect(";"); - cur_module->structs[strct->name] = strct.get(); + declared_types.insert(strct->name); return strct.release(); } @@ -693,6 +697,20 @@ Iteration *ProgramParser::parse_iteration() return loop.release(); } +Passthrough *ProgramParser::parse_passthrough() +{ + expect("passthrough"); + RefPtr pass = new Passthrough; + if(cur_context->type==GEOMETRY) + { + expect("["); + pass->subscript = parse_expression(); + expect("]"); + } + expect(";"); + return pass.release(); +} + Return *ProgramParser::parse_return() { expect("return");