0
0
mirror of https://github.com/vim/vim.git synced 2025-09-24 03:44:06 -04:00

patch 9.0.0481: in :def function all closures in loop get the same variables

Problem:    In a :def function all closures in a loop get the same variables.
Solution:   Use a separate list of variables for LOADOUTER and STOREOUTER.
            Not copied at end of loop yet.
This commit is contained in:
Bram Moolenaar
2022-09-16 19:04:24 +01:00
parent abd58d8aee
commit 8fa745e7be
13 changed files with 285 additions and 77 deletions

View File

@@ -1245,6 +1245,49 @@ compile_endwhile(char_u *arg, cctx_T *cctx)
return arg;
}
/*
* Get the current information about variables declared inside a loop.
* Returns zero if there are none, otherwise the count.
* "loop_var_idx" is then set to the index of the first variable.
*/
short
get_loop_var_info(cctx_T *cctx, short *loop_var_idx)
{
scope_T *scope = cctx->ctx_scope;
int start_local_count;
while (scope != NULL && scope->se_type != WHILE_SCOPE
&& scope->se_type != FOR_SCOPE)
scope = scope->se_outer;
if (scope == NULL)
return 0;
if (scope->se_type == WHILE_SCOPE)
start_local_count = scope->se_u.se_while.ws_local_count;
else
start_local_count = scope->se_u.se_for.fs_local_count;
if (cctx->ctx_locals.ga_len > start_local_count)
{
*loop_var_idx = (short)start_local_count;
return (short)(cctx->ctx_locals.ga_len - start_local_count);
}
return 0;
}
/*
* Get the index of the first variable in a loop, if any.
* Returns -1 if none.
*/
int
get_loop_var_idx(cctx_T *cctx)
{
short loop_var_idx;
if (get_loop_var_info(cctx, &loop_var_idx) > 0)
return loop_var_idx;
return -1;
}
/*
* compile "continue"
*/