Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
typval.h File Reference
#include <inttypes.h>
#include <stddef.h>
#include <string.h>
#include <stdbool.h>
#include <assert.h>
#include "nvim/types.h"
#include "nvim/hashtab.h"
#include "nvim/garray.h"
#include "nvim/mbyte.h"
#include "nvim/func_attr.h"
#include "nvim/lib/queue.h"
#include "nvim/profile.h"
#include "nvim/pos.h"
#include "nvim/gettext.h"
#include "nvim/message.h"
#include "nvim/macros.h"

Go to the source code of this file.

Data Structures

struct  Callback
 
struct  dict_watcher
 Structure holding dictionary watcher. More...
 
struct  typval_T
 Structure that holds an internal variable value. More...
 
union  typval_T::typval_vval_union
 
struct  listitem_S
 
struct  listwatch_S
 
struct  listvar_S
 
struct  staticList10_T
 
struct  dictvar_S
 Structure representing a Dictionary. More...
 
struct  sctx_T
 
struct  ufunc
 Structure to hold info for a user function. More...
 
struct  partial_S
 
struct  ht_stack_S
 Structure used for explicit stack while garbage collecting hash tables. More...
 
struct  list_stack_S
 Structure used for explicit stack while garbage collecting lists. More...
 
struct  ListSortItem
 Structure representing one list item, used for sort array. More...
 

Macros

#define VARNUMBER_MAX   INT64_MAX
 Maximal possible value of varnumber_T variable. More...
 
#define UVARNUMBER_MAX   UINT64_MAX
 
#define VARNUMBER_MIN   INT64_MIN
 Mimimal possible value of varnumber_T variable. More...
 
#define PRIdVARNUMBER   PRId64
 d printf format specifier for varnumber_T More...
 
#define CALLBACK_NONE   ((Callback){ .type = kCallbackNone })
 
#define TV_LIST_STATIC10_INIT
 
#define TV_DICTITEM_STRUCT(...)
 
#define PRIdSCID   "d"
 Format argument for scid_T. More...
 
#define MAX_FUNC_ARGS   20
 Maximum number of function arguments. More...
 
#define list_log(...)
 
#define list_write_log(...)
 
#define list_free_log()
 
#define TV_DICT_HI2DI(hi)   ((dictitem_T *)((hi)->hi_key - offsetof(dictitem_T, di_key)))
 Convert a hashitem pointer to a dictitem pointer. More...
 
#define TV_INITIAL_VALUE
 
#define _TV_LIST_ITER_MOD(modifier, l, li, code)
 
#define TV_LIST_ITER(l, li, code)   _TV_LIST_ITER_MOD(, l, li, code)
 
#define TV_LIST_ITER_CONST(l, li, code)   _TV_LIST_ITER_MOD(const, l, li, code)
 
#define TV_LIST_ITEM_TV(li)   (&(li)->li_tv)
 
#define TV_LIST_ITEM_NEXT(l, li)   ((li)->li_next)
 
#define TV_LIST_ITEM_PREV(l, li)   ((li)->li_prev)
 
#define TV_DICT_ITER(d, di, code)
 
#define TV_TRANSLATE   (SIZE_MAX)
 
#define TV_CSTRING   (SIZE_MAX - 1)
 

Typedefs

typedef int64_t varnumber_T
 Type used for VimL VAR_NUMBER values. More...
 
typedef uint64_t uvarnumber_T
 
typedef double float_T
 Type used for VimL VAR_FLOAT values. More...
 
typedef struct listvar_S list_T
 
typedef struct dictvar_S dict_T
 
typedef struct partial_S partial_T
 
typedef struct ufunc ufunc_T
 
typedef struct dict_watcher DictWatcher
 Structure holding dictionary watcher. More...
 
typedef struct listitem_S listitem_T
 Structure to hold an item of a list. More...
 
typedef struct listwatch_S listwatch_T
 Structure used by those that are using an item in a list. More...
 
typedef int scid_T
 Type used for script ID. More...
 
typedef struct funccall_S funccall_T
 
typedef struct ht_stack_S ht_stack_T
 Structure used for explicit stack while garbage collecting hash tables. More...
 
