mirror of
https://github.com/neovim/neovim.git
synced 2024-12-24 05:05:00 -07:00
refactor(IWYU): move evalarg_T to eval_defs.h (#26716)
This commit is contained in:
parent
0c3d2a7fd9
commit
242261d4e7
@ -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",
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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)
|
||||
|
@ -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 });
|
||||
|
||||
|
@ -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
|
||||
///
|
||||
|
@ -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"
|
||||
|
@ -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
|
||||
|
30
src/nvim/eval_defs.h
Normal file
30
src/nvim/eval_defs.h
Normal file
@ -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;
|
@ -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
|
||||
|
@ -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"
|
||||
|
@ -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.
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user