Go to the documentation of this file. 1 #ifndef NVIM_EVAL_TYPVAL_H
2 #define NVIM_EVAL_TYPVAL_H
21 #ifdef LOG_LIST_ACTIONS
55 #define VARNUMBER_MAX INT64_MAX
56 #define UVARNUMBER_MAX UINT64_MAX
59 #define VARNUMBER_MIN INT64_MIN
62 #define PRIdVARNUMBER PRId64
87 #define CALLBACK_INIT { .type = kCallbackNone }
88 #define CALLBACK_NONE ((Callback)CALLBACK_INIT)
201 #define TV_LIST_STATIC10_INIT { \
208 .lv_idx_item = NULL, \
209 .lv_lock = VAR_FIXED, \
210 .lv_used_next = NULL, \
211 .lv_used_prev = NULL, \
215 #define TV_DICTITEM_STRUCT(...) \
219 char_u di_key[__VA_ARGS__]; \
287 #define MAX_FUNC_ARGS 20
288 #define VAR_SHORT_LEN 20
290 #define FIXVAR_CNT 12
396 #ifdef LOG_LIST_ACTIONS
414 ListLogEntry entries[];
417 extern ListLog *list_log_first;
418 extern ListLog *list_log_last;
420 static inline ListLog *list_log_alloc(
const size_t size)
428 static inline ListLog *list_log_new(
const size_t size)
430 ListLog *
ret =
xmalloc(offsetof(ListLog, entries)
431 +
size *
sizeof(
ret->entries[0]));
435 if (list_log_first ==
NULL) {
436 list_log_first =
ret;
438 list_log_last->next =
ret;
463 if (list_log_first ==
NULL) {
464 tgt = list_log_new(128);
465 }
else if (list_log_last->size == list_log_last->capacity) {
466 tgt = list_log_new(list_log_last->capacity * 2);
470 tgt->entries[tgt->size++] = (ListLogEntry) {
472 .li1 = (uintptr_t)li1,
473 .li2 = (uintptr_t)li2,
479 # define list_log(...)
480 # define list_write_log(...)
481 # define list_free_log()
488 #define TV_DICT_HI2DI(hi) \
489 ((dictitem_T *)((hi)->hi_key - offsetof(dictitem_T, di_key)))
491 static inline void tv_list_ref(
list_T *
const l)
499 static inline void tv_list_ref(
list_T *
const l)
558 static inline void tv_list_set_copyid(
list_T *
const l,
const int copyid)
564 static inline int tv_list_len(
const list_T *
const l)
570 static inline int tv_list_len(
const list_T *
const l)
579 static inline int tv_list_copyid(
const list_T *
const l)
587 static inline int tv_list_copyid(
const list_T *
const l)
592 static inline list_T *tv_list_latest_copy(
const list_T *
const l)
602 static inline list_T *tv_list_latest_copy(
const list_T *
const l)
607 static inline int tv_list_uidx(
const list_T *
const l,
int n)
616 static inline int tv_list_uidx(
const list_T *
const l,
int n)
624 if (n < 0 || n >= tv_list_len(
l)) {
630 static inline bool tv_list_has_watchers(
const list_T *
const l)
640 static inline bool tv_list_has_watchers(
const list_T *
const l)
697 static inline long tv_dict_len(
const dict_T *
const d)
703 static inline long tv_dict_len(
const dict_T *
const d)
708 return (
long)d->dv_hashtab.ht_used;
711 static inline bool tv_dict_is_watched(
const dict_T *
const d)
719 static inline bool tv_dict_is_watched(
const dict_T *
const d)
721 return d && !QUEUE_EMPTY(&d->watchers);
742 static inline int tv_blob_len(
const blob_T *
const b)
748 static inline int tv_blob_len(
const blob_T *
const b)
756 static inline char_u tv_blob_get(
const blob_T *
const b,
int idx)
765 static inline char_u tv_blob_get(
const blob_T *
const b,
int idx)
770 static inline void tv_blob_set(
blob_T *
const b,
int idx,
char_u c)
778 static inline void tv_blob_set(
blob_T *
const b,
int idx,
char_u c)
788 static inline void tv_init(
typval_T *
const tv)
795 #define TV_INITIAL_VALUE \
797 .v_type = VAR_UNKNOWN, \
798 .v_lock = VAR_UNLOCKED, \
817 #define _TV_LIST_ITER_MOD(modifier, l, li, code) \
819 modifier list_T *const l_ = (l); \
820 list_log(l_, NULL, NULL, "iter" #modifier); \
822 for (modifier listitem_T *li = l_->lv_first; \
823 li != NULL; li = li->li_next) { \
837 #define TV_LIST_ITER(l, li, code) \
838 _TV_LIST_ITER_MOD( , l, li, code)
848 #define TV_LIST_ITER_CONST(l, li, code) \
849 _TV_LIST_ITER_MOD(const, l, li, code)
859 #define TV_LIST_ITEM_TV(li) (&(li)->li_tv)
867 #define TV_LIST_ITEM_NEXT(l, li) ((li)->li_next)
875 #define TV_LIST_ITEM_PREV(l, li) ((li)->li_prev)
885 #define TV_DICT_ITER(d, di, code) \
886 HASHTAB_ITER(&(d)->dv_hashtab, di##hi_, { \
888 dictitem_T *const di = TV_DICT_HI2DI(di##hi_); \
895 static inline bool tv_get_float_chk(
const typval_T *
const tv,
900 bool semsg(
const char *
const fmt, ...);
910 static inline bool tv_get_float_chk(
const typval_T *
const tv,
float_T *
const ret_f)
920 semsg(
"%s",
_(
"E808: Number or Float required"));
937 static inline bool tv_is_func(
const typval_T tv)
947 static inline bool tv_is_func(
const typval_T tv)
956 #define TV_TRANSLATE (SIZE_MAX)
961 #define TV_CSTRING (SIZE_MAX - 1)
969 #ifdef INCLUDE_GENERATED_DECLARATIONS
970 # include "eval/typval.h.generated.h"
972 #endif // NVIM_EVAL_TYPVAL_H
listitem_T * lv_first
First item, NULL if none.
Definition: typval.h:179
dict_T l_vars
l: local function variables.
Definition: typval.h:308
#define FUNC_ATTR_CONST
Definition: func_attr.h:243
proftime_T * uf_tml_self
time spent in a line itself
Definition: typval.h:349
LuaRef lua_table_ref
Definition: typval.h:192
listitem_T * lv_last
Last item, NULL if none.
Definition: typval.h:180
garray_T bv_ga
Growarray with the data.
Definition: typval.h:264
proftime_T * uf_tml_total
time spent in a line + children
Definition: typval.h:348
proftime_T uf_tm_total
time spent in function + children
Definition: typval.h:343
@ VAR_FLOAT
Floating-point value, .v_float is used.
Definition: typval.h:126
listitem_T * lv_idx_item
When not NULL item at index "lv_idx".
Definition: typval.h:182
struct ht_stack_S * prev
Definition: typval.h:379
ufunc_T * pt_func
Definition: typval.h:367
@ VAR_SCOPE
Scope dictionary which requires prefix (a:, v:, …).
Definition: typval.h:154
SpecialVarValue v_special
Special value, for VAR_SPECIAL.
Definition: typval.h:141
uint64_t uvarnumber_T
Definition: typval.h:27
dict_T * pt_dict
Dict for "self".
Definition: typval.h:373
typval_T tv
Definition: typval.c:1705
int(* ListSorter)(const void *, const void *)
Definition: typval.h:394
varnumber_T v_number
Number, for VAR_NUMBER.
Definition: typval.h:139
@ DI_FLAGS_ALLOC
Separately allocated.
Definition: typval.h:243
#define _(x)
Definition: gettext.h:20
CallbackType
Definition: typval.h:71
const char *const tv_empty_string
Definition: typval.c:48
int dv_copyID
ID used when recursivery traversing a value.
Definition: typval.h:252
proftime_T uf_tml_wait
start wait time for current line
Definition: typval.h:352
VarType
VimL variable types, for use in typval_T.v_type.
Definition: typval.h:119
Structure that holds an internal variable value.
Definition: typval.h:135
int lv_len
Number of items.
Definition: typval.h:187
#define REAL_FATTR_NONNULL_RET
Definition: func_attr.h:191
partial_T * v_partial
Closure: function with args.
Definition: typval.h:146
#define list_log(...)
Definition: typval.h:479
list_T l_varlist
List for a:000.
Definition: typval.h:312
int uf_flags
Definition: typval.h:329
linenr_T breakpoint
Next line with breakpoint or zero.
Definition: typval.h:315
QUEUE node
Definition: typval.h:95
typval_T * rettv
Return value.
Definition: typval.h:314
@ VAR_STRING
String, .v_string is used.
Definition: typval.h:122
hashtab_T dv_hashtab
Hashtab containing all items.
Definition: typval.h:253
int uf_varargs
variable nr of arguments
Definition: typval.h:328
@ kCallbackFuncref
Definition: typval.h:73
ScopeType
Values for (struct dictvar_S).dv_scope.
Definition: typval.h:152
int uf_tml_execed
line being timed was executed
Definition: typval.h:354
size_t size
Definition: regexp_nfa.c:5986
int fc_refcount
Number of user functions that reference this funccall.
Definition: typval.h:321
@ VAR_UNKNOWN
Unknown (unspecified) value.
Definition: typval.h:120
int returned
Definition: typval.h:305
CallbackType type
Definition: typval.h:84
int dv_refcount
Reference count.
Definition: typval.h:251
int lv_copyID
ID used by deepcopy().
Definition: typval.h:189
@ VAR_FIXED
Locked forever.
Definition: typval.h:115
char * key_pattern
Definition: typval.h:93
proftime_T uf_tml_start
start time for current line
Definition: typval.h:350
void * xmalloc(size_t size) FUNC_ATTR_MALLOC FUNC_ATTR_ALLOC_SIZE(1) FUNC_ATTR_NONNULL_RET
Definition: memory.c:105
Structure to hold info about a Blob.
Definition: typval.h:263
listwatch_T * lw_next
Next watcher.
Definition: typval.h:173
@ VAR_NO_SCOPE
Not a scope dictionary.
Definition: typval.h:153
size_t key_pattern_len
Definition: typval.h:94
@ DI_FLAGS_FIX
Fixed value: cannot be :unlet or remove()d.
Definition: typval.h:241
#define TV_TRANSLATE
Definition: typval.h:956
bool semsg(const char *const fmt,...)
Print an error message with unknown number of arguments.
#define QUEUE_DATA(ptr, type, field)
Definition: queue.h:33
int(* cfunc_T)(int argcount, typval_T *argvars, typval_T *rettv, void *state)
Definition: typval.h:295
char * v_string
String, for VAR_STRING and VAR_FUNC, can be NULL.
Definition: typval.h:143
proftime_T uf_tm_children
time spent in children this call
Definition: typval.h:345
listitem_T l_listitems[MAX_FUNC_ARGS]
List items for a:000.
Definition: typval.h:313
@ kCallbackLua
Definition: typval.h:75
list_T * v_list
List for VAR_LIST, can be NULL.
Definition: typval.h:144
@ kBoolVarFalse
v:false
Definition: typval.h:102
float_T v_float
Floating-point number, for VAR_FLOAT.
Definition: typval.h:142
hashtab_T * ht
Definition: typval.h:378
ListLenSpecials
Additional values for tv_list_alloc() len argument.
Definition: typval.h:36
const int ret
Definition: eval.c:746
BoolVarValue v_bool
Bool value, for VAR_BOOL.
Definition: typval.h:140
@ kListLenShouldKnow
Definition: typval.h:47
void(WINAPI *pClosePseudoConsole)(HPCON)
garray_T fc_funcs
List of ufunc_T* which keep a reference to "func".
Definition: typval.h:323
#define INIT(...)
Definition: macros.h:10
list_T * lv_used_next
next list in used lists list.
Definition: typval.h:184
VarType v_type
Variable type.
Definition: typval.h:136
bool needs_free
Definition: typval.h:97
#define TV_CSTRING
Definition: typval.h:961
void * ga_data
Definition: garray.h:17
proftime_T uf_tm_self
time spent in function itself
Definition: typval.h:344
scid_T sc_sid
Definition: typval.h:281
int LuaRef
Definition: types.h:23
int * uf_tml_count
nr of times line was executed
Definition: typval.h:347
@ kListLenUnknown
Definition: typval.h:41
int linenr
Next line to be executed.
Definition: typval.h:304
VarLockStatus
Variable lock status for typval_T.v_lock.
Definition: typval.h:112
listitem_T * lw_item
Item being watched.
Definition: typval.h:172
typval_T * pt_argv
Arguments in allocated array.
Definition: typval.h:372
int ga_len
Definition: garray.h:13
#define REAL_FATTR_NONNULL_ALL
Definition: func_attr.h:183
int scid_T
Type used for script ID.
Definition: typval.h:270
VarLockStatus v_lock
Variable lock status.
Definition: typval.h:137
Structure holding dictionary watcher.
Definition: typval.h:91
listitem_T * item
Sorted list item.
Definition: typval.h:390
funccall_T * caller
Definition: typval.h:319
BoolVarValue
Bool variable values.
Definition: typval.h:101
int uf_prof_initialized
Definition: typval.h:336
void(* cfunc_free_T)(void *state)
Callback to clear cfunc_T and any associated state.
Definition: typval.h:297
@ VAR_PARTIAL
Partial, .v_partial is used.
Definition: typval.h:130
@ VAR_BOOL
true, false
Definition: typval.h:127
int n
Definition: funcs.c:8317
struct list_stack_S list_stack_T
Structure used for explicit stack while garbage collecting lists.
bool tv_in_free_unref_items
Specifies that free_unref_items() function has (not) been entered.
Definition: typval.c:42
Structure to hold info for a user function.
Definition: typval.h:327
blob_T * v_blob
Blob for VAR_BLOB, can be NULL.
Definition: typval.h:147
dict_T * v_dict
Dictionary for VAR_DICT, can be NULL.
Definition: typval.h:145
@ VAR_BLOB
Blob, .v_blob is used.
Definition: typval.h:131
@ VAR_LIST
List, .v_list is used.
Definition: typval.h:124
memset(lp, 0, sizeof(lval_T))
list_T * lv_copylist
Copied list used by deepcopy().
Definition: typval.h:183
bool uf_cleared
func_clear() was already called
Definition: typval.h:331
garray_T uf_lines
function lines
Definition: typval.h:334
@ VAR_UNLOCKED
Not locked.
Definition: typval.h:113
Structure used for explicit stack while garbage collecting hash tables.
Definition: typval.h:377
DictItemFlags
Flags for dictitem_T.di_flags.
Definition: typval.h:238
char action
Definition: funcs.c:8779
@ VAR_SPECIAL
Definition: typval.h:128
@ kCallbackPartial
Definition: typval.h:74
list_T * list
Definition: typval.h:384
funccall_T * uf_scoped
l: local variables for closure
Definition: typval.h:358
double float_T
Type used for VimL VAR_FLOAT values.
Definition: typval.h:30
#define VAR_SHORT_LEN
Short variable name length.
Definition: typval.h:289
int level
Top nesting level of executed function.
Definition: typval.h:317
ufunc_T * func
Function being called.
Definition: typval.h:303
struct ht_stack_S ht_stack_T
Structure used for explicit stack while garbage collecting hash tables.
#define FUNC_ATTR_NONNULL_ALL
Definition: func_attr.h:247
ScopeDictDictItem l_avars_var
Variable for a: scope.
Definition: typval.h:311
@ VAR_NUMBER
Number, .v_number is used.
Definition: typval.h:121
int pt_refcount
Reference count.
Definition: typval.h:365
void * uf_cb_state
State of C function extension.
Definition: typval.h:340
int64_t varnumber_T
Type used for VimL VAR_NUMBER values.
Definition: typval.h:26
int uf_tml_idx
index of line being timed; -1 if none
Definition: typval.h:353
int dbg_tick
Debug_tick when breakpoint was set.
Definition: typval.h:316
int uf_calls
nr of active calls
Definition: typval.h:330
union typval_T::typval_vval_union vval
Actual value.
struct dict_watcher DictWatcher
Structure holding dictionary watcher.
@ DI_FLAGS_RO
Read-only value.
Definition: typval.h:239
list_T * lv_used_prev
Previous list in used lists list.
Definition: typval.h:185
dict_T * dv_used_next
Next dictionary in used dictionaries list.
Definition: typval.h:255
sctx_T uf_script_ctx
Definition: typval.h:355
Callback callback
Definition: typval.h:92
QUEUE watchers
Dictionary key watchers set by user code.
Definition: typval.h:257
proftime_T uf_tml_children
time spent in children for this line
Definition: typval.h:351
listwatch_T * lv_watch
First watcher, NULL if none.
Definition: typval.h:181
@ VAR_DEF_SCOPE
Definition: typval.h:155
#define REAL_FATTR_NONNULL_ARG(...)
Definition: func_attr.h:187
linenr_T sc_lnum
Definition: typval.h:283
int lv_refcount
Reference count.
Definition: typval.h:186
#define EXTERN
Definition: macros.h:9
int idx
Sorted list item index.
Definition: typval.h:391
garray_T uf_def_args
default argument expressions
Definition: typval.h:333
cfunc_free_T uf_cb_free
C function extension free callback.
Definition: typval.h:339
@ VAR_FUNC
Function reference, .v_string is used as function name.
Definition: typval.h:123
#define TV_DICTITEM_STRUCT(...)
Definition: typval.h:215
struct list_stack_S * prev
Definition: typval.h:385
m next
Definition: match.c:207
LuaRef luaref
Definition: typval.h:82
VarLockStatus lv_lock
Zero, VAR_LOCKED, VAR_FIXED.
Definition: typval.h:190
int fc_copyID
CopyID used for garbage collection.
Definition: typval.h:322
uint64_t proftime_T
Definition: profile.h:7
LuaRef lua_table_ref
Definition: typval.h:259
listitem_T * li_next
Next item in list.
Definition: typval.h:163
#define FUNC_ATTR_WARN_UNUSED_RESULT
Definition: func_attr.h:244
typval_T rettv
Definition: typval.c:1309
Definition: coverity-model.c:39
ScopeType dv_scope
Definition: typval.h:249
dict_T l_avars
a: argument variables.
Definition: typval.h:310
@ VAR_LOCKED
User lock, can be unlocked.
Definition: typval.h:114
char_u * pt_name
Function name; when NULL use pt_func->name.
Definition: typval.h:366
list_T *const l
Definition: funcs.c:8833
unsigned char char_u
Definition: types.h:12
Structure representing a Dictionary.
Definition: typval.h:247
list_T sl_list
Definition: typval.h:197
VarLockStatus bv_lock
VAR_UNLOCKED, VAR_LOCKED, VAR_FIXED.
Definition: typval.h:266
proftime_T prof_child
Time spent in a child.
Definition: typval.h:318
int uf_tm_count
nr of calls
Definition: typval.h:342
VarLockStatus dv_lock
Whole dictionary lock status.
Definition: typval.h:248
dict_T * dv_copydict
Copied dict used by deepcopy().
Definition: typval.h:254
#define REAL_FATTR_PURE
Definition: func_attr.h:163
int uf_profiling
true when func is being profiled
Definition: typval.h:335
garray_T uf_args
arguments
Definition: typval.h:332
int lv_idx
Index of a cached item, used for optimising repeated l[idx].
Definition: typval.h:188
#define FIXVAR_CNT
Number of fixed variables used for arguments.
Definition: typval.h:291
@ DI_FLAGS_RO_SBX
Value, read-only in the sandbox.
Definition: typval.h:240
Definition: coverity-model.c:40
dict_T * dv_used_prev
Previous dictionary in used dictionaries list.
Definition: typval.h:256
@ kBoolVarTrue
v:true
Definition: typval.h:103
@ kSpecialVarNull
v:null
Definition: typval.h:108
@ VAR_DICT
Dictionary, .v_dict is used.
Definition: typval.h:125
int sc_seq
Definition: typval.h:282
Structure used for explicit stack while garbage collecting lists.
Definition: typval.h:383
static int REAL_FATTR_WARN_UNUSED_RESULT REAL_FATTR_ALWAYS_INLINE
Definition: typval_encode.c.h:265
char * funcref
Definition: typval.h:80
Structure representing one list item, used for sort array.
Definition: typval.h:389
ScopeDictDictItem l_vars_var
Variable for l: scope.
Definition: typval.h:309
#define FUNC_ATTR_ALWAYS_INLINE
Definition: func_attr.h:245
@ kListLenMayKnow
Definition: typval.h:51
typval_T li_tv
Item value.
Definition: typval.h:165
long linenr_T
Line number type.
Definition: pos.h:5
SpecialVarValue
Special variable values.
Definition: typval.h:107
TV_DICTITEM_STRUCT(VAR_SHORT_LEN+1) fixvar[FIXVAR_CNT]
Fixed variables for arguments.
cfunc_T uf_cb
C function extension callback.
Definition: typval.h:338
bool busy
Definition: typval.h:96
return NULL
Definition: eval.c:9968
static int REAL_FATTR_WARN_UNUSED_RESULT
Definition: typval_encode.c.h:300
partial_T * partial
Definition: typval.h:81
int len
Definition: helpers.c:1105
@ DI_FLAGS_LOCK
Locked value.
Definition: typval.h:242
@ kCallbackNone
Definition: typval.h:72
listitem_T * li_prev
Previous item in list.
Definition: typval.h:164
int bv_refcount
Reference count.
Definition: typval.h:265
#define MAX_FUNC_ARGS
Maximum number of function arguments.
Definition: typval.h:287
@ DO_NOT_FREE_CNT
Definition: typval.h:33