From 42fc1323e16a948c64950012c679231e916c9124 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sat, 11 Jan 2025 13:20:46 +0900 Subject: [PATCH] [qfcc] Clean up glsl for loops The changes for deferred semantics in Ruamoko broke for loops for GLSL, but matching GLSL's structure to Ruamoko's cleaned things up nicely. --- tools/qfcc/source/glsl-parse.y | 41 +++++++++++++++++----------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/tools/qfcc/source/glsl-parse.y b/tools/qfcc/source/glsl-parse.y index 798fee123..dae446652 100644 --- a/tools/qfcc/source/glsl-parse.y +++ b/tools/qfcc/source/glsl-parse.y @@ -170,7 +170,7 @@ int yylex (YYSTYPE *yylval, YYLTYPE *yylloc); %type block_declaration %type declaration constant_expression %type expression primary_exprsssion assignment_expression -%type for_init_statement conditionopt expressionopt else line +%type for_init_statement opt_cond opt_expr else line %type conditional_expression unary_expression postfix_expression %type function_call function_call_or_method function_call_generic %type function_call_header_with_parameters identifier_list @@ -1111,12 +1111,8 @@ simple_statement ; compound_statement - : '{' '}' { $$ = nullptr; } - | '{' new_scope statement_list '}' - { - $$ = $3; - current_symtab = $new_scope->block.scope->parent; - } + : '{' '}' { $$ = nullptr; } + | '{' new_scope statement_list '}' end_scope { $$ = $3; } ; statement_no_new_scope @@ -1148,6 +1144,13 @@ new_scope } ; +end_scope + : /* empty */ + { + current_symtab = current_symtab->parent; + } + ; + statement_list : statement { @@ -1267,22 +1270,20 @@ iteration_statement continue_label = $continue_label; } | FOR new_scope break_label continue_label - '(' for_init_statement conditionopt ';' expressionopt ')' - statement_no_new_scope + '(' for_init_statement[init] opt_cond[test] ';' opt_expr[cont] ')' + statement_no_new_scope[body] end_scope { - auto loop = new_loop_expr (false, false, $conditionopt, - $statement_no_new_scope, - continue_label, $expressionopt, - break_label); - auto block = new_block_expr (nullptr); - if ($for_init_statement) { - append_expr (block, $for_init_statement); + auto test = $test; + if (!test) { + test = new_bool_expr (true); } + auto loop = new_loop_expr (false, false, test, $body, + continue_label, $cont, break_label); + auto block = $new_scope; + append_expr (block, $init); $$ = append_expr (block, loop); - break_label = $break_label; continue_label = $continue_label; - current_symtab = $new_scope->block.scope->parent; } ; @@ -1291,12 +1292,12 @@ for_init_statement | declaration_statement ; -conditionopt +opt_cond : condition | /* emtpy */ { $$ = nullptr; } ; -expressionopt +opt_expr : expression | /* emtpy */ { $$ = nullptr; } ;