diff options
Diffstat (limited to 'src/nvim/eval')
-rw-r--r-- | src/nvim/eval/decode.h | 3 | ||||
-rw-r--r-- | src/nvim/eval/encode.c | 5 | ||||
-rw-r--r-- | src/nvim/eval/encode.h | 6 | ||||
-rw-r--r-- | src/nvim/eval/funcs.c | 27 | ||||
-rw-r--r-- | src/nvim/eval/typval.c | 4 | ||||
-rw-r--r-- | src/nvim/eval/typval.h | 177 | ||||
-rw-r--r-- | src/nvim/eval/typval_encode.c.h | 789 | ||||
-rw-r--r-- | src/nvim/eval/typval_encode.h | 38 | ||||
-rw-r--r-- | src/nvim/eval/userfunc.h | 2 |
9 files changed, 509 insertions, 542 deletions
diff --git a/src/nvim/eval/decode.h b/src/nvim/eval/decode.h index 77fc4c78c2..f1be5a1f69 100644 --- a/src/nvim/eval/decode.h +++ b/src/nvim/eval/decode.h @@ -1,9 +1,8 @@ #ifndef NVIM_EVAL_DECODE_H #define NVIM_EVAL_DECODE_H -#include <stddef.h> - #include <msgpack.h> +#include <stddef.h> #include "nvim/eval/typval.h" #include "nvim/globals.h" diff --git a/src/nvim/eval/encode.c b/src/nvim/eval/encode.c index 1c0afc89f5..5ef0045659 100644 --- a/src/nvim/eval/encode.c +++ b/src/nvim/eval/encode.c @@ -268,9 +268,8 @@ int encode_read_from_list(ListReaderState *const state, char *const buf, const s || TV_LIST_ITEM_TV(state->li)->vval.v_string != NULL); for (size_t i = state->offset; i < state->li_length && p < buf_end; i++) { assert(TV_LIST_ITEM_TV(state->li)->vval.v_string != NULL); - const char ch = (char)( - TV_LIST_ITEM_TV(state->li)->vval.v_string[state->offset++]); - *p++ = (char)((char)ch == (char)NL ? (char)NUL : (char)ch); + const char ch = (char)(TV_LIST_ITEM_TV(state->li)->vval.v_string[state->offset++]); + *p++ = (char)(ch == (char)NL ? (char)NUL : ch); } if (p < buf_end) { state->li = TV_LIST_ITEM_NEXT(state->list, state->li); diff --git a/src/nvim/eval/encode.h b/src/nvim/eval/encode.h index 596bb49ae0..8755ff48ac 100644 --- a/src/nvim/eval/encode.h +++ b/src/nvim/eval/encode.h @@ -1,9 +1,8 @@ #ifndef NVIM_EVAL_ENCODE_H #define NVIM_EVAL_ENCODE_H -#include <stddef.h> - #include <msgpack.h> +#include <stddef.h> #include "nvim/eval.h" #include "nvim/garray.h" @@ -49,8 +48,7 @@ static inline ListReaderState encode_init_lrstate(const list_T *const list) .offset = 0, .li_length = (TV_LIST_ITEM_TV(tv_list_first(list))->vval.v_string == NULL ? 0 - : STRLEN(TV_LIST_ITEM_TV( - tv_list_first(list))->vval.v_string)), + : STRLEN(TV_LIST_ITEM_TV(tv_list_first(list))->vval.v_string)), }; } diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index b53b50e766..709ef8e5b6 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -3747,7 +3747,7 @@ static void f_getmatches(typval_T *argvars, typval_T *rettv, FunPtr fptr) if (cur->conceal_char) { char buf[MB_MAXBYTES + 1]; - buf[utf_char2bytes((int)cur->conceal_char, (char_u *)buf)] = NUL; + buf[utf_char2bytes(cur->conceal_char, (char_u *)buf)] = NUL; tv_dict_add_str(dict, S_LEN("conceal"), buf); } @@ -5155,7 +5155,7 @@ static void f_islocked(typval_T *argvars, typval_T *rettv, FunPtr fptr) EMSG(_(e_trailing)); } else { if (lv.ll_tv == NULL) { - di = find_var((const char *)lv.ll_name, lv.ll_name_len, NULL, true); + di = find_var(lv.ll_name, lv.ll_name_len, NULL, true); if (di != NULL) { // Consider a variable locked when: // 1. the variable itself is locked @@ -5236,7 +5236,7 @@ static void f_jobpid(typval_T *argvars, typval_T *rettv, FunPtr fptr) return; } - Process *proc = (Process *)&data->stream.proc; + Process *proc = &data->stream.proc; rettv->vval.v_number = proc->pid; } @@ -5534,7 +5534,7 @@ static void f_jobstop(typval_T *argvars, typval_T *rettv, FunPtr fptr) // Ignore return code, but show error later. (void)channel_close(data->id, kChannelPartRpc, &error); } - process_stop((Process *)&data->stream.proc); + process_stop(&data->stream.proc); rettv->vval.v_number = 1; if (error) { EMSG(error); @@ -5990,7 +5990,7 @@ static void get_maparg(typval_T *argvars, typval_T *rettv, int exact) static void f_luaeval(typval_T *argvars, typval_T *rettv, FunPtr fptr) FUNC_ATTR_NONNULL_ALL { - const char *const str = (const char *)tv_get_string_chk(&argvars[0]); + const char *const str = tv_get_string_chk(&argvars[0]); if (str == NULL) { return; } @@ -6141,7 +6141,7 @@ static void find_some_match(typval_T *const argvars, typval_T *const rettv, } } - match = vim_regexec_nl(®match, str, (colnr_T)startcol); + match = vim_regexec_nl(®match, str, startcol); if (match && --nth <= 0) { break; @@ -6352,7 +6352,7 @@ static void f_matcharg(typval_T *argvars, typval_T *rettv, FunPtr fptr) : 0)); if (id >= 1 && id <= 3) { - matchitem_T *const m = (matchitem_T *)get_match(curwin, id); + matchitem_T *const m = get_match(curwin, id); if (m != NULL) { tv_list_append_string(rettv->vval.v_list, @@ -6999,7 +6999,7 @@ static void f_range(typval_T *argvars, typval_T *rettv, FunPtr fptr) } else { tv_list_alloc_ret(rettv, (end - start) / stride); for (i = start; stride > 0 ? i <= end : i >= end; i += stride) { - tv_list_append_number(rettv->vval.v_list, (varnumber_T)i); + tv_list_append_number(rettv->vval.v_list, i); } } } @@ -7302,7 +7302,7 @@ static void f_getreginfo(typval_T *argvars, typval_T *rettv, FunPtr fptr) if (list == NULL) { return; } - tv_dict_add_list(dict, S_LEN("regcontents"), list); + (void)tv_dict_add_list(dict, S_LEN("regcontents"), list); char buf[NUMBUFLEN + 2]; buf[0] = NUL; @@ -7321,14 +7321,15 @@ static void f_getreginfo(typval_T *argvars, typval_T *rettv, FunPtr fptr) case kMTUnknown: abort(); } - tv_dict_add_str(dict, S_LEN("regtype"), buf); + (void)tv_dict_add_str(dict, S_LEN("regtype"), buf); buf[0] = get_register_name(get_unname_register()); buf[1] = NUL; if (regname == '"') { - tv_dict_add_str(dict, S_LEN("points_to"), buf); + (void)tv_dict_add_str(dict, S_LEN("points_to"), buf); } else { - tv_dict_add_bool(dict, S_LEN("isunnamed"), regname == buf[0] ? kBoolVarTrue : kBoolVarFalse); + (void)tv_dict_add_bool(dict, S_LEN("isunnamed"), + regname == buf[0] ? kBoolVarTrue : kBoolVarFalse); } } @@ -11364,7 +11365,7 @@ static void f_termopen(typval_T *argvars, typval_T *rettv, FunPtr fptr) if (new_cwd && *new_cwd != NUL) { cwd = new_cwd; // The new cwd must be a directory. - if (!os_isdir_executable((const char *)cwd)) { + if (!os_isdir_executable(cwd)) { EMSG2(_(e_invarg2), "expected valid directory"); shell_free_argv(argv); return; diff --git a/src/nvim/eval/typval.c b/src/nvim/eval/typval.c index 075b50a366..cfc95ba167 100644 --- a/src/nvim/eval/typval.c +++ b/src/nvim/eval/typval.c @@ -2861,7 +2861,7 @@ bool tv_equal(typval_T *const tv1, typval_T *const tv2, const bool ic, const boo char buf2[NUMBUFLEN]; const char *s1 = tv_get_string_buf(tv1, buf1); const char *s2 = tv_get_string_buf(tv2, buf2); - return mb_strcmp_ic((bool)ic, s1, s2) == 0; + return mb_strcmp_ic(ic, s1, s2) == 0; } case VAR_BOOL: return tv1->vval.v_bool == tv2->vval.v_bool; @@ -3260,7 +3260,7 @@ const char *tv_get_string(const typval_T *const tv) const char *tv_get_string_buf(const typval_T *const tv, char *const buf) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_RET FUNC_ATTR_WARN_UNUSED_RESULT { - const char *const res = (const char *)tv_get_string_buf_chk(tv, buf); + const char *const res = tv_get_string_buf_chk(tv, buf); return res != NULL ? res : ""; } diff --git a/src/nvim/eval/typval.h b/src/nvim/eval/typval.h index 5aecaccee9..a28feffd0b 100644 --- a/src/nvim/eval/typval.h +++ b/src/nvim/eval/typval.h @@ -1,23 +1,23 @@ #ifndef NVIM_EVAL_TYPVAL_H #define NVIM_EVAL_TYPVAL_H +#include <assert.h> #include <inttypes.h> +#include <stdbool.h> #include <stddef.h> #include <string.h> -#include <stdbool.h> -#include <assert.h> -#include "nvim/types.h" -#include "nvim/hashtab.h" -#include "nvim/garray.h" -#include "nvim/mbyte.h" #include "nvim/func_attr.h" -#include "nvim/lib/queue.h" -#include "nvim/profile.h" // for proftime_T -#include "nvim/pos.h" // for linenr_T +#include "nvim/garray.h" #include "nvim/gettext.h" -#include "nvim/message.h" +#include "nvim/hashtab.h" +#include "nvim/lib/queue.h" #include "nvim/macros.h" +#include "nvim/mbyte.h" +#include "nvim/message.h" +#include "nvim/pos.h" // for linenr_T +#include "nvim/profile.h" // for proftime_T +#include "nvim/types.h" #ifdef LOG_LIST_ACTIONS # include "nvim/memory.h" #endif @@ -156,8 +156,8 @@ typedef enum { typedef struct listitem_S listitem_T; struct listitem_S { - listitem_T *li_next; ///< Next item in list. - listitem_T *li_prev; ///< Previous item in list. + listitem_T *li_next; ///< Next item in list. + listitem_T *li_prev; ///< Previous item in list. typval_T li_tv; ///< Item value. }; @@ -195,25 +195,25 @@ typedef struct { } staticList10_T; #define TV_LIST_STATIC10_INIT { \ - .sl_list = { \ - .lv_first = NULL, \ - .lv_last = NULL, \ - .lv_refcount = 0, \ - .lv_len = 0, \ - .lv_watch = NULL, \ - .lv_idx_item = NULL, \ - .lv_lock = VAR_FIXED, \ - .lv_used_next = NULL, \ - .lv_used_prev = NULL, \ - }, \ - } + .sl_list = { \ + .lv_first = NULL, \ + .lv_last = NULL, \ + .lv_refcount = 0, \ + .lv_len = 0, \ + .lv_watch = NULL, \ + .lv_idx_item = NULL, \ + .lv_lock = VAR_FIXED, \ + .lv_used_next = NULL, \ + .lv_used_prev = NULL, \ + }, \ +} #define TV_DICTITEM_STRUCT(...) \ - struct { \ - typval_T di_tv; /* Structure that holds scope dictionary itself. */ \ - uint8_t di_flags; /* Flags. */ \ - char_u di_key[__VA_ARGS__]; /* Key value. */ \ - } + struct { \ + typval_T di_tv; /* Structure that holds scope dictionary itself. */ \ + uint8_t di_flags; /* Flags. */ \ + char_u di_key[__VA_ARGS__]; /* Key value. */ \ + } /// Structure to hold a scope dictionary /// @@ -321,40 +321,40 @@ struct funccall_S { /// Structure to hold info for a user function. struct ufunc { - int uf_varargs; ///< variable nr of arguments - int uf_flags; - int uf_calls; ///< nr of active calls - bool uf_cleared; ///< func_clear() was already called - garray_T uf_args; ///< arguments - garray_T uf_def_args; ///< default argument expressions - garray_T uf_lines; ///< function lines - int uf_profiling; ///< true when func is being profiled - int uf_prof_initialized; + int uf_varargs; ///< variable nr of arguments + int uf_flags; + int uf_calls; ///< nr of active calls + bool uf_cleared; ///< func_clear() was already called + garray_T uf_args; ///< arguments + garray_T uf_def_args; ///< default argument expressions + garray_T uf_lines; ///< function lines + int uf_profiling; ///< true when func is being profiled + int uf_prof_initialized; // Managing cfuncs - cfunc_T uf_cb; ///< C function extension callback + cfunc_T uf_cb; ///< C function extension callback cfunc_free_T uf_cb_free; ///< C function extension free callback - void *uf_cb_state; ///< State of C function extension. + void *uf_cb_state; ///< State of C function extension. // Profiling the function as a whole. - int uf_tm_count; ///< nr of calls - proftime_T uf_tm_total; ///< time spent in function + children - proftime_T uf_tm_self; ///< time spent in function itself - proftime_T uf_tm_children; ///< time spent in children this call + int uf_tm_count; ///< nr of calls + proftime_T uf_tm_total; ///< time spent in function + children + proftime_T uf_tm_self; ///< time spent in function itself + proftime_T uf_tm_children; ///< time spent in children this call // Profiling the function per line. - int *uf_tml_count; ///< nr of times line was executed - proftime_T *uf_tml_total; ///< time spent in a line + children - proftime_T *uf_tml_self; ///< time spent in a line itself - proftime_T uf_tml_start; ///< start time for current line - proftime_T uf_tml_children; ///< time spent in children for this line - proftime_T uf_tml_wait; ///< start wait time for current line - int uf_tml_idx; ///< index of line being timed; -1 if none - int uf_tml_execed; ///< line being timed was executed - sctx_T uf_script_ctx; ///< SCTX where function was defined, - ///< used for s: variables - int uf_refcount; ///< reference count, see func_name_refcount() - funccall_T *uf_scoped; ///< l: local variables for closure - char_u uf_name[]; ///< Name of function (actual size equals name); - ///< can start with <SNR>123_ - ///< (<SNR> is K_SPECIAL KS_EXTRA KE_SNR) + int *uf_tml_count; ///< nr of times line was executed + proftime_T *uf_tml_total; ///< time spent in a line + children + proftime_T *uf_tml_self; ///< time spent in a line itself + proftime_T uf_tml_start; ///< start time for current line + proftime_T uf_tml_children; ///< time spent in children for this line + proftime_T uf_tml_wait; ///< start wait time for current line + int uf_tml_idx; ///< index of line being timed; -1 if none + int uf_tml_execed; ///< line being timed was executed + sctx_T uf_script_ctx; ///< SCTX where function was defined, + ///< used for s: variables + int uf_refcount; ///< reference count, see func_name_refcount() + funccall_T *uf_scoped; ///< l: local variables for closure + char_u uf_name[]; ///< Name of function (actual size equals name); + ///< can start with <SNR>123_ + ///< (<SNR> is K_SPECIAL KS_EXTRA KE_SNR) }; struct partial_S { @@ -452,10 +452,8 @@ static inline void list_log(const list_T *const l, /// @param[in] li1 List item 1. /// @param[in] li2 List item 2, often used for integers and not list items. /// @param[in] action Logged action. -static inline void list_log(const list_T *const l, - const listitem_T *const li1, - const listitem_T *const li2, - const char *const action) +static inline void list_log(const list_T *const l, const listitem_T *const li1, + const listitem_T *const li2, const char *const action) { ListLog *tgt; if (list_log_first == NULL) { @@ -484,7 +482,7 @@ static inline void list_log(const list_T *const l, /// Convert a hashitem pointer to a dictitem pointer #define TV_DICT_HI2DI(hi) \ - ((dictitem_T *)((hi)->hi_key - offsetof(dictitem_T, di_key))) + ((dictitem_T *)((hi)->hi_key - offsetof(dictitem_T, di_key))) static inline void tv_list_ref(list_T *const l) REAL_FATTR_ALWAYS_INLINE; @@ -538,8 +536,7 @@ static inline VarLockStatus tv_list_locked(const list_T *const l) /// /// @param[out] l List to modify. /// @param[in] lock New lock status. -static inline void tv_list_set_lock(list_T *const l, - const VarLockStatus lock) +static inline void tv_list_set_lock(list_T *const l, const VarLockStatus lock) { if (l == NULL) { assert(lock == VAR_FIXED); @@ -554,8 +551,7 @@ static inline void tv_list_set_lock(list_T *const l, /// /// @param[out] l List to modify. /// @param[in] copyid New copyID. -static inline void tv_list_set_copyid(list_T *const l, - const int copyid) +static inline void tv_list_set_copyid(list_T *const l, const int copyid) FUNC_ATTR_NONNULL_ALL { l->lv_copyID = copyid; @@ -793,10 +789,10 @@ static inline void tv_init(typval_T *const tv) } #define TV_INITIAL_VALUE \ - ((typval_T) { \ - .v_type = VAR_UNKNOWN, \ - .v_lock = VAR_UNLOCKED, \ - }) + ((typval_T) { \ + .v_type = VAR_UNKNOWN, \ + .v_lock = VAR_UNLOCKED, \ + }) /// Empty string /// @@ -815,16 +811,16 @@ extern bool tv_in_free_unref_items; /// @param li Name of the variable with current listitem_T entry. /// @param code Cycle body. #define _TV_LIST_ITER_MOD(modifier, l, li, code) \ - do { \ - modifier list_T *const l_ = (l); \ - list_log(l_, NULL, NULL, "iter" #modifier); \ - if (l_ != NULL) { \ - for (modifier listitem_T *li = l_->lv_first; \ - li != NULL; li = li->li_next) { \ - code \ - } \ + do { \ + modifier list_T *const l_ = (l); \ + list_log(l_, NULL, NULL, "iter" #modifier); \ + if (l_ != NULL) { \ + for (modifier listitem_T *li = l_->lv_first; \ + li != NULL; li = li->li_next) { \ + code \ } \ - } while (0) + } \ + } while (0) /// Iterate over a list /// @@ -835,7 +831,7 @@ extern bool tv_in_free_unref_items; /// @param li Name of the variable with current listitem_T entry. /// @param code Cycle body. #define TV_LIST_ITER(l, li, code) \ - _TV_LIST_ITER_MOD(, l, li, code) + _TV_LIST_ITER_MOD(, l, li, code) /// Iterate over a list /// @@ -846,7 +842,7 @@ extern bool tv_in_free_unref_items; /// @param li Name of the variable with current listitem_T entry. /// @param code Cycle body. #define TV_LIST_ITER_CONST(l, li, code) \ - _TV_LIST_ITER_MOD(const, l, li, code) + _TV_LIST_ITER_MOD(const, l, li, code) // Below macros are macros to avoid duplicating code for functionally identical // const and non-const function variants. @@ -883,14 +879,14 @@ extern bool tv_in_free_unref_items; /// @param di Name of the variable with current dictitem_T entry. /// @param code Cycle body. #define TV_DICT_ITER(d, di, code) \ - HASHTAB_ITER(&(d)->dv_hashtab, di##hi_, { \ + HASHTAB_ITER(&(d)->dv_hashtab, di##hi_, { \ + { \ + dictitem_T *const di = TV_DICT_HI2DI(di##hi_); \ { \ - dictitem_T *const di = TV_DICT_HI2DI(di##hi_); \ - { \ - code \ - } \ + code \ } \ - }) + } \ + }) static inline bool tv_get_float_chk(const typval_T *const tv, float_T *const ret_f) @@ -907,8 +903,7 @@ bool emsgf(const char *const fmt, ...); /// @param[out] ret_f Location where resulting float is stored. /// /// @return true in case of success, false if tv is not a number or float. -static inline bool tv_get_float_chk(const typval_T *const tv, - float_T *const ret_f) +static inline bool tv_get_float_chk(const typval_T *const tv, float_T *const ret_f) { if (tv->v_type == VAR_FLOAT) { *ret_f = tv->vval.v_float; diff --git a/src/nvim/eval/typval_encode.c.h b/src/nvim/eval/typval_encode.c.h index cd1be1eecc..ece51cb046 100644 --- a/src/nvim/eval/typval_encode.c.h +++ b/src/nvim/eval/typval_encode.c.h @@ -240,15 +240,15 @@ /// /// This name will only be used by one of the above macros which are defined by /// the caller. Functions defined here do not use first argument directly. -#include <stddef.h> -#include <inttypes.h> #include <assert.h> +#include <inttypes.h> +#include <stddef.h> -#include "nvim/lib/kvec.h" -#include "nvim/eval/typval.h" #include "nvim/eval/encode.h" -#include "nvim/func_attr.h" +#include "nvim/eval/typval.h" #include "nvim/eval/typval_encode.h" +#include "nvim/func_attr.h" +#include "nvim/lib/kvec.h" /// Dummy variable used because some macros need lvalue /// @@ -257,12 +257,12 @@ const dict_T *const TYPVAL_ENCODE_NODICT_VAR = NULL; static inline int _TYPVAL_ENCODE_CHECK_SELF_REFERENCE( - TYPVAL_ENCODE_FIRST_ARG_TYPE TYPVAL_ENCODE_FIRST_ARG_NAME, - void *const val, int *const val_copyID, - const MPConvStack *const mpstack, const int copyID, - const MPConvStackValType conv_type, - const char *const objname) - REAL_FATTR_NONNULL_ARG(2, 3, 4, 7) REAL_FATTR_WARN_UNUSED_RESULT + TYPVAL_ENCODE_FIRST_ARG_TYPE TYPVAL_ENCODE_FIRST_ARG_NAME, + void *const val, int *const val_copyID, + const MPConvStack *const mpstack, const int copyID, + const MPConvStackValType conv_type, + const char *const objname) +REAL_FATTR_NONNULL_ARG(2, 3, 4, 7) REAL_FATTR_WARN_UNUSED_RESULT REAL_FATTR_ALWAYS_INLINE; /// Function for checking whether container references itself @@ -280,11 +280,9 @@ static inline int _TYPVAL_ENCODE_CHECK_SELF_REFERENCE( /// /// @return NOTDONE in case of success, what to return in case of failure. static inline int _TYPVAL_ENCODE_CHECK_SELF_REFERENCE( - TYPVAL_ENCODE_FIRST_ARG_TYPE TYPVAL_ENCODE_FIRST_ARG_NAME, - void *const val, int *const val_copyID, - const MPConvStack *const mpstack, const int copyID, - const MPConvStackValType conv_type, - const char *const objname) + TYPVAL_ENCODE_FIRST_ARG_TYPE TYPVAL_ENCODE_FIRST_ARG_NAME, void *const val, int *const val_copyID, + const MPConvStack *const mpstack, const int copyID, const MPConvStackValType conv_type, + const char *const objname) { if (*val_copyID == copyID) { TYPVAL_ENCODE_CONV_RECURSE(val, conv_type); @@ -295,11 +293,11 @@ static inline int _TYPVAL_ENCODE_CHECK_SELF_REFERENCE( } static int _TYPVAL_ENCODE_CONVERT_ONE_VALUE( - TYPVAL_ENCODE_FIRST_ARG_TYPE TYPVAL_ENCODE_FIRST_ARG_NAME, - MPConvStack *const mpstack, MPConvStackVal *const cur_mpsv, - typval_T *const tv, const int copyID, - const char *const objname) - REAL_FATTR_NONNULL_ARG(2, 4, 6) REAL_FATTR_WARN_UNUSED_RESULT; + TYPVAL_ENCODE_FIRST_ARG_TYPE TYPVAL_ENCODE_FIRST_ARG_NAME, + MPConvStack *const mpstack, MPConvStackVal *const cur_mpsv, + typval_T *const tv, const int copyID, + const char *const objname) +REAL_FATTR_NONNULL_ARG(2, 4, 6) REAL_FATTR_WARN_UNUSED_RESULT; /// Convert single value /// @@ -319,42 +317,35 @@ static int _TYPVAL_ENCODE_CONVERT_ONE_VALUE( /// /// @return OK in case of success, FAIL in case of failure. static int _TYPVAL_ENCODE_CONVERT_ONE_VALUE( - TYPVAL_ENCODE_FIRST_ARG_TYPE TYPVAL_ENCODE_FIRST_ARG_NAME, - MPConvStack *const mpstack, MPConvStackVal *const cur_mpsv, - typval_T *const tv, const int copyID, - const char *const objname) + TYPVAL_ENCODE_FIRST_ARG_TYPE TYPVAL_ENCODE_FIRST_ARG_NAME, MPConvStack *const mpstack, + MPConvStackVal *const cur_mpsv, typval_T *const tv, const int copyID, const char *const objname) { switch (tv->v_type) { - case VAR_STRING: { - TYPVAL_ENCODE_CONV_STRING(tv, tv->vval.v_string, tv_strlen(tv)); - break; - } - case VAR_NUMBER: { - TYPVAL_ENCODE_CONV_NUMBER(tv, tv->vval.v_number); - break; - } - case VAR_FLOAT: { - TYPVAL_ENCODE_CONV_FLOAT(tv, tv->vval.v_float); - break; - } - case VAR_BLOB: { - TYPVAL_ENCODE_CONV_BLOB(tv, tv->vval.v_blob, - tv_blob_len(tv->vval.v_blob)); - break; - } - case VAR_FUNC: { - TYPVAL_ENCODE_CONV_FUNC_START(tv, tv->vval.v_string); - TYPVAL_ENCODE_CONV_FUNC_BEFORE_ARGS(tv, 0); - TYPVAL_ENCODE_CONV_FUNC_BEFORE_SELF(tv, -1); - TYPVAL_ENCODE_CONV_FUNC_END(tv); - break; - } - case VAR_PARTIAL: { - partial_T *const pt = tv->vval.v_partial; - (void)pt; - TYPVAL_ENCODE_CONV_FUNC_START( // -V547 - tv, (pt == NULL ? NULL : partial_name(pt))); - _mp_push(*mpstack, ((MPConvStackVal) { // -V779 + case VAR_STRING: + TYPVAL_ENCODE_CONV_STRING(tv, tv->vval.v_string, tv_strlen(tv)); + break; + case VAR_NUMBER: + TYPVAL_ENCODE_CONV_NUMBER(tv, tv->vval.v_number); + break; + case VAR_FLOAT: + TYPVAL_ENCODE_CONV_FLOAT(tv, tv->vval.v_float); + break; + case VAR_BLOB: + TYPVAL_ENCODE_CONV_BLOB(tv, tv->vval.v_blob, + tv_blob_len(tv->vval.v_blob)); + break; + case VAR_FUNC: + TYPVAL_ENCODE_CONV_FUNC_START(tv, tv->vval.v_string); + TYPVAL_ENCODE_CONV_FUNC_BEFORE_ARGS(tv, 0); + TYPVAL_ENCODE_CONV_FUNC_BEFORE_SELF(tv, -1); + TYPVAL_ENCODE_CONV_FUNC_END(tv); + break; + case VAR_PARTIAL: { + partial_T *const pt = tv->vval.v_partial; + (void)pt; + TYPVAL_ENCODE_CONV_FUNC_START( // -V547 + tv, (pt == NULL ? NULL : partial_name(pt))); + _mp_push(*mpstack, ((MPConvStackVal) { // -V779 .type = kMPConvPartial, .tv = tv, .saved_copyID = copyID - 1, @@ -365,19 +356,19 @@ static int _TYPVAL_ENCODE_CONVERT_ONE_VALUE( }, }, })); + break; + } + case VAR_LIST: { + if (tv->vval.v_list == NULL || tv_list_len(tv->vval.v_list) == 0) { + TYPVAL_ENCODE_CONV_EMPTY_LIST(tv); break; } - case VAR_LIST: { - if (tv->vval.v_list == NULL || tv_list_len(tv->vval.v_list) == 0) { - TYPVAL_ENCODE_CONV_EMPTY_LIST(tv); - break; - } - const int saved_copyID = tv_list_copyid(tv->vval.v_list); - _TYPVAL_ENCODE_DO_CHECK_SELF_REFERENCE(tv->vval.v_list, lv_copyID, copyID, - kMPConvList); - TYPVAL_ENCODE_CONV_LIST_START(tv, tv_list_len(tv->vval.v_list)); - assert(saved_copyID != copyID); - _mp_push(*mpstack, ((MPConvStackVal) { + const int saved_copyID = tv_list_copyid(tv->vval.v_list); + _TYPVAL_ENCODE_DO_CHECK_SELF_REFERENCE(tv->vval.v_list, lv_copyID, copyID, + kMPConvList); + TYPVAL_ENCODE_CONV_LIST_START(tv, tv_list_len(tv->vval.v_list)); + assert(saved_copyID != copyID); + _mp_push(*mpstack, ((MPConvStackVal) { .type = kMPConvList, .tv = tv, .saved_copyID = saved_copyID, @@ -388,159 +379,151 @@ static int _TYPVAL_ENCODE_CONVERT_ONE_VALUE( }, }, })); - TYPVAL_ENCODE_CONV_REAL_LIST_AFTER_START(tv, _mp_last(*mpstack)); + TYPVAL_ENCODE_CONV_REAL_LIST_AFTER_START(tv, _mp_last(*mpstack)); + break; + } + case VAR_BOOL: + switch (tv->vval.v_bool) { + case kBoolVarTrue: + case kBoolVarFalse: + TYPVAL_ENCODE_CONV_BOOL(tv, tv->vval.v_bool == kBoolVarTrue); break; } - case VAR_BOOL: { - switch (tv->vval.v_bool) { - case kBoolVarTrue: - case kBoolVarFalse: { - TYPVAL_ENCODE_CONV_BOOL(tv, tv->vval.v_bool == kBoolVarTrue); - break; - } - } + break; + case VAR_SPECIAL: + switch (tv->vval.v_special) { + case kSpecialVarNull: + TYPVAL_ENCODE_CONV_NIL(tv); // -V1037 break; } - case VAR_SPECIAL: { - switch (tv->vval.v_special) { - case kSpecialVarNull: { - TYPVAL_ENCODE_CONV_NIL(tv); // -V1037 + break; + case VAR_DICT: { + if (tv->vval.v_dict == NULL + || tv->vval.v_dict->dv_hashtab.ht_used == 0) { + TYPVAL_ENCODE_CONV_EMPTY_DICT(tv, tv->vval.v_dict); + break; + } + const dictitem_T *type_di; + const dictitem_T *val_di; + if (TYPVAL_ENCODE_ALLOW_SPECIALS + && tv->vval.v_dict->dv_hashtab.ht_used == 2 + && (type_di = tv_dict_find((dict_T *)tv->vval.v_dict, + S_LEN("_TYPE"))) != NULL + && type_di->di_tv.v_type == VAR_LIST + && (val_di = tv_dict_find((dict_T *)tv->vval.v_dict, + S_LEN("_VAL"))) != NULL) { + size_t i; + for (i = 0; i < ARRAY_SIZE(eval_msgpack_type_lists); i++) { + if (type_di->di_tv.vval.v_list == eval_msgpack_type_lists[i]) { break; } } - break; - } - case VAR_DICT: { - if (tv->vval.v_dict == NULL - || tv->vval.v_dict->dv_hashtab.ht_used == 0) { - TYPVAL_ENCODE_CONV_EMPTY_DICT(tv, tv->vval.v_dict); - break; + if (i == ARRAY_SIZE(eval_msgpack_type_lists)) { + goto _convert_one_value_regular_dict; } - const dictitem_T *type_di; - const dictitem_T *val_di; - if (TYPVAL_ENCODE_ALLOW_SPECIALS - && tv->vval.v_dict->dv_hashtab.ht_used == 2 - && (type_di = tv_dict_find((dict_T *)tv->vval.v_dict, - S_LEN("_TYPE"))) != NULL - && type_di->di_tv.v_type == VAR_LIST - && (val_di = tv_dict_find((dict_T *)tv->vval.v_dict, - S_LEN("_VAL"))) != NULL) { - size_t i; - for (i = 0; i < ARRAY_SIZE(eval_msgpack_type_lists); i++) { - if (type_di->di_tv.vval.v_list == eval_msgpack_type_lists[i]) { - break; - } + switch ((MessagePackType)i) { + case kMPNil: + TYPVAL_ENCODE_CONV_NIL(tv); + break; + case kMPBoolean: + if (val_di->di_tv.v_type != VAR_NUMBER) { + goto _convert_one_value_regular_dict; } - if (i == ARRAY_SIZE(eval_msgpack_type_lists)) { + TYPVAL_ENCODE_CONV_BOOL(tv, val_di->di_tv.vval.v_number); + break; + case kMPInteger: { + const list_T *val_list; + varnumber_T sign; + varnumber_T highest_bits; + varnumber_T high_bits; + varnumber_T low_bits; + // List of 4 integers; first is signed (should be 1 or -1, but + // this is not checked), second is unsigned and have at most + // one (sign is -1) or two (sign is 1) non-zero bits (number of + // bits is not checked), other unsigned and have at most 31 + // non-zero bits (number of bits is not checked). + if (val_di->di_tv.v_type != VAR_LIST + || tv_list_len(val_list = val_di->di_tv.vval.v_list) != 4) { goto _convert_one_value_regular_dict; } - switch ((MessagePackType)i) { - case kMPNil: { - TYPVAL_ENCODE_CONV_NIL(tv); - break; - } - case kMPBoolean: { - if (val_di->di_tv.v_type != VAR_NUMBER) { - goto _convert_one_value_regular_dict; - } - TYPVAL_ENCODE_CONV_BOOL(tv, val_di->di_tv.vval.v_number); - break; - } - case kMPInteger: { - const list_T *val_list; - varnumber_T sign; - varnumber_T highest_bits; - varnumber_T high_bits; - varnumber_T low_bits; - // List of 4 integers; first is signed (should be 1 or -1, but - // this is not checked), second is unsigned and have at most - // one (sign is -1) or two (sign is 1) non-zero bits (number of - // bits is not checked), other unsigned and have at most 31 - // non-zero bits (number of bits is not checked). - if (val_di->di_tv.v_type != VAR_LIST - || tv_list_len(val_list = val_di->di_tv.vval.v_list) != 4) { - goto _convert_one_value_regular_dict; - } - const listitem_T *const sign_li = tv_list_first(val_list); - if (TV_LIST_ITEM_TV(sign_li)->v_type != VAR_NUMBER - || (sign = TV_LIST_ITEM_TV(sign_li)->vval.v_number) == 0) { - goto _convert_one_value_regular_dict; - } + const listitem_T *const sign_li = tv_list_first(val_list); + if (TV_LIST_ITEM_TV(sign_li)->v_type != VAR_NUMBER + || (sign = TV_LIST_ITEM_TV(sign_li)->vval.v_number) == 0) { + goto _convert_one_value_regular_dict; + } - const listitem_T *const highest_bits_li = ( - TV_LIST_ITEM_NEXT(val_list, sign_li)); - if (TV_LIST_ITEM_TV(highest_bits_li)->v_type != VAR_NUMBER - || ((highest_bits - = TV_LIST_ITEM_TV(highest_bits_li)->vval.v_number) - < 0)) { - goto _convert_one_value_regular_dict; - } + const listitem_T *const highest_bits_li = ( + TV_LIST_ITEM_NEXT(val_list, sign_li)); + if (TV_LIST_ITEM_TV(highest_bits_li)->v_type != VAR_NUMBER + || ((highest_bits + = TV_LIST_ITEM_TV(highest_bits_li)->vval.v_number) + < 0)) { + goto _convert_one_value_regular_dict; + } - const listitem_T *const high_bits_li = ( - TV_LIST_ITEM_NEXT(val_list, highest_bits_li)); - if (TV_LIST_ITEM_TV(high_bits_li)->v_type != VAR_NUMBER - || ((high_bits = TV_LIST_ITEM_TV(high_bits_li)->vval.v_number) - < 0)) { - goto _convert_one_value_regular_dict; - } + const listitem_T *const high_bits_li = ( + TV_LIST_ITEM_NEXT(val_list, highest_bits_li)); + if (TV_LIST_ITEM_TV(high_bits_li)->v_type != VAR_NUMBER + || ((high_bits = TV_LIST_ITEM_TV(high_bits_li)->vval.v_number) + < 0)) { + goto _convert_one_value_regular_dict; + } - const listitem_T *const low_bits_li = tv_list_last(val_list); - if (TV_LIST_ITEM_TV(low_bits_li)->v_type != VAR_NUMBER - || ((low_bits = TV_LIST_ITEM_TV(low_bits_li)->vval.v_number) - < 0)) { - goto _convert_one_value_regular_dict; - } + const listitem_T *const low_bits_li = tv_list_last(val_list); + if (TV_LIST_ITEM_TV(low_bits_li)->v_type != VAR_NUMBER + || ((low_bits = TV_LIST_ITEM_TV(low_bits_li)->vval.v_number) + < 0)) { + goto _convert_one_value_regular_dict; + } - const uint64_t number = ((uint64_t)(((uint64_t)highest_bits) << 62) - | (uint64_t)(((uint64_t)high_bits) << 31) - | (uint64_t)low_bits); - if (sign > 0) { - TYPVAL_ENCODE_CONV_UNSIGNED_NUMBER(tv, number); - } else { - TYPVAL_ENCODE_CONV_NUMBER(tv, -number); - } - break; - } - case kMPFloat: { - if (val_di->di_tv.v_type != VAR_FLOAT) { - goto _convert_one_value_regular_dict; - } - TYPVAL_ENCODE_CONV_FLOAT(tv, val_di->di_tv.vval.v_float); - break; - } - case kMPString: - case kMPBinary: { - const bool is_string = ((MessagePackType)i == kMPString); - if (val_di->di_tv.v_type != VAR_LIST) { - goto _convert_one_value_regular_dict; - } - size_t len; - char *buf; - if (!encode_vim_list_to_buf(val_di->di_tv.vval.v_list, &len, - &buf)) { - goto _convert_one_value_regular_dict; - } - if (is_string) { - TYPVAL_ENCODE_CONV_STR_STRING(tv, buf, len); - } else { // -V523 - TYPVAL_ENCODE_CONV_STRING(tv, buf, len); - } - xfree(buf); - break; - } - case kMPArray: { - if (val_di->di_tv.v_type != VAR_LIST) { - goto _convert_one_value_regular_dict; - } - const int saved_copyID = tv_list_copyid(val_di->di_tv.vval.v_list); - _TYPVAL_ENCODE_DO_CHECK_SELF_REFERENCE(val_di->di_tv.vval.v_list, - lv_copyID, copyID, - kMPConvList); - TYPVAL_ENCODE_CONV_LIST_START( - tv, tv_list_len(val_di->di_tv.vval.v_list)); - assert(saved_copyID != copyID && saved_copyID != copyID - 1); - _mp_push(*mpstack, ((MPConvStackVal) { + const uint64_t number = ((uint64_t)(((uint64_t)highest_bits) << 62) + | (uint64_t)(((uint64_t)high_bits) << 31) + | (uint64_t)low_bits); + if (sign > 0) { + TYPVAL_ENCODE_CONV_UNSIGNED_NUMBER(tv, number); + } else { + TYPVAL_ENCODE_CONV_NUMBER(tv, -number); + } + break; + } + case kMPFloat: + if (val_di->di_tv.v_type != VAR_FLOAT) { + goto _convert_one_value_regular_dict; + } + TYPVAL_ENCODE_CONV_FLOAT(tv, val_di->di_tv.vval.v_float); + break; + case kMPString: + case kMPBinary: { + const bool is_string = ((MessagePackType)i == kMPString); + if (val_di->di_tv.v_type != VAR_LIST) { + goto _convert_one_value_regular_dict; + } + size_t len; + char *buf; + if (!encode_vim_list_to_buf(val_di->di_tv.vval.v_list, &len, + &buf)) { + goto _convert_one_value_regular_dict; + } + if (is_string) { + TYPVAL_ENCODE_CONV_STR_STRING(tv, buf, len); + } else { // -V523 + TYPVAL_ENCODE_CONV_STRING(tv, buf, len); + } + xfree(buf); + break; + } + case kMPArray: { + if (val_di->di_tv.v_type != VAR_LIST) { + goto _convert_one_value_regular_dict; + } + const int saved_copyID = tv_list_copyid(val_di->di_tv.vval.v_list); + _TYPVAL_ENCODE_DO_CHECK_SELF_REFERENCE(val_di->di_tv.vval.v_list, + lv_copyID, copyID, + kMPConvList); + TYPVAL_ENCODE_CONV_LIST_START(tv, tv_list_len(val_di->di_tv.vval.v_list)); + assert(saved_copyID != copyID && saved_copyID != copyID - 1); + _mp_push(*mpstack, ((MPConvStackVal) { .tv = tv, .type = kMPConvList, .saved_copyID = saved_copyID, @@ -551,31 +534,31 @@ static int _TYPVAL_ENCODE_CONVERT_ONE_VALUE( }, }, })); - break; - } - case kMPMap: { - if (val_di->di_tv.v_type != VAR_LIST) { - goto _convert_one_value_regular_dict; - } - list_T *const val_list = val_di->di_tv.vval.v_list; - if (val_list == NULL || tv_list_len(val_list) == 0) { - TYPVAL_ENCODE_CONV_EMPTY_DICT( // -V501 - tv, TYPVAL_ENCODE_NODICT_VAR); - break; - } - TV_LIST_ITER_CONST(val_list, li, { + break; + } + case kMPMap: { + if (val_di->di_tv.v_type != VAR_LIST) { + goto _convert_one_value_regular_dict; + } + list_T *const val_list = val_di->di_tv.vval.v_list; + if (val_list == NULL || tv_list_len(val_list) == 0) { + TYPVAL_ENCODE_CONV_EMPTY_DICT( // -V501 + tv, TYPVAL_ENCODE_NODICT_VAR); + break; + } + TV_LIST_ITER_CONST(val_list, li, { if (TV_LIST_ITEM_TV(li)->v_type != VAR_LIST || tv_list_len(TV_LIST_ITEM_TV(li)->vval.v_list) != 2) { goto _convert_one_value_regular_dict; } }); - const int saved_copyID = tv_list_copyid(val_di->di_tv.vval.v_list); - _TYPVAL_ENCODE_DO_CHECK_SELF_REFERENCE(val_list, lv_copyID, copyID, - kMPConvPairs); - TYPVAL_ENCODE_CONV_DICT_START(tv, TYPVAL_ENCODE_NODICT_VAR, - tv_list_len(val_list)); - assert(saved_copyID != copyID && saved_copyID != copyID - 1); - _mp_push(*mpstack, ((MPConvStackVal) { + const int saved_copyID = tv_list_copyid(val_di->di_tv.vval.v_list); + _TYPVAL_ENCODE_DO_CHECK_SELF_REFERENCE(val_list, lv_copyID, copyID, + kMPConvPairs); + TYPVAL_ENCODE_CONV_DICT_START(tv, TYPVAL_ENCODE_NODICT_VAR, + tv_list_len(val_list)); + assert(saved_copyID != copyID && saved_copyID != copyID - 1); + _mp_push(*mpstack, ((MPConvStackVal) { .tv = tv, .type = kMPConvPairs, .saved_copyID = saved_copyID, @@ -586,46 +569,45 @@ static int _TYPVAL_ENCODE_CONVERT_ONE_VALUE( }, }, })); - break; - } - case kMPExt: { - const list_T *val_list; - varnumber_T type; - if (val_di->di_tv.v_type != VAR_LIST - || tv_list_len((val_list = val_di->di_tv.vval.v_list)) != 2 - || (TV_LIST_ITEM_TV(tv_list_first(val_list))->v_type - != VAR_NUMBER) - || ((type - = TV_LIST_ITEM_TV(tv_list_first(val_list))->vval.v_number) - > INT8_MAX) - || type < INT8_MIN - || (TV_LIST_ITEM_TV(tv_list_last(val_list))->v_type - != VAR_LIST)) { - goto _convert_one_value_regular_dict; - } - size_t len; - char *buf; - if (!( - encode_vim_list_to_buf( - TV_LIST_ITEM_TV(tv_list_last(val_list))->vval.v_list, &len, - &buf))) { - goto _convert_one_value_regular_dict; - } - TYPVAL_ENCODE_CONV_EXT_STRING(tv, buf, len, type); - xfree(buf); - break; - } + break; + } + case kMPExt: { + const list_T *val_list; + varnumber_T type; + if (val_di->di_tv.v_type != VAR_LIST + || tv_list_len((val_list = val_di->di_tv.vval.v_list)) != 2 + || (TV_LIST_ITEM_TV(tv_list_first(val_list))->v_type + != VAR_NUMBER) + || ((type + = TV_LIST_ITEM_TV(tv_list_first(val_list))->vval.v_number) + > INT8_MAX) + || type < INT8_MIN + || (TV_LIST_ITEM_TV(tv_list_last(val_list))->v_type + != VAR_LIST)) { + goto _convert_one_value_regular_dict; + } + size_t len; + char *buf; + if (!( + encode_vim_list_to_buf(TV_LIST_ITEM_TV(tv_list_last(val_list))->vval.v_list, &len, + &buf))) { + goto _convert_one_value_regular_dict; } + TYPVAL_ENCODE_CONV_EXT_STRING(tv, buf, len, type); + xfree(buf); break; } + } + break; + } _convert_one_value_regular_dict: {} - const int saved_copyID = tv->vval.v_dict->dv_copyID; - _TYPVAL_ENCODE_DO_CHECK_SELF_REFERENCE(tv->vval.v_dict, dv_copyID, copyID, - kMPConvDict); - TYPVAL_ENCODE_CONV_DICT_START(tv, tv->vval.v_dict, - tv->vval.v_dict->dv_hashtab.ht_used); - assert(saved_copyID != copyID); - _mp_push(*mpstack, ((MPConvStackVal) { + const int saved_copyID = tv->vval.v_dict->dv_copyID; + _TYPVAL_ENCODE_DO_CHECK_SELF_REFERENCE(tv->vval.v_dict, dv_copyID, copyID, + kMPConvDict); + TYPVAL_ENCODE_CONV_DICT_START(tv, tv->vval.v_dict, + tv->vval.v_dict->dv_hashtab.ht_used); + assert(saved_copyID != copyID); + _mp_push(*mpstack, ((MPConvStackVal) { .tv = tv, .type = kMPConvDict, .saved_copyID = saved_copyID, @@ -638,14 +620,13 @@ _convert_one_value_regular_dict: {} }, }, })); - TYPVAL_ENCODE_CONV_REAL_DICT_AFTER_START(tv, tv->vval.v_dict, - _mp_last(*mpstack)); - break; - } - case VAR_UNKNOWN: { - internal_error(STR(_TYPVAL_ENCODE_CONVERT_ONE_VALUE) "()"); - return FAIL; - } + TYPVAL_ENCODE_CONV_REAL_DICT_AFTER_START(tv, tv->vval.v_dict, + _mp_last(*mpstack)); + break; + } + case VAR_UNKNOWN: + internal_error(STR(_TYPVAL_ENCODE_CONVERT_ONE_VALUE) "()"); + return FAIL; } typval_encode_stop_converting_one_item: return OK; @@ -654,9 +635,9 @@ typval_encode_stop_converting_one_item: } TYPVAL_ENCODE_SCOPE int _TYPVAL_ENCODE_ENCODE( - TYPVAL_ENCODE_FIRST_ARG_TYPE TYPVAL_ENCODE_FIRST_ARG_NAME, - typval_T *const tv, const char *const objname) - REAL_FATTR_NONNULL_ARG(2, 3) REAL_FATTR_WARN_UNUSED_RESULT; + TYPVAL_ENCODE_FIRST_ARG_TYPE TYPVAL_ENCODE_FIRST_ARG_NAME, + typval_T *const tv, const char *const objname) +REAL_FATTR_NONNULL_ARG(2, 3) REAL_FATTR_WARN_UNUSED_RESULT; /// Convert the whole typval /// @@ -668,8 +649,8 @@ TYPVAL_ENCODE_SCOPE int _TYPVAL_ENCODE_ENCODE( /// /// @return OK in case of success, FAIL in case of failure. TYPVAL_ENCODE_SCOPE int _TYPVAL_ENCODE_ENCODE( - TYPVAL_ENCODE_FIRST_ARG_TYPE TYPVAL_ENCODE_FIRST_ARG_NAME, - typval_T *const top_tv, const char *const objname) + TYPVAL_ENCODE_FIRST_ARG_TYPE TYPVAL_ENCODE_FIRST_ARG_NAME, typval_T *const top_tv, + const char *const objname) { const int copyID = get_copyID(); MPConvStack mpstack; @@ -687,125 +668,121 @@ typval_encode_stop_converting_one_item: MPConvStackVal *cur_mpsv = &_mp_last(mpstack); typval_T *tv = NULL; switch (cur_mpsv->type) { - case kMPConvDict: { - if (!cur_mpsv->data.d.todo) { - (void)_mp_pop(mpstack); - cur_mpsv->data.d.dict->dv_copyID = cur_mpsv->saved_copyID; - TYPVAL_ENCODE_CONV_DICT_END(cur_mpsv->tv, *cur_mpsv->data.d.dictp); - continue; - } else if (cur_mpsv->data.d.todo - != cur_mpsv->data.d.dict->dv_hashtab.ht_used) { - TYPVAL_ENCODE_CONV_DICT_BETWEEN_ITEMS(cur_mpsv->tv, - *cur_mpsv->data.d.dictp); - } - while (HASHITEM_EMPTY(cur_mpsv->data.d.hi)) { - cur_mpsv->data.d.hi++; - } - dictitem_T *const di = TV_DICT_HI2DI(cur_mpsv->data.d.hi); - cur_mpsv->data.d.todo--; + case kMPConvDict: { + if (!cur_mpsv->data.d.todo) { + (void)_mp_pop(mpstack); + cur_mpsv->data.d.dict->dv_copyID = cur_mpsv->saved_copyID; + TYPVAL_ENCODE_CONV_DICT_END(cur_mpsv->tv, *cur_mpsv->data.d.dictp); + continue; + } else if (cur_mpsv->data.d.todo + != cur_mpsv->data.d.dict->dv_hashtab.ht_used) { + TYPVAL_ENCODE_CONV_DICT_BETWEEN_ITEMS(cur_mpsv->tv, + *cur_mpsv->data.d.dictp); + } + while (HASHITEM_EMPTY(cur_mpsv->data.d.hi)) { cur_mpsv->data.d.hi++; - TYPVAL_ENCODE_CONV_STR_STRING(NULL, &di->di_key[0], - strlen((char *)&di->di_key[0])); - TYPVAL_ENCODE_CONV_DICT_AFTER_KEY(cur_mpsv->tv, - *cur_mpsv->data.d.dictp); - tv = &di->di_tv; - break; } - case kMPConvList: { - if (cur_mpsv->data.l.li == NULL) { - (void)_mp_pop(mpstack); - tv_list_set_copyid(cur_mpsv->data.l.list, cur_mpsv->saved_copyID); - TYPVAL_ENCODE_CONV_LIST_END(cur_mpsv->tv); - continue; - } else if (cur_mpsv->data.l.li - != tv_list_first(cur_mpsv->data.l.list)) { - TYPVAL_ENCODE_CONV_LIST_BETWEEN_ITEMS(cur_mpsv->tv); - } - tv = TV_LIST_ITEM_TV(cur_mpsv->data.l.li); - cur_mpsv->data.l.li = TV_LIST_ITEM_NEXT(cur_mpsv->data.l.list, - cur_mpsv->data.l.li); - break; + dictitem_T *const di = TV_DICT_HI2DI(cur_mpsv->data.d.hi); + cur_mpsv->data.d.todo--; + cur_mpsv->data.d.hi++; + TYPVAL_ENCODE_CONV_STR_STRING(NULL, &di->di_key[0], + strlen((char *)&di->di_key[0])); + TYPVAL_ENCODE_CONV_DICT_AFTER_KEY(cur_mpsv->tv, + *cur_mpsv->data.d.dictp); + tv = &di->di_tv; + break; + } + case kMPConvList: + if (cur_mpsv->data.l.li == NULL) { + (void)_mp_pop(mpstack); + tv_list_set_copyid(cur_mpsv->data.l.list, cur_mpsv->saved_copyID); + TYPVAL_ENCODE_CONV_LIST_END(cur_mpsv->tv); + continue; + } else if (cur_mpsv->data.l.li + != tv_list_first(cur_mpsv->data.l.list)) { + TYPVAL_ENCODE_CONV_LIST_BETWEEN_ITEMS(cur_mpsv->tv); } - case kMPConvPairs: { - if (cur_mpsv->data.l.li == NULL) { - (void)_mp_pop(mpstack); - tv_list_set_copyid(cur_mpsv->data.l.list, cur_mpsv->saved_copyID); - TYPVAL_ENCODE_CONV_DICT_END(cur_mpsv->tv, TYPVAL_ENCODE_NODICT_VAR); - continue; - } else if (cur_mpsv->data.l.li - != tv_list_first(cur_mpsv->data.l.list)) { - TYPVAL_ENCODE_CONV_DICT_BETWEEN_ITEMS( - cur_mpsv->tv, TYPVAL_ENCODE_NODICT_VAR); - } - const list_T *const kv_pair = ( - TV_LIST_ITEM_TV(cur_mpsv->data.l.li)->vval.v_list); - TYPVAL_ENCODE_SPECIAL_DICT_KEY_CHECK( - encode_vim_to__error_ret, *TV_LIST_ITEM_TV(tv_list_first(kv_pair))); - if ( - _TYPVAL_ENCODE_CONVERT_ONE_VALUE( - TYPVAL_ENCODE_FIRST_ARG_NAME, &mpstack, cur_mpsv, - TV_LIST_ITEM_TV(tv_list_first(kv_pair)), copyID, objname) - == FAIL) { - goto encode_vim_to__error_ret; - } - TYPVAL_ENCODE_CONV_DICT_AFTER_KEY(cur_mpsv->tv, - TYPVAL_ENCODE_NODICT_VAR); - tv = TV_LIST_ITEM_TV(tv_list_last(kv_pair)); - cur_mpsv->data.l.li = TV_LIST_ITEM_NEXT(cur_mpsv->data.l.list, - cur_mpsv->data.l.li); - break; + tv = TV_LIST_ITEM_TV(cur_mpsv->data.l.li); + cur_mpsv->data.l.li = TV_LIST_ITEM_NEXT(cur_mpsv->data.l.list, + cur_mpsv->data.l.li); + break; + case kMPConvPairs: { + if (cur_mpsv->data.l.li == NULL) { + (void)_mp_pop(mpstack); + tv_list_set_copyid(cur_mpsv->data.l.list, cur_mpsv->saved_copyID); + TYPVAL_ENCODE_CONV_DICT_END(cur_mpsv->tv, TYPVAL_ENCODE_NODICT_VAR); + continue; + } else if (cur_mpsv->data.l.li + != tv_list_first(cur_mpsv->data.l.list)) { + TYPVAL_ENCODE_CONV_DICT_BETWEEN_ITEMS(cur_mpsv->tv, TYPVAL_ENCODE_NODICT_VAR); } - case kMPConvPartial: { - partial_T *const pt = cur_mpsv->data.p.pt; - tv = cur_mpsv->tv; - (void)tv; - switch (cur_mpsv->data.p.stage) { - case kMPConvPartialArgs: { - TYPVAL_ENCODE_CONV_FUNC_BEFORE_ARGS(tv, - pt == NULL ? 0 : pt->pt_argc); - cur_mpsv->data.p.stage = kMPConvPartialSelf; - if (pt != NULL && pt->pt_argc > 0) { - TYPVAL_ENCODE_CONV_LIST_START(NULL, pt->pt_argc); - _mp_push(mpstack, ((MPConvStackVal) { - .type = kMPConvPartialList, - .tv = NULL, - .saved_copyID = copyID - 1, - .data = { - .a = { - .arg = pt->pt_argv, - .argv = pt->pt_argv, - .todo = (size_t)pt->pt_argc, - }, + const list_T *const kv_pair = ( + TV_LIST_ITEM_TV(cur_mpsv->data.l.li)->vval.v_list); + TYPVAL_ENCODE_SPECIAL_DICT_KEY_CHECK(encode_vim_to__error_ret, + *TV_LIST_ITEM_TV(tv_list_first(kv_pair))); + if ( + _TYPVAL_ENCODE_CONVERT_ONE_VALUE(TYPVAL_ENCODE_FIRST_ARG_NAME, &mpstack, cur_mpsv, + TV_LIST_ITEM_TV(tv_list_first(kv_pair)), copyID, objname) + == FAIL) { + goto encode_vim_to__error_ret; + } + TYPVAL_ENCODE_CONV_DICT_AFTER_KEY(cur_mpsv->tv, + TYPVAL_ENCODE_NODICT_VAR); + tv = TV_LIST_ITEM_TV(tv_list_last(kv_pair)); + cur_mpsv->data.l.li = TV_LIST_ITEM_NEXT(cur_mpsv->data.l.list, + cur_mpsv->data.l.li); + break; + } + case kMPConvPartial: { + partial_T *const pt = cur_mpsv->data.p.pt; + tv = cur_mpsv->tv; + (void)tv; + switch (cur_mpsv->data.p.stage) { + case kMPConvPartialArgs: + TYPVAL_ENCODE_CONV_FUNC_BEFORE_ARGS(tv, + pt == NULL ? 0 : pt->pt_argc); + cur_mpsv->data.p.stage = kMPConvPartialSelf; + if (pt != NULL && pt->pt_argc > 0) { + TYPVAL_ENCODE_CONV_LIST_START(NULL, pt->pt_argc); + _mp_push(mpstack, ((MPConvStackVal) { + .type = kMPConvPartialList, + .tv = NULL, + .saved_copyID = copyID - 1, + .data = { + .a = { + .arg = pt->pt_argv, + .argv = pt->pt_argv, + .todo = (size_t)pt->pt_argc, }, - })); + }, + })); + } + break; + case kMPConvPartialSelf: { + cur_mpsv->data.p.stage = kMPConvPartialEnd; + dict_T *const dict = pt == NULL ? NULL : pt->pt_dict; + if (dict != NULL) { + TYPVAL_ENCODE_CONV_FUNC_BEFORE_SELF(tv, dict->dv_hashtab.ht_used); + if (dict->dv_hashtab.ht_used == 0) { + TYPVAL_ENCODE_CONV_EMPTY_DICT(NULL, pt->pt_dict); + continue; + } + const int saved_copyID = dict->dv_copyID; + const int te_csr_ret = _TYPVAL_ENCODE_CHECK_SELF_REFERENCE(TYPVAL_ENCODE_FIRST_ARG_NAME, + dict, &dict->dv_copyID, + &mpstack, copyID, kMPConvDict, + objname); + if (te_csr_ret != NOTDONE) { + if (te_csr_ret == FAIL) { + goto encode_vim_to__error_ret; + } else { + continue; } - break; } - case kMPConvPartialSelf: { - cur_mpsv->data.p.stage = kMPConvPartialEnd; - dict_T *const dict = pt == NULL ? NULL : pt->pt_dict; - if (dict != NULL) { - TYPVAL_ENCODE_CONV_FUNC_BEFORE_SELF(tv, dict->dv_hashtab.ht_used); - if (dict->dv_hashtab.ht_used == 0) { - TYPVAL_ENCODE_CONV_EMPTY_DICT(NULL, pt->pt_dict); - continue; - } - const int saved_copyID = dict->dv_copyID; - const int te_csr_ret = _TYPVAL_ENCODE_CHECK_SELF_REFERENCE( - TYPVAL_ENCODE_FIRST_ARG_NAME, - dict, &dict->dv_copyID, &mpstack, copyID, kMPConvDict, - objname); - if (te_csr_ret != NOTDONE) { - if (te_csr_ret == FAIL) { - goto encode_vim_to__error_ret; - } else { - continue; - } - } - TYPVAL_ENCODE_CONV_DICT_START(NULL, pt->pt_dict, - dict->dv_hashtab.ht_used); - assert(saved_copyID != copyID && saved_copyID != copyID - 1); - _mp_push(mpstack, ((MPConvStackVal) { + TYPVAL_ENCODE_CONV_DICT_START(NULL, pt->pt_dict, + dict->dv_hashtab.ht_used); + assert(saved_copyID != copyID && saved_copyID != copyID - 1); + _mp_push(mpstack, ((MPConvStackVal) { .type = kMPConvDict, .tv = NULL, .saved_copyID = saved_copyID, @@ -818,33 +795,31 @@ typval_encode_stop_converting_one_item: }, }, })); - TYPVAL_ENCODE_CONV_REAL_DICT_AFTER_START(NULL, pt->pt_dict, - _mp_last(mpstack)); - } else { - TYPVAL_ENCODE_CONV_FUNC_BEFORE_SELF(tv, -1); - } - break; - } - case kMPConvPartialEnd: { - TYPVAL_ENCODE_CONV_FUNC_END(tv); - (void)_mp_pop(mpstack); - break; - } + TYPVAL_ENCODE_CONV_REAL_DICT_AFTER_START(NULL, pt->pt_dict, + _mp_last(mpstack)); + } else { + TYPVAL_ENCODE_CONV_FUNC_BEFORE_SELF(tv, -1); } - continue; + break; } - case kMPConvPartialList: { - if (!cur_mpsv->data.a.todo) { - (void)_mp_pop(mpstack); - TYPVAL_ENCODE_CONV_LIST_END(NULL); - continue; - } else if (cur_mpsv->data.a.argv != cur_mpsv->data.a.arg) { - TYPVAL_ENCODE_CONV_LIST_BETWEEN_ITEMS(NULL); - } - tv = cur_mpsv->data.a.arg++; - cur_mpsv->data.a.todo--; + case kMPConvPartialEnd: + TYPVAL_ENCODE_CONV_FUNC_END(tv); + (void)_mp_pop(mpstack); break; } + continue; + } + case kMPConvPartialList: + if (!cur_mpsv->data.a.todo) { + (void)_mp_pop(mpstack); + TYPVAL_ENCODE_CONV_LIST_END(NULL); + continue; + } else if (cur_mpsv->data.a.argv != cur_mpsv->data.a.arg) { + TYPVAL_ENCODE_CONV_LIST_BETWEEN_ITEMS(NULL); + } + tv = cur_mpsv->data.a.arg++; + cur_mpsv->data.a.todo--; + break; } assert(tv != NULL); if (_TYPVAL_ENCODE_CONVERT_ONE_VALUE(TYPVAL_ENCODE_FIRST_ARG_NAME, &mpstack, diff --git a/src/nvim/eval/typval_encode.h b/src/nvim/eval/typval_encode.h index 3475f6d8b3..d5cf431870 100644 --- a/src/nvim/eval/typval_encode.h +++ b/src/nvim/eval/typval_encode.h @@ -5,14 +5,14 @@ #ifndef NVIM_EVAL_TYPVAL_ENCODE_H #define NVIM_EVAL_TYPVAL_ENCODE_H -#include <stddef.h> +#include <assert.h> #include <inttypes.h> +#include <stddef.h> #include <string.h> -#include <assert.h> -#include "nvim/lib/kvec.h" #include "nvim/eval/typval.h" #include "nvim/func_attr.h" +#include "nvim/lib/kvec.h" /// Type of the stack entry typedef enum { @@ -87,7 +87,7 @@ static inline size_t tv_strlen(const typval_T *const tv) assert(tv->v_type == VAR_STRING); return (tv->vval.v_string == NULL ? 0 - : strlen((char *) tv->vval.v_string)); + : strlen((char *)tv->vval.v_string)); } /// Code for checking whether container references itself @@ -100,19 +100,19 @@ static inline size_t tv_strlen(const typval_T *const tv) /// @param conv_type Type of the conversion, @see MPConvStackValType. #define _TYPVAL_ENCODE_DO_CHECK_SELF_REFERENCE(val, copyID_attr, copyID, \ conv_type) \ - do { \ - const int te_csr_ret = _TYPVAL_ENCODE_CHECK_SELF_REFERENCE( \ - TYPVAL_ENCODE_FIRST_ARG_NAME, \ - (val), &(val)->copyID_attr, mpstack, copyID, conv_type, objname); \ - if (te_csr_ret != NOTDONE) { \ - return te_csr_ret; \ - } \ - } while (0) + do { \ + const int te_csr_ret = _TYPVAL_ENCODE_CHECK_SELF_REFERENCE(TYPVAL_ENCODE_FIRST_ARG_NAME, \ + (val), &(val)->copyID_attr, mpstack, \ + copyID, conv_type, objname); \ + if (te_csr_ret != NOTDONE) { \ + return te_csr_ret; \ + } \ + } while (0) #define _TYPVAL_ENCODE_FUNC_NAME_INNER_2(pref, name, suf) \ - pref##name##suf + pref##name##suf #define _TYPVAL_ENCODE_FUNC_NAME_INNER(pref, name, suf) \ - _TYPVAL_ENCODE_FUNC_NAME_INNER_2(pref, name, suf) + _TYPVAL_ENCODE_FUNC_NAME_INNER_2(pref, name, suf) /// Construct function name, possibly using macros /// @@ -125,22 +125,22 @@ static inline size_t tv_strlen(const typval_T *const tv) /// /// @return Concat: pref + #TYPVAL_ENCODE_NAME + suf. #define _TYPVAL_ENCODE_FUNC_NAME(pref, suf) \ - _TYPVAL_ENCODE_FUNC_NAME_INNER(pref, TYPVAL_ENCODE_NAME, suf) + _TYPVAL_ENCODE_FUNC_NAME_INNER(pref, TYPVAL_ENCODE_NAME, suf) /// Self reference checker function name #define _TYPVAL_ENCODE_CHECK_SELF_REFERENCE \ - _TYPVAL_ENCODE_FUNC_NAME(_typval_encode_, _check_self_reference) + _TYPVAL_ENCODE_FUNC_NAME(_typval_encode_, _check_self_reference) /// Entry point function name #define _TYPVAL_ENCODE_ENCODE \ - _TYPVAL_ENCODE_FUNC_NAME(encode_vim_to_, ) + _TYPVAL_ENCODE_FUNC_NAME(encode_vim_to_, ) /// Name of the …convert_one_value function #define _TYPVAL_ENCODE_CONVERT_ONE_VALUE \ - _TYPVAL_ENCODE_FUNC_NAME(_typval_encode_, _convert_one_value) + _TYPVAL_ENCODE_FUNC_NAME(_typval_encode_, _convert_one_value) /// Name of the dummy const dict_T *const variable #define TYPVAL_ENCODE_NODICT_VAR \ - _TYPVAL_ENCODE_FUNC_NAME(_typval_encode_, _nodict_var) + _TYPVAL_ENCODE_FUNC_NAME(_typval_encode_, _nodict_var) #endif // NVIM_EVAL_TYPVAL_ENCODE_H diff --git a/src/nvim/eval/userfunc.h b/src/nvim/eval/userfunc.h index 3f111343d2..ed86aaad4a 100644 --- a/src/nvim/eval/userfunc.h +++ b/src/nvim/eval/userfunc.h @@ -8,7 +8,7 @@ typedef struct { dict_T *fd_dict; ///< Dictionary used. char_u *fd_newkey; ///< New key in "dict" in allocated memory. - dictitem_T *fd_di; ///< Dictionary item used. + dictitem_T *fd_di; ///< Dictionary item used. } funcdict_T; typedef struct funccal_entry funccal_entry_T; |