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

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".
This commit is contained in:
Bram Moolenaar
2022-01-09 21:36:37 +00:00
parent 5f25c38550
commit dc4451df61
15 changed files with 402 additions and 117 deletions

View File

@@ -268,7 +268,7 @@ variable_exists(char_u *name, size_t len, cctx_T *cctx)
&& (lookup_local(name, len, NULL, cctx) == OK
|| arg_exists(name, len, NULL, NULL, NULL, cctx) == OK))
|| script_var_exists(name, len, cctx) == OK
|| find_imported(name, len, cctx) != NULL;
|| find_imported(name, len, FALSE, cctx) != NULL;
}
/*
@@ -331,7 +331,7 @@ check_defined(char_u *p, size_t len, cctx_T *cctx, int is_arg)
if ((cctx != NULL
&& (lookup_local(p, len, NULL, cctx) == OK
|| arg_exists(p, len, NULL, NULL, NULL, cctx) == OK))
|| find_imported(p, len, cctx) != NULL
|| find_imported(p, len, FALSE, cctx) != NULL
|| (ufunc = find_func_even_dead(p, FALSE, cctx)) != NULL)
{
// A local or script-local function can shadow a global function.
@@ -581,11 +581,13 @@ find_imported_in_script(char_u *name, size_t len, int sid)
/*
* Find "name" in imported items of the current script or in "cctx" if not
* NULL.
* If "load" is TRUE and the script was not loaded yet, load it now.
*/
imported_T *
find_imported(char_u *name, size_t len, cctx_T *cctx)
find_imported(char_u *name, size_t len, int load, cctx_T *cctx)
{
int idx;
imported_T *ret = NULL;
if (!SCRIPT_ID_VALID(current_sctx.sc_sid))
return NULL;
@@ -598,10 +600,23 @@ find_imported(char_u *name, size_t len, cctx_T *cctx)
if (len == 0 ? STRCMP(name, import->imp_name) == 0
: STRLEN(import->imp_name) == len
&& STRNCMP(name, import->imp_name, len) == 0)
return import;
{
ret = import;
break;
}
}
return find_imported_in_script(name, len, current_sctx.sc_sid);
if (ret == NULL)
ret = find_imported_in_script(name, len, current_sctx.sc_sid);
if (ret != NULL && load && ret->imp_flags == IMP_FLAGS_AUTOLOAD)
{
// script found before but not loaded yet
ret->imp_flags = 0;
(void)do_source(SCRIPT_ITEM(ret->imp_sid)->sn_name, FALSE,
DOSO_NONE, NULL);
}
return ret;
}
/*
@@ -1326,7 +1341,7 @@ compile_lhs(
: script_var_exists(var_start, lhs->lhs_varlen,
cctx)) == OK;
imported_T *import =
find_imported(var_start, lhs->lhs_varlen, cctx);
find_imported(var_start, lhs->lhs_varlen, FALSE, cctx);
if (script_namespace || script_var || import != NULL)
{