eval.c: factor out eval/funcs.c #11828

close #11828
ref #5081
cf. vim patch 7.4.2063
This commit is contained in:
Jakub Łuczyński
2020-02-10 00:33:26 -08:00
committed by Justin M. Keyes
parent d34f042ed5
commit 6c5bbf07d9
7 changed files with 11262 additions and 11236 deletions

View File

@@ -150,6 +150,7 @@ set(CONV_SOURCES
diff.c diff.c
edit.c edit.c
eval.c eval.c
eval/funcs.c
ex_cmds.c ex_cmds.c
ex_docmd.c ex_docmd.c
fileio.c fileio.c
@@ -180,10 +181,10 @@ if(NOT MSVC)
check_c_compiler_flag(-Wstatic-in-inline HAS_WSTATIC_IN_INLINE) check_c_compiler_flag(-Wstatic-in-inline HAS_WSTATIC_IN_INLINE)
if(HAS_WSTATIC_IN_INLINE) if(HAS_WSTATIC_IN_INLINE)
set_source_files_properties( set_source_files_properties(
eval.c PROPERTIES COMPILE_FLAGS "${COMPILE_FLAGS} -Wno-static-in-inline -Wno-conversion") eval/funcs.c PROPERTIES COMPILE_FLAGS "${COMPILE_FLAGS} -Wno-static-in-inline -Wno-conversion")
else() else()
set_source_files_properties( set_source_files_properties(
eval.c PROPERTIES COMPILE_FLAGS "${COMPILE_FLAGS} -Wno-conversion") eval/funcs.c PROPERTIES COMPILE_FLAGS "${COMPILE_FLAGS} -Wno-conversion")
endif() endif()
# tree-sitter: inlined external project, we don't maintain it. #10124 # tree-sitter: inlined external project, we don't maintain it. #10124

File diff suppressed because it is too large Load Diff

View File

@@ -1,16 +1,13 @@
#ifndef NVIM_EVAL_H #ifndef NVIM_EVAL_H
#define NVIM_EVAL_H #define NVIM_EVAL_H
#include "nvim/hashtab.h" // For hashtab_T
#include "nvim/buffer_defs.h" #include "nvim/buffer_defs.h"
#include "nvim/ex_cmds_defs.h" // For exarg_T
#include "nvim/eval/typval.h"
#include "nvim/profile.h"
#include "nvim/garray.h"
#include "nvim/event/rstream.h"
#include "nvim/event/wstream.h"
#include "nvim/channel.h" #include "nvim/channel.h"
#include "nvim/os/stdpaths_defs.h" #include "nvim/eval/funcs.h" // For FunPtr
#include "nvim/event/time.h" // For TimeWatcher
#include "nvim/ex_cmds_defs.h" // For exarg_T
#include "nvim/os/fileio.h" // For FileDescriptor
#include "nvim/os/stdpaths_defs.h" // For XDGVarType
#define COPYID_INC 2 #define COPYID_INC 2
#define COPYID_MASK (~0x1) #define COPYID_MASK (~0x1)
@@ -18,12 +15,63 @@
// All user-defined functions are found in this hashtable. // All user-defined functions are found in this hashtable.
extern hashtab_T func_hashtab; extern hashtab_T func_hashtab;
///< Structure used by trans_function_name()
typedef struct {
dict_T *fd_dict; ///< Dictionary used.
char_u *fd_newkey; ///< New key in "dict" in allocated memory.
dictitem_T *fd_di; ///< Dictionary item used.
} funcdict_T;
// From user function to hashitem and back. // From user function to hashitem and back.
EXTERN ufunc_T dumuf; EXTERN ufunc_T dumuf;
#define UF2HIKEY(fp) ((fp)->uf_name) #define UF2HIKEY(fp) ((fp)->uf_name)
#define HIKEY2UF(p) ((ufunc_T *)(p - offsetof(ufunc_T, uf_name))) #define HIKEY2UF(p) ((ufunc_T *)(p - offsetof(ufunc_T, uf_name)))
#define HI2UF(hi) HIKEY2UF((hi)->hi_key) #define HI2UF(hi) HIKEY2UF((hi)->hi_key)
/*
* Structure returned by get_lval() and used by set_var_lval().
* For a plain name:
* "name" points to the variable name.
* "exp_name" is NULL.
* "tv" is NULL
* For a magic braces name:
* "name" points to the expanded variable name.
* "exp_name" is non-NULL, to be freed later.
* "tv" is NULL
* For an index in a list:
* "name" points to the (expanded) variable name.
* "exp_name" NULL or non-NULL, to be freed later.
* "tv" points to the (first) list item value
* "li" points to the (first) list item
* "range", "n1", "n2" and "empty2" indicate what items are used.
* For an existing Dict item:
* "name" points to the (expanded) variable name.
* "exp_name" NULL or non-NULL, to be freed later.
* "tv" points to the dict item value
* "newkey" is NULL
* For a non-existing Dict item:
* "name" points to the (expanded) variable name.
* "exp_name" NULL or non-NULL, to be freed later.
* "tv" points to the Dictionary typval_T
* "newkey" is the key for the new item.
*/
typedef struct lval_S {
const char *ll_name; ///< Start of variable name (can be NULL).
size_t ll_name_len; ///< Length of the .ll_name.
char *ll_exp_name; ///< NULL or expanded name in allocated memory.
typval_T *ll_tv; ///< Typeval of item being used. If "newkey"
///< isn't NULL it's the Dict to which to add the item.
listitem_T *ll_li; ///< The list item or NULL.
list_T *ll_list; ///< The list or NULL.
int ll_range; ///< TRUE when a [i:j] range was used.
long ll_n1; ///< First index for list.
long ll_n2; ///< Second index for list range.
int ll_empty2; ///< Second index is empty: [i:].
dict_T *ll_dict; ///< The Dictionary or NULL.
dictitem_T *ll_di; ///< The dictitem or NULL.
char_u *ll_newkey; ///< New key for Dict in allocated memory or NULL.
} lval_T;
/// enum used by var_flavour() /// enum used by var_flavour()
typedef enum { typedef enum {
VAR_FLAVOUR_DEFAULT = 1, // doesn't start with uppercase VAR_FLAVOUR_DEFAULT = 1, // doesn't start with uppercase
@@ -142,6 +190,58 @@ extern const list_T *eval_msgpack_type_lists[LAST_MSGPACK_TYPE + 1];
typedef int (*ArgvFunc)(int current_argcount, typval_T *argv, typedef int (*ArgvFunc)(int current_argcount, typval_T *argv,
int called_func_argcount); int called_func_argcount);
/// trans_function_name() flags
typedef enum {
TFN_INT = 1, ///< May use internal function name
TFN_QUIET = 2, ///< Do not emit error messages.
TFN_NO_AUTOLOAD = 4, ///< Do not use script autoloading.
TFN_NO_DEREF = 8, ///< Do not dereference a Funcref.
TFN_READ_ONLY = 16, ///< Will not change the variable.
} TransFunctionNameFlags;
/// get_lval() flags
typedef enum {
GLV_QUIET = TFN_QUIET, ///< Do not emit error messages.
GLV_NO_AUTOLOAD = TFN_NO_AUTOLOAD, ///< Do not use script autoloading.
GLV_READ_ONLY = TFN_READ_ONLY, ///< Indicates that caller will not change
///< the value (prevents error message).
} GetLvalFlags;
/// flags for find_name_end()
#define FNE_INCL_BR 1 /* find_name_end(): include [] in name */
#define FNE_CHECK_START 2 /* find_name_end(): check name starts with
valid character */
typedef struct {
TimeWatcher tw;
int timer_id;
int repeat_count;
int refcount;
int emsg_count; ///< Errors in a repeating timer.
long timeout;
bool stopped;
bool paused;
Callback callback;
} timer_T;
/// Type of assert_* check being performed
typedef enum
{
ASSERT_EQUAL,
ASSERT_NOTEQUAL,
ASSERT_MATCH,
ASSERT_NOTMATCH,
ASSERT_INRANGE,
ASSERT_OTHER,
} assert_type_T;
/// Type for dict_list function
typedef enum {
kDictListKeys, ///< List dictionary keys.
kDictListValues, ///< List dictionary values.
kDictListItems, ///< List dictionary contents: [keys, values].
} DictListType;
#ifdef INCLUDE_GENERATED_DECLARATIONS #ifdef INCLUDE_GENERATED_DECLARATIONS
# include "eval.h.generated.h" # include "eval.h.generated.h"
#endif #endif

10920
src/nvim/eval/funcs.c Normal file

File diff suppressed because it is too large Load Diff

24
src/nvim/eval/funcs.h Normal file
View File

@@ -0,0 +1,24 @@
#ifndef NVIM_EVAL_FUNCS_H
#define NVIM_EVAL_FUNCS_H
#include "nvim/buffer_defs.h"
#include "nvim/eval/typval.h"
typedef void (*FunPtr)(void);
/// Prototype of C function that implements VimL function
typedef void (*VimLFunc)(typval_T *args, typval_T *rvar, FunPtr data);
/// Structure holding VimL function definition
typedef struct fst {
char *name; ///< Name of the function.
uint8_t min_argc; ///< Minimal number of arguments.
uint8_t max_argc; ///< Maximal number of arguments.
VimLFunc func; ///< Function implementation.
FunPtr data; ///< Userdata for function implementation.
} VimLFuncDef;
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "eval/funcs.h.generated.h"
#endif
#endif // NVIM_EVAL_FUNCS_H

View File

@@ -993,6 +993,14 @@ EXTERN char_u e_re_damg[] INIT(= N_("E43: Damaged match string"));
EXTERN char_u e_re_corr[] INIT(= N_("E44: Corrupted regexp program")); EXTERN char_u e_re_corr[] INIT(= N_("E44: Corrupted regexp program"));
EXTERN char_u e_readonly[] INIT(= N_( EXTERN char_u e_readonly[] INIT(= N_(
"E45: 'readonly' option is set (add ! to override)")); "E45: 'readonly' option is set (add ! to override)"));
EXTERN char_u e_readonlyvar[] INIT(= N_(
"E46: Cannot change read-only variable \"%.*s\""));
EXTERN char_u e_dictreq[] INIT(= N_("E715: Dictionary required"));
EXTERN char_u e_toomanyarg[] INIT(= N_("E118: Too many arguments for function: %s"));
EXTERN char_u e_dictkey[] INIT(= N_("E716: Key not present in Dictionary: %s"));
EXTERN char_u e_listreq[] INIT(= N_("E714: List required"));
EXTERN char_u e_listdictarg[] INIT(= N_(
"E712: Argument of %s must be a List or Dictionary"));
EXTERN char_u e_readerrf[] INIT(= N_("E47: Error while reading errorfile")); EXTERN char_u e_readerrf[] INIT(= N_("E47: Error while reading errorfile"));
EXTERN char_u e_sandbox[] INIT(= N_("E48: Not allowed in sandbox")); EXTERN char_u e_sandbox[] INIT(= N_("E48: Not allowed in sandbox"));
EXTERN char_u e_secure[] INIT(= N_("E523: Not allowed here")); EXTERN char_u e_secure[] INIT(= N_("E523: Not allowed here"));

View File

@@ -528,7 +528,7 @@ int nlua_debug(lua_State *lstate)
for (;;) { for (;;) {
lua_settop(lstate, 0); lua_settop(lstate, 0);
typval_T input; typval_T input;
get_user_input(input_args, &input, false); get_user_input(input_args, &input, false, false);
msg_putchar('\n'); // Avoid outputting on input line. msg_putchar('\n'); // Avoid outputting on input line.
if (input.v_type != VAR_STRING if (input.v_type != VAR_STRING
|| input.vval.v_string == NULL || input.vval.v_string == NULL