Mercurial > vim
comparison src/evalvars.c @ 19108:44c6498535c9 v8.2.0114
patch 8.2.0114: info about sourced scripts is scattered
Commit: https://github.com/vim/vim/commit/7ebcba61b20d25d23109fff73d0346ad44ba1b3b
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Jan 12 17:42:55 2020 +0100
patch 8.2.0114: info about sourced scripts is scattered
Problem: Info about sourced scripts is scattered.
Solution: Use scriptitem_T for info about a script, including s: variables.
Drop ga_scripts.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 12 Jan 2020 17:45:03 +0100 |
parents | ba9f50bfda83 |
children | 94eda51ba9ba |
comparison
equal
deleted
inserted
replaced
19107:d66161509163 | 19108:44c6498535c9 |
---|---|
161 #define vimvarht vimvardict.dv_hashtab | 161 #define vimvarht vimvardict.dv_hashtab |
162 | 162 |
163 // for VIM_VERSION_ defines | 163 // for VIM_VERSION_ defines |
164 #include "version.h" | 164 #include "version.h" |
165 | 165 |
166 /* | 166 #define SCRIPT_SV(id) (SCRIPT_ITEM(id).sn_vars) |
167 * Array to hold the hashtab with variables local to each sourced script. | |
168 * Each item holds a variable (nameless) that points to the dict_T. | |
169 */ | |
170 typedef struct | |
171 { | |
172 dictitem_T sv_var; | |
173 dict_T sv_dict; | |
174 } scriptvar_T; | |
175 | |
176 static garray_T ga_scripts = {0, 0, sizeof(scriptvar_T *), 4, NULL}; | |
177 #define SCRIPT_SV(id) (((scriptvar_T **)ga_scripts.ga_data)[(id) - 1]) | |
178 #define SCRIPT_VARS(id) (SCRIPT_SV(id)->sv_dict.dv_hashtab) | 167 #define SCRIPT_VARS(id) (SCRIPT_SV(id)->sv_dict.dv_hashtab) |
179 | 168 |
180 static void ex_let_const(exarg_T *eap, int is_const); | 169 static void ex_let_const(exarg_T *eap, int is_const); |
181 static char_u *skip_var_one(char_u *arg); | 170 static char_u *skip_var_one(char_u *arg); |
182 static void list_glob_vars(int *first); | 171 static void list_glob_vars(int *first); |
287 hash_clear(&compat_hashtab); | 276 hash_clear(&compat_hashtab); |
288 | 277 |
289 // global variables | 278 // global variables |
290 vars_clear(&globvarht); | 279 vars_clear(&globvarht); |
291 | 280 |
292 // Script-local variables. First clear all the variables and in a second | 281 // Script-local variables. Clear all the variables here. |
293 // loop free the scriptvar_T, because a variable in one script might hold | 282 // The scriptvar_T is cleared later in free_scriptnames(), because a |
294 // a reference to the whole scope of another script. | 283 // variable in one script might hold a reference to the whole scope of |
295 for (i = 1; i <= ga_scripts.ga_len; ++i) | 284 // another script. |
285 for (i = 1; i <= script_items.ga_len; ++i) | |
296 vars_clear(&SCRIPT_VARS(i)); | 286 vars_clear(&SCRIPT_VARS(i)); |
297 for (i = 1; i <= ga_scripts.ga_len; ++i) | |
298 vim_free(SCRIPT_SV(i)); | |
299 ga_clear(&ga_scripts); | |
300 } | 287 } |
301 #endif | 288 #endif |
302 | 289 |
303 int | 290 int |
304 garbage_collect_globvars(int copyID) | 291 garbage_collect_globvars(int copyID) |
316 garbage_collect_scriptvars(int copyID) | 303 garbage_collect_scriptvars(int copyID) |
317 { | 304 { |
318 int i; | 305 int i; |
319 int abort = FALSE; | 306 int abort = FALSE; |
320 | 307 |
321 for (i = 1; i <= ga_scripts.ga_len; ++i) | 308 for (i = 1; i <= script_items.ga_len; ++i) |
322 abort = abort || set_ref_in_ht(&SCRIPT_VARS(i), copyID, NULL); | 309 abort = abort || set_ref_in_ht(&SCRIPT_VARS(i), copyID, NULL); |
323 | 310 |
324 return abort; | 311 return abort; |
325 } | 312 } |
326 | 313 |
536 * List script-local variables, if there is a script. | 523 * List script-local variables, if there is a script. |
537 */ | 524 */ |
538 static void | 525 static void |
539 list_script_vars(int *first) | 526 list_script_vars(int *first) |
540 { | 527 { |
541 if (current_sctx.sc_sid > 0 && current_sctx.sc_sid <= ga_scripts.ga_len) | 528 if (current_sctx.sc_sid > 0 && current_sctx.sc_sid <= script_items.ga_len) |
542 list_hashtable_vars(&SCRIPT_VARS(current_sctx.sc_sid), | 529 list_hashtable_vars(&SCRIPT_VARS(current_sctx.sc_sid), |
543 "s:", FALSE, first); | 530 "s:", FALSE, first); |
544 } | 531 } |
545 | 532 |
546 /* | 533 /* |
2431 return get_funccal_args_ht(); | 2418 return get_funccal_args_ht(); |
2432 if (*name == 'l') // l: local function variable | 2419 if (*name == 'l') // l: local function variable |
2433 return get_funccal_local_ht(); | 2420 return get_funccal_local_ht(); |
2434 if (*name == 's' // script variable | 2421 if (*name == 's' // script variable |
2435 && current_sctx.sc_sid > 0 | 2422 && current_sctx.sc_sid > 0 |
2436 && current_sctx.sc_sid <= ga_scripts.ga_len) | 2423 && current_sctx.sc_sid <= script_items.ga_len) |
2437 return &SCRIPT_VARS(current_sctx.sc_sid); | 2424 return &SCRIPT_VARS(current_sctx.sc_sid); |
2438 return NULL; | 2425 return NULL; |
2439 } | 2426 } |
2440 | 2427 |
2441 /* | 2428 /* |
2459 * sourcing this script and when executing functions defined in the script. | 2446 * sourcing this script and when executing functions defined in the script. |
2460 */ | 2447 */ |
2461 void | 2448 void |
2462 new_script_vars(scid_T id) | 2449 new_script_vars(scid_T id) |
2463 { | 2450 { |
2464 int i; | |
2465 hashtab_T *ht; | |
2466 scriptvar_T *sv; | 2451 scriptvar_T *sv; |
2467 | 2452 |
2468 if (ga_grow(&ga_scripts, (int)(id - ga_scripts.ga_len)) == OK) | 2453 sv = ALLOC_CLEAR_ONE(scriptvar_T); |
2469 { | 2454 if (sv == NULL) |
2470 // Re-allocating ga_data means that an ht_array pointing to | 2455 return; |
2471 // ht_smallarray becomes invalid. We can recognize this: ht_mask is | 2456 init_var_dict(&sv->sv_dict, &sv->sv_var, VAR_SCOPE); |
2472 // at its init value. Also reset "v_dict", it's always the same. | 2457 SCRIPT_ITEM(id).sn_vars = sv; |
2473 for (i = 1; i <= ga_scripts.ga_len; ++i) | |
2474 { | |
2475 ht = &SCRIPT_VARS(i); | |
2476 if (ht->ht_mask == HT_INIT_SIZE - 1) | |
2477 ht->ht_array = ht->ht_smallarray; | |
2478 sv = SCRIPT_SV(i); | |
2479 sv->sv_var.di_tv.vval.v_dict = &sv->sv_dict; | |
2480 } | |
2481 | |
2482 while (ga_scripts.ga_len < id) | |
2483 { | |
2484 sv = SCRIPT_SV(ga_scripts.ga_len + 1) = | |
2485 ALLOC_CLEAR_ONE(scriptvar_T); | |
2486 init_var_dict(&sv->sv_dict, &sv->sv_var, VAR_SCOPE); | |
2487 ++ga_scripts.ga_len; | |
2488 } | |
2489 } | |
2490 } | 2458 } |
2491 | 2459 |
2492 /* | 2460 /* |
2493 * Initialize dictionary "dict" as a scope and set variable "dict_var" to | 2461 * Initialize dictionary "dict" as a scope and set variable "dict_var" to |
2494 * point to it. | 2462 * point to it. |