aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2023-12-23 08:28:17 +0800
committerGitHub <noreply@github.com>2023-12-23 08:28:17 +0800
commit242261d4e77806cdb4559c2be58613113a393a4e (patch)
tree9a6a6e1ded19514fe118833d2698532811691d0b
parent0c3d2a7fd99d6171fad81cc8b010281b1cd1c3e0 (diff)
downloadrneovim-242261d4e77806cdb4559c2be58613113a393a4e.tar.gz
rneovim-242261d4e77806cdb4559c2be58613113a393a4e.tar.bz2
rneovim-242261d4e77806cdb4559c2be58613113a393a4e.zip
refactor(IWYU): move evalarg_T to eval_defs.h (#26716)
-rwxr-xr-xsrc/clint.py2
-rw-r--r--src/nvim/decoration.c1
-rw-r--r--src/nvim/drawline.c1
-rw-r--r--src/nvim/drawscreen.c1
-rw-r--r--src/nvim/eval.c89
-rw-r--r--src/nvim/eval.h42
-rw-r--r--src/nvim/eval/typval_encode.c.h3
-rw-r--r--src/nvim/eval/userfunc.h2
-rw-r--r--src/nvim/eval/vars.c2
-rw-r--r--src/nvim/eval_defs.h30
-rw-r--r--src/nvim/ex_session.c46
-rw-r--r--src/nvim/move.c1
-rw-r--r--src/nvim/shada.c42
-rw-r--r--src/nvim/statusline_defs.h3
14 files changed, 132 insertions, 133 deletions
diff --git a/src/clint.py b/src/clint.py
index 663416553e..32ed81f95c 100755
--- a/src/clint.py
+++ b/src/clint.py
@@ -903,11 +903,9 @@ def CheckIncludes(filename, lines, error):
"src/nvim/buffer.h",
"src/nvim/channel.h",
"src/nvim/charset.h",
- "src/nvim/eval.h",
"src/nvim/eval/encode.h",
"src/nvim/eval/typval.h",
"src/nvim/eval/typval_defs.h",
- "src/nvim/eval/userfunc.h",
"src/nvim/event/libuv_process.h",
"src/nvim/event/multiqueue.h",
"src/nvim/garray.h",
diff --git a/src/nvim/decoration.c b/src/nvim/decoration.c
index 6f1416711a..8766f2ca76 100644
--- a/src/nvim/decoration.c
+++ b/src/nvim/decoration.c
@@ -2,6 +2,7 @@
#include <limits.h>
#include <stddef.h>
#include <stdlib.h>
+#include <string.h>
#include "nvim/api/extmark.h"
#include "nvim/api/private/helpers.h"
diff --git a/src/nvim/drawline.c b/src/nvim/drawline.c
index e7b56dcd68..77d554d759 100644
--- a/src/nvim/drawline.c
+++ b/src/nvim/drawline.c
@@ -36,6 +36,7 @@
#include "nvim/move.h"
#include "nvim/option.h"
#include "nvim/option_vars.h"
+#include "nvim/os/os_defs.h"
#include "nvim/plines.h"
#include "nvim/pos_defs.h"
#include "nvim/quickfix.h"
diff --git a/src/nvim/drawscreen.c b/src/nvim/drawscreen.c
index 21e8438367..4200ff70bc 100644
--- a/src/nvim/drawscreen.c
+++ b/src/nvim/drawscreen.c
@@ -98,7 +98,6 @@
#include "nvim/profile.h"
#include "nvim/regexp.h"
#include "nvim/search.h"
-#include "nvim/sign_defs.h"
#include "nvim/spell.h"
#include "nvim/state.h"
#include "nvim/statusline.h"
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index 3818944fc9..43aeda06ef 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -36,7 +36,6 @@
#include "nvim/ex_docmd.h"
#include "nvim/ex_eval.h"
#include "nvim/ex_getln.h"
-#include "nvim/ex_session.h"
#include "nvim/garray.h"
#include "nvim/getchar.h"
#include "nvim/gettext.h"
@@ -8160,7 +8159,7 @@ const char *find_option_var_end(const char **const arg, OptIndex *const opt_idxp
return end;
}
-static var_flavour_T var_flavour(char *varname)
+var_flavour_T var_flavour(char *varname)
FUNC_ATTR_PURE
{
char *p = varname;
@@ -8176,48 +8175,6 @@ static var_flavour_T var_flavour(char *varname)
return VAR_FLAVOUR_DEFAULT;
}
-/// Iterate over global variables
-///
-/// @warning No modifications to global variable dictionary must be performed
-/// while iteration is in progress.
-///
-/// @param[in] iter Iterator. Pass NULL to start iteration.
-/// @param[out] name Variable name.
-/// @param[out] rettv Variable value.
-///
-/// @return Pointer that needs to be passed to next `var_shada_iter` invocation
-/// or NULL to indicate that iteration is over.
-const void *var_shada_iter(const void *const iter, const char **const name, typval_T *rettv,
- var_flavour_T flavour)
- FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ARG(2, 3)
-{
- const hashitem_T *hi;
- const hashitem_T *hifirst = globvarht.ht_array;
- const size_t hinum = (size_t)globvarht.ht_mask + 1;
- *name = NULL;
- if (iter == NULL) {
- hi = globvarht.ht_array;
- while ((size_t)(hi - hifirst) < hinum
- && (HASHITEM_EMPTY(hi)
- || !(var_flavour(hi->hi_key) & flavour))) {
- hi++;
- }
- if ((size_t)(hi - hifirst) == hinum) {
- return NULL;
- }
- } else {
- hi = (const hashitem_T *)iter;
- }
- *name = TV_DICT_HI2DI(hi)->di_key;
- tv_copy(&TV_DICT_HI2DI(hi)->di_tv, rettv);
- while ((size_t)(++hi - hifirst) < hinum) {
- if (!HASHITEM_EMPTY(hi) && (var_flavour(hi->hi_key) & flavour)) {
- return hi;
- }
- }
- return NULL;
-}
-
void var_set_global(const char *const name, typval_T vartv)
{
funccal_entry_T funccall_entry;
@@ -8227,50 +8184,6 @@ void var_set_global(const char *const name, typval_T vartv)
restore_funccal();
}
-int store_session_globals(FILE *fd)
-{
- TV_DICT_ITER(&globvardict, this_var, {
- if ((this_var->di_tv.v_type == VAR_NUMBER
- || this_var->di_tv.v_type == VAR_STRING)
- && var_flavour(this_var->di_key) == VAR_FLAVOUR_SESSION) {
- // Escape special characters with a backslash. Turn a LF and
- // CR into \n and \r.
- char *const p = vim_strsave_escaped(tv_get_string(&this_var->di_tv), "\\\"\n\r");
- for (char *t = p; *t != NUL; t++) {
- if (*t == '\n') {
- *t = 'n';
- } else if (*t == '\r') {
- *t = 'r';
- }
- }
- if ((fprintf(fd, "let %s = %c%s%c",
- this_var->di_key,
- ((this_var->di_tv.v_type == VAR_STRING) ? '"' : ' '),
- p,
- ((this_var->di_tv.v_type == VAR_STRING) ? '"' : ' ')) < 0)
- || put_eol(fd) == FAIL) {
- xfree(p);
- return FAIL;
- }
- xfree(p);
- } else if (this_var->di_tv.v_type == VAR_FLOAT
- && var_flavour(this_var->di_key) == VAR_FLAVOUR_SESSION) {
- float_T f = this_var->di_tv.vval.v_float;
- int sign = ' ';
-
- if (f < 0) {
- f = -f;
- sign = '-';
- }
- if ((fprintf(fd, "let %s = %c%f", this_var->di_key, sign, f) < 0)
- || put_eol(fd) == FAIL) {
- return FAIL;
- }
- }
- });
- return OK;
-}
-
/// Display script name where an item was last set.
/// Should only be invoked when 'verbose' is non-zero.
void last_set_msg(sctx_T script_ctx)
diff --git a/src/nvim/eval.h b/src/nvim/eval.h
index 9ee5d99806..951a6313b6 100644
--- a/src/nvim/eval.h
+++ b/src/nvim/eval.h
@@ -7,8 +7,9 @@
#include "nvim/channel_defs.h" // IWYU pragma: keep
#include "nvim/cmdexpand_defs.h" // IWYU pragma: keep
#include "nvim/eval/typval_defs.h"
-#include "nvim/event/time.h"
-#include "nvim/ex_cmds_defs.h"
+#include "nvim/eval_defs.h" // IWYU pragma: export
+#include "nvim/event/defs.h"
+#include "nvim/ex_cmds_defs.h" // IWYU pragma: keep
#include "nvim/grid_defs.h" // IWYU pragma: keep
#include "nvim/hashtab_defs.h"
#include "nvim/macros_defs.h"
@@ -177,24 +178,8 @@ typedef enum {
VV_VIRTNUM,
} VimVarIndex;
-/// All recognized msgpack types
-typedef enum {
- kMPNil,
- kMPBoolean,
- kMPInteger,
- kMPFloat,
- kMPString,
- kMPBinary,
- kMPArray,
- kMPMap,
- kMPExt,
-} MessagePackType;
-#define LAST_MSGPACK_TYPE kMPExt
-
/// Array mapping values from MessagePackType to corresponding list pointers
-extern const list_T *eval_msgpack_type_lists[LAST_MSGPACK_TYPE + 1];
-
-#undef LAST_MSGPACK_TYPE
+extern const list_T *eval_msgpack_type_lists[NUM_MSGPACK_TYPES];
// Struct passed to get_v_event() and restore_v_event().
typedef struct {
@@ -258,32 +243,17 @@ typedef enum {
kDictListItems, ///< List dictionary contents: [keys, values].
} DictListType;
-typedef int (*ex_unletlock_callback)(lval_T *, char *, exarg_T *, int);
-
// Used for checking if local variables or arguments used in a lambda.
extern bool *eval_lavars_used;
-/// Struct passed through eval() functions.
-/// See EVALARG_EVALUATE for a fixed value with eval_flags set to EVAL_EVALUATE.
-typedef struct {
- int eval_flags; ///< EVAL_ flag values below
-
- /// copied from exarg_T when "getline" is "getsourceline". Can be NULL.
- LineGetter eval_getline;
- void *eval_cookie; ///< argument for eval_getline()
-
- /// pointer to the last line obtained with getsourceline()
- char *eval_tofree;
-} evalarg_T;
+// Character used as separated in autoload function/variable names.
+#define AUTOLOAD_CHAR '#'
/// Flag for expression evaluation.
enum {
EVAL_EVALUATE = 1, ///< when missing don't actually evaluate
};
-// Character used as separated in autoload function/variable names.
-#define AUTOLOAD_CHAR '#'
-
/// Passed to an eval() function to enable evaluation.
EXTERN evalarg_T EVALARG_EVALUATE INIT( = { EVAL_EVALUATE, NULL, NULL, NULL });
diff --git a/src/nvim/eval/typval_encode.c.h b/src/nvim/eval/typval_encode.c.h
index 2e0b68d486..c0cd0ce557 100644
--- a/src/nvim/eval/typval_encode.c.h
+++ b/src/nvim/eval/typval_encode.c.h
@@ -246,11 +246,12 @@
#include <inttypes.h>
#include <stddef.h>
+#include "klib/kvec.h"
+#include "nvim/eval.h"
#include "nvim/eval/encode.h"
#include "nvim/eval/typval.h"
#include "nvim/eval/typval_encode.h"
#include "nvim/func_attr.h"
-#include "klib/kvec.h"
/// Dummy variable used because some macros need lvalue
///
diff --git a/src/nvim/eval/userfunc.h b/src/nvim/eval/userfunc.h
index 270ca7db4e..b3488b15a7 100644
--- a/src/nvim/eval/userfunc.h
+++ b/src/nvim/eval/userfunc.h
@@ -4,8 +4,8 @@
#include <stddef.h>
#include "nvim/cmdexpand_defs.h" // IWYU pragma: keep
-#include "nvim/eval.h" // IWYU pragma: keep
#include "nvim/eval/typval_defs.h"
+#include "nvim/eval_defs.h" // IWYU pragma: keep
#include "nvim/ex_cmds_defs.h" // IWYU pragma: keep
#include "nvim/hashtab_defs.h" // IWYU pragma: keep
#include "nvim/pos_defs.h"
diff --git a/src/nvim/eval/vars.c b/src/nvim/eval/vars.c
index 8ed76341b0..dd984e8819 100644
--- a/src/nvim/eval/vars.c
+++ b/src/nvim/eval/vars.c
@@ -43,6 +43,8 @@
#include "nvim/vim_defs.h"
#include "nvim/window.h"
+typedef int (*ex_unletlock_callback)(lval_T *, char *, exarg_T *, int);
+
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "eval/vars.c.generated.h"
#endif
diff --git a/src/nvim/eval_defs.h b/src/nvim/eval_defs.h
new file mode 100644
index 0000000000..4bbebb14f5
--- /dev/null
+++ b/src/nvim/eval_defs.h
@@ -0,0 +1,30 @@
+#pragma once
+
+#include "nvim/ex_cmds_defs.h"
+
+/// All recognized msgpack types
+typedef enum {
+ kMPNil,
+ kMPBoolean,
+ kMPInteger,
+ kMPFloat,
+ kMPString,
+ kMPBinary,
+ kMPArray,
+ kMPMap,
+ kMPExt,
+} MessagePackType;
+#define NUM_MSGPACK_TYPES (kMPExt + 1)
+
+/// Struct passed through eval() functions.
+/// See EVALARG_EVALUATE for a fixed value with eval_flags set to EVAL_EVALUATE.
+typedef struct {
+ int eval_flags; ///< EVAL_ flag values below
+
+ /// copied from exarg_T when "getline" is "getsourceline". Can be NULL.
+ LineGetter eval_getline;
+ void *eval_cookie; ///< argument for eval_getline()
+
+ /// pointer to the last line obtained with getsourceline()
+ char *eval_tofree;
+} evalarg_T;
diff --git a/src/nvim/ex_session.c b/src/nvim/ex_session.c
index 82e3fe09d2..98869c0a25 100644
--- a/src/nvim/ex_session.c
+++ b/src/nvim/ex_session.c
@@ -13,6 +13,7 @@
#include "nvim/ascii_defs.h"
#include "nvim/buffer.h"
#include "nvim/eval.h"
+#include "nvim/eval/typval.h"
#include "nvim/ex_cmds_defs.h"
#include "nvim/ex_docmd.h"
#include "nvim/ex_getln.h"
@@ -35,6 +36,7 @@
#include "nvim/path.h"
#include "nvim/pos_defs.h"
#include "nvim/runtime.h"
+#include "nvim/strings.h"
#include "nvim/types_defs.h"
#include "nvim/vim_defs.h"
#include "nvim/window.h"
@@ -519,6 +521,50 @@ static int put_view(FILE *fd, win_T *wp, int add_edit, unsigned *flagp, int curr
return OK;
}
+static int store_session_globals(FILE *fd)
+{
+ TV_DICT_ITER(&globvardict, this_var, {
+ if ((this_var->di_tv.v_type == VAR_NUMBER
+ || this_var->di_tv.v_type == VAR_STRING)
+ && var_flavour(this_var->di_key) == VAR_FLAVOUR_SESSION) {
+ // Escape special characters with a backslash. Turn a LF and
+ // CR into \n and \r.
+ char *const p = vim_strsave_escaped(tv_get_string(&this_var->di_tv), "\\\"\n\r");
+ for (char *t = p; *t != NUL; t++) {
+ if (*t == '\n') {
+ *t = 'n';
+ } else if (*t == '\r') {
+ *t = 'r';
+ }
+ }
+ if ((fprintf(fd, "let %s = %c%s%c",
+ this_var->di_key,
+ ((this_var->di_tv.v_type == VAR_STRING) ? '"' : ' '),
+ p,
+ ((this_var->di_tv.v_type == VAR_STRING) ? '"' : ' ')) < 0)
+ || put_eol(fd) == FAIL) {
+ xfree(p);
+ return FAIL;
+ }
+ xfree(p);
+ } else if (this_var->di_tv.v_type == VAR_FLOAT
+ && var_flavour(this_var->di_key) == VAR_FLAVOUR_SESSION) {
+ float_T f = this_var->di_tv.vval.v_float;
+ int sign = ' ';
+
+ if (f < 0) {
+ f = -f;
+ sign = '-';
+ }
+ if ((fprintf(fd, "let %s = %c%f", this_var->di_key, sign, f) < 0)
+ || put_eol(fd) == FAIL) {
+ return FAIL;
+ }
+ }
+ });
+ return OK;
+}
+
/// Writes commands for restoring the current buffers, for :mksession.
///
/// Legacy 'sessionoptions'/'viewoptions' flags SSOP_UNIX, SSOP_SLASH are
diff --git a/src/nvim/move.c b/src/nvim/move.c
index c4f8eca493..d7bd18f23b 100644
--- a/src/nvim/move.c
+++ b/src/nvim/move.c
@@ -40,7 +40,6 @@
#include "nvim/popupmenu.h"
#include "nvim/pos_defs.h"
#include "nvim/search.h"
-#include "nvim/sign_defs.h"
#include "nvim/strings.h"
#include "nvim/types_defs.h"
#include "nvim/vim_defs.h"
diff --git a/src/nvim/shada.c b/src/nvim/shada.c
index 09142e55e0..efef6f8511 100644
--- a/src/nvim/shada.c
+++ b/src/nvim/shada.c
@@ -996,6 +996,48 @@ static inline void hms_dealloc(HistoryMergerState *const hms_p)
#define HMS_ITER(hms_p, cur_entry, code) \
HMLL_FORALL(&((hms_p)->hmll), cur_entry, code)
+/// Iterate over global variables
+///
+/// @warning No modifications to global variable dictionary must be performed
+/// while iteration is in progress.
+///
+/// @param[in] iter Iterator. Pass NULL to start iteration.
+/// @param[out] name Variable name.
+/// @param[out] rettv Variable value.
+///
+/// @return Pointer that needs to be passed to next `var_shada_iter` invocation
+/// or NULL to indicate that iteration is over.
+static const void *var_shada_iter(const void *const iter, const char **const name, typval_T *rettv,
+ var_flavour_T flavour)
+ FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ARG(2, 3)
+{
+ const hashitem_T *hi;
+ const hashitem_T *hifirst = globvarht.ht_array;
+ const size_t hinum = (size_t)globvarht.ht_mask + 1;
+ *name = NULL;
+ if (iter == NULL) {
+ hi = globvarht.ht_array;
+ while ((size_t)(hi - hifirst) < hinum
+ && (HASHITEM_EMPTY(hi)
+ || !(var_flavour(hi->hi_key) & flavour))) {
+ hi++;
+ }
+ if ((size_t)(hi - hifirst) == hinum) {
+ return NULL;
+ }
+ } else {
+ hi = (const hashitem_T *)iter;
+ }
+ *name = TV_DICT_HI2DI(hi)->di_key;
+ tv_copy(&TV_DICT_HI2DI(hi)->di_tv, rettv);
+ while ((size_t)(++hi - hifirst) < hinum) {
+ if (!HASHITEM_EMPTY(hi) && (var_flavour(hi->hi_key) & flavour)) {
+ return hi;
+ }
+ }
+ return NULL;
+}
+
/// Find buffer for given buffer name (cached)
///
/// @param[in,out] fname_bufs Cache containing fname to buffer mapping.
diff --git a/src/nvim/statusline_defs.h b/src/nvim/statusline_defs.h
index e4b1c627ad..a8588b54d7 100644
--- a/src/nvim/statusline_defs.h
+++ b/src/nvim/statusline_defs.h
@@ -1,11 +1,8 @@
#pragma once
#include <stdbool.h>
-#include <stddef.h>
#include "nvim/fold_defs.h"
-#include "nvim/macros_defs.h"
-#include "nvim/os/os_defs.h"
#include "nvim/sign_defs.h"
/// Status line click definition