neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

userfunc.h (3444B)


      1 #pragma once
      2 
      3 #include <stdbool.h>
      4 #include <stddef.h>
      5 
      6 #include "nvim/cmdexpand_defs.h"  // IWYU pragma: keep
      7 #include "nvim/eval/typval_defs.h"
      8 #include "nvim/eval_defs.h"  // IWYU pragma: keep
      9 #include "nvim/ex_cmds_defs.h"  // IWYU pragma: keep
     10 #include "nvim/hashtab_defs.h"  // IWYU pragma: keep
     11 #include "nvim/pos_defs.h"
     12 #include "nvim/types_defs.h"  // IWYU pragma: keep
     13 
     14 // From user function to hashitem and back.
     15 #define UF2HIKEY(fp) ((fp)->uf_name)
     16 #define HIKEY2UF(p)  ((ufunc_T *)((p) - offsetof(ufunc_T, uf_name)))
     17 #define HI2UF(hi)    HIKEY2UF((hi)->hi_key)
     18 
     19 // flags used in uf_flags
     20 #define FC_ABORT    0x01          // abort function on error
     21 #define FC_RANGE    0x02          // function accepts range
     22 #define FC_DICT     0x04          // Dict function, uses "self"
     23 #define FC_CLOSURE  0x08          // closure, uses outer scope variables
     24 #define FC_DELETED  0x10          // :delfunction used while uf_refcount > 0
     25 #define FC_REMOVED  0x20          // function redefined while uf_refcount > 0
     26 #define FC_SANDBOX  0x40          // function defined in the sandbox
     27 // #define FC_DEAD     0x80          // function kept only for reference to dfunc
     28 // #define FC_EXPORT   0x100         // "export def Func()"
     29 #define FC_NOARGS   0x200         // no a: variables in lambda
     30 // #define FC_VIM9     0x400         // defined in vim9 script file
     31 #define FC_LUAREF  0x800          // luaref callback
     32 
     33 /// Structure used by trans_function_name()
     34 typedef struct {
     35  dict_T *fd_dict;    ///< Dict used.
     36  char *fd_newkey;    ///< New key in "dict" in allocated memory.
     37  dictitem_T *fd_di;  ///< Dict item used.
     38 } funcdict_T;
     39 
     40 typedef struct funccal_entry funccal_entry_T;
     41 struct funccal_entry {
     42  void *top_funccal;
     43  funccal_entry_T *next;
     44 };
     45 
     46 /// errors for when calling a function
     47 typedef enum {
     48  FCERR_UNKNOWN = 0,
     49  FCERR_TOOMANY = 1,
     50  FCERR_TOOFEW = 2,
     51  FCERR_SCRIPT = 3,
     52  FCERR_DICT = 4,
     53  FCERR_NONE = 5,
     54  FCERR_OTHER = 6,
     55  FCERR_DELETED = 7,
     56  FCERR_NOTMETHOD = 8,  ///< function cannot be used as a method
     57 } FnameTransError;
     58 
     59 /// Used in funcexe_T. Returns the new argcount.
     60 typedef int (*ArgvFunc)(int current_argcount, typval_T *argv, int partial_argcount,
     61                        ufunc_T *called_func);
     62 
     63 /// Structure passed between functions dealing with function call execution.
     64 typedef struct {
     65  ArgvFunc fe_argv_func;  ///< when not NULL, can be used to fill in arguments only
     66                          ///< when the invoked function uses them
     67  linenr_T fe_firstline;  ///< first line of range
     68  linenr_T fe_lastline;   ///< last line of range
     69  bool *fe_doesrange;     ///< [out] if not NULL: function handled range
     70  bool fe_evaluate;       ///< actually evaluate expressions
     71  partial_T *fe_partial;  ///< for extra arguments
     72  dict_T *fe_selfdict;    ///< Dict for "self"
     73  typval_T *fe_basetv;    ///< base for base->method()
     74  bool fe_found_var;      ///< if the function is not found then give an
     75                          ///< error that a variable is not callable.
     76 } funcexe_T;
     77 
     78 #define FUNCEXE_INIT (funcexe_T) { \
     79  .fe_argv_func = NULL, \
     80  .fe_firstline = 0, \
     81  .fe_lastline = 0, \
     82  .fe_doesrange = NULL, \
     83  .fe_evaluate = false, \
     84  .fe_partial = NULL, \
     85  .fe_selfdict = NULL, \
     86  .fe_basetv = NULL, \
     87  .fe_found_var = false, \
     88 }
     89 
     90 #define FUNCARG(fp, j)  ((char **)(fp->uf_args.ga_data))[j]
     91 #define FUNCLINE(fp, j) ((char **)(fp->uf_lines.ga_data))[j]
     92 
     93 #include "eval/userfunc.h.generated.h"