X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fglsl%2Fpreprocessor.cpp;h=ea6dd6de700fce75cb96141fd021b7b1ec5146bb;hb=3fe1aab63922eec99d8bf6fd4fd60bec10df173c;hp=354b2a7a84b6d8f6a0fda875f8b396caaba211df;hpb=7a16308e72aef363727b21348779673edf8e5c07;p=libs%2Fgl.git diff --git a/source/glsl/preprocessor.cpp b/source/glsl/preprocessor.cpp index 354b2a7a..ea6dd6de 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); @@ -78,6 +100,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