1 #include "glsl_error.h"
2 #include "preprocessor.h"
11 Preprocessor::Preprocessor(Tokenizer &t):
15 void Preprocessor::preprocess()
17 tokenizer.expect("#");
19 string token = tokenizer.peek_token();
22 else if(token=="version")
24 else if(token=="define" || token=="undef" || token=="if" || token=="ifdef" || token=="ifndef" || token=="else" ||
25 token=="elif" || token=="endif" || token=="error" || token=="extension" || token=="line")
26 throw invalid_shader_source(tokenizer.get_location(), "Unsupported preprocessor directive '%s'", token);
27 else if(!token.empty())
28 throw parse_error(tokenizer.get_location(), token, "a preprocessor directive");
31 void Preprocessor::preprocess_version()
33 tokenizer.expect("version");
34 string token = tokenizer.parse_token();
35 unsigned version = lexical_cast<unsigned>(token);
36 signal_version.emit(Version(version/100, version%100));
38 token = tokenizer.parse_token();
40 throw parse_error(tokenizer.get_location(), token, "end of line");
43 void Preprocessor::preprocess_pragma()
45 tokenizer.expect("pragma");
46 string token = tokenizer.parse_token();
48 preprocess_pragma_msp();
51 void Preprocessor::preprocess_pragma_msp()
53 string token = tokenizer.peek_token();
57 throw invalid_shader_source(tokenizer.get_location(), "Unrecognized MSP pragma '%s'", token);
59 token = tokenizer.parse_token();
61 throw parse_error(tokenizer.get_location(), token, "end of line");
64 void Preprocessor::preprocess_stage()
66 tokenizer.expect("stage");
67 tokenizer.expect("(");
68 string token = tokenizer.parse_token();
69 StageType stage = SHARED;
72 else if(token=="geometry")
74 else if(token=="fragment")
77 throw parse_error(tokenizer.get_location(), token, "stage identifier");
78 tokenizer.expect(")");
80 signal_stage_change.emit(stage);