Macros | Functions | Variables
userfunc.c File Reference
#include "nvim/ascii.h"
#include "nvim/charset.h"
#include "nvim/debugger.h"
#include "nvim/edit.h"
#include "nvim/eval.h"
#include "nvim/eval/encode.h"
#include "nvim/eval/userfunc.h"
#include "nvim/ex_cmds2.h"
#include "nvim/ex_docmd.h"
#include "nvim/ex_getln.h"
#include "nvim/fileio.h"
#include "nvim/getchar.h"
#include "nvim/globals.h"
#include "nvim/lua/executor.h"
#include "nvim/misc1.h"
#include "nvim/os/input.h"
#include "nvim/regexp.h"
#include "nvim/search.h"
#include "nvim/ui.h"
#include "nvim/vim.h"

Macros

#define FC_ABORT   0x01
 
#define FC_RANGE   0x02
 
#define FC_DICT   0x04
 
#define FC_CLOSURE   0x08
 
#define FC_DELETED   0x10
 
#define FC_REMOVED   0x20
 
#define FC_SANDBOX   0x40
 
#define FC_DEAD   0x80
 
#define FC_EXPORT   0x100
 
#define FC_NOARGS   0x200
 
#define FC_VIM9   0x400
 
#define FC_CFUNC   0x800
 
#define FLEN_FIXED   40
 

Functions

void func_init (void)
 
char_uget_lambda_name (void)
 Get a name for a lambda. Returned in static memory. More...
 
int get_lambda_tv (char_u **arg, typval_T *rettv, bool evaluate)
 
