mirror of
https://github.com/neovim/neovim.git
synced 2025-09-20 02:08:17 +00:00
eval/decode: Replace INIT_SPECIAL_DICT macros with inline function
This commit is contained in:
@@ -25,6 +25,34 @@ typedef kvec_t(ContainerStackItem) ContainerStack;
|
||||
# include "eval/decode.c.generated.h"
|
||||
#endif
|
||||
|
||||
/// Create special dictionary
|
||||
///
|
||||
/// @param[out] rettv Location where created dictionary will be saved.
|
||||
/// @param[in] type Type of the dictionary.
|
||||
/// @param[in] val Value associated with the _VAL key.
|
||||
static inline void create_special_dict(typval_T *const rettv,
|
||||
const MessagePackType type,
|
||||
typval_T val)
|
||||
FUNC_ATTR_NONNULL_ALL
|
||||
{
|
||||
dict_T *const dict = dict_alloc();
|
||||
dictitem_T *const type_di = dictitem_alloc((char_u *) "_TYPE");
|
||||
type_di->di_tv.v_type = VAR_LIST;
|
||||
type_di->di_tv.v_lock = 0;
|
||||
type_di->di_tv.vval.v_list = (list_T *) eval_msgpack_type_lists[type];
|
||||
type_di->di_tv.vval.v_list->lv_refcount++;
|
||||
dict_add(dict, type_di);
|
||||
dictitem_T *const val_di = dictitem_alloc((char_u *) "_VAL");
|
||||
val_di->di_tv = val;
|
||||
dict_add(dict, val_di);
|
||||
dict->dv_refcount++;
|
||||
*rettv = (typval_T) {
|
||||
.v_type = VAR_DICT,
|
||||
.v_lock = VAR_UNLOCKED,
|
||||
.vval = { .v_dict = dict },
|
||||
};
|
||||
}
|
||||
|
||||
/// Helper function used for working with stack vectors used by JSON decoder
|
||||
///
|
||||
/// @param[in] obj New object.
|
||||
@@ -521,25 +549,9 @@ json_decode_string_ret:
|
||||
int msgpack_to_vim(const msgpack_object mobj, typval_T *const rettv)
|
||||
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT
|
||||
{
|
||||
#define INIT_SPECIAL_DICT(tv, type, val) \
|
||||
do { \
|
||||
dict_T *const dict = dict_alloc(); \
|
||||
dictitem_T *const type_di = dictitem_alloc((char_u *) "_TYPE"); \
|
||||
type_di->di_tv.v_type = VAR_LIST; \
|
||||
type_di->di_tv.v_lock = 0; \
|
||||
type_di->di_tv.vval.v_list = (list_T *) eval_msgpack_type_lists[type]; \
|
||||
type_di->di_tv.vval.v_list->lv_refcount++; \
|
||||
dict_add(dict, type_di); \
|
||||
dictitem_T *const val_di = dictitem_alloc((char_u *) "_VAL"); \
|
||||
val_di->di_tv = val; \
|
||||
dict_add(dict, val_di); \
|
||||
tv->v_type = VAR_DICT; \
|
||||
dict->dv_refcount++; \
|
||||
tv->vval.v_dict = dict; \
|
||||
} while (0)
|
||||
switch (mobj.type) {
|
||||
case MSGPACK_OBJECT_NIL: {
|
||||
INIT_SPECIAL_DICT(rettv, kMPNil, ((typval_T) {
|
||||
create_special_dict(rettv, kMPNil, ((typval_T) {
|
||||
.v_type = VAR_NUMBER,
|
||||
.v_lock = 0,
|
||||
.vval = { .v_number = 0 },
|
||||
@@ -547,8 +559,7 @@ int msgpack_to_vim(const msgpack_object mobj, typval_T *const rettv)
|
||||
break;
|
||||
}
|
||||
case MSGPACK_OBJECT_BOOLEAN: {
|
||||
INIT_SPECIAL_DICT(rettv, kMPBoolean,
|
||||
((typval_T) {
|
||||
create_special_dict(rettv, kMPBoolean, ((typval_T) {
|
||||
.v_type = VAR_NUMBER,
|
||||
.v_lock = 0,
|
||||
.vval = {
|
||||
@@ -567,8 +578,7 @@ int msgpack_to_vim(const msgpack_object mobj, typval_T *const rettv)
|
||||
} else {
|
||||
list_T *const list = list_alloc();
|
||||
list->lv_refcount++;
|
||||
INIT_SPECIAL_DICT(rettv, kMPInteger,
|
||||
((typval_T) {
|
||||
create_special_dict(rettv, kMPInteger, ((typval_T) {
|
||||
.v_type = VAR_LIST,
|
||||
.v_lock = 0,
|
||||
.vval = { .v_list = list },
|
||||
@@ -591,8 +601,7 @@ int msgpack_to_vim(const msgpack_object mobj, typval_T *const rettv)
|
||||
} else {
|
||||
list_T *const list = list_alloc();
|
||||
list->lv_refcount++;
|
||||
INIT_SPECIAL_DICT(rettv, kMPInteger,
|
||||
((typval_T) {
|
||||
create_special_dict(rettv, kMPInteger, ((typval_T) {
|
||||
.v_type = VAR_LIST,
|
||||
.v_lock = 0,
|
||||
.vval = { .v_list = list },
|
||||
@@ -616,8 +625,7 @@ int msgpack_to_vim(const msgpack_object mobj, typval_T *const rettv)
|
||||
case MSGPACK_OBJECT_STR: {
|
||||
list_T *const list = list_alloc();
|
||||
list->lv_refcount++;
|
||||
INIT_SPECIAL_DICT(rettv, kMPString,
|
||||
((typval_T) {
|
||||
create_special_dict(rettv, kMPString, ((typval_T) {
|
||||
.v_type = VAR_LIST,
|
||||
.v_lock = 0,
|
||||
.vval = { .v_list = list },
|
||||
@@ -639,8 +647,7 @@ int msgpack_to_vim(const msgpack_object mobj, typval_T *const rettv)
|
||||
}
|
||||
list_T *const list = list_alloc();
|
||||
list->lv_refcount++;
|
||||
INIT_SPECIAL_DICT(rettv, kMPBinary,
|
||||
((typval_T) {
|
||||
create_special_dict(rettv, kMPBinary, ((typval_T) {
|
||||
.v_type = VAR_LIST,
|
||||
.v_lock = 0,
|
||||
.vval = { .v_list = list },
|
||||
@@ -705,8 +712,7 @@ int msgpack_to_vim(const msgpack_object mobj, typval_T *const rettv)
|
||||
msgpack_to_vim_generic_map: {}
|
||||
list_T *const list = list_alloc();
|
||||
list->lv_refcount++;
|
||||
INIT_SPECIAL_DICT(rettv, kMPMap,
|
||||
((typval_T) {
|
||||
create_special_dict(rettv, kMPMap, ((typval_T) {
|
||||
.v_type = VAR_LIST,
|
||||
.v_lock = 0,
|
||||
.vval = { .v_list = list },
|
||||
@@ -735,8 +741,7 @@ msgpack_to_vim_generic_map: {}
|
||||
list_append_number(list, mobj.via.ext.type);
|
||||
list_T *const ext_val_list = list_alloc();
|
||||
list_append_list(list, ext_val_list);
|
||||
INIT_SPECIAL_DICT(rettv, kMPExt,
|
||||
((typval_T) {
|
||||
create_special_dict(rettv, kMPExt, ((typval_T) {
|
||||
.v_type = VAR_LIST,
|
||||
.v_lock = 0,
|
||||
.vval = { .v_list = list },
|
||||
@@ -748,6 +753,5 @@ msgpack_to_vim_generic_map: {}
|
||||
break;
|
||||
}
|
||||
}
|
||||
#undef INIT_SPECIAL_DICT
|
||||
return OK;
|
||||
}
|
||||
|
Reference in New Issue
Block a user