X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fprogramparser.cpp;h=c02adb325c25eaba6d4df7f31d9b8963506a5cd4;hp=f38f39097615c94185c0d4bf7504d70e0dc7d646;hb=ff85f90d33023d908c534b0bf5d9a65e9fc2cce2;hpb=684fadb0eb3e6a7dc274d6ed26abd28d5787d60d diff --git a/source/programparser.cpp b/source/programparser.cpp index f38f3909..c02adb32 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(); @@ -475,7 +484,9 @@ RefPtr ProgramParser::parse_statement() if(token=="if") return parse_conditional(); else if(token=="for") - return parse_iteration(); + return parse_for(); + else if(token=="while") + return parse_while(); else if(token=="passthrough") return parse_passthrough(); else if(token=="return") @@ -718,25 +729,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(); @@ -837,7 +845,7 @@ RefPtr ProgramParser::parse_conditional() return cond; } -RefPtr ProgramParser::parse_iteration() +RefPtr ProgramParser::parse_for() { expect("for"); expect("("); @@ -847,14 +855,32 @@ 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); + + return loop; +} + +RefPtr ProgramParser::parse_while() +{ + expect("while"); + expect("("); + RefPtr loop = new Iteration; + loop->condition = parse_expression(); expect(")"); parse_block(loop->body, false);