0
0
mirror of https://github.com/vim/vim.git synced 2025-09-25 03:54:15 -04:00

patch 8.2.4989: cannot specify a function name for :defcompile

Problem:    Cannot specify a function name for :defcompile.
Solution:   Implement a function name argument for :defcompile.
This commit is contained in:
Bram Moolenaar
2022-05-21 15:39:02 +01:00
parent 2d8ed0203a
commit f79d9dd43f
8 changed files with 127 additions and 65 deletions

View File

@@ -4996,37 +4996,116 @@ ex_function(exarg_T *eap)
ga_clear_strings(&lines_to_free);
}
/*
* Find a function by name, including "<lambda>123".
* Check for "profile" and "debug" arguments and set"compile_type".
* Return NULL if not found.
*/
ufunc_T *
find_func_by_name(char_u *name, compiletype_T *compile_type)
{
char_u *arg = name;
char_u *fname;
ufunc_T *ufunc;
int is_global = FALSE;
*compile_type = CT_NONE;
if (STRNCMP(arg, "profile", 7) == 0 && VIM_ISWHITE(arg[7]))
{
*compile_type = CT_PROFILE;
arg = skipwhite(arg + 7);
}
else if (STRNCMP(arg, "debug", 5) == 0 && VIM_ISWHITE(arg[5]))
{
*compile_type = CT_DEBUG;
arg = skipwhite(arg + 5);
}
if (STRNCMP(arg, "<lambda>", 8) == 0)
{
arg += 8;
(void)getdigits(&arg);
fname = vim_strnsave(name, arg - name);
}
else
fname = trans_function_name(&arg, &is_global, FALSE,
TFN_INT | TFN_QUIET | TFN_NO_AUTOLOAD, NULL, NULL, NULL);
if (fname == NULL)
{
semsg(_(e_invalid_argument_str), name);
return NULL;
}
if (!ends_excmd2(name, arg))
{
emsg(ex_errmsg(e_trailing_characters_str, arg));
return NULL;
}
ufunc = find_func(fname, is_global);
if (ufunc == NULL)
{
char_u *p = untrans_function_name(fname);
if (p != NULL)
// Try again without making it script-local.
ufunc = find_func(p, FALSE);
}
vim_free(fname);
if (ufunc == NULL)
semsg(_(e_cannot_find_function_str), name);
return ufunc;
}
/*
* :defcompile - compile all :def functions in the current script that need to
* be compiled. Except dead functions. Doesn't do profiling.
* be compiled or the one specified by the argument.
* Skips dead functions. Doesn't do profiling.
*/
void
ex_defcompile(exarg_T *eap UNUSED)
ex_defcompile(exarg_T *eap)
{
long todo = (long)func_hashtab.ht_used;
int changed = func_hashtab.ht_changed;
hashitem_T *hi;
ufunc_T *ufunc;
for (hi = func_hashtab.ht_array; todo > 0 && !got_int; ++hi)
if (*eap->arg != NUL)
{
if (!HASHITEM_EMPTY(hi))
{
--todo;
ufunc = HI2UF(hi);
if (ufunc->uf_script_ctx.sc_sid == current_sctx.sc_sid
&& ufunc->uf_def_status == UF_TO_BE_COMPILED
&& (ufunc->uf_flags & FC_DEAD) == 0)
{
(void)compile_def_function(ufunc, FALSE, CT_NONE, NULL);
compiletype_T compile_type;
if (func_hashtab.ht_changed != changed)
ufunc = find_func_by_name(eap->arg, &compile_type);
if (ufunc != NULL)
{
if (func_needs_compiling(ufunc, compile_type))
(void)compile_def_function(ufunc, FALSE, compile_type, NULL);
else
smsg(_("Function %s does not need compiling"), eap->arg);
}
}
else
{
long todo = (long)func_hashtab.ht_used;
int changed = func_hashtab.ht_changed;
hashitem_T *hi;
for (hi = func_hashtab.ht_array; todo > 0 && !got_int; ++hi)
{
if (!HASHITEM_EMPTY(hi))
{
--todo;
ufunc = HI2UF(hi);
if (ufunc->uf_script_ctx.sc_sid == current_sctx.sc_sid
&& ufunc->uf_def_status == UF_TO_BE_COMPILED
&& (ufunc->uf_flags & FC_DEAD) == 0)
{
// a function has been added or removed, need to start over
todo = (long)func_hashtab.ht_used;
changed = func_hashtab.ht_changed;
hi = func_hashtab.ht_array;
--hi;
(void)compile_def_function(ufunc, FALSE, CT_NONE, NULL);
if (func_hashtab.ht_changed != changed)
{
// a function has been added or removed, need to start
// over
todo = (long)func_hashtab.ht_used;
changed = func_hashtab.ht_changed;
hi = func_hashtab.ht_array;
--hi;
}
}
}
}