typedef struct list_stack_S list_stack_T
 Structure used for explicit stack while garbage collecting lists. More...
 
typedef int(* ListSorter) (const void *, const void *)
 

Enumerations

enum  { DO_NOT_FREE_CNT = (INT_MAX / 2) }
 Refcount for dict or list that should not be freed. More...
 
enum  { kListLenUnknown = -1, kListLenShouldKnow = -2, kListLenMayKnow = -3 }
 Additional values for tv_list_alloc() len argument. More...
 
enum  CallbackType { kCallbackNone = 0, kCallbackFuncref, kCallbackPartial }
 
enum  SpecialVarValue { kSpecialVarFalse, kSpecialVarTrue, kSpecialVarNull }
 Special variable values. More...
 
enum  VarLockStatus { VAR_UNLOCKED = 0, VAR_LOCKED = 1, VAR_FIXED = 2 }
 Variable lock status for typval_T.v_lock. More...
 
enum  VarType {
  VAR_UNKNOWN = 0, VAR_NUMBER, VAR_STRING, VAR_FUNC,
  VAR_LIST, VAR_DICT, VAR_FLOAT, VAR_SPECIAL,
  VAR_PARTIAL
}
 VimL variable types, for use in typval_T.v_type. More...
 
enum  ScopeType { VAR_NO_SCOPE = 0, VAR_SCOPE = 1, VAR_DEF_SCOPE = 2 }
 Values for (struct dictvar_S).dv_scope. More...
 
enum  DictItemFlags {
  DI_FLAGS_RO = 1, DI_FLAGS_RO_SBX = 2, DI_FLAGS_FIX = 4, DI_FLAGS_LOCK = 8,
  DI_FLAGS_ALLOC = 16
}
 Flags for dictitem_T.di_flags. More...
 

Functions

typedef TV_DICTITEM_STRUCT (1) ScopeDictDictItem
 
typedef TV_DICTITEM_STRUCT () dictitem_T
 
bool emsgf (const char *const fmt,...)
 Print an error message with unknown number of arguments. More...
 

Variables

enum { ... }  ListLenSpecials
 Additional values for tv_list_alloc() len argument. More...
 
const char *const tv_empty_string
 
bool tv_in_free_unref_items
 Specifies that free_unref_items() function has (not) been entered. More...
 

Macro Definition Documentation

#define _TV_LIST_ITER_MOD (   modifier,
  l,
  li,
  code 
)
Value:
do { \
modifier list_T *const l_ = (l); \
list_log(l_, NULL, NULL, "iter" #modifier); \
if (l_ != NULL) { \
for (modifier listitem_T *li = l_->lv_first; \
li != NULL; li = li->li_next) { \
code \
} \
} \
} while (0)
listitem_T * li_next
Next item in list.
Definition: typval.h:149
Definition: typval.h:164
if(len)
Definition: encode.c:222
Definition: typval.h:148
return NULL
Definition: eval.c:23987
for(size_t i=1;i< ARRAY_SIZE(argv);i++)
Definition: typval.c:1217
list_T * l
Definition: eval.c:15536
listitem_T * li
Definition: eval.c:15537
#define list_log(...)
Definition: typval.h:416

Iterate over a list

Parameters
modifierModifier: expected to be const or nothing, volatile should also work if you have any uses for the volatile list.
[in]lList to iterate over.
liName of the variable with current listitem_T entry.
codeCycle body.
#define CALLBACK_NONE   ((Callback){ .type = kCallbackNone })
#define list_free_log ( )
#define list_log (   ...)
#define list_write_log (   ...)
#define MAX_FUNC_ARGS   20

Maximum number of function arguments.

#define PRIdSCID   "d"

Format argument for scid_T.

#define PRIdVARNUMBER   PRId64

d printf format specifier for varnumber_T

#define TV_CSTRING   (SIZE_MAX - 1)

Specify that argument is a NUL-terminated C string

Used for size_t length arguments to avoid calling strlen() unless needed.

#define TV_DICT_HI2DI (   hi)    ((dictitem_T *)((hi)->hi_key - offsetof(dictitem_T, di_key)))

Convert a hashitem pointer to a dictitem pointer.

#define TV_DICT_ITER (   d,
  di,
  code 
)
Value:
HASHTAB_ITER(&(d)->dv_hashtab, di##hi_, { \
{ \
dictitem_T *const di = TV_DICT_HI2DI(di##hi_); \
{ \
code \
} \
} \
})
#define TV_DICT_HI2DI(hi)
Convert a hashitem pointer to a dictitem pointer.
Definition: typval.h:425
dict_T * d
Definition: eval.c:15831
dictitem_T *const di
Definition: typval.c:1533
#define HASHTAB_ITER(ht, hi, code)
Definition: hashtab.h:78

