]> git.tdb.fi Git - libs/gl.git/blobdiff - source/glsl/preprocessor.cpp
Check the flat qualifier from the correct member
[libs/gl.git] / source / glsl / preprocessor.cpp
index 354b2a7a84b6d8f6a0fda875f8b396caaba211df..ca12ec6169c106bf4b4480f02218713184a08e3e 100644 (file)
@@ -1,3 +1,4 @@
+#include <msp/strings/utils.h>
 #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<unsigned>(tokenizer.parse_token());
+
+       int source_index = -1;
+       string token = tokenizer.parse_token();
+       if(!token.empty())
+               source_index = lexical_cast<unsigned>(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);
 
@@ -67,10 +89,16 @@ void Preprocessor::preprocess_stage()
        Stage::Type stage = Stage::SHARED;
        if(token=="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 = Stage::GEOMETRY;
        else if(token=="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<unsigned>(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