mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
vim-patch:9.1.0411: too long functions in eval.c (#29925)
Problem: too long functions in eval.c
Solution: refactor functions (Yegappan Lakshmanan)
closes: vim/vim#14755
4ceb4dc825
The remaining eval_expr_typval() changes.
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
This commit is contained in:
parent
410be968d5
commit
c9b129a02a
117
src/nvim/eval.c
117
src/nvim/eval.c
@ -847,6 +847,80 @@ bool eval_expr_valid_arg(const typval_T *const tv)
|
|||||||
&& (tv->v_type != VAR_STRING || (tv->vval.v_string != NULL && *tv->vval.v_string != NUL));
|
&& (tv->v_type != VAR_STRING || (tv->vval.v_string != NULL && *tv->vval.v_string != NUL));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Evaluate a partial.
|
||||||
|
/// Pass arguments "argv[argc]".
|
||||||
|
/// Return the result in "rettv" and OK or FAIL.
|
||||||
|
static int eval_expr_partial(const typval_T *expr, typval_T *argv, int argc, typval_T *rettv)
|
||||||
|
FUNC_ATTR_NONNULL_ALL
|
||||||
|
{
|
||||||
|
partial_T *const partial = expr->vval.v_partial;
|
||||||
|
if (partial == NULL) {
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *const s = partial_name(partial);
|
||||||
|
if (s == NULL || *s == NUL) {
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
funcexe_T funcexe = FUNCEXE_INIT;
|
||||||
|
funcexe.fe_evaluate = true;
|
||||||
|
funcexe.fe_partial = partial;
|
||||||
|
if (call_func(s, -1, rettv, argc, argv, &funcexe) == FAIL) {
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Evaluate an expression which is a function.
|
||||||
|
/// Pass arguments "argv[argc]".
|
||||||
|
/// Return the result in "rettv" and OK or FAIL.
|
||||||
|
static int eval_expr_func(const typval_T *expr, typval_T *argv, int argc, typval_T *rettv)
|
||||||
|
FUNC_ATTR_NONNULL_ALL
|
||||||
|
{
|
||||||
|
char buf[NUMBUFLEN];
|
||||||
|
const char *const s = (expr->v_type == VAR_FUNC
|
||||||
|
? expr->vval.v_string
|
||||||
|
: tv_get_string_buf_chk(expr, buf));
|
||||||
|
if (s == NULL || *s == NUL) {
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
funcexe_T funcexe = FUNCEXE_INIT;
|
||||||
|
funcexe.fe_evaluate = true;
|
||||||
|
if (call_func(s, -1, rettv, argc, argv, &funcexe) == FAIL) {
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Evaluate an expression, which is a string.
|
||||||
|
/// Return the result in "rettv" and OK or FAIL.
|
||||||
|
static int eval_expr_string(const typval_T *expr, typval_T *rettv)
|
||||||
|
FUNC_ATTR_NONNULL_ALL
|
||||||
|
{
|
||||||
|
char buf[NUMBUFLEN];
|
||||||
|
char *s = (char *)tv_get_string_buf_chk(expr, buf);
|
||||||
|
if (s == NULL) {
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
s = skipwhite(s);
|
||||||
|
if (eval1_emsg(&s, rettv, NULL) == FAIL) {
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*skipwhite(s) != NUL) { // check for trailing chars after expr
|
||||||
|
tv_clear(rettv);
|
||||||
|
semsg(_(e_invexpr2), s);
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
/// Evaluate an expression, which can be a function, partial or string.
|
/// Evaluate an expression, which can be a function, partial or string.
|
||||||
/// Pass arguments "argv[argc]".
|
/// Pass arguments "argv[argc]".
|
||||||
/// Return the result in "rettv" and OK or FAIL.
|
/// Return the result in "rettv" and OK or FAIL.
|
||||||
@ -856,49 +930,14 @@ int eval_expr_typval(const typval_T *expr, bool want_func, typval_T *argv, int a
|
|||||||
typval_T *rettv)
|
typval_T *rettv)
|
||||||
FUNC_ATTR_NONNULL_ALL
|
FUNC_ATTR_NONNULL_ALL
|
||||||
{
|
{
|
||||||
char buf[NUMBUFLEN];
|
|
||||||
funcexe_T funcexe = FUNCEXE_INIT;
|
|
||||||
|
|
||||||
if (expr->v_type == VAR_PARTIAL) {
|
if (expr->v_type == VAR_PARTIAL) {
|
||||||
partial_T *const partial = expr->vval.v_partial;
|
return eval_expr_partial(expr, argv, argc, rettv);
|
||||||
if (partial == NULL) {
|
|
||||||
return FAIL;
|
|
||||||
}
|
|
||||||
const char *const s = partial_name(partial);
|
|
||||||
if (s == NULL || *s == NUL) {
|
|
||||||
return FAIL;
|
|
||||||
}
|
|
||||||
funcexe.fe_evaluate = true;
|
|
||||||
funcexe.fe_partial = partial;
|
|
||||||
if (call_func(s, -1, rettv, argc, argv, &funcexe) == FAIL) {
|
|
||||||
return FAIL;
|
|
||||||
}
|
|
||||||
} else if (expr->v_type == VAR_FUNC || want_func) {
|
} else if (expr->v_type == VAR_FUNC || want_func) {
|
||||||
const char *const s = (expr->v_type == VAR_FUNC
|
return eval_expr_func(expr, argv, argc, rettv);
|
||||||
? expr->vval.v_string
|
|
||||||
: tv_get_string_buf_chk(expr, buf));
|
|
||||||
if (s == NULL || *s == NUL) {
|
|
||||||
return FAIL;
|
|
||||||
}
|
|
||||||
funcexe.fe_evaluate = true;
|
|
||||||
if (call_func(s, -1, rettv, argc, argv, &funcexe) == FAIL) {
|
|
||||||
return FAIL;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
char *s = (char *)tv_get_string_buf_chk(expr, buf);
|
return eval_expr_string(expr, rettv);
|
||||||
if (s == NULL) {
|
|
||||||
return FAIL;
|
|
||||||
}
|
|
||||||
s = skipwhite(s);
|
|
||||||
if (eval1_emsg(&s, rettv, NULL) == FAIL) {
|
|
||||||
return FAIL;
|
|
||||||
}
|
|
||||||
if (*skipwhite(s) != NUL) { // check for trailing chars after expr
|
|
||||||
tv_clear(rettv);
|
|
||||||
semsg(_(e_invexpr2), s);
|
|
||||||
return FAIL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user