robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Jan Edmund Lazovim-patch:8.1.1939: code for handling v: variables in generic eval file (#36312)b38ce04283

master
5.2 KiB146 linesraw
1#pragma once
2
3#include <stdbool.h>
4#include <stddef.h>
5#include <stdint.h>
6
7#include "nvim/channel_defs.h"  // IWYU pragma: keep
8#include "nvim/cmdexpand_defs.h"  // IWYU pragma: keep
9#include "nvim/eval/typval_defs.h"
10#include "nvim/eval_defs.h"  // IWYU pragma: keep
11#include "nvim/event/defs.h"
12#include "nvim/ex_cmds_defs.h"  // IWYU pragma: keep
13#include "nvim/grid_defs.h"  // IWYU pragma: keep
14#include "nvim/hashtab_defs.h"
15#include "nvim/macros_defs.h"
16#include "nvim/mbyte_defs.h"  // IWYU pragma: keep
17#include "nvim/msgpack_rpc/channel_defs.h"  // IWYU pragma: keep
18#include "nvim/option_defs.h"  // IWYU pragma: keep
19#include "nvim/os/fileio_defs.h"  // IWYU pragma: keep
20#include "nvim/os/stdpaths_defs.h"  // IWYU pragma: keep
21#include "nvim/types_defs.h"  // IWYU pragma: keep
22#include "nvim/vim_defs.h"  // IWYU pragma: keep
23
24#define COPYID_INC 2
25#define COPYID_MASK (~0x1)
26
27// Structure returned by get_lval() and used by set_var_lval().
28// For a plain name:
29//      "name"      points to the variable name.
30//      "exp_name"  is NULL.
31//      "tv"        is NULL
32// For a magic braces name:
33//      "name"      points to the expanded variable name.
34//      "exp_name"  is non-NULL, to be freed later.
35//      "tv"        is NULL
36// For an index in a list:
37//      "name"      points to the (expanded) variable name.
38//      "exp_name"  NULL or non-NULL, to be freed later.
39//      "tv"        points to the (first) list item value
40//      "li"        points to the (first) list item
41//      "range", "n1", "n2" and "empty2" indicate what items are used.
42// For an existing Dict item:
43//      "name"      points to the (expanded) variable name.
44//      "exp_name"  NULL or non-NULL, to be freed later.
45//      "tv"        points to the dict item value
46//      "newkey"    is NULL
47// For a non-existing Dict item:
48//      "name"      points to the (expanded) variable name.
49//      "exp_name"  NULL or non-NULL, to be freed later.
50//      "tv"        points to the Dictionary typval_T
51//      "newkey"    is the key for the new item.
52typedef struct {
53  const char *ll_name;  ///< Start of variable name (can be NULL).
54  size_t ll_name_len;   ///< Length of the .ll_name.
55  char *ll_exp_name;    ///< NULL or expanded name in allocated memory.
56  typval_T *ll_tv;      ///< Typeval of item being used.  If "newkey"
57  ///< isn't NULL it's the Dict to which to add the item.
58  listitem_T *ll_li;  ///< The list item or NULL.
59  list_T *ll_list;    ///< The list or NULL.
60  bool ll_range;      ///< true when a [i:j] range was used.
61  bool ll_empty2;     ///< Second index is empty: [i:].
62  int ll_n1;          ///< First index for list.
63  int ll_n2;          ///< Second index for list range.
64  dict_T *ll_dict;    ///< The Dict or NULL.
65  dictitem_T *ll_di;  ///< The dictitem or NULL.
66  char *ll_newkey;    ///< New key for Dict in allocated memory or NULL.
67  blob_T *ll_blob;    ///< The Blob or NULL.
68} lval_T;
69
70/// enum used by var_flavour()
71typedef enum {
72  VAR_FLAVOUR_DEFAULT = 1,   // doesn't start with uppercase
73  VAR_FLAVOUR_SESSION = 2,   // starts with uppercase, some lower
74  VAR_FLAVOUR_SHADA   = 4,  // all uppercase
75} var_flavour_T;
76
77// Struct passed to get_v_event() and restore_v_event().
78typedef struct {
79  bool sve_did_save;
80  hashtab_T sve_hashtab;
81} save_v_event_T;
82
83/// trans_function_name() flags
84typedef enum {
85  TFN_INT = 1,  ///< May use internal function name
86  TFN_QUIET = 2,  ///< Do not emit error messages.
87  TFN_NO_AUTOLOAD = 4,  ///< Do not use script autoloading.
88  TFN_NO_DEREF = 8,  ///< Do not dereference a Funcref.
89  TFN_READ_ONLY = 16,  ///< Will not change the variable.
90} TransFunctionNameFlags;
91
92/// get_lval() flags
93typedef enum {
94  GLV_QUIET = TFN_QUIET,  ///< Do not emit error messages.
95  GLV_NO_AUTOLOAD = TFN_NO_AUTOLOAD,  ///< Do not use script autoloading.
96  GLV_READ_ONLY = TFN_READ_ONLY,  ///< Indicates that caller will not change
97                                  ///< the value (prevents error message).
98} GetLvalFlags;
99
100/// flags for find_name_end()
101#define FNE_INCL_BR     1       // find_name_end(): include [] in name
102#define FNE_CHECK_START 2       // find_name_end(): check name starts with
103                                // valid character
104
105typedef struct {
106  TimeWatcher tw;
107  int timer_id;
108  int repeat_count;
109  int refcount;
110  int emsg_count;  ///< Errors in a repeating timer.
111  int64_t timeout;
112  bool stopped;
113  bool paused;
114  Callback callback;
115} timer_T;
116
117/// types for expressions.
118typedef enum {
119  EXPR_UNKNOWN = 0,
120  EXPR_EQUAL,         ///< ==
121  EXPR_NEQUAL,        ///< !=
122  EXPR_GREATER,       ///< >
123  EXPR_GEQUAL,        ///< >=
124  EXPR_SMALLER,       ///< <
125  EXPR_SEQUAL,        ///< <=
126  EXPR_MATCH,         ///< =~
127  EXPR_NOMATCH,       ///< !~
128  EXPR_IS,            ///< is
129  EXPR_ISNOT,         ///< isnot
130} exprtype_T;
131
132// Used for checking if local variables or arguments used in a lambda.
133extern bool *eval_lavars_used;
134
135// Character used as separated in autoload function/variable names.
136#define AUTOLOAD_CHAR '#'
137
138/// Flag for expression evaluation.
139enum {
140  EVAL_EVALUATE = 1,  ///< when missing don't actually evaluate
141};
142
143/// Passed to an eval() function to enable evaluation.
144EXTERN evalarg_T EVALARG_EVALUATE INIT( = { EVAL_EVALUATE, NULL, NULL, NULL });
145
146#include "eval.h.generated.h"