char_uderef_func_name (const char *name, int *lenp, partial_T **const partialp, bool no_autoload) FUNC_ATTR_NONNULL_ARG(1
 
char_u if (v !=NULL &&v->di_tv.v_type==VAR_FUNC)
 
 return (char_u *)
 
int get_func_tv (const char_u *name, int len, typval_T *rettv, char_u **arg, funcexe_T *funcexe)
 
ufunc_Tfind_func (const char_u *name)
 
void call_user_func (ufunc_T *fp, int argcount, typval_T *argvars, typval_T *rettv, linenr_T firstline, linenr_T lastline, dict_T *selfdict) FUNC_ATTR_NONNULL_ARG(1
 
 if (depth >=p_mfd)
 
 save_search_patterns ()
 
 if (!ins_compl_active())
 
 line_breakcheck ()
 
ga_initfc (ufunc_T *), 1
 
 func_ptr_ref (fp)
 
 if (STRNCMP(fp->uf_name, "<lambda>", 8)==0)
 
 if (selfdict !=NULL)
 
 if ((fp->uf_flags &FC_NOARGS)==0)
 
 for (int i=0;i< argcount||i< fp->uf_args.ga_len;i++)
 
 if (fp->uf_flags &FC_SANDBOX)
 
 if (p_verbose >=12)
 
 if (func_not_yet_profiling_but_should)
 
 if (func_or_func_caller_profiling)
 
 if (do_profiling_yes)
 
 if (default_arg_err &&(fp->uf_flags &FC_ABORT))
 
else if (islambda)
 
 if ((did_emsg &&(fp->uf_flags &FC_ABORT))||rettv->v_type==VAR_UNKNOWN)
 
 xfree (sourcing_name)
 
 if (using_sandbox)
 
 if (p_verbose >=12 &&sourcing_name !=NULL)
 
 cleanup_function_call (fc)
 
 if (--fp->uf_calls<=0 &&fp->uf_refcount<=0)
 
 if (did_save_redo)
 
 restore_search_patterns ()
 
void save_funccal (funccal_entry_T *entry)
 
void restore_funccal (void)
 
funccall_Tget_current_funccal (void)
 
void set_current_funccal (funccall_T *fc)
 
int func_call (char_u *name, typval_T *args, partial_T *partial, dict_T *selfdict, typval_T *rettv)
 

Variables

hashtab_T func_hashtab
 
void linenr_T save_sourcing_lnum
 
bool using_sandbox = false
 
funccall_Tfc = xcalloc(1, sizeof(funccall_T))
 
int save_did_emsg = did_emsg
 
dictitem_Tv
 
int fixvar_idx = 0
 
int ai
 
bool islambda = false
 
char_u numbuf [NUMBUFLEN]
 
char_uname = NULL
 
typval_Ttv_to_free [MAX_FUNC_ARGS]
 
int tv_to_free_len = 0
 
proftime_T wait_start
 
proftime_T call_start
 
int started_profiling = false
 
bool did_save_redo = false
 
save_redo_T save_redo
 
fp uf_calls
 
fc caller = current_funccal
 
fc func = fp
 
fc rettv = rettv
 
fc level = ex_nesting_level
 
fc breakpoint = dbg_find_breakpoint(false, fp->uf_name, (linenr_T)0)
 
fc dbg_tick = debug_tick
 
fc l_avars dv_lock = VAR_FIXED
 
bool default_arg_err = false
 
 RedrawingDisabled
 
 save_sourcing_name = sourcing_name
 
 sourcing_lnum = 1
 
size_t len
 
 sourcing_name = xmalloc(len)
 
const bool do_profiling_yes = do_profiling == PROF_YES
 
bool func_not_yet_profiling_but_should
 
bool func_or_func_caller_profiling
 
const sctx_T save_current_sctx = current_sctx
 
 current_sctx = fp->uf_script_ctx
 
 did_emsg = FALSE
 
 else
 

Macro Definition Documentation

◆ FC_ABORT

#define FC_ABORT   0x01

◆ FC_CFUNC

#define FC_CFUNC   0x800

◆ FC_CLOSURE

#define FC_CLOSURE   0x08

◆ FC_DEAD

#define FC_DEAD   0x80

◆ FC_DELETED

#define FC_DELETED   0x10

◆ FC_DICT

#define FC_DICT   0x04

◆ FC_EXPORT

#define FC_EXPORT   0x100

◆ FC_NOARGS

#define FC_NOARGS   0x200

◆ FC_RANGE

#define FC_RANGE   0x02

◆ FC_REMOVED

#define FC_REMOVED   0x20

◆ FC_SANDBOX

#define FC_SANDBOX   0x40

◆ FC_VIM9

#define FC_VIM9   0x400

◆ FLEN_FIXED

#define FLEN_FIXED   40

Function Documentation

◆ call_user_func()

void call_user_func ( ufunc_T fp,
int  argcount,
typval_T argvars,
typval_T rettv,
linenr_T  firstline,
linenr_T  lastline,
dict_T selfdict 
)

Call a user function

Parameters
fpFunction to call.
[in]argcountNumber of arguments.
argvarsArguments.
[out]rettvReturn value.
[in]firstlineFirst line of range.
[in]lastlineLast line of range.
selfdictDictionary for "self" for dictionary functions.

◆ cleanup_function_call()

cleanup_function_call ( fc  )

◆ deref_func_name()

char_u* deref_func_name ( const char *  name,
int *  lenp,
partial_T **const  partialp,
bool  no_autoload 
)

Return name of the function corresponding to name

If name points to variable that is either a function or partial then corresponding function name is returned. Otherwise it returns name itself.

Parameters
[in]nameFunction name to check.
[in,out]lenpLocation where length of the returned name is stored. Must be set to the length of the name argument.
[out]partialpLocation where partial will be stored if found function appears to be a partial. May be NULL if this is not needed.
[in]no_autoloadIf true, do not source autoload scripts if function was not found.
Returns
name of the function.

◆ fc()

ga_init& fc ( ufunc_T )

◆ find_func()

ufunc_T* find_func ( const char_u name)

Find a function by name, return pointer to it in ufuncs.

Returns
NULL for unknown function.

◆ for()

for ( )

◆ func_call()

int func_call ( char_u name,
typval_T args,
partial_T partial,
dict_T selfdict,
typval_T rettv 
)

◆ func_init()

void func_init ( void  )

◆ func_ptr_ref()

func_ptr_ref ( fp  )

◆ get_current_funccal()

funccall_T* get_current_funccal ( void  )

◆ get_func_tv()

int get_func_tv ( const char_u name,
int  len,
typval_T rettv,
char_u **  arg,
funcexe_T funcexe 
)

Allocate a variable for the result of a function.

Parameters
namename of the function
lenlength of "name" or -1 to use strlen()
argargument, pointing to the '('
funcexevarious values
Returns
OK or FAIL.

◆ get_lambda_name()

char_u* get_lambda_name ( void  )

Get a name for a lambda. Returned in static memory.

◆ get_lambda_tv()

int get_lambda_tv ( char_u **  arg,
typval_T rettv,
bool  evaluate 
)

Parse a lambda expression and get a Funcref from "*arg".

Returns
OK or FAIL. Returns NOTDONE for dict or {expr}.

◆ if() [1/18]

if ( ins_compl_active())

◆ if() [2/18]

if ( (did_emsg &&(fp->uf_flags &FC_ABORT))||rettv->  v_type = VAR_UNKNOWN)

◆ if() [3/18]

if ( (fp->uf_flags &FC_NOARGS = = 0)

◆ if() [4/18]

if ( --fp->uf_calls<=0 &&fp->uf_refcount<=  0)

◆ if() [5/18]

if ( default_arg_err &&  fp->uf_flags &FC_ABORT)

◆ if() [6/18]

if ( depth >=  p_mfd)

◆ if() [7/18]

if ( did_save_redo  )

◆ if() [8/18]

if ( do_profiling_yes  )

◆ if() [9/18]

if ( fp->uf_flags &  FC_SANDBOX)

◆ if() [10/18]

◆ if() [11/18]

◆ if() [12/18]

else if ( islambda  )

◆ if() [13/18]

if ( p_verbose >=12 &&sourcing_name = NULL)

◆ if() [14/18]

if ( p_verbose >=  12)

◆ if() [15/18]

if ( selfdict = NULL)

◆ if() [16/18]

if ( STRNCMP(fp->uf_name, "<lambda>", 8)  = = 0)

◆ if() [17/18]

if ( using_sandbox  )

◆ if() [18/18]

if ( v = NULL && v->di_tv.v_type == VAR_FUNC)

◆ line_breakcheck()

line_breakcheck ( )

◆ restore_funccal()

void restore_funccal ( void  )

◆ restore_search_patterns()

restore_search_patterns ( )

◆ return()

return ( char_u )

◆ save_funccal()

void save_funccal ( funccal_entry_T entry)

◆ save_search_patterns()

save_search_patterns ( )

◆ set_current_funccal()

void set_current_funccal ( funccall_T fc)

◆ xfree()

xfree ( sourcing_name  )

Variable Documentation

◆ ai

int ai

◆ breakpoint

fc breakpoint = dbg_find_breakpoint(false, fp->uf_name, (linenr_T)0)

◆ call_start

proftime_T call_start

◆ caller

fc caller = current_funccal

◆ current_sctx

current_sctx = fp->uf_script_ctx

◆ dbg_tick

fc dbg_tick = debug_tick

◆ default_arg_err

bool default_arg_err = false

◆ did_emsg

did_emsg = FALSE

◆ did_save_redo

bool did_save_redo = false

◆ do_profiling_yes

const bool do_profiling_yes = do_profiling == PROF_YES

◆ dv_lock

fc l_avars dv_lock = VAR_FIXED

◆ else

else
Initial value:

◆ fc

tv_list_set_lock & fc = xcalloc(1, sizeof(funccall_T))

◆ fixvar_idx

int fixvar_idx = 0

◆ func

fc func = fp

◆ func_hashtab

hashtab_T func_hashtab

◆ func_not_yet_profiling_but_should

bool func_not_yet_profiling_but_should
Initial value:
=
&& !fp->uf_profiling && has_profiling(false, fp->uf_name, NULL)

◆ func_or_func_caller_profiling

bool func_or_func_caller_profiling
Initial value:
=
&& (fp->uf_profiling

◆ islambda

bool islambda = false

◆ len

size_t len
Initial value:
+ STRLEN(fp->uf_name) + 27

◆ level

fc level = ex_nesting_level

◆ name

* name = NULL

◆ numbuf

char_u numbuf[NUMBUFLEN]

◆ RedrawingDisabled

RedrawingDisabled

◆ rettv

fc rettv = rettv

◆ save_current_sctx

const sctx_T save_current_sctx = current_sctx

◆ save_did_emsg

save_did_emsg = did_emsg

◆ save_redo

save_redo_T save_redo

◆ save_sourcing_lnum

save_sourcing_lnum
Initial value:

◆ save_sourcing_name

save_sourcing_name = sourcing_name

◆ sourcing_lnum

sourcing_lnum = 1

◆ sourcing_name

sourcing_name = xmalloc(len)

◆ started_profiling

int started_profiling = false

◆ tv_to_free

typval_T* tv_to_free[MAX_FUNC_ARGS]

◆ tv_to_free_len

int tv_to_free_len = 0

◆ uf_calls

fp uf_calls

◆ using_sandbox

bool using_sandbox = false

◆ v

◆ wait_start

proftime_T wait_start
DOCMD_REPEAT
#define DOCMD_REPEAT
Definition: ex_docmd.h:10
fp
FILE * fp
Definition: edit.c:3000
save_sourcing_name
save_sourcing_name
Definition: userfunc.c:1001
DOCMD_NOWAIT
#define DOCMD_NOWAIT
Definition: ex_docmd.h:9
funccall_S::caller
funccall_T * caller
Definition: typval.h:315
funccall_S::func
ufunc_T * func
Function being called.
Definition: typval.h:299
do_profiling_yes
const bool do_profiling_yes
Definition: userfunc.c:1071
char_u
unsigned char char_u
Definition: types.h:12
STRLEN
#define STRLEN(s)
Definition: vim.h:215
DOCMD_VERBOSE
#define DOCMD_VERBOSE
Definition: ex_docmd.h:8
has_profiling
bool has_profiling(bool file, char_u *fname, bool *fp)
Definition: debugger.c:735
ufunc::uf_profiling
int uf_profiling
true when func is being profiled
Definition: typval.h:331
fc
funccall_T * fc
Definition: userfunc.c:813
do_cmdline
int do_cmdline(char_u *cmdline, LineGetter fgetline, void *cookie, int flags)
Definition: ex_docmd.c:312
NULL
return NULL
Definition: eval.c:10355