Iterate over a dictionary

Parameters
[in]dDictionary to iterate over.
diName of the variable with current dictitem_T entry.
codeCycle body.
#define TV_DICTITEM_STRUCT (   ...)
Value:
struct { \
typval_T di_tv; /* Structure that holds scope dictionary itself. */ \
uint8_t di_flags; /* Flags. */ \
char_u di_key[__VA_ARGS__]; /* Key value. */ \
}
v di_flags
Definition: eval.c:23197
unsigned char char_u
Definition: types.h:11
#define TV_INITIAL_VALUE
Value:
((typval_T) { \
.v_type = VAR_UNKNOWN, \
.v_lock = VAR_UNLOCKED, \
})
Unknown (unspecified) value.
Definition: typval.h:110
Structure that holds an internal variable value.
Definition: typval.h:123
Not locked.
Definition: typval.h:103
#define TV_LIST_ITEM_NEXT (   l,
  li 
)    ((li)->li_next)

Get next list item given the current one

Parameters
[in]lList to get item from.
[in]liList item to get typval_T from.
Returns
Pointer to the next item or NULL.
#define TV_LIST_ITEM_PREV (   l,
  li 
)    ((li)->li_prev)

Get previous list item given the current one

Parameters
[in]lList to get item from.
[in]liList item to get typval_T from.
Returns
Pointer to the previous item or NULL.
#define TV_LIST_ITEM_TV (   li)    (&(li)->li_tv)

Get typval_T out of list item

Parameters
[in]liList item to get typval_T from, must not be NULL.
Returns
Pointer to typval_T.
#define TV_LIST_ITER (   l,
  li,
  code 
)    _TV_LIST_ITER_MOD(, l, li, code)

Iterate over a list

To be used when you need to modify list or values you iterate over, use TV_LIST_ITER_CONST if you don’t.

Parameters
[in]lList to iterate over.
liName of the variable with current listitem_T entry.
codeCycle body.
#define TV_LIST_ITER_CONST (   l,
  li,
  code 
)    _TV_LIST_ITER_MOD(const, l, li, code)

Iterate over a list

To be used when you don’t need to modify list or values you iterate over, use TV_LIST_ITER if you do.

Parameters
[in]lList to iterate over.
liName of the variable with current listitem_T entry.
codeCycle body.
#define TV_LIST_STATIC10_INIT
Value:
{ \
.sl_list = { \
.lv_first = NULL, \
.lv_last = NULL, \
.lv_refcount = 0, \
.lv_len = 0, \
.lv_watch = NULL, \
.lv_idx_item = NULL, \
.lv_lock = VAR_FIXED, \
.lv_used_next = NULL, \
.lv_used_prev = NULL, \
}, \
}
return NULL
Definition: eval.c:23987
Locked forever.
Definition: typval.h:105
#define TV_TRANSLATE   (SIZE_MAX)

Specify that argument needs to be translated

Used for size_t length arguments to avoid calling gettext() and strlen() unless needed.

#define UVARNUMBER_MAX   UINT64_MAX
#define VARNUMBER_MAX   INT64_MAX

Maximal possible value of varnumber_T variable.

#define VARNUMBER_MIN   INT64_MIN

Mimimal possible value of varnumber_T variable.

Typedef Documentation

typedef struct dictvar_S dict_T
typedef struct dict_watcher DictWatcher

Structure holding dictionary watcher.

typedef double float_T

