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 <assert.h>
9 #include <inttypes.h>
10 #include <stddef.h>
11 #include <string.h>
12 
13 #include "nvim/eval/typval.h"
14 #include "nvim/func_attr.h"
15 #include "nvim/lib/kvec.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 {
88  return (tv->vval.v_string == NULL ? 0 : strlen(tv->vval.v_string));
89 }
90 
99 #define _TYPVAL_ENCODE_DO_CHECK_SELF_REFERENCE(val, copyID_attr, copyID, \
100  conv_type) \
101  do { \
102  const int te_csr_ret = _TYPVAL_ENCODE_CHECK_SELF_REFERENCE(TYPVAL_ENCODE_FIRST_ARG_NAME, \
103  (val), &(val)->copyID_attr, mpstack, \
104  copyID, conv_type, objname); \
105  if (te_csr_ret != NOTDONE) { \
106  return te_csr_ret; \
107  } \
108  } while (0)
109 
110 #define _TYPVAL_ENCODE_FUNC_NAME_INNER_2(pref, name, suf) \
111  pref##name##suf
112 #define _TYPVAL_ENCODE_FUNC_NAME_INNER(pref, name, suf) \
113  _TYPVAL_ENCODE_FUNC_NAME_INNER_2(pref, name, suf)
114 
125 #define _TYPVAL_ENCODE_FUNC_NAME(pref, suf) \
126  _TYPVAL_ENCODE_FUNC_NAME_INNER(pref, TYPVAL_ENCODE_NAME, suf)
127 
129 #define _TYPVAL_ENCODE_CHECK_SELF_REFERENCE \
130  _TYPVAL_ENCODE_FUNC_NAME(_typval_encode_, _check_self_reference)
131 
133 #define _TYPVAL_ENCODE_ENCODE \
134  _TYPVAL_ENCODE_FUNC_NAME(encode_vim_to_, )
135 
137 #define _TYPVAL_ENCODE_CONVERT_ONE_VALUE \
138  _TYPVAL_ENCODE_FUNC_NAME(_typval_encode_, _convert_one_value)
139 
141 #define TYPVAL_ENCODE_NODICT_VAR \
142  _TYPVAL_ENCODE_FUNC_NAME(_typval_encode_, _nodict_var)
143 
144 #endif // NVIM_EVAL_TYPVAL_ENCODE_H
tv
typval_T tv
Definition: typval.c:1705
MPConvStackVal::saved_copyID
int saved_copyID
copyID item used to have.
Definition: typval_encode.h:37
typval_T
Structure that holds an internal variable value.
Definition: typval.h:135
MPConvStackVal::stage
MPConvPartialStage stage
Stage at which partial is being converted.
Definition: typval_encode.h:52
VAR_STRING
@ VAR_STRING
String, .v_string is used.
Definition: typval.h:122
p
char * p
Definition: eval.c:2017
kMPConvPartialArgs
@ kMPConvPartialArgs
About to convert arguments.
Definition: typval_encode.h:28
listvar_S
Definition: typval.h:178
kMPConvPartialSelf
@ kMPConvPartialSelf
About to convert self dictionary.
Definition: typval_encode.h:29
MPConvStackValType
MPConvStackValType
Type of the stack entry.
Definition: typval_encode.h:18
MPConvStackVal::argv
typval_T * argv
Start of the argument list.
Definition: typval_encode.h:57
assert.h
MPConvPartialStage
MPConvPartialStage
Stage at which partial is being converted.
Definition: typval_encode.h:27
MPConvStackVal
Structure representing current VimL to messagepack conversion state.
Definition: typval_encode.h:34
kMPConvPairs
@ kMPConvPairs
Convert mapping represented as a list_T* of pairs.
Definition: typval_encode.h:21
typval_T::typval_vval_union::v_string
char * v_string
String, for VAR_STRING and VAR_FUNC, can be NULL.
Definition: typval.h:143
typval_T::v_type
VarType v_type
Variable type.
Definition: typval.h:136
kMPConvPartialEnd
@ kMPConvPartialEnd
Already converted everything.
Definition: typval_encode.h:30
MPConvStackVal::type
MPConvStackValType type
Type of the stack entry.
Definition: typval_encode.h:35
MPConvStackVal::tv
typval_T * tv
Currently converted typval_T.
Definition: typval_encode.h:36
REAL_FATTR_NONNULL_ALL
#define REAL_FATTR_NONNULL_ALL
Definition: func_attr.h:183
MPConvStackVal::li
listitem_T * li
Currently converted list item.
Definition: typval_encode.h:49
MPConvStackVal::list
list_T * list
Currently converted list.
Definition: typval_encode.h:48
MPConvStackVal::arg
typval_T * arg
Currently converted argument.
Definition: typval_encode.h:56
kvec.h
kMPConvPartial
@ kMPConvPartial
Convert partial_T* partial.
Definition: typval_encode.h:22
partial_S
Definition: typval.h:364
kMPConvPartialList
@ kMPConvPartialList
Convert argc/argv pair coming from a partial.
Definition: typval_encode.h:23
MPConvStackVal::dict
dict_T * dict
Currently converted dictionary.
Definition: typval_encode.h:40
assert
assert(len >=0)
typval.h
typval_T::vval
union typval_T::typval_vval_union vval
Actual value.
kMPConvList
@ kMPConvList
Convert list_T *list.
Definition: typval_encode.h:20
kvec_withinit_t
typedef kvec_withinit_t(MPConvStackVal, 8) MPConvStack
Stack used to convert VimL values to messagepack.
MPConvStackVal::todo
size_t todo
Amount of items left to process.
Definition: typval_encode.h:45
listitem_S
Definition: typval.h:162
l
list_T *const l
Definition: funcs.c:8835
REAL_FATTR_PURE
#define REAL_FATTR_PURE
Definition: func_attr.h:163
kMPConvDict
@ kMPConvDict
Convert dict_T *dictionary.
Definition: typval_encode.h:19
dict_T
Definition: coverity-model.c:40
func_attr.h
MPConvStackVal::pt
partial_T * pt
Currently converted partial.
Definition: typval_encode.h:53
REAL_FATTR_ALWAYS_INLINE
static int REAL_FATTR_WARN_UNUSED_RESULT REAL_FATTR_ALWAYS_INLINE
Definition: typval_encode.c.h:267
NULL
return NULL
Definition: eval.c:9971
REAL_FATTR_WARN_UNUSED_RESULT
static int REAL_FATTR_WARN_UNUSED_RESULT
Definition: typval_encode.c.h:302
MPConvStackVal::dictp
dict_T ** dictp
Definition: typval_encode.h:41
hashitem_S
Definition: hashtab.h:38