comparison src/vim9compile.c @ 27043:15f40772e10a v8.2.4050

patch 8.2.4050: Vim9: need to prefix every item in an autoload script Commit: https://github.com/vim/vim/commit/dc4451df61a6aa12a0661817b7094fb32f09e11d Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jan 9 21:36:37 2022 +0000 patch 8.2.4050: Vim9: need to prefix every item in an autoload script Problem: Vim9: need to prefix every item in an autoload script. Solution: First step in supporting "vim9script autoload" and "import autoload".
author Bram Moolenaar <Bram@vim.org>
date Sun, 09 Jan 2022 22:45:04 +0100
parents 18cafa092e8d
children f17bdc9cda64
comparison
equal deleted inserted replaced
27042:8fc14d120630 27043:15f40772e10a
266 { 266 {
267 return (cctx != NULL 267 return (cctx != NULL
268 && (lookup_local(name, len, NULL, cctx) == OK 268 && (lookup_local(name, len, NULL, cctx) == OK
269 || arg_exists(name, len, NULL, NULL, NULL, cctx) == OK)) 269 || arg_exists(name, len, NULL, NULL, NULL, cctx) == OK))
270 || script_var_exists(name, len, cctx) == OK 270 || script_var_exists(name, len, cctx) == OK
271 || find_imported(name, len, cctx) != NULL; 271 || find_imported(name, len, FALSE, cctx) != NULL;
272 } 272 }
273 273
274 /* 274 /*
275 * Return TRUE if "name" is a local variable, argument, script variable, 275 * Return TRUE if "name" is a local variable, argument, script variable,
276 * imported or function. 276 * imported or function.
329 329
330 p[len] = NUL; 330 p[len] = NUL;
331 if ((cctx != NULL 331 if ((cctx != NULL
332 && (lookup_local(p, len, NULL, cctx) == OK 332 && (lookup_local(p, len, NULL, cctx) == OK
333 || arg_exists(p, len, NULL, NULL, NULL, cctx) == OK)) 333 || arg_exists(p, len, NULL, NULL, NULL, cctx) == OK))
334 || find_imported(p, len, cctx) != NULL 334 || find_imported(p, len, FALSE, cctx) != NULL
335 || (ufunc = find_func_even_dead(p, FALSE, cctx)) != NULL) 335 || (ufunc = find_func_even_dead(p, FALSE, cctx)) != NULL)
336 { 336 {
337 // A local or script-local function can shadow a global function. 337 // A local or script-local function can shadow a global function.
338 if (ufunc == NULL || ((ufunc->uf_flags & FC_DEAD) == 0 338 if (ufunc == NULL || ((ufunc->uf_flags & FC_DEAD) == 0
339 && (!func_is_global(ufunc) 339 && (!func_is_global(ufunc)
579 } 579 }
580 580
581 /* 581 /*
582 * Find "name" in imported items of the current script or in "cctx" if not 582 * Find "name" in imported items of the current script or in "cctx" if not
583 * NULL. 583 * NULL.
584 * If "load" is TRUE and the script was not loaded yet, load it now.
584 */ 585 */
585 imported_T * 586 imported_T *
586 find_imported(char_u *name, size_t len, cctx_T *cctx) 587 find_imported(char_u *name, size_t len, int load, cctx_T *cctx)
587 { 588 {
588 int idx; 589 int idx;
590 imported_T *ret = NULL;
589 591
590 if (!SCRIPT_ID_VALID(current_sctx.sc_sid)) 592 if (!SCRIPT_ID_VALID(current_sctx.sc_sid))
591 return NULL; 593 return NULL;
592 if (cctx != NULL) 594 if (cctx != NULL)
593 for (idx = 0; idx < cctx->ctx_imports.ga_len; ++idx) 595 for (idx = 0; idx < cctx->ctx_imports.ga_len; ++idx)
596 + idx; 598 + idx;
597 599
598 if (len == 0 ? STRCMP(name, import->imp_name) == 0 600 if (len == 0 ? STRCMP(name, import->imp_name) == 0
599 : STRLEN(import->imp_name) == len 601 : STRLEN(import->imp_name) == len
600 && STRNCMP(name, import->imp_name, len) == 0) 602 && STRNCMP(name, import->imp_name, len) == 0)
601 return import; 603 {
602 } 604 ret = import;
603 605 break;
604 return find_imported_in_script(name, len, current_sctx.sc_sid); 606 }
607 }
608
609 if (ret == NULL)
610 ret = find_imported_in_script(name, len, current_sctx.sc_sid);
611
612 if (ret != NULL && load && ret->imp_flags == IMP_FLAGS_AUTOLOAD)
613 {
614 // script found before but not loaded yet
615 ret->imp_flags = 0;
616 (void)do_source(SCRIPT_ITEM(ret->imp_sid)->sn_name, FALSE,
617 DOSO_NONE, NULL);
618 }
619 return ret;
605 } 620 }
606 621
607 /* 622 /*
608 * Free all imported variables. 623 * Free all imported variables.
609 */ 624 */
1324 ? script_var_exists(var_start + 2, lhs->lhs_varlen - 2, 1339 ? script_var_exists(var_start + 2, lhs->lhs_varlen - 2,
1325 cctx) 1340 cctx)
1326 : script_var_exists(var_start, lhs->lhs_varlen, 1341 : script_var_exists(var_start, lhs->lhs_varlen,
1327 cctx)) == OK; 1342 cctx)) == OK;
1328 imported_T *import = 1343 imported_T *import =
1329 find_imported(var_start, lhs->lhs_varlen, cctx); 1344 find_imported(var_start, lhs->lhs_varlen, FALSE, cctx);
1330 1345
1331 if (script_namespace || script_var || import != NULL) 1346 if (script_namespace || script_var || import != NULL)
1332 { 1347 {
1333 char_u *rawname = lhs->lhs_name 1348 char_u *rawname = lhs->lhs_name
1334 + (lhs->lhs_name[1] == ':' ? 2 : 0); 1349 + (lhs->lhs_name[1] == ':' ? 2 : 0);