X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fprogramparser.cpp;h=ca554f427464b8863b03ed8211c0f8598e2c7c03;hp=c02adb325c25eaba6d4df7f31d9b8963506a5cd4;hb=56beca9d8b4f7b4edac81411d31e24df88e84ac3;hpb=48453f59ec93d9b8f70a17d3034e5ca3e4780ecd diff --git a/source/programparser.cpp b/source/programparser.cpp index c02adb32..ca554f42 100644 --- a/source/programparser.cpp +++ b/source/programparser.cpp @@ -3,6 +3,8 @@ #include #include "programparser.h" +#undef interface + using namespace std; namespace Msp { @@ -68,18 +70,20 @@ ProgramParser::~ProgramParser() delete module; } -Module &ProgramParser::parse(const string &s, const string &n) +Module &ProgramParser::parse(const string &s, const string &n, unsigned i) { source = s; source_name = n; + source_index = i; parse_source(); return *module; } -Module &ProgramParser::parse(IO::Base &io, const string &n) +Module &ProgramParser::parse(IO::Base &io, const string &n, unsigned i) { source = string(); source_name = n; + source_index = i; while(!io.eof()) { char buffer[4096]; @@ -110,7 +114,7 @@ void ProgramParser::parse_source() source_end = source.end(); current_line = 1; allow_preprocess = true; - while(RefPtr statement = parse_global_declaration()) + while(RefPtr statement = parse_global_declaration()) cur_stage->content.body.push_back(statement); } @@ -424,7 +428,7 @@ void ProgramParser::preprocess_stage() cur_stage = &module->stages.back(); } -RefPtr ProgramParser::parse_global_declaration() +RefPtr ProgramParser::parse_global_declaration() { allow_stage_change = true; string token = peek_token(); @@ -441,6 +445,8 @@ RefPtr ProgramParser::parse_global_declaration() if(is_interface_qualifier(token) && peek_token(1)==";") { RefPtr iface_lo = new InterfaceLayout; + iface_lo->source = source_index; + iface_lo->line = current_line; iface_lo->layout.qualifiers = layout->qualifiers; iface_lo->interface = parse_token(); expect(";"); @@ -478,7 +484,7 @@ RefPtr ProgramParser::parse_global_declaration() throw runtime_error(format_syntax_error("a global declaration")); } -RefPtr ProgramParser::parse_statement() +RefPtr ProgramParser::parse_statement() { string token = peek_token(); if(token=="if") @@ -494,6 +500,8 @@ RefPtr ProgramParser::parse_statement() else if(token=="break" || token=="continue" || token=="discard") { RefPtr jump = new Jump; + jump->source = source_index; + jump->line = current_line; jump->keyword = parse_token(); expect(";"); @@ -504,6 +512,8 @@ RefPtr ProgramParser::parse_statement() else if(!token.empty()) { RefPtr expr = new ExpressionStatement; + expr->source = source_index; + expr->line = current_line; expr->expression = parse_expression(); expect(";"); @@ -520,7 +530,9 @@ RefPtr ProgramParser::parse_import() expect("import"); RefPtr import = new Import; - import->module = parse_token(); + import->source = source_index; + import->line = current_line; + import->module = expect_identifier(); expect(";"); return import; } @@ -529,6 +541,8 @@ RefPtr ProgramParser::parse_precision() { expect("precision"); RefPtr precision = new Precision; + precision->source = source_index; + precision->line = current_line; precision->precision = parse_token(); if(!is_precision_qualifier(precision->precision)) @@ -715,6 +729,8 @@ RefPtr ProgramParser::parse_struct_declaration() { expect("struct"); RefPtr strct = new StructDeclaration; + strct->source = source_index; + strct->line = current_line; strct->name = expect_identifier(); parse_block(strct->members, true); @@ -727,6 +743,8 @@ RefPtr ProgramParser::parse_struct_declaration() RefPtr ProgramParser::parse_variable_declaration() { RefPtr var = new VariableDeclaration; + var->source = source_index; + var->line = current_line; string token = peek_token(); while(is_qualifier(token)) @@ -768,6 +786,8 @@ RefPtr ProgramParser::parse_variable_declaration() RefPtr ProgramParser::parse_function_declaration() { RefPtr func = new FunctionDeclaration; + func->source = source_index; + func->line = current_line; func->return_type = expect_type(); func->name = expect_identifier(); @@ -804,6 +824,8 @@ RefPtr ProgramParser::parse_function_declaration() RefPtr ProgramParser::parse_interface_block() { RefPtr iface = new InterfaceBlock; + iface->source = source_index; + iface->line = current_line; iface->interface = parse_token(); if(!is_interface_qualifier(iface->interface)) @@ -828,8 +850,10 @@ RefPtr ProgramParser::parse_interface_block() RefPtr ProgramParser::parse_conditional() { expect("if"); - expect("("); RefPtr cond = new Conditional; + cond->source = source_index; + cond->line = current_line; + expect("("); cond->condition = parse_expression(); expect(")"); @@ -848,8 +872,10 @@ RefPtr ProgramParser::parse_conditional() RefPtr ProgramParser::parse_for() { expect("for"); - expect("("); RefPtr loop = new Iteration; + loop->source = source_index; + loop->line = current_line; + expect("("); string token = peek_token(); if(is_type(token)) loop->init_statement = parse_statement(); @@ -878,8 +904,10 @@ RefPtr ProgramParser::parse_for() RefPtr ProgramParser::parse_while() { expect("while"); - expect("("); RefPtr loop = new Iteration; + loop->source = source_index; + loop->line = current_line; + expect("("); loop->condition = parse_expression(); expect(")"); @@ -892,6 +920,8 @@ RefPtr ProgramParser::parse_passthrough() { expect("passthrough"); RefPtr pass = new Passthrough; + pass->source = source_index; + pass->line = current_line; if(cur_stage->type==GEOMETRY) { expect("["); @@ -906,6 +936,8 @@ RefPtr ProgramParser::parse_return() { expect("return"); RefPtr ret = new Return; + ret->source = source_index; + ret->line = current_line; if(peek_token()!=";") ret->expression = parse_expression(); expect(";");