mirror of
https://github.com/vim/vim.git
synced 2025-07-26 11:04:33 -04:00
patch 8.2.4367: calling in_vim9script() multiple times
Problem: Calling in_vim9script() multiple times. Solution: Call it once and keep the result.
This commit is contained in:
parent
4d03d87000
commit
4525a57afb
65
src/eval.c
65
src/eval.c
@ -865,6 +865,7 @@ get_lval(
|
||||
hashtab_T *ht = NULL;
|
||||
int quiet = flags & GLV_QUIET;
|
||||
int writing;
|
||||
int vim9script = in_vim9script();
|
||||
|
||||
// Clear everything in "lp".
|
||||
CLEAR_POINTER(lp);
|
||||
@ -879,7 +880,7 @@ get_lval(
|
||||
}
|
||||
|
||||
// Cannot use "s:var" at the Vim9 script level. "s: type" is OK.
|
||||
if (in_vim9script() && at_script_level()
|
||||
if (vim9script && at_script_level()
|
||||
&& name[0] == 's' && name[1] == ':' && !VIM_ISWHITE(name[2]))
|
||||
{
|
||||
semsg(_(e_cannot_use_s_colon_in_vim9_script_str), name);
|
||||
@ -918,7 +919,7 @@ get_lval(
|
||||
{
|
||||
lp->ll_name = name;
|
||||
|
||||
if (in_vim9script())
|
||||
if (vim9script)
|
||||
{
|
||||
// "a: type" is declaring variable "a" with a type, not "a:".
|
||||
if (p == name + 2 && p[-1] == ':')
|
||||
@ -996,7 +997,7 @@ get_lval(
|
||||
if ((*p != '[' && *p != '.'))
|
||||
return p;
|
||||
|
||||
if (in_vim9script() && lval_root != NULL)
|
||||
if (vim9script && lval_root != NULL)
|
||||
{
|
||||
// using local variable
|
||||
lp->ll_tv = lval_root;
|
||||
@ -1018,7 +1019,7 @@ get_lval(
|
||||
lp->ll_tv = &v->di_tv;
|
||||
}
|
||||
|
||||
if (in_vim9script() && (flags & GLV_NO_DECL) == 0)
|
||||
if (vim9script && (flags & GLV_NO_DECL) == 0)
|
||||
{
|
||||
if (!quiet)
|
||||
semsg(_(e_variable_already_declared), lp->ll_name);
|
||||
@ -1061,7 +1062,7 @@ get_lval(
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (in_vim9script() && lp->ll_valtype == NULL
|
||||
if (vim9script && lp->ll_valtype == NULL
|
||||
&& v != NULL
|
||||
&& lp->ll_tv == &v->di_tv
|
||||
&& ht != NULL && ht == get_script_local_ht())
|
||||
@ -2612,7 +2613,7 @@ eval2(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
|
||||
*arg = eval_next_line(evalarg_used);
|
||||
else
|
||||
{
|
||||
if (evaluate && in_vim9script() && !VIM_ISWHITE(p[-1]))
|
||||
if (evaluate && vim9script && !VIM_ISWHITE(p[-1]))
|
||||
{
|
||||
error_white_both(p, 2);
|
||||
clear_tv(rettv);
|
||||
@ -2624,7 +2625,7 @@ eval2(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
|
||||
/*
|
||||
* Get the second variable.
|
||||
*/
|
||||
if (evaluate && in_vim9script() && !IS_WHITE_OR_NUL((*arg)[2]))
|
||||
if (evaluate && vim9script && !IS_WHITE_OR_NUL((*arg)[2]))
|
||||
{
|
||||
error_white_both(*arg, 2);
|
||||
clear_tv(rettv);
|
||||
@ -2750,7 +2751,7 @@ eval3(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
|
||||
/*
|
||||
* Get the second variable.
|
||||
*/
|
||||
if (evaluate && in_vim9script() && !IS_WHITE_OR_NUL((*arg)[2]))
|
||||
if (evaluate && vim9script && !IS_WHITE_OR_NUL((*arg)[2]))
|
||||
{
|
||||
error_white_both(*arg, 2);
|
||||
clear_tv(rettv);
|
||||
@ -3527,7 +3528,8 @@ eval7(
|
||||
char_u *start_leader, *end_leader;
|
||||
int ret = OK;
|
||||
char_u *alias;
|
||||
static int recurse = 0;
|
||||
static int recurse = 0;
|
||||
int vim9script = in_vim9script();
|
||||
|
||||
/*
|
||||
* Initialise variable so that clear_tv() can't mistake this for a
|
||||
@ -3539,7 +3541,7 @@ eval7(
|
||||
* Skip '!', '-' and '+' characters. They are handled later.
|
||||
*/
|
||||
start_leader = *arg;
|
||||
if (eval_leader(arg, in_vim9script()) == FAIL)
|
||||
if (eval_leader(arg, vim9script) == FAIL)
|
||||
return FAIL;
|
||||
end_leader = *arg;
|
||||
|
||||
@ -3614,7 +3616,7 @@ eval7(
|
||||
/*
|
||||
* Dictionary: #{key: val, key: val}
|
||||
*/
|
||||
case '#': if (in_vim9script())
|
||||
case '#': if (vim9script)
|
||||
{
|
||||
ret = vim9_bad_comment(*arg) ? FAIL : NOTDONE;
|
||||
}
|
||||
@ -3631,10 +3633,10 @@ eval7(
|
||||
* Lambda: {arg, arg -> expr}
|
||||
* Dictionary: {'key': val, 'key': val}
|
||||
*/
|
||||
case '{': if (in_vim9script())
|
||||
case '{': if (vim9script)
|
||||
ret = NOTDONE;
|
||||
else
|
||||
ret = get_lambda_tv(arg, rettv, in_vim9script(), evalarg);
|
||||
ret = get_lambda_tv(arg, rettv, vim9script, evalarg);
|
||||
if (ret == NOTDONE)
|
||||
ret = eval_dict(arg, rettv, evalarg, FALSE);
|
||||
break;
|
||||
@ -3657,9 +3659,9 @@ eval7(
|
||||
case '@': ++*arg;
|
||||
if (evaluate)
|
||||
{
|
||||
if (in_vim9script() && IS_WHITE_OR_NUL(**arg))
|
||||
if (vim9script && IS_WHITE_OR_NUL(**arg))
|
||||
semsg(_(e_syntax_error_at_str), *arg);
|
||||
else if (in_vim9script() && !valid_yank_reg(**arg, FALSE))
|
||||
else if (vim9script && !valid_yank_reg(**arg, FALSE))
|
||||
emsg_invreg(**arg);
|
||||
else
|
||||
{
|
||||
@ -3677,7 +3679,7 @@ eval7(
|
||||
* or lambda: (arg) => expr
|
||||
*/
|
||||
case '(': ret = NOTDONE;
|
||||
if (in_vim9script())
|
||||
if (vim9script)
|
||||
{
|
||||
ret = get_lambda_tv(arg, rettv, TRUE, evalarg);
|
||||
if (ret == OK && evaluate)
|
||||
@ -3735,18 +3737,18 @@ eval7(
|
||||
{
|
||||
int flags = evalarg == NULL ? 0 : evalarg->eval_flags;
|
||||
|
||||
if (evaluate && in_vim9script() && len == 1 && *s == '_')
|
||||
if (evaluate && vim9script && len == 1 && *s == '_')
|
||||
{
|
||||
emsg(_(e_cannot_use_underscore_here));
|
||||
ret = FAIL;
|
||||
}
|
||||
else if (evaluate && in_vim9script() && len > 2
|
||||
else if (evaluate && vim9script && len > 2
|
||||
&& s[0] == 's' && s[1] == ':')
|
||||
{
|
||||
semsg(_(e_cannot_use_s_colon_in_vim9_script_str), s);
|
||||
ret = FAIL;
|
||||
}
|
||||
else if ((in_vim9script() ? **arg : *skipwhite(*arg)) == '(')
|
||||
else if ((vim9script ? **arg : *skipwhite(*arg)) == '(')
|
||||
{
|
||||
// "name(..." recursive!
|
||||
*arg = skipwhite(*arg);
|
||||
@ -3757,21 +3759,19 @@ eval7(
|
||||
else if (evaluate)
|
||||
{
|
||||
// get the value of "true", "false" or a variable
|
||||
if (len == 4 && in_vim9script() && STRNCMP(s, "true", 4) == 0)
|
||||
if (len == 4 && vim9script && STRNCMP(s, "true", 4) == 0)
|
||||
{
|
||||
rettv->v_type = VAR_BOOL;
|
||||
rettv->vval.v_number = VVAL_TRUE;
|
||||
ret = OK;
|
||||
}
|
||||
else if (len == 5 && in_vim9script()
|
||||
&& STRNCMP(s, "false", 5) == 0)
|
||||
else if (len == 5 && vim9script && STRNCMP(s, "false", 5) == 0)
|
||||
{
|
||||
rettv->v_type = VAR_BOOL;
|
||||
rettv->vval.v_number = VVAL_FALSE;
|
||||
ret = OK;
|
||||
}
|
||||
else if (len == 4 && in_vim9script()
|
||||
&& STRNCMP(s, "null", 4) == 0)
|
||||
else if (len == 4 && vim9script && STRNCMP(s, "null", 4) == 0)
|
||||
{
|
||||
rettv->v_type = VAR_SPECIAL;
|
||||
rettv->vval.v_number = VVAL_NULL;
|
||||
@ -3826,6 +3826,7 @@ eval7_leader(
|
||||
int error = FALSE;
|
||||
varnumber_T val = 0;
|
||||
vartype_T type = rettv->v_type;
|
||||
int vim9script = in_vim9script();
|
||||
#ifdef FEAT_FLOAT
|
||||
float_T f = 0.0;
|
||||
|
||||
@ -3836,7 +3837,7 @@ eval7_leader(
|
||||
{
|
||||
while (VIM_ISWHITE(end_leader[-1]))
|
||||
--end_leader;
|
||||
if (in_vim9script() && end_leader[-1] == '!')
|
||||
if (vim9script && end_leader[-1] == '!')
|
||||
val = tv2bool(rettv);
|
||||
else
|
||||
val = tv_get_number_chk(rettv, &error);
|
||||
@ -3861,7 +3862,7 @@ eval7_leader(
|
||||
#ifdef FEAT_FLOAT
|
||||
if (rettv->v_type == VAR_FLOAT)
|
||||
{
|
||||
if (in_vim9script())
|
||||
if (vim9script)
|
||||
{
|
||||
rettv->v_type = VAR_BOOL;
|
||||
val = f == 0.0 ? VVAL_TRUE : VVAL_FALSE;
|
||||
@ -3899,7 +3900,7 @@ eval7_leader(
|
||||
#endif
|
||||
{
|
||||
clear_tv(rettv);
|
||||
if (in_vim9script())
|
||||
if (vim9script)
|
||||
rettv->v_type = type;
|
||||
else
|
||||
rettv->v_type = VAR_NUMBER;
|
||||
@ -4151,7 +4152,7 @@ eval_index(
|
||||
int range = FALSE;
|
||||
char_u *key = NULL;
|
||||
int keylen = -1;
|
||||
int vim9 = in_vim9script();
|
||||
int vim9script = in_vim9script();
|
||||
|
||||
if (check_can_index(rettv, evaluate, verbose) == FAIL)
|
||||
return FAIL;
|
||||
@ -4182,7 +4183,7 @@ eval_index(
|
||||
empty1 = TRUE;
|
||||
else if (eval1(arg, &var1, evalarg) == FAIL) // recursive!
|
||||
return FAIL;
|
||||
else if (vim9 && **arg == ':')
|
||||
else if (vim9script && **arg == ':')
|
||||
{
|
||||
semsg(_(e_white_space_required_before_and_after_str_at_str),
|
||||
":", *arg);
|
||||
@ -4195,14 +4196,14 @@ eval_index(
|
||||
|
||||
#ifdef FEAT_FLOAT
|
||||
// allow for indexing with float
|
||||
if (vim9 && rettv->v_type == VAR_DICT
|
||||
if (vim9script && rettv->v_type == VAR_DICT
|
||||
&& var1.v_type == VAR_FLOAT)
|
||||
{
|
||||
var1.vval.v_string = typval_tostring(&var1, TRUE);
|
||||
var1.v_type = VAR_STRING;
|
||||
}
|
||||
#endif
|
||||
if (vim9 && rettv->v_type == VAR_LIST)
|
||||
if (vim9script && rettv->v_type == VAR_LIST)
|
||||
tv_get_number_chk(&var1, &error);
|
||||
else
|
||||
error = tv_get_string_chk(&var1) == NULL;
|
||||
@ -4222,7 +4223,7 @@ eval_index(
|
||||
{
|
||||
range = TRUE;
|
||||
++*arg;
|
||||
if (vim9 && !IS_WHITE_OR_NUL(**arg) && **arg != ']')
|
||||
if (vim9script && !IS_WHITE_OR_NUL(**arg) && **arg != ']')
|
||||
{
|
||||
semsg(_(e_white_space_required_before_and_after_str_at_str),
|
||||
":", *arg - 1);
|
||||
|
@ -1328,8 +1328,9 @@ get_lambda_tv(
|
||||
int equal_arrow = **arg == '(';
|
||||
int white_error = FALSE;
|
||||
int called_emsg_start = called_emsg;
|
||||
int vim9script = in_vim9script();
|
||||
|
||||
if (equal_arrow && !in_vim9script())
|
||||
if (equal_arrow && !vim9script)
|
||||
return NOTDONE;
|
||||
|
||||
ga_init(&newargs);
|
||||
@ -1360,7 +1361,7 @@ get_lambda_tv(
|
||||
FALSE, NULL, NULL);
|
||||
if (ret == FAIL
|
||||
|| (s = skip_arrow(*arg, equal_arrow, &ret_type,
|
||||
equal_arrow || in_vim9script() ? &white_error : NULL)) == NULL)
|
||||
equal_arrow || vim9script ? &white_error : NULL)) == NULL)
|
||||
{
|
||||
if (types_optional)
|
||||
ga_clear_strings(&argtypes);
|
||||
@ -1485,7 +1486,7 @@ get_lambda_tv(
|
||||
if (types_optional)
|
||||
{
|
||||
if (parse_argument_types(fp, &argtypes,
|
||||
in_vim9script() && varargs) == FAIL)
|
||||
vim9script && varargs) == FAIL)
|
||||
goto errret;
|
||||
if (ret_type != NULL)
|
||||
{
|
||||
@ -1514,7 +1515,7 @@ get_lambda_tv(
|
||||
flags |= FC_SANDBOX;
|
||||
// In legacy script a lambda can be called with more args than
|
||||
// uf_args.ga_len. In Vim9 script "...name" has to be used.
|
||||
fp->uf_varargs = !in_vim9script() || varargs;
|
||||
fp->uf_varargs = !vim9script || varargs;
|
||||
fp->uf_flags = flags;
|
||||
fp->uf_calls = 0;
|
||||
fp->uf_script_ctx = current_sctx;
|
||||
@ -1779,7 +1780,7 @@ get_func_tv(
|
||||
}
|
||||
|
||||
ret = call_func(name, len, rettv, argcount, argvars, funcexe);
|
||||
if (in_vim9script() && did_emsg > did_emsg_before)
|
||||
if (vim9script && did_emsg > did_emsg_before)
|
||||
{
|
||||
// An error in a builtin function does not return FAIL, but we do
|
||||
// want to abort further processing if an error was given.
|
||||
@ -1800,7 +1801,7 @@ get_func_tv(
|
||||
while (--argcount >= 0)
|
||||
clear_tv(&argvars[argcount]);
|
||||
|
||||
if (in_vim9script())
|
||||
if (vim9script)
|
||||
*arg = argp;
|
||||
else
|
||||
*arg = skipwhite(argp);
|
||||
@ -3714,7 +3715,8 @@ trans_function_name(
|
||||
int extra = 0;
|
||||
int prefix_g = FALSE;
|
||||
lval_T lv;
|
||||
int vim9script;
|
||||
int vim9script = in_vim9script();
|
||||
int vim9_local;
|
||||
|
||||
if (fdp != NULL)
|
||||
CLEAR_POINTER(fdp);
|
||||
@ -3739,7 +3741,7 @@ trans_function_name(
|
||||
// Note that TFN_ flags use the same values as GLV_ flags.
|
||||
end = get_lval(start, NULL, &lv, FALSE, skip, flags | GLV_READ_ONLY,
|
||||
lead > 2 ? 0 : FNE_CHECK_START);
|
||||
if (end == start || (in_vim9script() && end != NULL
|
||||
if (end == start || (vim9script && end != NULL
|
||||
&& end[-1] == AUTOLOAD_CHAR && *end == '('))
|
||||
{
|
||||
if (!skip)
|
||||
@ -3905,7 +3907,7 @@ trans_function_name(
|
||||
|
||||
// In Vim9 script a user function is script-local by default, unless it
|
||||
// starts with a lower case character: dict.func().
|
||||
vim9script = ASCII_ISUPPER(*start) && in_vim9script();
|
||||
vim9_local = ASCII_ISUPPER(*start) && vim9script;
|
||||
|
||||
/*
|
||||
* Copy the function name to allocated memory.
|
||||
@ -3914,13 +3916,13 @@ trans_function_name(
|
||||
*/
|
||||
if (skip)
|
||||
lead = 0; // do nothing
|
||||
else if (lead > 0 || vim9script)
|
||||
else if (lead > 0 || vim9_local)
|
||||
{
|
||||
if (!vim9script)
|
||||
if (!vim9_local)
|
||||
{
|
||||
if (in_vim9script() && lead == 2 && !ASCII_ISUPPER(*lv.ll_name))
|
||||
if (vim9script && lead == 2 && !ASCII_ISUPPER(*lv.ll_name))
|
||||
{
|
||||
semsg(_(in_vim9script()
|
||||
semsg(_(vim9script
|
||||
? e_function_name_must_start_with_capital_str
|
||||
: e_function_name_must_start_with_capital_or_s_str),
|
||||
start);
|
||||
@ -3928,7 +3930,7 @@ trans_function_name(
|
||||
}
|
||||
lead = 3;
|
||||
}
|
||||
if (vim9script || (lv.ll_exp_name != NULL
|
||||
if (vim9_local || (lv.ll_exp_name != NULL
|
||||
&& eval_fname_sid(lv.ll_exp_name))
|
||||
|| eval_fname_sid(*pp))
|
||||
{
|
||||
@ -3939,17 +3941,16 @@ trans_function_name(
|
||||
goto theend;
|
||||
}
|
||||
sprintf((char *)sid_buf, "%ld_", (long)current_sctx.sc_sid);
|
||||
if (vim9script)
|
||||
if (vim9_local)
|
||||
extra = 3 + (int)STRLEN(sid_buf);
|
||||
else
|
||||
lead += (int)STRLEN(sid_buf);
|
||||
}
|
||||
}
|
||||
else if (!(flags & TFN_INT) && (builtin_function(lv.ll_name, len)
|
||||
|| (in_vim9script() && *lv.ll_name == '_')))
|
||||
|| (vim9script && *lv.ll_name == '_')))
|
||||
{
|
||||
semsg(_(in_vim9script()
|
||||
? e_function_name_must_start_with_capital_str
|
||||
semsg(_(vim9script ? e_function_name_must_start_with_capital_str
|
||||
: e_function_name_must_start_with_capital_or_s_str),
|
||||
start);
|
||||
goto theend;
|
||||
@ -3968,12 +3969,12 @@ trans_function_name(
|
||||
name = alloc(len + lead + extra + 1);
|
||||
if (name != NULL)
|
||||
{
|
||||
if (!skip && (lead > 0 || vim9script))
|
||||
if (!skip && (lead > 0 || vim9_local))
|
||||
{
|
||||
name[0] = K_SPECIAL;
|
||||
name[1] = KS_EXTRA;
|
||||
name[2] = (int)KE_SNR;
|
||||
if (vim9script || lead > 3) // If it's "<SID>"
|
||||
if (vim9_local || lead > 3) // If it's "<SID>"
|
||||
STRCPY(name + 3, sid_buf);
|
||||
}
|
||||
else if (prefix_g)
|
||||
@ -4546,7 +4547,7 @@ define_function(exarg_T *eap, char_u *name_arg, garray_T *lines_to_free)
|
||||
int ffed_flags = is_global ? FFED_IS_GLOBAL : 0;
|
||||
|
||||
v = find_var(name, &ht, TRUE);
|
||||
if (v != NULL && (in_vim9script() || v->di_tv.v_type == VAR_FUNC))
|
||||
if (v != NULL && (vim9script || v->di_tv.v_type == VAR_FUNC))
|
||||
var_conflict = TRUE;
|
||||
|
||||
if (SCRIPT_ID_VALID(current_sctx.sc_sid))
|
||||
@ -5299,6 +5300,7 @@ ex_call(exarg_T *eap)
|
||||
evalarg_T evalarg;
|
||||
type_T *type = NULL;
|
||||
int found_var = FALSE;
|
||||
int vim9script = in_vim9script();
|
||||
|
||||
fill_evalarg_from_eap(&evalarg, eap, eap->skip);
|
||||
if (eap->skip)
|
||||
@ -5315,7 +5317,7 @@ ex_call(exarg_T *eap)
|
||||
}
|
||||
|
||||
tofree = trans_function_name(&arg, NULL, eap->skip, TFN_INT,
|
||||
&fudi, &partial, in_vim9script() ? &type : NULL);
|
||||
&fudi, &partial, vim9script ? &type : NULL);
|
||||
if (fudi.fd_newkey != NULL)
|
||||
{
|
||||
// Still need to give an error message for missing key.
|
||||
@ -5335,7 +5337,7 @@ ex_call(exarg_T *eap)
|
||||
// from trans_function_name().
|
||||
len = (int)STRLEN(tofree);
|
||||
name = deref_func_name(tofree, &len, partial != NULL ? NULL : &partial,
|
||||
in_vim9script() && type == NULL ? &type : NULL,
|
||||
vim9script && type == NULL ? &type : NULL,
|
||||
FALSE, FALSE, &found_var);
|
||||
|
||||
// Skip white space to allow ":call func ()". Not good, but required for
|
||||
@ -5346,7 +5348,7 @@ ex_call(exarg_T *eap)
|
||||
semsg(_(e_missing_parenthesis_str), eap->arg);
|
||||
goto end;
|
||||
}
|
||||
if (in_vim9script() && startarg > arg)
|
||||
if (vim9script && startarg > arg)
|
||||
{
|
||||
semsg(_(e_no_white_space_allowed_before_str_str), "(", eap->arg);
|
||||
goto end;
|
||||
|
@ -750,6 +750,8 @@ static char *(features[]) =
|
||||
|
||||
static int included_patches[] =
|
||||
{ /* Add new patch number below this line */
|
||||
/**/
|
||||
4367,
|
||||
/**/
|
||||
4366,
|
||||
/**/
|
||||
|
Loading…
x
Reference in New Issue
Block a user