typval_encode.h
Go to the documentation of this file.
1 #ifndef NVIM_EVAL_TYPVAL_ENCODE_H
6 #define NVIM_EVAL_TYPVAL_ENCODE_H
7 
8 #include <stddef.h>
9 #include <inttypes.h>
10 #include <string.h>
11 #include <assert.h>
12 
13 #include "nvim/lib/kvec.h"
14 #include "nvim/eval/typval.h"
15 #include "nvim/func_attr.h"
16 
18 typedef enum {
25 
27 typedef enum {
32 
34 typedef struct {
38  union {
39  struct {
42  hashitem_T *hi;
45  size_t todo;
46  } d;
47  struct {
50  } l;
51  struct {
54  } p;
55  struct {
58  size_t todo;
59  } a;
60  } data;
62 
64 typedef kvec_withinit_t(MPConvStackVal, 8) MPConvStack;
65 
66 // Defines for MPConvStack
67 #define _mp_size kv_size
68 #define _mp_init kvi_init
69 #define _mp_destroy kvi_destroy
70 #define _mp_push kvi_push
71 #define _mp_pop kv_pop
72 #define _mp_last kv_last
73 
74 static inline size_t tv_strlen(const typval_T *const tv)
77 
85 static inline size_t tv_strlen(const typval_T *const tv)
86 {
87  assert(tv->v_type == VAR_STRING);
88  return (tv->vval.v_string == NULL
89  ? 0
90  : strlen((char *) tv->vval.v_string));
91 }
92 
101 #define _TYPVAL_ENCODE_DO_CHECK_SELF_REFERENCE(val, copyID_attr, copyID, \
102  conv_type) \
103  do { \
104  const int te_csr_ret = _TYPVAL_ENCODE_CHECK_SELF_REFERENCE( \
105  TYPVAL_ENCODE_FIRST_ARG_NAME, \
106  (val), &(val)->copyID_attr, mpstack, copyID, conv_type, objname); \
107  if (te_csr_ret != NOTDONE) { \
108  return te_csr_ret; \
109  } \
110  } while (0)
111 
112 #define _TYPVAL_ENCODE_FUNC_NAME_INNER_2(pref, name, suf) \
113  pref##name##suf
114 #define _TYPVAL_ENCODE_FUNC_NAME_INNER(pref, name, suf) \
115  _TYPVAL_ENCODE_FUNC_NAME_INNER_2(pref, name, suf)
116 
127 #define _TYPVAL_ENCODE_FUNC_NAME(pref, suf) \
128  _TYPVAL_ENCODE_FUNC_NAME_INNER(pref, TYPVAL_ENCODE_NAME, suf)
129 
131 #define _TYPVAL_ENCODE_CHECK_SELF_REFERENCE \
132  _TYPVAL_ENCODE_FUNC_NAME(_typval_encode_, _check_self_reference)
133 
135 #define _TYPVAL_ENCODE_ENCODE \
136  _TYPVAL_ENCODE_FUNC_NAME(encode_vim_to_, )
137 
139 #define _TYPVAL_ENCODE_CONVERT_ONE_VALUE \
140  _TYPVAL_ENCODE_FUNC_NAME(_typval_encode_, _convert_one_value)
141 
143 #define TYPVAL_ENCODE_NODICT_VAR \
144  _TYPVAL_ENCODE_FUNC_NAME(_typval_encode_, _nodict_var)
145 
146 #endif // NVIM_EVAL_TYPVAL_ENCODE_H
typval_T tv
Definition: typval.c:1542
Already converted everything.
Definition: typval_encode.h:30
MPConvPartialStage
Stage at which partial is being converted.
Definition: typval_encode.h:27
Convert mapping represented as a list_T* of pairs.
Definition: typval_encode.h:21
Definition: typval.h:166
Structure that holds an internal variable value.
Definition: typval.h:125
Definition: typval.h:150
MPConvStackValType type
Type of the stack entry.
Definition: typval_encode.h:35
typedef kvec_withinit_t(MPConvStackVal, 8) MPConvStack
Stack used to convert VimL values to messagepack.
dict_T * d
Definition: eval.c:15234
return NULL
Definition: eval.c:23240
String, .v_string is used.
Definition: typval.h:114
Structure representing current VimL to messagepack conversion state.
Definition: typval_encode.h:34
Convert partial_T* partial.
Definition: typval_encode.h:22
int saved_copyID
copyID item used to have.
Definition: typval_encode.h:37
typval_T * argv
Start of the argument list.
Definition: typval_encode.h:57
Convert argc/argv pair coming from a partial.
Definition: typval_encode.h:23
listitem_T * li
Currently converted list item.
Definition: typval_encode.h:49
static int REAL_FATTR_WARN_UNUSED_RESULT
Definition: typval_encode.c.h:295
Convert list_T *list.
Definition: typval_encode.h:20
list_T * list
Currently converted list.
Definition: typval_encode.h:48
#define REAL_FATTR_NONNULL_ALL
Definition: func_attr.h:183
VarType v_type
Variable type.
Definition: typval.h:126
Definition: typval.h:289
assert(len >=0)
Definition: coverity-model.c:40
Convert dict_T *dictionary.
Definition: typval_encode.h:19
typval_T * tv
Currently converted typval_T.
Definition: typval_encode.h:36
char_u * v_string
String, for VAR_STRING and VAR_FUNC, can be NULL.
Definition: typval.h:132
union typval_T::typval_vval_union vval
Actual value.
MPConvStackValType
Type of the stack entry.
Definition: typval_encode.h:18
dict_T * dict
Currently converted dictionary.
Definition: typval_encode.h:40
About to convert arguments.
Definition: typval_encode.h:28
typval_T * arg
Currently converted argument.
Definition: typval_encode.h:56
static int REAL_FATTR_WARN_UNUSED_RESULT REAL_FATTR_ALWAYS_INLINE
Definition: typval_encode.c.h:258
size_t todo
Amount of items left to process.
Definition: typval_encode.h:45
partial_T * pt
Currently converted partial.
Definition: typval_encode.h:53
char_u * p
Definition: eval.c:2174
#define REAL_FATTR_PURE
Definition: func_attr.h:163
dict_T ** dictp
Definition: typval_encode.h:41
list_T *const l
Definition: eval.c:15285
MPConvPartialStage stage
Stage at which partial is being converted.
Definition: typval_encode.h:52
About to convert self dictionary.
Definition: typval_encode.h:29
Definition: hashtab.h:38