X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fprogramparser.cpp;h=453eb18d31db554f0dd1fc47241a5c770db858dd;hb=141ebfc5ed84f95edfd0fba0c354336785eb9807;hp=da3ee0b99f5c383b5f9475676dd2d7b3eeb8c3ff;hpb=57c1139e4fe21aeca7118b18eb3ba6fa43d7bf90;p=libs%2Fgl.git diff --git a/source/programparser.cpp b/source/programparser.cpp index da3ee0b9..453eb18d 100644 --- a/source/programparser.cpp +++ b/source/programparser.cpp @@ -307,9 +307,14 @@ bool ProgramParser::is_sampling_qualifier(const string &token) return token=="centroid"; } +bool ProgramParser::is_precision_qualifier(const string &token) +{ + return (token=="highp" || token=="mediump" || token=="lowp"); +} + bool ProgramParser::is_qualifier(const string &token) { - return (token=="const" || is_interface_qualifier(token) || is_sampling_qualifier(token)); + return (token=="const" || is_interface_qualifier(token) || is_sampling_qualifier(token) || is_precision_qualifier(token)); } bool ProgramParser::is_builtin_type(const string &token) @@ -334,6 +339,8 @@ RefPtr ProgramParser::parse_global_declaration() string token = peek_token(); if(token=="import") return parse_import(); + else if(token=="precision") + return parse_precision(); else if(token=="layout") { RefPtr layout = parse_layout(); @@ -355,15 +362,16 @@ RefPtr ProgramParser::parse_global_declaration() } else if(token=="struct") return parse_struct_declaration(); - else if(is_sampling_qualifier(token) || token=="const") - return parse_variable_declaration(); else if(is_interface_qualifier(token)) { - if(is_type(peek_token(1))) + string next = peek_token(1); + if(is_type(next) || is_precision_qualifier(next)) return parse_variable_declaration(); else return parse_interface_block(); } + else if(is_qualifier(token)) + return parse_variable_declaration(); else if(is_type(token)) { if(peek_token(2)=="(") @@ -388,6 +396,14 @@ RefPtr ProgramParser::parse_statement() return parse_passthrough(); else if(token=="return") return parse_return(); + else if(token=="break" || token=="continue" || token=="discard") + { + RefPtr jump = new Jump; + jump->keyword = parse_token(); + expect(";"); + + return jump; + } else if(is_qualifier(token) || is_type(token)) return parse_variable_declaration(); else if(!token.empty()) @@ -414,6 +430,25 @@ RefPtr ProgramParser::parse_import() return import; } +RefPtr ProgramParser::parse_precision() +{ + expect("precision"); + RefPtr precision = new Precision; + + precision->precision = parse_token(); + if(!is_precision_qualifier(precision->precision)) + throw runtime_error(format("Parse error at '%s': expected a precision qualifier", precision->precision)); + + precision->type = parse_token(); + // Not entirely accurate; only float, int and sampler types are allowed + if(!is_builtin_type(precision->type)) + throw runtime_error(format("Parse error at '%s': expected a builtin type", precision->type)); + + expect(";"); + + return precision; +} + RefPtr ProgramParser::parse_layout() { expect("layout"); @@ -615,6 +650,9 @@ RefPtr ProgramParser::parse_variable_declaration() parse_token(); } + if(is_precision_qualifier(token)) + var->precision = parse_token(); + var->type = expect_type(); var->name = expect_identifier();