Type used for VimL VAR_FLOAT values.

typedef struct funccall_S funccall_T
typedef struct ht_stack_S ht_stack_T

Structure used for explicit stack while garbage collecting hash tables.

typedef struct list_stack_S list_stack_T

Structure used for explicit stack while garbage collecting lists.

typedef struct listvar_S list_T
typedef struct listitem_S listitem_T

Structure to hold an item of a list.

typedef int(* ListSorter) (const void *, const void *)
typedef struct listwatch_S listwatch_T

Structure used by those that are using an item in a list.

typedef struct partial_S partial_T
typedef int scid_T

Type used for script ID.

typedef struct ufunc ufunc_T
typedef uint64_t uvarnumber_T
typedef int64_t varnumber_T

Type used for VimL VAR_NUMBER values.

Enumeration Type Documentation

anonymous enum

Refcount for dict or list that should not be freed.

Enumerator
DO_NOT_FREE_CNT 
anonymous enum

Additional values for tv_list_alloc() len argument.

Enumerator
kListLenUnknown 

List length is not known in advance

To be used when there is neither a way to know how many elements will be needed nor are any educated guesses.

kListLenShouldKnow 

List length should be known, but is actually not

All occurrences of this value should be eventually removed. This is for the case when the only reason why list length is not known is that it would be hard to code without refactoring, but refactoring is needed.

kListLenMayKnow 

List length may be known in advance, but it requires too much effort

To be used when it looks impractical to determine list length.

Enumerator
kCallbackNone 
kCallbackFuncref 
kCallbackPartial 

Flags for dictitem_T.di_flags.

Enumerator
DI_FLAGS_RO 

Read-only value.

DI_FLAGS_RO_SBX 

Value, read-only in the sandbox.

DI_FLAGS_FIX 

Fixed value: cannot be :unlet or remove()d.

DI_FLAGS_LOCK 

Locked value.

DI_FLAGS_ALLOC 

Separately allocated.

enum ScopeType

Values for (struct dictvar_S).dv_scope.

Enumerator
VAR_NO_SCOPE 

Not a scope dictionary.

VAR_SCOPE 

Scope dictionary which requires prefix (a:, v:, …).

VAR_DEF_SCOPE 

Scope dictionary which may be accessed without prefix (l:, g:).

Special variable values.

Enumerator
kSpecialVarFalse 

v:false

kSpecialVarTrue 

v:true

kSpecialVarNull 

v:null

Variable lock status for typval_T.v_lock.

Enumerator
VAR_UNLOCKED 

Not locked.

VAR_LOCKED 

User lock, can be unlocked.

VAR_FIXED 

Locked forever.

enum VarType

VimL variable types, for use in typval_T.v_type.

Enumerator
VAR_UNKNOWN 

Unknown (unspecified) value.

VAR_NUMBER 

Number, .v_number is used.

VAR_STRING 

String, .v_string is used.

VAR_FUNC 

Function reference, .v_string is used as function name.

VAR_LIST 

List, .v_list is used.

VAR_DICT 

Dictionary, .v_dict is used.

VAR_FLOAT 

Floating-point value, .v_float is used.

VAR_SPECIAL 

Special value (true, false, null), .v_special is used.

VAR_PARTIAL 

Partial, .v_partial is used.

Function Documentation

bool emsgf ( const char *const  fmt,
  ... 
)

Print an error message with unknown number of arguments.

typedef TV_DICTITEM_STRUCT ( )

Structure to hold a scope dictionary

Warning
Must be compatible with dictitem_T.

For use in find_var_in_ht to pretend that it found dictionary item when it finds scope dictionary.

typedef TV_DICTITEM_STRUCT ( )

Structure to hold an item of a Dictionary

Warning
Must be compatible with ScopeDictDictItem.

Also used for a variable.

Variable Documentation

enum { ... } ListLenSpecials

Additional values for tv_list_alloc() len argument.

const char* const tv_empty_string

Empty string

Needed for hack which allows not allocating empty string and still not crashing when freeing it.

bool tv_in_free_unref_items

Specifies that free_unref_items() function has (not) been entered.