aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/eval/decode.c
diff options
context:
space:
mode:
authorZyX <kp-pav@yandex.ru>2016-02-06 03:14:10 +0300
committerZyX <kp-pav@yandex.ru>2016-04-18 02:45:49 +0300
commit33778c36ccc62d83d24ab30181926ba44fa4eecf (patch)
treef573a6b0fa30b4f83fea9f057fdf52b80e305e24 /src/nvim/eval/decode.c
parent6167ce6df2753d5474ad49aea19f5957128ab015 (diff)
downloadrneovim-33778c36ccc62d83d24ab30181926ba44fa4eecf.tar.gz
rneovim-33778c36ccc62d83d24ab30181926ba44fa4eecf.tar.bz2
rneovim-33778c36ccc62d83d24ab30181926ba44fa4eecf.zip
*: Fix linter errors
Diffstat (limited to 'src/nvim/eval/decode.c')
-rw-r--r--src/nvim/eval/decode.c55
1 files changed, 30 insertions, 25 deletions
diff --git a/src/nvim/eval/decode.c b/src/nvim/eval/decode.c
index de89f9c132..29a1b2a82a 100644
--- a/src/nvim/eval/decode.c
+++ b/src/nvim/eval/decode.c
@@ -69,6 +69,8 @@ static inline void create_special_dict(typval_T *const rettv,
};
}
+#define DICT_LEN(dict) (dict)->dv_hashtab.ht_used
+
/// Helper function used for working with stack vectors used by JSON decoder
///
/// @param[in] obj New object.
@@ -158,8 +160,7 @@ static inline int json_decoder_pop(ValuesStackItem obj,
return FAIL;
} else if (!obj.didcomma
&& (last_container.special_val == NULL
- && (last_container.container.vval.v_dict->dv_hashtab.ht_used
- != 0))) {
+ && (DICT_LEN(last_container.container.vval.v_dict) != 0))) {
EMSG2(_("E474: Expected comma before dictionary key: %s"), val_location);
clear_tv(&obj.val);
return FAIL;
@@ -191,6 +192,25 @@ static inline int json_decoder_pop(ValuesStackItem obj,
return OK;
}
+#define OBJ(obj_tv, is_sp_string) \
+ ((ValuesStackItem) { \
+ .is_special_string = (is_sp_string), \
+ .val = (obj_tv), \
+ .didcomma = didcomma, \
+ .didcolon = didcolon, \
+ })
+#define POP(obj_tv, is_sp_string) \
+ do { \
+ if (json_decoder_pop(OBJ(obj_tv, is_sp_string), &stack, &container_stack, \
+ &p, &next_map_special, &didcomma, &didcolon) \
+ == FAIL) { \
+ goto json_decode_string_fail; \
+ } \
+ if (next_map_special) { \
+ goto json_decode_string_cycle_start; \
+ } \
+ } while (0)
+
/// Convert JSON string into VimL object
///
/// @param[in] buf String to convert. UTF-8 encoding is assumed.
@@ -215,24 +235,6 @@ int json_decode_string(const char *const buf, const size_t len,
bool didcomma = false;
bool didcolon = false;
bool next_map_special = false;
-#define OBJ(obj_tv, is_sp_string) \
- ((ValuesStackItem) { \
- .is_special_string = (is_sp_string), \
- .val = (obj_tv), \
- .didcomma = didcomma, \
- .didcolon = didcolon, \
- })
-#define POP(obj_tv, is_sp_string) \
- do { \
- if (json_decoder_pop(OBJ(obj_tv, is_sp_string), &stack, &container_stack, \
- &p, &next_map_special, &didcomma, &didcolon) \
- == FAIL) { \
- goto json_decode_string_fail; \
- } \
- if (next_map_special) { \
- goto json_decode_string_cycle_start; \
- } \
- } while (0)
const char *p = buf;
for (; p < e; p++) {
json_decode_string_cycle_start:
@@ -268,7 +270,8 @@ json_decode_string_cycle_start:
goto json_decode_string_after_cycle;
} else {
if (json_decoder_pop(kv_pop(stack), &stack, &container_stack, &p,
- &next_map_special, &didcomma, &didcolon) == FAIL) {
+ &next_map_special, &didcomma, &didcolon)
+ == FAIL) {
goto json_decode_string_fail;
}
assert(!next_map_special);
@@ -293,8 +296,7 @@ json_decode_string_cycle_start:
goto json_decode_string_fail;
} else if (last_container.special_val == NULL
? (last_container.container.v_type == VAR_DICT
- ? (last_container.container.vval.v_dict->dv_hashtab.ht_used
- == 0)
+ ? (DICT_LEN(last_container.container.vval.v_dict) == 0)
: (last_container.container.vval.v_list->lv_len == 0))
: (last_container.special_val->lv_len == 0)) {
EMSG2(_("E474: Leading comma: %s"), p);
@@ -686,8 +688,6 @@ json_decode_string_cycle_start:
break;
}
}
-#undef POP
-#undef OBJ
json_decode_string_after_cycle:
for (; p < e; p++) {
switch (*p) {
@@ -722,6 +722,11 @@ json_decode_string_ret:
return ret;
}
+#undef POP
+#undef OBJ
+
+#undef DICT_LEN
+
/// Convert msgpack object to a VimL one
int msgpack_to_vim(const msgpack_object mobj, typval_T *const rettv)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT