X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fglsl%2Fpreprocessor.cpp;h=ea6dd6de700fce75cb96141fd021b7b1ec5146bb;hp=bf2d4b4de0c2b226fcbb90becd48047b9c93946b;hb=HEAD;hpb=c1ec86d6b9ceb6c71f787fed3b2ea6c75457a474 diff --git a/source/glsl/preprocessor.cpp b/source/glsl/preprocessor.cpp index bf2d4b4d..ca12ec61 100644 --- a/source/glsl/preprocessor.cpp +++ b/source/glsl/preprocessor.cpp @@ -1,3 +1,4 @@ +#include #include "glsl_error.h" #include "preprocessor.h" #include "tokenizer.h" @@ -19,8 +20,10 @@ void Preprocessor::preprocess() preprocess_pragma(); else if(token=="version") preprocess_version(); + else if(token=="line") + preprocess_line(); else if(token=="define" || token=="undef" || token=="if" || token=="ifdef" || token=="ifndef" || token=="else" || - token=="elif" || token=="endif" || token=="error" || token=="extension" || token=="line") + token=="elif" || token=="endif" || token=="error" || token=="extension") throw invalid_shader_source(tokenizer.get_location(), "Unsupported preprocessor directive '%s'", token); else if(!token.empty()) throw parse_error(tokenizer.get_location(), token, "a preprocessor directive"); @@ -38,6 +41,23 @@ void Preprocessor::preprocess_version() throw parse_error(tokenizer.get_location(), token, "end of line"); } +void Preprocessor::preprocess_line() +{ + tokenizer.expect("line"); + unsigned line_number = lexical_cast(tokenizer.parse_token()); + + int source_index = -1; + string token = tokenizer.parse_token(); + if(!token.empty()) + source_index = lexical_cast(token); + + token = tokenizer.parse_token(); + if(!token.empty()) + throw parse_error(tokenizer.get_location(), token, "end of line"); + + signal_line.emit(source_index, line_number); +} + void Preprocessor::preprocess_pragma() { tokenizer.expect("pragma"); @@ -51,6 +71,8 @@ void Preprocessor::preprocess_pragma_msp() string token = tokenizer.peek_token(); if(token=="stage") preprocess_stage(); + else if(token=="source") + preprocess_source(); else throw invalid_shader_source(tokenizer.get_location(), "Unrecognized MSP pragma '%s'", token); @@ -64,13 +86,19 @@ void Preprocessor::preprocess_stage() tokenizer.expect("stage"); tokenizer.expect("("); string token = tokenizer.parse_token(); - StageType stage = SHARED; + Stage::Type stage = Stage::SHARED; if(token=="vertex") - stage = VERTEX; + stage = Stage::VERTEX; + else if(token=="tess_control") + stage = Stage::TESS_CONTROL; + else if(token=="tess_eval") + stage = Stage::TESS_EVAL; else if(token=="geometry") - stage = GEOMETRY; + stage = Stage::GEOMETRY; else if(token=="fragment") - stage = FRAGMENT; + stage = Stage::FRAGMENT; + else if(token=="compute") + stage = Stage::COMPUTE; else throw parse_error(tokenizer.get_location(), token, "stage identifier"); tokenizer.expect(")"); @@ -78,6 +106,21 @@ void Preprocessor::preprocess_stage() signal_stage_change.emit(stage); } +void Preprocessor::preprocess_source() +{ + tokenizer.expect("source"); + tokenizer.expect("("); + unsigned source_index = lexical_cast(tokenizer.parse_token()); + tokenizer.expect(","); + string filename = tokenizer.parse_token(); + if(filename[0]!='"') + throw parse_error(tokenizer.get_location(), filename, "a string literal"); + filename = c_unescape(filename.substr(1, filename.size()-2)); + tokenizer.expect(")"); + + signal_source.emit(source_index, filename); +} + } // namespace SL } // namespace GL } // namespace Msp