From: Ian Romanick Date: Tue, 6 Apr 2010 00:01:53 +0000 (-0700) Subject: Begin tracking the nesting of loops and switch-statements X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=e9d0f265aabb39928d4d8a527684bf3b9eebc21c;p=mesa.git Begin tracking the nesting of loops and switch-statements --- diff --git a/ast_to_hir.cpp b/ast_to_hir.cpp index 823bab9dfa0..444cb7d54e3 100644 --- a/ast_to_hir.cpp +++ b/ast_to_hir.cpp @@ -2093,6 +2093,12 @@ ast_iteration_statement::hir(exec_list *instructions, ir_loop *const stmt = new ir_loop(); instructions->push_tail(stmt); + /* Track the current loop and / or switch-statement nesting. + */ + ir_instruction *const nesting = state->loop_or_switch_nesting; + state->loop_or_switch_nesting = stmt; + + if (condition != NULL) { ir_rvalue *const cond = condition->hir(& stmt->body_instructions, state); @@ -2135,6 +2141,10 @@ ast_iteration_statement::hir(exec_list *instructions, if (mode == ast_for) state->symbols->pop_scope(); + /* Restore previous nesting before returning. + */ + state->loop_or_switch_nesting = nesting; + /* Loops do not have r-values. */ return NULL; diff --git a/glsl_parser_extras.cpp b/glsl_parser_extras.cpp index 538d77c663c..877b165ad71 100644 --- a/glsl_parser_extras.cpp +++ b/glsl_parser_extras.cpp @@ -637,6 +637,7 @@ main(int argc, char **argv) state.symbols = new glsl_symbol_table; state.error = false; state.temp_index = 0; + state.loop_or_switch_nesting = NULL; _mesa_glsl_lexer_ctor(& state, shader, shader_len); _mesa_glsl_parse(& state); diff --git a/glsl_parser_extras.h b/glsl_parser_extras.h index 96c975ba117..373d295bba4 100644 --- a/glsl_parser_extras.h +++ b/glsl_parser_extras.h @@ -56,6 +56,9 @@ struct _mesa_glsl_parse_state { /** Index of last generated anonymous temporary. */ unsigned temp_index; + + /** Loop or switch statement containing the current instructions. */ + class ir_instruction *loop_or_switch_nesting; }; typedef struct YYLTYPE {