X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fprogramparser.cpp;h=b607e1cfb8f063abfec2127b7c57247809677a81;hp=f38f39097615c94185c0d4bf7504d70e0dc7d646;hb=9339ae44a89f295523b6c25681d87642767864c4;hpb=684fadb0eb3e6a7dc274d6ed26abd28d5787d60d diff --git a/source/programparser.cpp b/source/programparser.cpp index f38f3909..b607e1cf 100644 --- a/source/programparser.cpp +++ b/source/programparser.cpp @@ -263,7 +263,7 @@ void ProgramParser::skip_comment_and_whitespace() { if(*iter=='/') comment = 0; - else + else if(*iter!='*') comment = 3; } @@ -315,7 +315,12 @@ bool ProgramParser::is_interface_qualifier(const string &token) bool ProgramParser::is_sampling_qualifier(const string &token) { - return token=="centroid"; + return (token=="centroid" || token=="sample"); +} + +bool ProgramParser::is_interpolation_qualifier(const string &token) +{ + return (token=="smooth" || token=="flat" || token=="noperspective"); } bool ProgramParser::is_precision_qualifier(const string &token) @@ -325,7 +330,11 @@ bool ProgramParser::is_precision_qualifier(const string &token) bool ProgramParser::is_qualifier(const string &token) { - return (token=="const" || is_interface_qualifier(token) || is_sampling_qualifier(token) || is_precision_qualifier(token)); + return (token=="const" || + is_interface_qualifier(token) || + is_sampling_qualifier(token) || + is_interpolation_qualifier(token) || + is_precision_qualifier(token)); } bool ProgramParser::is_builtin_type(const string &token) @@ -449,7 +458,7 @@ RefPtr ProgramParser::parse_global_declaration() else if(is_interface_qualifier(token)) { string next = peek_token(1); - if(is_type(next) || is_precision_qualifier(next)) + if(is_type(next) || is_qualifier(next)) return parse_variable_declaration(); else return parse_interface_block(); @@ -718,25 +727,22 @@ RefPtr ProgramParser::parse_variable_declaration() RefPtr var = new VariableDeclaration; string token = peek_token(); - if(is_sampling_qualifier(token)) - { - var->sampling = parse_token(); - token = peek_token(); - if(!is_interface_qualifier(token)) - throw runtime_error(format_syntax_error("an interface qualifier")); - } - - if(is_interface_qualifier(token)) - var->interface = parse_token(); - else if(token=="const") + while(is_qualifier(token)) { - var->constant = true; parse_token(); + if(is_interface_qualifier(token)) + var->interface = token; + else if(is_sampling_qualifier(token)) + var->sampling = token; + else if(is_interpolation_qualifier(token)) + var->interpolation = token; + else if(is_precision_qualifier(token)) + var->precision = token; + else if(token=="const") + var->constant = true; + token = peek_token(); } - if(is_precision_qualifier(token)) - var->precision = parse_token(); - var->type = expect_type(); var->name = expect_identifier(); @@ -847,14 +853,19 @@ RefPtr ProgramParser::parse_iteration() loop->init_statement = parse_statement(); else { - RefPtr expr = new ExpressionStatement; - expr->expression = parse_expression(); + if(token!=";") + { + RefPtr expr = new ExpressionStatement; + expr->expression = parse_expression(); + loop->init_statement = expr; + } expect(";"); - loop->init_statement = expr; } - loop->condition = parse_expression(); + if(peek_token()!=";") + loop->condition = parse_expression(); expect(";"); - loop->loop_expression = parse_expression(); + if(peek_token()!=")") + loop->loop_expression = parse_expression(); expect(")"); parse_block(loop->body, false);